Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,8 @@ typedef struct uiAreaKeyEvent uiAreaKeyEvent;

typedef struct uiDrawContext uiDrawContext;

// TO CONSIDER: the uiAreaHandler param there seems useless
// (might use individual callbacks instead of handler struct?)
struct uiAreaHandler {
void (*Draw)(uiAreaHandler *, uiArea *, uiAreaDrawParams *);
// TODO document that resizes cause a full redraw for non-scrolling areas; implementation-defined for scrolling areas
Expand All @@ -311,6 +313,7 @@ struct uiAreaHandler {
void (*MouseCrossed)(uiAreaHandler *, uiArea *, int left);
void (*DragBroken)(uiAreaHandler *, uiArea *);
int (*KeyEvent)(uiAreaHandler *, uiArea *, uiAreaKeyEvent *);
void (*Resize)(uiAreaHandler *, uiArea *, int, int);
};

// TODO RTL layouts?
Expand Down Expand Up @@ -343,6 +346,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);

Expand Down
21 changes: 21 additions & 0 deletions unix/area.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ struct uiArea {
GtkWidget *areaWidget;
GtkDrawingArea *drawingArea;
areaWidget *area;
int bgR, bgG, bgB;

uiAreaHandler *ah;

Expand Down Expand Up @@ -96,6 +97,8 @@ static void areaWidget_size_allocate(GtkWidget *w, GtkAllocation *allocation)
// TODO drop this rule; it was stupid and documenting this was stupid — let platforms where it matters do it on their own
// TODO or do we not, for parity of performance?
gtk_widget_queue_resize(w);

a->ah->Resize(a->ah, a, allocation->width, allocation->height);
}

static void loadAreaSize(uiArea *a, double *width, double *height)
Expand Down Expand Up @@ -133,6 +136,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);

Expand All @@ -155,6 +163,8 @@ static void areaWidget_get_preferred_height(GtkWidget *w, gint *min, gint *nat)
*min = a->scrollHeight;
*nat = a->scrollHeight;
}

// TODO: min size
}

static void areaWidget_get_preferred_width(GtkWidget *w, gint *min, gint *nat)
Expand Down Expand Up @@ -496,6 +506,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)
Expand Down Expand Up @@ -603,6 +620,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)

a->widget = a->areaWidget;

uiAreaSetBackgroundColor(a, -1, -1, -1);

return a;
}

Expand All @@ -629,6 +648,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);
Expand Down
14 changes: 14 additions & 0 deletions windows/area.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
RECT client;
WINDOWPOS *wp = (WINDOWPOS *) lParam;
LRESULT lResult;
double w, h;

a = (uiArea *) GetWindowLongPtrW(hwnd, GWLP_USERDATA);
if (a == NULL) {
Expand All @@ -37,6 +38,8 @@ static LRESULT CALLBACK areaWndProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM
uiWindowsEnsureGetClientRect(a->hwnd, &client);
areaDrawOnResize(a, &client);
areaScrollOnResize(a, &client);
loadAreaSize(a, a->rt, &w, &h);
a->ah->Resize(a->ah, a, (int)w, (int)h);
return 0;
}

Expand Down Expand Up @@ -160,6 +163,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;
Expand All @@ -177,6 +187,8 @@ uiArea *uiNewArea(uiAreaHandler *ah)
hInstance, a,
FALSE);

uiAreaSetBackgroundColor(a, -1, -1, -1);

return a;
}

Expand All @@ -199,6 +211,8 @@ uiArea *uiNewScrollingArea(uiAreaHandler *ah, int width, int height)
hInstance, a,
FALSE);

uiAreaSetBackgroundColor(a, -1, -1, -1);

// set initial scrolling parameters
areaUpdateScroll(a);

Expand Down
2 changes: 2 additions & 0 deletions windows/area.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ struct uiArea {
BOOL inside;
BOOL tracking;

int bgR, bgG, bgB;

ID2D1HwndRenderTarget *rt;
};

Expand Down
23 changes: 15 additions & 8 deletions windows/areadraw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,21 @@ static HRESULT doPaint(uiArea *a, ID2D1RenderTarget *rt, RECT *clip)

// TODO only clear the clip area
// TODO clear with actual background brush
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
// it has not worked since 2008 and they have *never* fixed it
// TODO now that -RTCc has just been deprecated entirely, should we switch back?
bgcolor.g = ((float) ((BYTE) ((bgcolorref & 0xFF00) >> 8))) / 255.0;
bgcolor.b = ((float) GetBValue(bgcolorref)) / 255.0;
bgcolor.a = 1.0;
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
// it has not worked since 2008 and they have *never* fixed it
// TODO now that -RTCc has just been deprecated entirely, should we switch back?
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);
Expand Down