ReactOS  0.4.12-dev-75-g00dd17e
toolsettings.cpp
Go to the documentation of this file.
1 /*
2  * PROJECT: PAINT for ReactOS
3  * LICENSE: LGPL
4  * FILE: base/applications/mspaint/toolsettings.cpp
5  * PURPOSE: Window procedure of the tool settings window
6  * PROGRAMMERS: Benedikt Freisen
7  * Stanislav Motylkov
8  */
9 
10 /* INCLUDES *********************************************************/
11 
12 #include "precomp.h"
13 
14 /* FUNCTIONS ********************************************************/
15 
17 {
18  RECT trackbarZoomPos = {1, 1, 1 + 40, 1 + 64};
19  trackbarZoom.Create(TRACKBAR_CLASS, m_hWnd, trackbarZoomPos, NULL, WS_CHILD | TBS_VERT | TBS_AUTOTICKS);
22  return 0;
23 }
24 
26 {
27  if (!zoomTo(125 << trackbarZoom.SendMessage(TBM_GETPOS, 0, 0), 0, 0))
28  {
29  OnToolsModelZoomChanged(nMsg, wParam, lParam, bHandled);
30  }
31  return 0;
32 }
33 
35 {
36  HDC hdc = GetDC();
37  RECT rect1 = { 0, 0, 42, 66 };
38  RECT rect2 = { 0, 70, 42, 136 };
39 
40  DefWindowProc(WM_PAINT, wParam, lParam);
41 
44  switch (toolsModel.GetActiveTool())
45  {
46  case TOOL_FREESEL:
47  case TOOL_RECTSEL:
48  case TOOL_TEXT:
49  {
50  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
53  DeleteObject(SelectObject(hdc, oldPen));
54  DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
55  DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
56  break;
57  }
58  case TOOL_RUBBER:
59  {
60  int i;
61  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
62  for(i = 0; i < 4; i++)
63  {
64  if (toolsModel.GetRubberRadius() == i + 2)
65  {
67  Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
69  }
70  else
72  Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
73  }
74  DeleteObject(SelectObject(hdc, oldPen));
75  break;
76  }
77  case TOOL_BRUSH:
78  {
79  int i;
80  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
82  Rectangle(hdc, toolsModel.GetBrushStyle() % 3 * 13 + 2, toolsModel.GetBrushStyle() / 3 * 15 + 2, toolsModel.GetBrushStyle() % 3 * 13 + 15,
83  toolsModel.GetBrushStyle() / 3 * 15 + 17);
84  DeleteObject(SelectObject(hdc, oldPen));
85  for(i = 0; i < 12; i++)
86  Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
88  break;
89  }
90  case TOOL_AIRBRUSH:
91  {
92  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
94  switch (toolsModel.GetAirBrushWidth())
95  {
96  case 5:
97  Rectangle(hdc, 2, 2, 21, 31);
98  break;
99  case 8:
100  Rectangle(hdc, 20, 2, 41, 31);
101  break;
102  case 3:
103  Rectangle(hdc, 2, 30, 16, 61);
104  break;
105  case 12:
106  Rectangle(hdc, 15, 30, 41, 61);
107  break;
108  }
109  Airbrush(hdc, 10, 15,
111  Airbrush(hdc, 30, 15,
112  GetSysColor((toolsModel.GetAirBrushWidth() == 8) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 8);
113  Airbrush(hdc, 8, 45,
114  GetSysColor((toolsModel.GetAirBrushWidth() == 3) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 3);
115  Airbrush(hdc, 27, 45,
116  GetSysColor((toolsModel.GetAirBrushWidth() == 12) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT), 12);
117  DeleteObject(SelectObject(hdc, oldPen));
118  break;
119  }
120  case TOOL_LINE:
121  case TOOL_BEZIER:
122  {
123  int i;
124  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
125  for(i = 0; i < 5; i++)
126  {
127  if (toolsModel.GetLineWidth() == i + 1)
128  {
130  Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
132  }
133  else
135  Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
136  }
137  DeleteObject(SelectObject(hdc, oldPen));
138  break;
139  }
140  case TOOL_RECT:
141  case TOOL_SHAPE:
142  case TOOL_ELLIPSE:
143  case TOOL_RRECT:
144  {
145  int i;
146  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
147  for(i = 0; i < 3; i++)
148  {
149  if (toolsModel.GetShapeStyle() == i)
150  {
152  Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
153  }
154  }
155  Rect(hdc, 5, 6, 37, 16,
158  Rect(hdc, 5, 26, 37, 36,
159  GetSysColor((toolsModel.GetShapeStyle() == 1) ? COLOR_HIGHLIGHTTEXT : COLOR_WINDOWTEXT),
162  1, 1);
163  for(i = 0; i < 5; i++)
164  {
165  if (toolsModel.GetLineWidth() == i + 1)
166  {
168  Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
170  }
171  else
172  SelectObject(hdc, GetSysColorBrush(COLOR_WINDOWTEXT));
173  Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
174  }
175  DeleteObject(SelectObject(hdc, oldPen));
176  break;
177  }
178  }
179  ReleaseDC(hdc);
180  return 0;
181 }
182 
184 {
185  int x = GET_X_LPARAM(lParam);
186  int y = GET_Y_LPARAM(lParam);
187  switch (toolsModel.GetActiveTool())
188  {
189  case TOOL_FREESEL:
190  case TOOL_RECTSEL:
191  case TOOL_TEXT:
192  if ((y > 1) && (y < 64))
193  toolsModel.SetBackgroundTransparent((y - 2) / 31);
194  break;
195  case TOOL_RUBBER:
196  if ((y > 1) && (y < 62))
197  toolsModel.SetRubberRadius((y - 2) / 15 + 2);
198  break;
199  case TOOL_BRUSH:
200  if ((x > 1) && (x < 40) && (y > 1) && (y < 62))
201  toolsModel.SetBrushStyle((y - 2) / 15 * 3 + (x - 2) / 13);
202  break;
203  case TOOL_AIRBRUSH:
204  if (y < 62)
205  {
206  if (y < 30)
207  {
208  if (x < 20)
210  else
212  }
213  else
214  {
215  if (x < 15)
217  else
219  }
220  }
221  break;
222  case TOOL_LINE:
223  case TOOL_BEZIER:
224  if (y <= 62)
225  toolsModel.SetLineWidth((y - 2) / 12 + 1);
226  break;
227  case TOOL_RECT:
228  case TOOL_SHAPE:
229  case TOOL_ELLIPSE:
230  case TOOL_RRECT:
231  if (y <= 60)
232  toolsModel.SetShapeStyle((y - 2) / 20);
233  if ((y >= 70) && (y <= 132))
234  toolsModel.SetLineWidth((y - 72) / 12 + 1);
235  break;
236  }
237  return 0;
238 }
239 
241 {
242  Invalidate();
244  return 0;
245 }
246 
248 {
249  Invalidate();
250  return 0;
251 }
252 
254 {
255  int tbPos = 0;
256  int tempZoom = toolsModel.GetZoom();
257 
258  while (tempZoom > 125)
259  {
260  tbPos++;
261  tempZoom = tempZoom >> 1;
262  }
264  return 0;
265 }
int GetLineWidth()
Definition: toolsmodel.cpp:27
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define HDC
Definition: msvc.h:22
RECT rect2
Definition: edittest.c:51
#define BF_MIDDLE
Definition: winuser.h:468
ToolsModel toolsModel
Definition: main.cpp:18
#define TRUE
Definition: types.h:120
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define COLOR_HIGHLIGHT
Definition: winuser.h:916
#define TOOL_TEXT
Definition: definitions.h:144
#define TOOL_RECT
Definition: definitions.h:147
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
HDC WINAPI GetDC(_In_opt_ HWND)
#define TOOL_LINE
Definition: definitions.h:145
#define SW_HIDE
Definition: winuser.h:762
BOOL zoomTo(int, int, int)
Definition: winproc.cpp:21
#define TRACKBAR_CLASS
Definition: commctrl.h:1983
LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define MAKELPARAM(l, h)
Definition: winuser.h:3915
#define TBM_SETRANGE
Definition: commctrl.h:2007
#define TOOL_RUBBER
Definition: definitions.h:137
void SetLineWidth(int nLineWidth)
Definition: toolsmodel.cpp:32
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1497
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
int GetRubberRadius()
Definition: toolsmodel.cpp:82
#define TBM_SETPOS
Definition: commctrl.h:2006
#define COLOR_APPWORKSPACE
Definition: winuser.h:915
#define TOOL_SHAPE
Definition: definitions.h:148
#define WS_CHILD
Definition: pedump.c:617
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
int GetZoom()
Definition: toolsmodel.cpp:104
UINT_PTR WPARAM
Definition: windef.h:207
INT INT y
Definition: msvc.h:62
HICON hNontranspIcon
Definition: main.cpp:39
#define BF_RECT
Definition: winuser.h:462
GLenum GLclampf GLint i
Definition: glfuncs.h:14
#define TOOL_BEZIER
Definition: definitions.h:146
LONG_PTR LPARAM
Definition: windef.h:208
#define TBM_GETPOS
Definition: commctrl.h:2001
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
int WINAPI ReleaseDC(_In_opt_ HWND, _In_ HDC)
void SetBackgroundTransparent(BOOL bTransparent)
Definition: toolsmodel.cpp:98
int GetAirBrushWidth()
Definition: toolsmodel.cpp:71
HDC hdc
Definition: msvc.h:53
void Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG style)
Definition: drawing.cpp:160
#define TOOL_AIRBRUSH
Definition: definitions.h:143
smooth NULL
Definition: ftsmooth.c:416
void SetAirBrushWidth(int nAirBrushWidth)
Definition: toolsmodel.cpp:76
#define GET_X_LPARAM(lp)
Definition: precomp.h:67
#define TBS_AUTOTICKS
Definition: commctrl.h:1985
#define SW_SHOW
Definition: winuser.h:769
#define COLOR_HIGHLIGHTTEXT
Definition: winuser.h:917
int GetShapeStyle()
Definition: toolsmodel.cpp:38
#define DefWindowProc
Definition: ros2win.h:31
BOOL IsBackgroundTransparent()
Definition: toolsmodel.cpp:93
unsigned int BOOL
Definition: ntddk_ex.h:94
int32_t WINBOOL
Definition: typedefs.h:56
BOOL WINAPI DrawIconEx(_In_ HDC, _In_ int, _In_ int, _In_ HICON, _In_ int, _In_ int, _In_ UINT, _In_opt_ HBRUSH, _In_ UINT)
Definition: cursoricon.c:1997
LRESULT OnCreate(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
HWND Create(LPCTSTR lpstrWndClass, HWND hWndParent, _U_RECT rect=NULL, LPCTSTR szWindowName=NULL, DWORD dwStyle=0, DWORD dwExStyle=0, _U_MENUorID MenuOrID=0U, LPVOID lpCreateParam=NULL)
Definition: atlwin.h:374
#define COLOR_WINDOWTEXT
Definition: winuser.h:911
unsigned int UINT
Definition: ndis.h:50
#define TOOL_RRECT
Definition: definitions.h:150
#define TBS_VERT
Definition: commctrl.h:1986
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define WM_PAINT
Definition: winuser.h:1602
#define DI_NORMAL
Definition: wingdi.h:72
#define TOOL_FREESEL
Definition: definitions.h:135
#define TOOL_BRUSH
Definition: definitions.h:142
#define TOOL_ELLIPSE
Definition: definitions.h:149
#define TOOL_RECTSEL
Definition: definitions.h:136
#define BDR_SUNKENOUTER
Definition: winuser.h:443
void SetShapeStyle(int nShapeStyle)
Definition: toolsmodel.cpp:43
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1256
void SetBrushStyle(int nBrushStyle)
Definition: toolsmodel.cpp:54
INT x
Definition: msvc.h:62
#define TOOL_ZOOM
Definition: definitions.h:140
int GetActiveTool()
Definition: toolsmodel.cpp:60
int GetBrushStyle()
Definition: toolsmodel.cpp:49
#define PS_NULL
Definition: wingdi.h:589
void SetRubberRadius(int nRubberRadius)
Definition: toolsmodel.cpp:87
HICON hTranspIcon
Definition: main.cpp:40
#define GET_Y_LPARAM(lp)
Definition: precomp.h:68
void Airbrush(HDC hdc, LONG x, LONG y, COLORREF color, LONG r)
Definition: drawing.cpp:149
LRESULT SendMessage(UINT message, WPARAM wParam=0, LPARAM lParam=0)
Definition: atlwin.h:1039
LONG_PTR LRESULT
Definition: windef.h:209
HBRUSH WINAPI GetSysColorBrush(_In_ int)
LPARAM lParam
Definition: combotst.c:139
LRESULT OnToolsModelToolChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
struct Rect Rect