add disabled widgets
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
Some checks failed
pyrite-dev/milsko/pipeline/head There was a failure building this commit
This commit is contained in:
parent
9e165b71d4
commit
149f99622a
7 changed files with 91 additions and 20 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#include <Mw/Milsko.h>
|
||||
|
||||
MwWidget window, menu, button, button2, button3, button4, button5, button6;
|
||||
MwWidget window, menu, button, button2, button3, button4, button5, button6, button7;
|
||||
|
||||
void MWAPI handler(MwWidget handle, void* user_data, void* call_data) {
|
||||
(void)handle;
|
||||
|
|
@ -51,24 +51,29 @@ void MWAPI resize(MwWidget handle, void* user_data, void* call_data) {
|
|||
|
||||
MwVaApply(button,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button2,
|
||||
MwNx, 50 + (w - 50 * 2) / 3,
|
||||
MwNx, 50 + (w - 50 * 2) / 4,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button3,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 2,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 2,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 3,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
MwVaApply(button7,
|
||||
MwNx, 50 + (w - 50 * 2) / 4 * 3,
|
||||
MwNy, 50 + mh,
|
||||
MwNwidth, (w - 50 * 2) / 4,
|
||||
MwNheight, h - 125 - 50 * 3,
|
||||
NULL);
|
||||
|
||||
MwVaApply(button4,
|
||||
MwNx, 50 + (w - 50 * 2) / 3 * 0,
|
||||
MwNy, h - 50 - 125 + mh,
|
||||
|
|
@ -121,6 +126,10 @@ int main() {
|
|||
MwNbackground, "#66f",
|
||||
MwNforeground, "#000",
|
||||
NULL);
|
||||
button7 = MwVaCreateWidget(MwButtonClass, "button", window, 250, 50, 100, 125,
|
||||
MwNtext, "disabled",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwAddUserHandler(window, MwNresizeHandler, resize, NULL);
|
||||
MwAddUserHandler(button, MwNactivateHandler, handler_theme, NULL);
|
||||
|
|
|
|||
|
|
@ -202,9 +202,16 @@ int main() {
|
|||
MwNcolumns, 5,
|
||||
NULL);
|
||||
|
||||
f = frame("Button", -PaddingContent, -PaddingContent, MwButtonClass,
|
||||
MwNtext, "Press me",
|
||||
f = frame("Button", -PaddingContent, -PaddingContent, MwBoxClass,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Press me",
|
||||
NULL);
|
||||
b = MwVaCreateWidget(MwButtonClass, "btn_disabled", child(f), 0, 0, 0, 0,
|
||||
MwNtext, "Cannot press me",
|
||||
MwNdisabled, 1,
|
||||
NULL);
|
||||
|
||||
MwVaCreateWidget(MwLabelClass, "label", table, 0, 0, 0, 0,
|
||||
MwNbold, 1,
|
||||
|
|
@ -221,11 +228,11 @@ int main() {
|
|||
MwNorientation, MwVERTICAL,
|
||||
MwNfixedSize, 16,
|
||||
NULL);
|
||||
for(j = 0; j < 5; j++) MwCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0);
|
||||
for(j = 0; j < 6; j++) MwVaCreateWidget(i == 0 ? MwCheckBoxClass : MwRadioBoxClass, i == 0 ? "cb" : "rb", b, 0, 0, 0, 0, MwNdisabled, (j == 5) ? 1 : 0, NULL);
|
||||
b = MwVaCreateWidget(MwBoxClass, "table1", w, 0, 0, 0, 0,
|
||||
MwNorientation, MwVERTICAL,
|
||||
NULL);
|
||||
for(j = 0; j < 5; j++) {
|
||||
for(j = 0; j < 6; j++) {
|
||||
char buf[32];
|
||||
sprintf(buf, "%sBox %d", i == 0 ? "Check" : "Radio", j + 1);
|
||||
MwVaCreateWidget(MwLabelClass, "label", b, 0, 0, 0, 0,
|
||||
|
|
|
|||
|
|
@ -52,6 +52,7 @@
|
|||
#define MwNcolumns "Icolumns"
|
||||
#define MwNcolumnSpan "IcolumnSpan"
|
||||
#define MwNrowSpan "IrowSpan"
|
||||
#define MwNdisabled "Idisabled"
|
||||
|
||||
#define MwNtitle "Stitle"
|
||||
#define MwNtext "Stext"
|
||||
|
|
|
|||
|
|
@ -1652,8 +1652,11 @@ static void MwLLEndStateChangeImpl(MwLL handle) {
|
|||
}
|
||||
|
||||
static void MwLLSetDarkThemeImpl(MwLL handle, int toggle) {
|
||||
(void)handle;
|
||||
(void)toggle;
|
||||
|
||||
/* Not Really what's supposed to happen with this function, but take this opprutunity to do the handlers that will force everything to redraw. */
|
||||
MwLLDispatch(handle, resize, NULL);
|
||||
MwLLDispatch(handle, draw, NULL);
|
||||
}
|
||||
|
||||
static MwBool MwLLDoModernImpl(MwLL handle) {
|
||||
|
|
|
|||
|
|
@ -57,6 +57,7 @@ static void lldrawhandler(MwLL handle, void* data) {
|
|||
static void lluphandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
MwMouse* p = data;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
if(p->button == MwMOUSE_LEFT) h->pressed = 0;
|
||||
h->mouse_point.x = p->point.x;
|
||||
|
|
@ -70,6 +71,7 @@ static void lluphandler(MwLL handle, void* data) {
|
|||
static void lldownhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
MwMouse* p = data;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
if(p->button == MwMOUSE_LEFT) h->pressed = 1;
|
||||
h->mouse_point.x = p->point.x;
|
||||
|
|
@ -124,6 +126,7 @@ static void llmovehandler(MwLL handle, void* data) {
|
|||
static void llkeyhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
int key = *(int*)data;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
MwDispatch3(h, key, key);
|
||||
MwDispatchUserHandler(h, MwNkeyHandler, data);
|
||||
|
|
@ -131,24 +134,28 @@ static void llkeyhandler(MwLL handle, void* data) {
|
|||
|
||||
static void llkeyrelhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
MwDispatchUserHandler(h, MwNkeyReleaseHandler, data);
|
||||
}
|
||||
|
||||
static void llfocusinhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
MwDispatchUserHandler(h, MwNfocusInHandler, data);
|
||||
}
|
||||
|
||||
static void llfocusouthandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
MwDispatchUserHandler(h, MwNfocusOutHandler, data);
|
||||
}
|
||||
|
||||
static void llclipboardhandler(MwLL handle, void* data) {
|
||||
MwWidget h = (MwWidget)handle->common.user;
|
||||
if(MwGetInteger(h, MwNdisabled) == 1) return;
|
||||
|
||||
MwDispatch3(h, clipboard, data);
|
||||
MwDispatchUserHandler(h, MwNclipboardHandler, data);
|
||||
|
|
@ -691,6 +698,7 @@ int MwGetInteger(MwWidget handle, const char* key) {
|
|||
#endif
|
||||
if(strcmp(key, MwNdarkTheme) == 0) return inherit_integer(handle, key, 0);
|
||||
if(strcmp(key, MwNuseMonospace) == 0) return inherit_integer(handle, key, 0);
|
||||
if(strcmp(key, MwNdisabled) == 0) return inherit_integer(handle, key, 0);
|
||||
}
|
||||
return shget(handle->integer, key);
|
||||
}
|
||||
|
|
|
|||
31
src/draw.c
31
src/draw.c
|
|
@ -38,6 +38,18 @@ static int hex(const char* txt, int len) {
|
|||
return r;
|
||||
}
|
||||
|
||||
static void color_set_disabled_if_disabled(MwWidget handle, MwLLColor rgb) {
|
||||
if(MwGetInteger(handle, MwNdisabled) == 1) {
|
||||
MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground));
|
||||
|
||||
if(c != NULL) {
|
||||
rgb->common.red = rgb->common.red + (c->common.red - rgb->common.red) * 0.5;
|
||||
rgb->common.green = rgb->common.green + (c->common.green - rgb->common.green) * 0.5;
|
||||
rgb->common.blue = rgb->common.blue + (c->common.blue - rgb->common.blue) * 0.5;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
void MwParseColorNoAllocate(const char* text, MwRGB* rgb) {
|
||||
if(text[0] == '#' && strlen(text) == 4) {
|
||||
rgb->red = hex(text + 1, 1);
|
||||
|
|
@ -125,6 +137,7 @@ void MwDrawRectFading(MwWidget handle, MwRect* rect, MwLLColor color) {
|
|||
for(y = 0; y < rect->height; y++) {
|
||||
MwLLColor col = MwLightenColor(handle, color, -darken, -darken, -darken);
|
||||
int idx = y * 4;
|
||||
color_set_disabled_if_disabled(handle, col);
|
||||
data[idx] = col->common.red;
|
||||
data[idx + 1] = col->common.green;
|
||||
data[idx + 2] = col->common.blue;
|
||||
|
|
@ -204,6 +217,8 @@ void MwDrawWidgetBack(MwWidget handle, MwRect* rect, MwLLColor color, int invert
|
|||
if(rect->width <= 0 || rect->height <= 0) return;
|
||||
|
||||
col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
|
||||
color_set_disabled_if_disabled(handle, col);
|
||||
|
||||
if(MwGetInteger(handle, MwNmodernLook)) {
|
||||
MwDrawRectFading(handle, rect, col);
|
||||
} else {
|
||||
|
|
@ -219,6 +234,9 @@ void MwDrawDiamond(MwWidget handle, MwRect* rect, MwLLColor color, int invert) {
|
|||
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
|
||||
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
|
||||
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
|
||||
color_set_disabled_if_disabled(handle, col);
|
||||
color_set_disabled_if_disabled(handle, darker);
|
||||
color_set_disabled_if_disabled(handle, lighter);
|
||||
|
||||
p[0].x = rect->x;
|
||||
p[0].y = rect->y + rect->height / 2;
|
||||
|
|
@ -284,8 +302,11 @@ static void MwDrawFrameEx_simple(MwWidget handle, MwRect* rect, MwLLColor color,
|
|||
int ColorDiff = get_color_diff(handle);
|
||||
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff, -ColorDiff * 3 / 2 + diff);
|
||||
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, ColorDiff - diff, ColorDiff - diff, ColorDiff - diff);
|
||||
p[0].x = rect->x;
|
||||
p[0].y = rect->y;
|
||||
color_set_disabled_if_disabled(handle, darker);
|
||||
color_set_disabled_if_disabled(handle, lighter);
|
||||
|
||||
p[0].x = rect->x;
|
||||
p[0].y = rect->y;
|
||||
|
||||
p[1].x = rect->x + rect->width;
|
||||
p[1].y = rect->y;
|
||||
|
|
@ -380,6 +401,9 @@ static void MwDrawFrameEx_complex(MwWidget handle, MwRect* rect, MwLLColor color
|
|||
MwLLColor lighter = same ? MwLightenColor(handle, darker, 0, 0, 0) : MwLightenColor(handle, color, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff, (ColorDiff / 2) - diff);
|
||||
MwRect r = *rect;
|
||||
|
||||
color_set_disabled_if_disabled(handle, darker);
|
||||
color_set_disabled_if_disabled(handle, lighter);
|
||||
|
||||
frame_border_complex(handle, rect, lighter, darker, invert, border == 1 ? 1 : (border / 2), diff, same);
|
||||
|
||||
if(border > 1) {
|
||||
|
|
@ -416,6 +440,9 @@ void MwDrawTriangle(MwWidget handle, MwRect* rect, MwLLColor color, int invert,
|
|||
MwLLColor darker = MwLightenColor(handle, color, -ColorDiff, -ColorDiff, -ColorDiff);
|
||||
MwLLColor lighter = MwLightenColor(handle, color, ColorDiff, ColorDiff, ColorDiff);
|
||||
MwLLColor col = invert ? MwLightenColor(handle, color, -8, -8, -8) : color;
|
||||
color_set_disabled_if_disabled(handle, col);
|
||||
color_set_disabled_if_disabled(handle, darker);
|
||||
color_set_disabled_if_disabled(handle, lighter);
|
||||
|
||||
double deg = 30 * ((direction == MwEAST || direction == MwWEST) ? 2 : 1);
|
||||
double c = cos(deg / 180 * M_PI);
|
||||
|
|
|
|||
|
|
@ -76,10 +76,22 @@ static MwFLFont assume_ttf(MwWidget handle, MwFLFont ttf) {
|
|||
#endif
|
||||
|
||||
void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text, int align, MwLLColor color) {
|
||||
MwPoint p = *point;
|
||||
char* input = (char*)text;
|
||||
char* last = input;
|
||||
int cp;
|
||||
MwPoint p = *point;
|
||||
char* input = (char*)text;
|
||||
char* last = input;
|
||||
int cp;
|
||||
MwLLColor fadedColor = NULL;
|
||||
|
||||
if(MwGetInteger(handle, MwNdisabled) == 1) {
|
||||
MwLLColor c = handle->parent == NULL ? NULL : MwParseColor(handle->parent, MwGetText(handle->parent, MwNbackground));
|
||||
|
||||
if(c != NULL) {
|
||||
fadedColor = MwLLAllocColor(handle->lowlevel, color->common.red, color->common.blue, color->common.green);
|
||||
fadedColor->common.red = fadedColor->common.red + (c->common.red - fadedColor->common.red) * 0.5;
|
||||
fadedColor->common.green = fadedColor->common.green + (c->common.green - fadedColor->common.green) * 0.5;
|
||||
fadedColor->common.blue = fadedColor->common.blue + (c->common.blue - fadedColor->common.blue) * 0.5;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef TTF
|
||||
if(ttf <= MwFLBuildFont(0xff) && !is_bitmap(handle, ttf)) ttf = assume_ttf(handle, ttf);
|
||||
|
|
@ -122,9 +134,9 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
|
|||
|
||||
#ifdef TTF
|
||||
if(MwFLDrawText)
|
||||
if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, color))
|
||||
if(is_bitmap(handle, ttf) || ttf == NULL || MwFLDrawText(handle, ttf, &p, line, fadedColor ? fadedColor : color))
|
||||
#endif
|
||||
bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), color);
|
||||
bitmap_MwDrawText(handle, &p, line, is_bold(handle, ttf), fadedColor ? fadedColor : color);
|
||||
|
||||
p.y += MwTextHeight(handle, ttf, line);
|
||||
|
||||
|
|
@ -133,6 +145,10 @@ void MwDrawText(MwWidget handle, MwFLFont ttf, MwPoint* point, const char* text,
|
|||
last = input;
|
||||
}
|
||||
}
|
||||
|
||||
if(fadedColor) {
|
||||
MwLLFreeColor(fadedColor);
|
||||
}
|
||||
}
|
||||
|
||||
int MwTextWidth(MwWidget handle, MwFLFont ttf, const char* text) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue