diff --git a/gb.gtk/src/CDraw.cpp b/gb.gtk/src/CDraw.cpp index a6c3d4655..faba4bb62 100644 --- a/gb.gtk/src/CDraw.cpp +++ b/gb.gtk/src/CDraw.cpp @@ -316,6 +316,18 @@ static void set_clipping_enabled(GB_DRAW *d, int enable) DR(d)->setClipEnabled(enable); } +static GtkStateType get_state(int state) +{ + if (state & GB_DRAW_STATE_DISABLED) + return GTK_STATE_INSENSITIVE; + if (state & GB_DRAW_STATE_ACTIVE) + return GTK_STATE_ACTIVE; + if (state & GB_DRAW_STATE_HOVER) + return GTK_STATE_PRELIGHT; + + return GTK_STATE_NORMAL; +} + static void style_arrow(GB_DRAW *d, int x, int y, int w, int h, int type, int state) { GtkArrowType arrow; @@ -331,13 +343,11 @@ static void style_arrow(GB_DRAW *d, int x, int y, int w, int h, int type, int st return; } - gtk_paint_arrow(DR(d)->style(), DR(d)->drawable(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + gtk_paint_arrow(DR(d)->style(), DR(d)->drawable(), get_state(state), GTK_SHADOW_NONE, NULL, NULL, NULL, arrow, TRUE, x, y, w, h); if (DR(d)->mask()) - gtk_paint_arrow(DR(d)->style(), DR(d)->mask(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + gtk_paint_arrow(DR(d)->style(), DR(d)->mask(), get_state(state), GTK_SHADOW_NONE, NULL, NULL, NULL, arrow, TRUE, x, y, w, h); } @@ -345,7 +355,7 @@ static void style_arrow(GB_DRAW *d, int x, int y, int w, int h, int type, int st static void style_check(GB_DRAW *d, int x, int y, int w, int h, int value, int state) { GtkShadowType shadow; - GtkStateType st = state ? GTK_STATE_INSENSITIVE : (value ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL); + GtkStateType st = get_state(state | (value ? GB_DRAW_STATE_ACTIVE : 0)); switch (value) { @@ -368,7 +378,7 @@ static void style_check(GB_DRAW *d, int x, int y, int w, int h, int value, int s static void style_option(GB_DRAW *d, int x, int y, int w, int h, int value, int state) { GtkShadowType shadow; - GtkStateType st = state ? GTK_STATE_INSENSITIVE : (value ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL); + GtkStateType st = get_state(state | (value ? GB_DRAW_STATE_ACTIVE : 0)); shadow = value ? GTK_SHADOW_IN : GTK_SHADOW_OUT; @@ -383,7 +393,7 @@ static void style_option(GB_DRAW *d, int x, int y, int w, int h, int value, int static void style_separator(GB_DRAW *d, int x, int y, int w, int h, int vertical, int state) { - GtkStateType st = state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL; + GtkStateType st = get_state(state); if (vertical) { @@ -426,7 +436,7 @@ static void style_focus(GB_DRAW *d, int x, int y, int w, int h) static void style_button(GB_DRAW *d, int x, int y, int w, int h, int value, int state) { - GtkStateType st = state ? GTK_STATE_INSENSITIVE : (value ? GTK_STATE_ACTIVE : GTK_STATE_NORMAL); + GtkStateType st = get_state(state | (value ? GB_DRAW_STATE_ACTIVE : 0)); gtk_paint_box(DR(d)->style(), DR(d)->drawable(), st, value ? GTK_SHADOW_IN : GTK_SHADOW_OUT, @@ -471,14 +481,14 @@ static void style_panel(GB_DRAW *d, int x, int y, int w, int h, int border, int static void style_handle(GB_DRAW *d, int x, int y, int w, int h, int vertical, int state) { - gtk_paint_handle(DR(d)->style(), DR(d)->drawable(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + GtkStateType st = get_state(state); + + gtk_paint_handle(DR(d)->style(), DR(d)->drawable(), st, GTK_SHADOW_NONE, NULL, NULL, NULL, x, y, w, h, (!vertical) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL); if (DR(d)->mask()) - gtk_paint_handle(DR(d)->style(), DR(d)->mask(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + gtk_paint_handle(DR(d)->style(), DR(d)->mask(), st, GTK_SHADOW_NONE, NULL, NULL, NULL, x, y, w, h, (!vertical) ? GTK_ORIENTATION_HORIZONTAL : GTK_ORIENTATION_VERTICAL); @@ -486,12 +496,12 @@ static void style_handle(GB_DRAW *d, int x, int y, int w, int h, int vertical, i static void style_box(GB_DRAW *d, int x, int y, int w, int h, int state) { - gtk_paint_shadow(DR(d)->style(), DR(d)->drawable(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + GtkStateType st = get_state(state); + + gtk_paint_shadow(DR(d)->style(), DR(d)->drawable(), st, GTK_SHADOW_IN, NULL, NULL, "entry", x, y, w, h); if (DR(d)->mask()) - gtk_paint_shadow(DR(d)->style(), DR(d)->mask(), - state ? GTK_STATE_INSENSITIVE : GTK_STATE_NORMAL, + gtk_paint_shadow(DR(d)->style(), DR(d)->mask(), st, GTK_SHADOW_IN, NULL, NULL, "entry", x, y, w, h); } diff --git a/gb.qt4/src/CDraw.cpp b/gb.qt4/src/CDraw.cpp index 74bb063c0..384ab4288 100644 --- a/gb.qt4/src/CDraw.cpp +++ b/gb.qt4/src/CDraw.cpp @@ -960,8 +960,17 @@ static void set_clipping_enabled(GB_DRAW *d, int enable) static void init_option(QStyleOption &opt, int x, int y, int w, int h, int state) { opt.rect = QRect(x, y, w ,h); - if (!state) - opt.state |= QStyle::State_Enabled; + if (state & GB_DRAW_STATE_DISABLED) + return; + + opt.state |= QStyle::State_Enabled; + + if (state & GB_DRAW_STATE_FOCUS) + opt.state |= QStyle::State_HasFocus; + if (state & GB_DRAW_STATE_HOVER) + opt.state |= QStyle::State_MouseOver; + if (state & GB_DRAW_STATE_ACTIVE) + opt.state |= QStyle::State_On | QStyle::State_Sunken | QStyle::State_Active; } static void style_arrow(GB_DRAW *d, int x, int y, int w, int h, int type, int state) diff --git a/main/lib/draw/CDraw.c b/main/lib/draw/CDraw.c index e56937198..b225fcedd 100644 --- a/main/lib/draw/CDraw.c +++ b/main/lib/draw/CDraw.c @@ -1195,8 +1195,10 @@ GB_DESC CDrawDesc[] = GB_STATIC_METHOD("Translate", NULL, CDRAW_translate, "(DX)f(DY)f"), GB_STATIC_METHOD("Scale", NULL, CDRAW_scale, "(SX)f(SY)f"), - GB_CONSTANT("Normal", "i", GB_DRAW_STATE_NORMAL), + GB_CONSTANT("Normale", "i", GB_DRAW_STATE_NORMAL), GB_CONSTANT("Disabled", "i", GB_DRAW_STATE_DISABLED), + GB_CONSTANT("Focus", "i", GB_DRAW_STATE_FOCUS), + GB_CONSTANT("Hover", "i", GB_DRAW_STATE_HOVER), //GB_CONSTANT("ToolButton", "i", GB_DRAW_STATE_TOOL_BUTTON), #if 0 diff --git a/main/lib/draw/gb.draw.h b/main/lib/draw/gb.draw.h index 938acc461..2c35919be 100644 --- a/main/lib/draw/gb.draw.h +++ b/main/lib/draw/gb.draw.h @@ -32,7 +32,9 @@ enum { GB_DRAW_STATE_NORMAL = 0, GB_DRAW_STATE_DISABLED = 1, - GB_DRAW_STATE_TOOL_BUTTON = 2 + GB_DRAW_STATE_FOCUS = 2, + GB_DRAW_STATE_HOVER = 4, + GB_DRAW_STATE_ACTIVE = 8 }; typedef