ReactOS  0.4.15-dev-4614-ga5a6101
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  PAINTSTRUCT ps;
37  RECT rect1 = { 0, 0, 42, 66 };
38  RECT rect2 = { 0, 70, 42, 136 };
39 
40  HDC hdc = BeginPaint(&ps);
43  switch (toolsModel.GetActiveTool())
44  {
45  case TOOL_FREESEL:
46  case TOOL_RECTSEL:
47  case TOOL_TEXT:
48  {
49  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
52  DeleteObject(SelectObject(hdc, oldPen));
53  DrawIconEx(hdc, 1, 2, hNontranspIcon, 40, 30, 0, NULL, DI_NORMAL);
54  DrawIconEx(hdc, 1, 33, hTranspIcon, 40, 30, 0, NULL, DI_NORMAL);
55  break;
56  }
57  case TOOL_RUBBER:
58  {
59  int i;
60  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
61  for(i = 0; i < 4; i++)
62  {
63  if (toolsModel.GetRubberRadius() == i + 2)
64  {
66  Rectangle(hdc, 14, i * 15 + 2, 29, i * 15 + 17);
68  }
69  else
71  Rectangle(hdc, 19 - i, i * 14 + 7, 24 + i, i * 16 + 12);
72  }
73  DeleteObject(SelectObject(hdc, oldPen));
74  break;
75  }
76  case TOOL_BRUSH:
77  {
78  int i;
79  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
81  Rectangle(hdc, toolsModel.GetBrushStyle() % 3 * 13 + 2, toolsModel.GetBrushStyle() / 3 * 15 + 2, toolsModel.GetBrushStyle() % 3 * 13 + 15,
82  toolsModel.GetBrushStyle() / 3 * 15 + 17);
83  DeleteObject(SelectObject(hdc, oldPen));
84  for(i = 0; i < 12; i++)
85  Brush(hdc, i % 3 * 13 + 7, i / 3 * 15 + 8, i % 3 * 13 + 7, i / 3 * 15 + 8,
87  break;
88  }
89  case TOOL_AIRBRUSH:
90  {
91  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
93  switch (toolsModel.GetAirBrushWidth())
94  {
95  case 5:
96  Rectangle(hdc, 2, 2, 21, 31);
97  break;
98  case 8:
99  Rectangle(hdc, 20, 2, 41, 31);
100  break;
101  case 3:
102  Rectangle(hdc, 2, 30, 16, 61);
103  break;
104  case 12:
105  Rectangle(hdc, 15, 30, 41, 61);
106  break;
107  }
108  Airbrush(hdc, 10, 15,
110  Airbrush(hdc, 30, 15,
112  Airbrush(hdc, 8, 45,
114  Airbrush(hdc, 27, 45,
116  DeleteObject(SelectObject(hdc, oldPen));
117  break;
118  }
119  case TOOL_LINE:
120  case TOOL_BEZIER:
121  {
122  int i;
123  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
124  for(i = 0; i < 5; i++)
125  {
126  if (toolsModel.GetLineWidth() == i + 1)
127  {
129  Rectangle(hdc, 2, i * 12 + 2, 41, i * 12 + 14);
131  }
132  else
134  Rectangle(hdc, 5, i * 12 + 6, 38, i * 12 + 8 + i);
135  }
136  DeleteObject(SelectObject(hdc, oldPen));
137  break;
138  }
139  case TOOL_RECT:
140  case TOOL_SHAPE:
141  case TOOL_ELLIPSE:
142  case TOOL_RRECT:
143  {
144  int i;
145  HPEN oldPen = (HPEN) SelectObject(hdc, CreatePen(PS_NULL, 0, 0));
146  for(i = 0; i < 3; i++)
147  {
148  if (toolsModel.GetShapeStyle() == i)
149  {
151  Rectangle(hdc, 2, i * 20 + 2, 41, i * 20 + 22);
152  }
153  }
154  Rect(hdc, 5, 6, 37, 16,
157  Rect(hdc, 5, 26, 37, 36,
161  1, 1);
162  for(i = 0; i < 5; i++)
163  {
164  if (toolsModel.GetLineWidth() == i + 1)
165  {
167  Rectangle(hdc, 2, i * 12 + 72, 41, i * 12 + 84);
169  }
170  else
172  Rectangle(hdc, 5, i * 12 + 76, 38, i * 12 + 78 + i);
173  }
174  DeleteObject(SelectObject(hdc, oldPen));
175  break;
176  }
177  case TOOL_FILL:
178  case TOOL_COLOR:
179  case TOOL_ZOOM:
180  case TOOL_PEN:
181  break;
182  }
183  EndPaint(&ps);
184  return 0;
185 }
186 
188 {
189  int x = GET_X_LPARAM(lParam);
190  int y = GET_Y_LPARAM(lParam);
191  switch (toolsModel.GetActiveTool())
192  {
193  case TOOL_FREESEL:
194  case TOOL_RECTSEL:
195  case TOOL_TEXT:
196  if ((y > 1) && (y < 64))
198  break;
199  case TOOL_RUBBER:
200  if ((y > 1) && (y < 62))
201  toolsModel.SetRubberRadius((y - 2) / 15 + 2);
202  break;
203  case TOOL_BRUSH:
204  if ((x > 1) && (x < 40) && (y > 1) && (y < 62))
205  toolsModel.SetBrushStyle((y - 2) / 15 * 3 + (x - 2) / 13);
206  break;
207  case TOOL_AIRBRUSH:
208  if (y < 62)
209  {
210  if (y < 30)
211  {
212  if (x < 20)
214  else
216  }
217  else
218  {
219  if (x < 15)
221  else
223  }
224  }
225  break;
226  case TOOL_LINE:
227  case TOOL_BEZIER:
228  if (y <= 62)
229  toolsModel.SetLineWidth((y - 2) / 12 + 1);
230  break;
231  case TOOL_RECT:
232  case TOOL_SHAPE:
233  case TOOL_ELLIPSE:
234  case TOOL_RRECT:
235  if (y <= 60)
236  toolsModel.SetShapeStyle((y - 2) / 20);
237  if ((y >= 70) && (y <= 132))
238  toolsModel.SetLineWidth((y - 72) / 12 + 1);
239  break;
240  case TOOL_FILL:
241  case TOOL_COLOR:
242  case TOOL_ZOOM:
243  case TOOL_PEN:
244  break;
245  }
246  return 0;
247 }
248 
250 {
251  Invalidate();
253  return 0;
254 }
255 
257 {
258  Invalidate();
259  return 0;
260 }
261 
263 {
264  int tbPos = 0;
265  int tempZoom = toolsModel.GetZoom();
266 
267  while (tempZoom > MIN_ZOOM)
268  {
269  tbPos++;
270  tempZoom = tempZoom >> 1;
271  }
273  return 0;
274 }
LRESULT OnVScroll(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
RECT rect2
Definition: edittest.c:51
#define BF_MIDDLE
Definition: winuser.h:468
ToolsModel toolsModel
Definition: main.cpp:18
HPEN WINAPI CreatePen(_In_ int, _In_ int, _In_ COLORREF)
#define COLOR_HIGHLIGHT
Definition: winuser.h:920
BOOL WINAPI Rectangle(_In_ HDC, _In_ int, _In_ int, _In_ int, _In_ int)
#define TRUE
Definition: types.h:120
#define SW_HIDE
Definition: winuser.h:762
#define TRACKBAR_CLASS
Definition: commctrl.h:2013
LRESULT OnToolsModelZoomChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
#define MAKELPARAM(l, h)
Definition: winuser.h:3988
static HDC
Definition: imagelist.c:92
#define TBM_SETRANGE
Definition: commctrl.h:2037
#define GET_X_LPARAM(lp)
Definition: windowsx.h:274
void SetLineWidth(int nLineWidth)
Definition: toolsmodel.cpp:48
HGDIOBJ WINAPI SelectObject(_In_ HDC, _In_ HGDIOBJ)
Definition: dc.c:1539
BOOL WINAPI DeleteObject(_In_ HGDIOBJ)
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
#define TBM_SETPOS
Definition: commctrl.h:2036
#define COLOR_APPWORKSPACE
Definition: winuser.h:919
UINT_PTR WPARAM
Definition: windef.h:207
#define WS_CHILD
Definition: pedump.c:617
BOOL WINAPI EndPaint(_In_ HWND, _In_ const PAINTSTRUCT *)
int GetBrushStyle() const
Definition: toolsmodel.cpp:65
DWORD WINAPI GetSysColor(_In_ int)
WPARAM wParam
Definition: combotst.c:138
int GetRubberRadius() const
Definition: toolsmodel.cpp:124
HICON hNontranspIcon
Definition: main.cpp:39
#define BF_RECT
Definition: winuser.h:462
unsigned int BOOL
Definition: ntddk_ex.h:94
#define TBM_GETPOS
Definition: commctrl.h:2031
HDC WINAPI BeginPaint(_In_ HWND, _Out_ LPPAINTSTRUCT)
BOOL WINAPI DrawEdge(_In_ HDC, _Inout_ LPRECT, _In_ UINT, _In_ UINT)
LRESULT OnToolsModelSettingsChanged(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
void SetBackgroundTransparent(BOOL bTransparent)
Definition: toolsmodel.cpp:140
void Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG style)
Definition: drawing.cpp:160
LONG_PTR LPARAM
Definition: windef.h:208
void SetAirBrushWidth(int nAirBrushWidth)
Definition: toolsmodel.cpp:118
#define TBS_AUTOTICKS
Definition: commctrl.h:2015
#define SW_SHOW
Definition: winuser.h:769
#define COLOR_HIGHLIGHTTEXT
Definition: winuser.h:921
int GetLineWidth() const
Definition: toolsmodel.cpp:43
int32_t WINBOOL
Definition: typedefs.h:58
int GetShapeStyle() const
Definition: toolsmodel.cpp:54
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:383
#define COLOR_WINDOWTEXT
Definition: winuser.h:915
#define MIN_ZOOM
Definition: common.h:14
#define TBS_VERT
Definition: commctrl.h:2016
int GetZoom() const
Definition: toolsmodel.cpp:148
LRESULT OnPaint(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
TOOLTYPE GetActiveTool() const
Definition: toolsmodel.cpp:76
HDC hdc
Definition: main.c:9
#define DI_NORMAL
Definition: wingdi.h:72
BOOL zoomTo(int newZoom, int mouseX, int mouseY)
Definition: winproc.cpp:19
#define BDR_SUNKENOUTER
Definition: winuser.h:443
void SetShapeStyle(int nShapeStyle)
Definition: toolsmodel.cpp:59
LRESULT OnLButtonDown(UINT nMsg, WPARAM wParam, LPARAM lParam, BOOL &bHandled)
BOOL ShowWindow(int nCmdShow)
Definition: atlwin.h:1299
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
void SetBrushStyle(int nBrushStyle)
Definition: toolsmodel.cpp:70
int GetAirBrushWidth() const
Definition: toolsmodel.cpp:113
unsigned int UINT
Definition: ndis.h:50
#define NULL
Definition: types.h:112
#define PS_NULL
Definition: wingdi.h:591
void SetRubberRadius(int nRubberRadius)
Definition: toolsmodel.cpp:129
GLint GLint GLint GLint GLint GLint y
Definition: gl.h:1548
HICON hTranspIcon
Definition: main.cpp:40
#define GET_Y_LPARAM(lp)
Definition: windowsx.h:275
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:1082
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
BOOL IsBackgroundTransparent() const
Definition: toolsmodel.cpp:135