2 * PROJECT: PAINT for ReactOS
4 * FILE: base/applications/mspaint_new/palette.cpp
5 * PURPOSE: Window procedure of the palette window
6 * PROGRAMMERS: Benedikt Freisen
9 /* INCLUDES *********************************************************/
13 /* FUNCTIONS ********************************************************/
15 LRESULT
CPaletteWindow::OnPaint(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
17 RECT rc
= { 0, 0, 31, 32 };
23 DefWindowProc(WM_PAINT
, wParam
, lParam
);
25 for(b
= 2; b
< 30; b
++)
26 for(a
= 2; a
< 29; a
++)
28 SetPixel(hDC
, a
, b
, GetSysColor(COLOR_BTNHILIGHT
));
30 DrawEdge(hDC
, &rc
, EDGE_RAISED
, BF_TOPLEFT
);
31 DrawEdge(hDC
, &rc
, BDR_SUNKENOUTER
, BF_TOPLEFT
| BF_BOTTOMRIGHT
);
32 SetRect(&rc
, 11, 12, 26, 27);
33 DrawEdge(hDC
, &rc
, BDR_RAISEDINNER
, BF_RECT
| BF_MIDDLE
);
34 oldPen
= (HPEN
) SelectObject(hDC
, CreatePen(PS_NULL
, 0, 0));
35 oldBrush
= (HBRUSH
) SelectObject(hDC
, CreateSolidBrush(bgColor
));
36 Rectangle(hDC
, rc
.left
, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1);
37 DeleteObject(SelectObject(hDC
, oldBrush
));
38 SetRect(&rc
, 4, 5, 19, 20);
39 DrawEdge(hDC
, &rc
, BDR_RAISEDINNER
, BF_RECT
| BF_MIDDLE
);
40 oldBrush
= (HBRUSH
) SelectObject(hDC
, CreateSolidBrush(fgColor
));
41 Rectangle(hDC
, rc
.left
+ 2, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1);
42 DeleteObject(SelectObject(hDC
, oldBrush
));
43 DeleteObject(SelectObject(hDC
, oldPen
));
45 for(i
= 0; i
< 28; i
++)
47 SetRect(&rc
, 31 + (i
% 14) * 16,
48 0 + (i
/ 14) * 16, 16 + 31 + (i
% 14) * 16, 16 + 0 + (i
/ 14) * 16);
49 DrawEdge(hDC
, &rc
, EDGE_RAISED
, BF_TOPLEFT
);
50 DrawEdge(hDC
, &rc
, BDR_SUNKENOUTER
, BF_RECT
);
51 oldPen
= (HPEN
) SelectObject(hDC
, CreatePen(PS_NULL
, 0, 0));
52 oldBrush
= (HBRUSH
) SelectObject(hDC
, CreateSolidBrush(palColors
[i
]));
53 Rectangle(hDC
, rc
.left
+ 2, rc
.top
+ 2, rc
.right
- 1, rc
.bottom
- 1);
54 DeleteObject(SelectObject(hDC
, oldBrush
));
55 DeleteObject(SelectObject(hDC
, oldPen
));
61 LRESULT
CPaletteWindow::OnLButtonDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
63 if (GET_X_LPARAM(lParam
) >= 31)
65 fgColor
= palColors
[(GET_X_LPARAM(lParam
) - 31) / 16 + (GET_Y_LPARAM(lParam
) / 16) * 14];
66 InvalidateRect(NULL
, FALSE
);
68 ForceRefreshSelectionContents();
73 LRESULT
CPaletteWindow::OnRButtonDown(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
75 if (GET_X_LPARAM(lParam
) >= 31)
77 bgColor
= palColors
[(GET_X_LPARAM(lParam
) - 31) / 16 + (GET_Y_LPARAM(lParam
) / 16) * 14];
78 InvalidateRect(NULL
, FALSE
);
80 ForceRefreshSelectionContents();
85 LRESULT
CPaletteWindow::OnLButtonDblClk(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
87 if (GET_X_LPARAM(lParam
) >= 31)
88 if (ChooseColor(&choosecolor
))
90 palColors
[(GET_X_LPARAM(lParam
) - 31) / 16 + (GET_Y_LPARAM(lParam
) / 16) * 14] =
91 choosecolor
.rgbResult
;
92 fgColor
= choosecolor
.rgbResult
;
93 InvalidateRect(NULL
, FALSE
);
95 ForceRefreshSelectionContents();
100 LRESULT
CPaletteWindow::OnRButtonDblClk(UINT nMsg
, WPARAM wParam
, LPARAM lParam
, BOOL
& bHandled
)
102 if (GET_X_LPARAM(lParam
) >= 31)
103 if (ChooseColor(&choosecolor
))
105 palColors
[(GET_X_LPARAM(lParam
) - 31) / 16 + (GET_Y_LPARAM(lParam
) / 16) * 14] =
106 choosecolor
.rgbResult
;
107 bgColor
= choosecolor
.rgbResult
;
108 InvalidateRect(NULL
, FALSE
);
109 if (activeTool
== 10)
110 ForceRefreshSelectionContents();