summaryrefslogtreecommitdiff
path: root/widgetfactory.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'widgetfactory.cpp')
-rw-r--r--widgetfactory.cpp126
1 files changed, 120 insertions, 6 deletions
diff --git a/widgetfactory.cpp b/widgetfactory.cpp
index 53ba72d..3c8e35a 100644
--- a/widgetfactory.cpp
+++ b/widgetfactory.cpp
@@ -28,6 +28,8 @@ static HBRUSH green;
static HBRUSH blue;
static HBRUSH white;
+BOOL (WINAPI *fnGradientFill)(HDC, PTRIVERTEX, ULONG, PVOID, ULONG, ULONG) = NULL;
+
LRESULT
handleMessage(void *closure, HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
{
@@ -77,6 +79,14 @@ handleCommand(void *closure, HWND window, WORD notificationcode, WORD sourceid,
if (control != NULL && sourceid == ID_B2) {
MessageBox(window, TEXT("Hello World!"), TEXT("Hello"), MB_ICONASTERISK|MB_OK);
}
+ if (control != NULL && sourceid == ID_B3) {
+ ALFColor oldcolor = ALF_GetBackgroundColor(window);
+ if (oldcolor == ALF_COLOR_TRANSPARENT) {
+ ALF_SetBackgroundColor(window, ALF_COLOR_SYS(COLOR_BTNFACE));
+ } else {
+ ALF_SetBackgroundColor(window, ALF_COLOR_TRANSPARENT);
+ }
+ }
return 0;
}
@@ -85,10 +95,108 @@ static void
handlePaint(void *closure, HWND window, HDC dc, RECT *rcPaint)
{
(void)closure;
- (void)window;
- SetBkColor(dc, RGB(255, 0, 0));
- ExtTextOut(dc, 0, 0, ETO_OPAQUE, rcPaint, TEXT(""), 0, NULL);
+ ALFColor color = ALF_GetBackgroundColor(window);
+
+ if (color == ALF_COLOR_TRANSPARENT) {
+ RECT rcClient;
+ GetClientRect(window, &rcClient);
+
+ if (fnGradientFill) {
+ TRIVERTEX vertex[6];
+ vertex[0].x = rcClient.left;
+ vertex[0].y = rcClient.top;
+ vertex[0].Red = 0xff00;
+ vertex[0].Green = 0x8000;
+ vertex[0].Blue = 0x0000;
+ vertex[0].Alpha = 0x0000;
+
+ vertex[1].x = rcClient.left;
+ vertex[1].y = rcClient.bottom;
+ vertex[1].Red = 0x9000;
+ vertex[1].Green = 0x0000;
+ vertex[1].Blue = 0x9000;
+ vertex[1].Alpha = 0x0000;
+
+ vertex[2].x = rcClient.right;
+ vertex[2].y = rcClient.top;
+ vertex[2].Red = 0x9000;
+ vertex[2].Green = 0x0000;
+ vertex[2].Blue = 0x9000;
+ vertex[2].Alpha = 0x0000;
+
+ vertex[3].x = rcClient.right;
+ vertex[3].y = rcClient.bottom;
+ vertex[3].Red = 0x0000;
+ vertex[3].Green = 0xd000;
+ vertex[3].Blue = 0xd000;
+ vertex[3].Alpha = 0x0000;
+
+ vertex[4].x = rcClient.left;
+ vertex[4].y = rcClient.bottom;
+ vertex[4].Red = 0x9000;
+ vertex[4].Green = 0x0000;
+ vertex[4].Blue = 0x9000;
+ vertex[4].Alpha = 0x0000;
+
+ vertex[5].x = rcClient.right;
+ vertex[5].y = rcClient.top;
+ vertex[5].Red = 0x9000;
+ vertex[5].Green = 0x0000;
+ vertex[5].Blue = 0x9000;
+ vertex[5].Alpha = 0x0000;
+
+ GRADIENT_TRIANGLE gTriangle[2];
+ gTriangle[0].Vertex1 = 0;
+ gTriangle[0].Vertex2 = 1;
+ gTriangle[0].Vertex3 = 2;
+ gTriangle[1].Vertex1 = 3;
+ gTriangle[1].Vertex2 = 4;
+ gTriangle[1].Vertex3 = 5;
+
+ fnGradientFill(dc, vertex, 6, gTriangle, 2, GRADIENT_FILL_TRIANGLE);
+ } else {
+ HBRUSH white = (HBRUSH)GetStockObject(WHITE_BRUSH);
+ HBRUSH gray = (HBRUSH)GetStockObject(GRAY_BRUSH);
+
+ int s = 10;
+ for (int y = rcClient.top; y < rcClient.bottom; y += 2*s) {
+ for (int x = rcClient.left; x < rcClient.right; x += 2*s) {
+ RECT a = { x, y, x + s, y + s };
+ RECT b = { x + s, y, x + s + s, y + s };
+ RECT c = { x, y + s, x + s, y + s + s };
+ RECT d = { x + s, y + s, x + s + s, y + s + s };
+ FillRect(dc, &a, white);
+ FillRect(dc, &b, gray);
+ FillRect(dc, &c, gray);
+ FillRect(dc, &d, white);
+ }
+ }
+ }
+ } else {
+ if (rcPaint) {
+ SetBkColor(dc, ALF_ColorToGdi(color));
+ ExtTextOut(dc, 0, 0, ETO_OPAQUE, rcPaint, TEXT(""), 0, NULL);
+ } else {
+ RECT rcClient;
+ GetClientRect(window, &rcClient);
+
+ SetBkColor(dc, ALF_ColorToGdi(color));
+ ExtTextOut(dc, 0, 0, ETO_OPAQUE, &rcClient, TEXT(""), 0, NULL);
+ }
+ }
+}
+
+static void handleWindowPosChanged(void *closure, HWND window, WINDOWPOS *pos)
+{
+ (void)closure;
+
+ if (!(pos->flags & SWP_NOSIZE)) {
+ ALFColor bgcolor = ALF_GetBackgroundColor(window);
+
+ if (bgcolor == ALF_COLOR_TRANSPARENT)
+ ALF_InvalidateBackground(window);
+ }
}
int CALLBACK
@@ -110,6 +218,13 @@ WinMain
blue = CreateSolidBrush(RGB(0,0,255));
white = CreateSolidBrush(RGB(255,255,255));
+ if (LOBYTE(LOWORD(GetVersion())) >= 4) {
+ HMODULE hMsimg32 = LoadLibraryA("msimg32.dll");
+ if (hMsimg32) {
+ *((void**)&fnGradientFill) = (void*)GetProcAddress(hMsimg32, "GradientFill");
+ }
+ }
+
ALFWindowClassParams cparams;
ZeroMemory(&cparams, sizeof(cparams));
@@ -117,6 +232,7 @@ WinMain
cparams.vtbl.message = handleMessage;
cparams.vtbl.command = handleCommand;
cparams.vtbl.paint = handlePaint;
+ cparams.vtbl.windowposchanged = handleWindowPosChanged;
ALF_Initialize();
@@ -150,7 +266,7 @@ WinMain
ALF_AddLabel(win, ID_LBL4, 0, 3, TEXT("&Editable Combo Box:"));
HWND hwndCombo1 = ALF_AddEditableComboBox(win, ID_COMBO1, 1, 3, TEXT("Hello!"));
- ALF_AddButton(win, ID_B3, 3, 3, TEXT("Ok"));
+ ALF_AddButton(win, ID_B3, 3, 3, TEXT("Change Background"));
ALF_ComboBoxInsertString(hwndCombo1, 0, TEXT("Hello World!"));
ALF_ComboBoxInsertString(hwndCombo1, -1, TEXT("Goodbye World!"));
@@ -234,8 +350,6 @@ WinMain
EnableWindow(ALF_WidgetHwndById(win, ID_LBL3), FALSE);
- SendMessage(win, ALF_WM_SETBGCOLOR, (WPARAM)ALF_COLOR_TRANSPARENT, 0);
-
ALF_ResizeWindow(win, 1, 1);
ALF_ShowModal(win);