[melonDS] uiAreaSetBackgroundColor

This commit is contained in:
StapleButter 2017-11-23 19:28:06 +01:00 committed by Mike Sinkovsky
parent 5bd78c1932
commit 3ea407f050
5 changed files with 46 additions and 8 deletions

1
ui.h
View File

@ -343,6 +343,7 @@ _UI_EXTERN void uiAreaScrollTo(uiArea *a, double x, double y, double width, doub
// TODO release capture?
_UI_EXTERN void uiAreaBeginUserWindowMove(uiArea *a);
_UI_EXTERN void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge);
_UI_EXTERN void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b);
_UI_EXTERN uiArea *uiNewArea(uiAreaHandler *ah);
_UI_EXTERN uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height);

View File

@ -37,6 +37,7 @@ struct uiArea {
GtkWidget *areaWidget;
GtkDrawingArea *drawingArea;
areaWidget *area;
int bgR, bgG, bgB;
uiAreaHandler *ah;
@ -133,6 +134,11 @@ static gboolean areaWidget_draw(GtkWidget *w, cairo_t *cr)
dp.ClipWidth = clipX1 - clipX0;
dp.ClipHeight = clipY1 - clipY0;
if (a->bgR != -1) {
cairo_set_source_rgb(cr, a->bgR/255.0, a->bgG/255.0, a->bgB/255.0);
cairo_paint(cr);
}
// no need to save or restore the graphics state to reset transformations; GTK+ does that for us
(*(a->ah->Draw))(a->ah, a, &dp);
@ -496,6 +502,13 @@ static void areaWidget_class_init(areaWidgetClass *class)
uiUnixControlAllDefaults(uiArea)
void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b)
{
a->bgR = r;
a->bgG = g;
a->bgB = b;
}
void uiAreaSetSize(uiArea *a, int width, int height)
{
if (!a->scrolling)
@ -603,6 +616,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)
a->widget = a->areaWidget;
uiAreaSetBackgroundColor(a, -1, -1, -1);
return a;
}
@ -629,6 +644,8 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
a->widget = a->swidget;
uiAreaSetBackgroundColor(a, -1, -1, -1);
gtk_container_add(a->scontainer, a->areaWidget);
// and make the area visible; only the scrolled window's visibility is controlled by libui
gtk_widget_show(a->areaWidget);

View File

@ -160,6 +160,13 @@ void uiAreaBeginUserWindowResize(uiArea *a, uiWindowResizeEdge edge)
wParam, 0);
}
void uiAreaSetBackgroundColor(uiArea *a, int r, int g, int b)
{
a->bgR = r;
a->bgG = g;
a->bgB = b;
}
uiArea *uiNewArea(uiAreaHandler *ah)
{
uiArea *a;
@ -177,6 +184,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)
hInstance, a,
FALSE);
uiAreaSetBackgroundColor(a, -1, -1, -1);
return a;
}
@ -199,6 +208,8 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
hInstance, a,
FALSE);
uiAreaSetBackgroundColor(a, -1, -1, -1);
// set initial scrolling parameters
areaUpdateScroll(a);

View File

@ -24,6 +24,8 @@ struct uiArea {
BOOL inside;
BOOL tracking;
int bgR, bgG, bgB;
ID2D1HwndRenderTarget *rt;
};

View File

@ -40,6 +40,12 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
// TODO only clear the clip area
// TODO clear with actual background brush
if (a->bgR != -1) {
bgcolor.r = ((float) a->bgR) / 255.0;
bgcolor.g = ((float) a->bgG) / 255.0;
bgcolor.b = ((float) a->bgB) / 255.0;
bgcolor.a = 1.0;
} else {
bgcolorref = GetSysColor(COLOR_BTNFACE);
bgcolor.r = ((float) GetRValue(bgcolorref)) / 255.0;
// due to utter apathy on Microsoft's part, GetGValue() does not work with MSVC's Run-Time Error Checks
@ -48,6 +54,7 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)
bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0;
bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0;
bgcolor.a = 1.0;
}
rt->Clear(&bgcolor);
(*(ah->Draw))(ah, a, &dp);