label: replace giant if/else block in draw, just change the draw handler function when MwSetSevenSegment is called
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
All checks were successful
pyrite-dev/milsko/pipeline/head This commit looks good
This commit is contained in:
parent
206dd9a0a6
commit
b258f1e05d
1 changed files with 201 additions and 176 deletions
|
|
@ -122,9 +122,8 @@ static void draw_h(MwWidget handle, unsigned char* raw, int x, int y, int stride
|
|||
}
|
||||
}
|
||||
|
||||
static void draw(MwWidget handle) {
|
||||
static void draw_seven_segment(MwWidget handle) {
|
||||
MwRect r;
|
||||
MwPoint p;
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||
MwLLColor shadow = MwLightenColor(handle, base, MwDefaultShadow, MwDefaultShadow, MwDefaultShadow);
|
||||
|
|
@ -134,6 +133,10 @@ static void draw(MwWidget handle) {
|
|||
MwLabel lab = handle->internal;
|
||||
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
|
||||
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
|
||||
MwLLPixmap px;
|
||||
unsigned char* raw;
|
||||
int w = 0, h = s_one * 3 + l_one * 2, i;
|
||||
int x = 0;
|
||||
|
||||
if(str == NULL) str = "";
|
||||
|
||||
|
|
@ -146,11 +149,6 @@ static void draw(MwWidget handle) {
|
|||
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
|
||||
|
||||
align = MwGetInteger(handle, MwNalignment);
|
||||
if(MwGetInteger(handle, MwNsevenSegment)) {
|
||||
MwLLPixmap px;
|
||||
unsigned char* raw;
|
||||
int w = 0, h = s_one * 3 + l_one * 2, i;
|
||||
int x = 0;
|
||||
|
||||
/* so - this mode cannot do unicode.
|
||||
* but you wouldn't show unicode on 7 segment anyways
|
||||
|
|
@ -312,7 +310,33 @@ static void draw(MwWidget handle) {
|
|||
free(raw);
|
||||
|
||||
MwLLDestroyPixmap(px);
|
||||
} else {
|
||||
}
|
||||
|
||||
static void draw_normal(MwWidget handle) {
|
||||
MwRect r;
|
||||
MwPoint p;
|
||||
MwLLColor base = MwParseColor(handle, MwGetText(handle, MwNbackground));
|
||||
MwLLColor text = MwParseColor(handle, MwGetText(handle, MwNforeground));
|
||||
MwLLColor shadow = MwLightenColor(handle, base, MwDefaultShadow, MwDefaultShadow, MwDefaultShadow);
|
||||
int align;
|
||||
const char* str = MwGetText(handle, MwNtext);
|
||||
MwLLPixmap bgpx = MwGetVoid(handle, MwNbackgroundPixmap);
|
||||
MwLabel lab = handle->internal;
|
||||
int l_one = MwGetInteger(handle, MwNlength) - (MwGetInteger(handle, MwNlength) % 2);
|
||||
int s_one = (l_one * 3 / 4) - ((l_one * 3 / 4) % 2) + 1;
|
||||
|
||||
if(str == NULL) str = "";
|
||||
|
||||
r.x = 0;
|
||||
r.y = 0;
|
||||
r.width = MwGetInteger(handle, MwNwidth);
|
||||
r.height = MwGetInteger(handle, MwNheight);
|
||||
|
||||
MwDrawRect(handle, &r, base);
|
||||
if(bgpx != NULL) MwLLDrawPixmap(handle->lowlevel, &r, bgpx);
|
||||
|
||||
align = MwGetInteger(handle, MwNalignment);
|
||||
|
||||
r.width -= MwGetInteger(handle, MwNleftPadding);
|
||||
|
||||
if(align == MwALIGNMENT_CENTER) {
|
||||
|
|
@ -333,7 +357,6 @@ static void draw(MwWidget handle) {
|
|||
p.x -= 1;
|
||||
p.y -= 1;
|
||||
MwDrawText(handle, NULL, &p, str, MwALIGNMENT_CENTER, text);
|
||||
}
|
||||
|
||||
MwLLFreeColor(shadow);
|
||||
MwLLFreeColor(text);
|
||||
|
|
@ -348,6 +371,8 @@ static void mwLabelSetSevenSegmentImpl(MwWidget handle, int index, unsigned char
|
|||
MwLabel lab = handle->internal;
|
||||
|
||||
hmput(lab->segment, index, data);
|
||||
|
||||
handle->widget_class->draw = draw_seven_segment;
|
||||
}
|
||||
|
||||
static void func_handler(MwWidget handle, const char* name, void* out, va_list va) {
|
||||
|
|
@ -364,7 +389,7 @@ static void func_handler(MwWidget handle, const char* name, void* out, va_list v
|
|||
MwClassRec MwLabelClassRec = {
|
||||
wcreate, /* create */
|
||||
destroy, /* destroy */
|
||||
draw, /* draw */
|
||||
draw_normal, /* draw */
|
||||
NULL, /* click */
|
||||
NULL, /* parent_resize */
|
||||
prop_change, /* prop_change */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue