[MSPAINT_NEW] bootstrap mspaint_new from mspaint
[reactos.git] / reactos / base / applications / mspaint_new / palette.c
1 /*
2 * PROJECT: PAINT for ReactOS
3 * LICENSE: LGPL
4 * FILE: base/applications/paint/palette.c
5 * PURPOSE: Window procedure of the palette window
6 * PROGRAMMERS: Benedikt Freisen
7 */
8
9 /* INCLUDES *********************************************************/
10
11 #include "precomp.h"
12 #include "palette.h"
13
14 /* FUNCTIONS ********************************************************/
15
16 void
17 RegisterWclPal()
18 {
19 WNDCLASSEX wclPal;
20 /* initializing and registering the window class used for the palette window */
21 wclPal.hInstance = hProgInstance;
22 wclPal.lpszClassName = _T("Palette");
23 wclPal.lpfnWndProc = PalWinProc;
24 wclPal.style = CS_DBLCLKS;
25 wclPal.cbSize = sizeof(WNDCLASSEX);
26 wclPal.hIcon = NULL;
27 wclPal.hIconSm = NULL;
28 wclPal.hCursor = LoadCursor(NULL, IDC_ARROW);
29 wclPal.lpszMenuName = NULL;
30 wclPal.cbClsExtra = 0;
31 wclPal.cbWndExtra = 0;
32 wclPal.hbrBackground = GetSysColorBrush(COLOR_BTNFACE);
33 RegisterClassEx (&wclPal);
34 }
35
36 LRESULT CALLBACK
37 PalWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
38 {
39 switch (message)
40 {
41 case WM_PAINT:
42 {
43 RECT rc = { 0, 0, 31, 32 };
44 HDC hDC = GetDC(hwnd);
45 HPEN oldPen;
46 HBRUSH oldBrush;
47 int i, a, b;
48
49 DefWindowProc(hwnd, message, wParam, lParam);
50
51 for(b = 2; b < 30; b++)
52 for(a = 2; a < 29; a++)
53 if ((a + b) % 2 == 1)
54 SetPixel(hDC, a, b, GetSysColor(COLOR_BTNHILIGHT));
55
56 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
57 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_TOPLEFT | BF_BOTTOMRIGHT);
58 SetRect(&rc, 11, 12, 26, 27);
59 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
60 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
61 oldBrush = SelectObject(hDC, CreateSolidBrush(bgColor));
62 Rectangle(hDC, rc.left, rc.top + 2, rc.right - 1, rc.bottom - 1);
63 DeleteObject(SelectObject(hDC, oldBrush));
64 SetRect(&rc, 4, 5, 19, 20);
65 DrawEdge(hDC, &rc, BDR_RAISEDINNER, BF_RECT | BF_MIDDLE);
66 oldBrush = SelectObject(hDC, CreateSolidBrush(fgColor));
67 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
68 DeleteObject(SelectObject(hDC, oldBrush));
69 DeleteObject(SelectObject(hDC, oldPen));
70
71 for(i = 0; i < 28; i++)
72 {
73 SetRect(&rc, 31 + (i % 14) * 16,
74 0 + (i / 14) * 16, 16 + 31 + (i % 14) * 16, 16 + 0 + (i / 14) * 16);
75 DrawEdge(hDC, &rc, EDGE_RAISED, BF_TOPLEFT);
76 DrawEdge(hDC, &rc, BDR_SUNKENOUTER, BF_RECT);
77 oldPen = SelectObject(hDC, CreatePen(PS_NULL, 0, 0));
78 oldBrush = SelectObject(hDC, CreateSolidBrush(palColors[i]));
79 Rectangle(hDC, rc.left + 2, rc.top + 2, rc.right - 1, rc.bottom - 1);
80 DeleteObject(SelectObject(hDC, oldBrush));
81 DeleteObject(SelectObject(hDC, oldPen));
82 }
83 ReleaseDC(hwnd, hDC);
84 break;
85 }
86 case WM_LBUTTONDOWN:
87 if (GET_X_LPARAM(lParam) >= 31)
88 {
89 fgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14];
90 InvalidateRect(hwnd, NULL, FALSE);
91 if (activeTool == 10)
92 ForceRefreshSelectionContents();
93 }
94 break;
95 case WM_RBUTTONDOWN:
96 if (GET_X_LPARAM(lParam) >= 31)
97 {
98 bgColor = palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14];
99 InvalidateRect(hwnd, NULL, FALSE);
100 if (activeTool == 10)
101 ForceRefreshSelectionContents();
102 }
103 break;
104 case WM_LBUTTONDBLCLK:
105 if (GET_X_LPARAM(lParam) >= 31)
106 if (ChooseColor(&choosecolor))
107 {
108 palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14] =
109 choosecolor.rgbResult;
110 fgColor = choosecolor.rgbResult;
111 InvalidateRect(hwnd, NULL, FALSE);
112 if (activeTool == 10)
113 ForceRefreshSelectionContents();
114 }
115 break;
116 case WM_RBUTTONDBLCLK:
117 if (GET_X_LPARAM(lParam) >= 31)
118 if (ChooseColor(&choosecolor))
119 {
120 palColors[(GET_X_LPARAM(lParam) - 31) / 16 + (GET_Y_LPARAM(lParam) / 16) * 14] =
121 choosecolor.rgbResult;
122 bgColor = choosecolor.rgbResult;
123 InvalidateRect(hwnd, NULL, FALSE);
124 if (activeTool == 10)
125 ForceRefreshSelectionContents();
126 }
127 break;
128
129 default:
130 return DefWindowProc(hwnd, message, wParam, lParam);
131 }
132
133 return 0;
134 }