8e873041327bbdf2f91cc5dd31bcefdb7e8e1444
[reactos.git] / reactos / base / applications / paint / palette.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: palette.c
5 * PURPOSE: Window procedure of the palette window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include <windows.h>
12 #include "globalvar.h"
13
14 /* FUNCTIONS ********************************************************/
15
16 LRESULT CALLBACK PalWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
17 {
18 switch (message)
19 {
20 case WM_PAINT:
21 {
22 RECT rc = {0, 0, 31, 32};
23 HDC hDC = GetDC(hwnd);
24 HPEN oldPen;
25 HBRUSH oldBrush;
26 int i, a, b;
27
28 DefWindowProc (hwnd, message, wParam, lParam);
29
30 for (b = 2; b < 30; b++)
31 for (a = 2; a < 29; a++)
32 if ((a + b) % 2 == 1)
33 SetPixel(hDC, a, b, GetSysColor(COLOR_BTNHILIGHT));
34
35 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
36 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_TOPLEFT|BF_BOTTOMRIGHT);
37 SetRect(&rc, 11, 12, 26, 27);
38 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
39 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
40 oldBrush = SelectObject(hDC, CreateSolidBrush(bgColor));
41 Rectangle(hDC, rc.left, rc.top + 2, rc.right -1, rc.bottom - 1);
42 DeleteObject(SelectObject(hDC, oldBrush));
43 SetRect(&rc, 4, 5, 19, 20);
44 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT|BF_MIDDLE);
45 oldBrush = SelectObject(hDC, CreateSolidBrush(fgColor));
46 Rectangle( hDC, rc.left + 2,rc.top + 2, rc.right - 1, rc.bottom - 1);
47 DeleteObject(SelectObject(hDC, oldBrush));
48 DeleteObject(SelectObject(hDC, oldPen));
49
50 for (i=0; i<28; i++)
51 {
52 SetRect(&rc, 31 + (i % 14) * 16,
53 0 + (i / 14) * 16,
54 16 + 31 + (i % 14) * 16,
55 16 + 0 + (i / 14) * 16);
56 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
57 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
58 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
59 oldBrush = SelectObject(hDC, CreateSolidBrush(palColors[i]));
60 Rectangle(hDC, rc.left + 2,rc.top + 2,rc.right - 1, rc.bottom - 1);
61 DeleteObject(SelectObject(hDC, oldBrush));
62 DeleteObject(SelectObject(hDC, oldPen));
63 }
64 ReleaseDC(hwnd, hDC);
65 }
66 break;
67 case WM_LBUTTONDOWN:
68 if (LOWORD(lParam)>=31)
69 {
70 fgColor = palColors[(LOWORD(lParam)-31)/16+(HIWORD(lParam)/16)*14];
71 SendMessage(hwnd, WM_PAINT, 0, 0);
72 }
73 break;
74 case WM_RBUTTONDOWN:
75 if (LOWORD(lParam)>=31)
76 {
77 bgColor = palColors[(LOWORD(lParam)-31)/16+(HIWORD(lParam)/16)*14];
78 SendMessage(hwnd, WM_PAINT, 0, 0);
79 }
80 break;
81 case WM_LBUTTONDBLCLK:
82 if (LOWORD(lParam)>=31) if (ChooseColor(&choosecolor))
83 {
84 palColors[(LOWORD(lParam)-31)/16+(HIWORD(lParam)/16)*14] = choosecolor.rgbResult;
85 fgColor = choosecolor.rgbResult;
86 SendMessage(hwnd, WM_PAINT, 0, 0);
87 }
88 break;
89 case WM_RBUTTONDBLCLK:
90 if (LOWORD(lParam)>=31) if (ChooseColor(&choosecolor))
91 {
92 palColors[(LOWORD(lParam)-31)/16+(HIWORD(lParam)/16)*14] = choosecolor.rgbResult;
93 bgColor = choosecolor.rgbResult;
94 SendMessage(hwnd, WM_PAINT, 0, 0);
95 }
96 break;
97
98 default:
99 return DefWindowProc (hwnd, message, wParam, lParam);
100 }
101
102 return 0;
103 }
104