Author: bfreisen
Date: Thu Jul 2 21:02:37 2009
New Revision: 41742
URL:
http://svn.reactos.org/svn/reactos?rev=41742&view=rev
Log:
Fixed cropping function and implemented size boxes
Added:
trunk/reactos/base/applications/paint/sizebox.c (with props)
trunk/reactos/base/applications/paint/sizebox.h (with props)
Modified:
trunk/reactos/base/applications/paint/globalvar.h
trunk/reactos/base/applications/paint/history.c
trunk/reactos/base/applications/paint/history.h
trunk/reactos/base/applications/paint/main.c
trunk/reactos/base/applications/paint/paint.rbuild
trunk/reactos/base/applications/paint/winproc.c
Modified: trunk/reactos/base/applications/paint/globalvar.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/gl…
==============================================================================
--- trunk/reactos/base/applications/paint/globalvar.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/globalvar.h [iso-8859-1] Thu Jul 2 21:02:37
2009
@@ -76,3 +76,12 @@
extern BOOL showMiniature;
extern HWND hwndMiniature;
+
+extern HWND hSizeboxLeftTop;
+extern HWND hSizeboxCenterTop;
+extern HWND hSizeboxRightTop;
+extern HWND hSizeboxLeftCenter;
+extern HWND hSizeboxRightCenter;
+extern HWND hSizeboxLeftBottom;
+extern HWND hSizeboxCenterBottom;
+extern HWND hSizeboxRightBottom;
Modified: trunk/reactos/base/applications/paint/history.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/hi…
==============================================================================
--- trunk/reactos/base/applications/paint/history.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/history.c [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -91,27 +91,30 @@
setImgXYRes(GetDIBWidth(hBms[currInd]), GetDIBHeight(hBms[currInd]));
}
-void cropReversible(int x, int y)//FIXME: This function is broken
+void cropReversible(int width, int height, int xOffset, int yOffset)
{
- HBITMAP oldBitmap;
+ HDC hdc;
HPEN oldPen;
HBRUSH oldBrush;
SelectObject(hDrawingDC, hBms[currInd]);
DeleteObject(hBms[(currInd+1)%4]);
- hBms[(currInd+1)%4] = CreateDIBWithProperties(x, y);
+ hBms[(currInd+1)%4] = CreateDIBWithProperties(width, height);
currInd = (currInd+1)%4;
if (undoSteps<3) undoSteps++;
redoSteps = 0;
- oldBitmap = SelectObject(hSelDC, hBms[currInd]);
- oldPen = SelectObject(hSelDC, CreatePen(PS_SOLID, 1, bgColor));
- oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor));
- Rectangle(hSelDC, 0, 0, x, y);
- DeleteObject(SelectObject(hSelDC, oldBrush));
- DeleteObject(SelectObject(hSelDC, oldPen));
- BitBlt(hDrawingDC, 0, 0, imgXRes, imgYRes, hSelDC, 0, 0, SRCCOPY);
- SelectObject(hDrawingDC, SelectObject(hSelDC, oldBitmap));
+ hdc = CreateCompatibleDC(hDrawingDC);
+ SelectObject(hdc, hBms[currInd]);
- setImgXYRes(x, y);
+ oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, bgColor));
+ oldBrush = SelectObject(hdc, CreateSolidBrush(bgColor));
+ Rectangle(hdc, 0, 0, width, height);
+ BitBlt(hdc, -xOffset, -yOffset, imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
+ DeleteObject(SelectObject(hdc, oldBrush));
+ DeleteObject(SelectObject(hdc, oldPen));
+ DeleteDC(hdc);
+ SelectObject(hDrawingDC, hBms[currInd]);
+
+ setImgXYRes(width, height);
}
Modified: trunk/reactos/base/applications/paint/history.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/hi…
==============================================================================
--- trunk/reactos/base/applications/paint/history.h [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/history.h [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -18,4 +18,4 @@
void insertReversible();
-void cropReversible(int x, int y);
+void cropReversible(int width, int height, int xOffset, int yOffset);
Modified: trunk/reactos/base/applications/paint/main.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/ma…
==============================================================================
--- trunk/reactos/base/applications/paint/main.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/main.c [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -26,6 +26,7 @@
#include "palette.h"
#include "toolsettings.h"
#include "selection.h"
+#include "sizebox.h"
/* FUNCTIONS ********************************************************/
@@ -106,6 +107,15 @@
BOOL showMiniature = FALSE;
HWND hwndMiniature;
+
+HWND hSizeboxLeftTop;
+HWND hSizeboxCenterTop;
+HWND hSizeboxRightTop;
+HWND hSizeboxLeftCenter;
+HWND hSizeboxRightCenter;
+HWND hSizeboxLeftBottom;
+HWND hSizeboxCenterBottom;
+HWND hSizeboxRightBottom;
int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR
lpszArgument, int nFunsterStil)
{
@@ -217,6 +227,21 @@
wclSelection.hbrBackground = NULL;//GetSysColorBrush(COLOR_BTNFACE);
RegisterClassEx (&wclSelection);
+ /* initializing and registering the window class for the size boxes */
+ wclSettings.hInstance = hThisInstance;
+ wclSettings.lpszClassName = _T("Sizebox");
+ wclSettings.lpfnWndProc = SizeboxWinProc;
+ wclSettings.style = CS_DBLCLKS;
+ wclSettings.cbSize = sizeof (WNDCLASSEX);
+ wclSettings.hIcon = NULL;
+ wclSettings.hIconSm = NULL;
+ wclSettings.hCursor = LoadCursor (NULL, IDC_ARROW);
+ wclSettings.lpszMenuName = NULL;
+ wclSettings.cbClsExtra = 0;
+ wclSettings.cbWndExtra = 0;
+ wclSettings.hbrBackground = GetSysColorBrush(COLOR_HIGHLIGHT);
+ RegisterClassEx (&wclSettings);
+
LoadString(hThisInstance, IDS_DEFAULTFILENAME, filename, SIZEOF(filename));
LoadString(hThisInstance, IDS_WINDOWTITLE, resstr, SIZEOF(resstr));
_stprintf(progtitle, resstr, filename);
@@ -348,6 +373,15 @@
sfn.nMaxFileTitle = SIZEOF(sfnFiletitle);
sfn.Flags = OFN_OVERWRITEPROMPT | OFN_HIDEREADONLY;
+ hSizeboxLeftTop = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxCenterTop = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxRightTop = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxLeftCenter = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxRightCenter = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxLeftBottom = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxCenterBottom= CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ hSizeboxRightBottom = CreateWindowEx(0, _T("Sizebox"), _T(""),
WS_CHILD | WS_VISIBLE, 0, 0, 3, 3, hScrlClient, NULL, hThisInstance, NULL);
+ SendMessage(hImageArea, WM_SIZE, 0, 0);
/* by moving the window, the things in WM_SIZE are done */
MoveWindow(hwnd, 100, 100, 600, 450, TRUE);
Modified: trunk/reactos/base/applications/paint/paint.rbuild
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/pa…
==============================================================================
--- trunk/reactos/base/applications/paint/paint.rbuild [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/paint.rbuild [iso-8859-1] Thu Jul 2 21:02:37
2009
@@ -18,6 +18,7 @@
<file>palette.c</file>
<file>registry.c</file>
<file>selection.c</file>
+ <file>sizebox.c</file>
<file>toolsettings.c</file>
<file>winproc.c</file>
<file>rsrc.rc</file>
Added: trunk/reactos/base/applications/paint/sizebox.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/si…
==============================================================================
--- trunk/reactos/base/applications/paint/sizebox.c (added)
+++ trunk/reactos/base/applications/paint/sizebox.c [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -1,0 +1,81 @@
+/*
+ * PROJECT: PAINT for ReactOS
+ * LICENSE: LGPL
+ * FILE: sizebox.c
+ * PURPOSE: Window procedure of the size boxes
+ * PROGRAMMERS: Benedikt Freisen
+ */
+
+/* INCLUDES *********************************************************/
+
+#include <windows.h>
+#include "globalvar.h"
+#include "drawing.h"
+#include "history.h"
+#include "mouse.h"
+
+/* FUNCTIONS ********************************************************/
+
+BOOL resizing = FALSE;
+short xOrig;
+short yOrig;
+
+LRESULT CALLBACK SizeboxWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ switch (message)
+ {
+ case WM_SETCURSOR:
+ {
+ if ((hwnd==hSizeboxLeftTop)||(hwnd==hSizeboxRightBottom))
+ SetCursor(LoadCursor(NULL, IDC_SIZENWSE));
+ if ((hwnd==hSizeboxLeftBottom)||(hwnd==hSizeboxRightTop))
+ SetCursor(LoadCursor(NULL, IDC_SIZENESW));
+ if ((hwnd==hSizeboxLeftCenter)||(hwnd==hSizeboxRightCenter))
+ SetCursor(LoadCursor(NULL, IDC_SIZEWE));
+ if ((hwnd==hSizeboxCenterTop)||(hwnd==hSizeboxCenterBottom))
+ SetCursor(LoadCursor(NULL, IDC_SIZENS));
+ }
+ break;
+ case WM_LBUTTONDOWN:
+ resizing = TRUE;
+ xOrig = LOWORD(lParam);
+ yOrig = HIWORD(lParam);
+ SetCapture(hwnd);
+ break;
+ case WM_MOUSEMOVE:
+ // TODO: print things in the status bar
+ break;
+ case WM_LBUTTONUP:
+ if (resizing)
+ {
+ short xRel;
+ short yRel;
+ ReleaseCapture();
+ resizing = FALSE;
+ xRel = ((short)LOWORD(lParam)-xOrig)*1000/zoom;
+ yRel = ((short)HIWORD(lParam)-yOrig)*1000/zoom;
+ if (hwnd==hSizeboxLeftTop)
+ cropReversible(imgXRes-xRel, imgYRes-yRel, xRel, yRel);
+ if (hwnd==hSizeboxCenterTop)
+ cropReversible(imgXRes, imgYRes-yRel, 0, yRel);
+ if (hwnd==hSizeboxRightTop)
+ cropReversible(imgXRes+xRel, imgYRes-yRel, 0, yRel);
+ if (hwnd==hSizeboxLeftCenter)
+ cropReversible(imgXRes-xRel, imgYRes, xRel, 0);
+ if (hwnd==hSizeboxRightCenter)
+ cropReversible(imgXRes+xRel, imgYRes, 0, 0);
+ if (hwnd==hSizeboxLeftBottom)
+ cropReversible(imgXRes-xRel, imgYRes+yRel, xRel, 0);
+ if (hwnd==hSizeboxCenterBottom)
+ cropReversible(imgXRes, imgYRes+yRel, 0, 0);
+ if (hwnd==hSizeboxRightBottom)
+ cropReversible(imgXRes+xRel, imgYRes+yRel, 0, 0);
+ }
+ break;
+
+ default:
+ return DefWindowProc (hwnd, message, wParam, lParam);
+ }
+
+ return 0;
+}
Propchange: trunk/reactos/base/applications/paint/sizebox.c
------------------------------------------------------------------------------
svn:eol-style = native
Added: trunk/reactos/base/applications/paint/sizebox.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/si…
==============================================================================
--- trunk/reactos/base/applications/paint/sizebox.h (added)
+++ trunk/reactos/base/applications/paint/sizebox.h [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -1,0 +1,9 @@
+/*
+ * PROJECT: PAINT for ReactOS
+ * LICENSE: LGPL
+ * FILE: sizebox.h
+ * PURPOSE: Window procedure of the size boxes
+ * PROGRAMMERS: Benedikt Freisen
+ */
+
+LRESULT CALLBACK SizeboxWinProc (HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
Propchange: trunk/reactos/base/applications/paint/sizebox.h
------------------------------------------------------------------------------
svn:eol-style = native
Modified: trunk/reactos/base/applications/paint/winproc.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/base/applications/paint/wi…
==============================================================================
--- trunk/reactos/base/applications/paint/winproc.c [iso-8859-1] (original)
+++ trunk/reactos/base/applications/paint/winproc.c [iso-8859-1] Thu Jul 2 21:02:37 2009
@@ -197,6 +197,33 @@
SendMessage(hStatusBar, SB_SETPARTS, 3, (int)&test);
MoveWindow(hScrollbox, 56, 49,LOWORD(lParam)-56, HIWORD(lParam)-72,
TRUE);
//InvalidateRect(hwnd, NULL, TRUE);
+ }
+ if (hwnd==hImageArea)
+ {
+ MoveWindow(hSizeboxLeftTop,
+ 0,
+ 0, 3, 3, TRUE);
+ MoveWindow(hSizeboxCenterTop,
+ imgXRes*zoom/2000+3*3/4,
+ 0, 3, 3, TRUE);
+ MoveWindow(hSizeboxRightTop,
+ imgXRes*zoom/1000+3,
+ 0, 3, 3, TRUE);
+ MoveWindow(hSizeboxLeftCenter,
+ 0,
+ imgYRes*zoom/2000+3*3/4, 3, 3, TRUE);
+ MoveWindow(hSizeboxRightCenter,
+ imgXRes*zoom/1000+3,
+ imgYRes*zoom/2000+3*3/4, 3, 3, TRUE);
+ MoveWindow(hSizeboxLeftBottom,
+ 0,
+ imgYRes*zoom/1000+3, 3, 3, TRUE);
+ MoveWindow(hSizeboxCenterBottom,
+ imgXRes*zoom/2000+3*3/4,
+ imgYRes*zoom/1000+3, 3, 3, TRUE);
+ MoveWindow(hSizeboxRightBottom,
+ imgXRes*zoom/1000+3,
+ imgYRes*zoom/1000+3, 3, 3, TRUE);
}
if ((hwnd==hImageArea)||(hwnd==hScrollbox))
{
@@ -287,8 +314,8 @@
long mclient[4];
GetClientRect(hwndMiniature, (LPRECT)&mclient);
HDC hdc = GetDC(hwndMiniature);
- BitBlt(hdc, 0, 0, imgXRes, imgYRes, hDrawingDC,
min(imgXRes*GetScrollPos(hScrollbox, SB_HORZ)/10000, imgXRes-mclient[2]),
- min(imgYRes*GetScrollPos(hScrollbox, SB_VERT)/10000,
imgYRes-mclient[3]), SRCCOPY);
+ BitBlt(hdc, -min(imgXRes*GetScrollPos(hScrollbox, SB_HORZ)/10000,
imgXRes-mclient[2]),
+ -min(imgYRes*GetScrollPos(hScrollbox, SB_VERT)/10000,
imgYRes-mclient[3]), imgXRes, imgYRes, hDrawingDC, 0, 0, SRCCOPY);
ReleaseDC(hwndMiniature, hdc);
}
break;
@@ -591,9 +618,7 @@
int retVal = attributesDlg();
if ((LOWORD(retVal)!=0)&&(HIWORD(retVal)!=0))
{
- // cropReversible broken, dirty hack:
- // insertReversible(CopyImage(hBms[currInd], IMAGE_BITMAP,
LOWORD(retVal), HIWORD(retVal), 0));
- cropReversible(LOWORD(retVal), HIWORD(retVal));
+ cropReversible(LOWORD(retVal), HIWORD(retVal), 0, 0);
updateCanvasAndScrollbars();
}
}