Fixed cropping function and implemented size boxes
authorBenedikt Freisen <b.freisen@gmx.net>
Thu, 2 Jul 2009 17:02:37 +0000 (17:02 +0000)
committerBenedikt Freisen <b.freisen@gmx.net>
Thu, 2 Jul 2009 17:02:37 +0000 (17:02 +0000)
svn path=/trunk/; revision=41742

reactos/base/applications/paint/globalvar.h
reactos/base/applications/paint/history.c
reactos/base/applications/paint/history.h
reactos/base/applications/paint/main.c
reactos/base/applications/paint/paint.rbuild
reactos/base/applications/paint/sizebox.c [new file with mode: 0644]
reactos/base/applications/paint/sizebox.h [new file with mode: 0644]
reactos/base/applications/paint/winproc.c

index 1641af5..a0df72f 100644 (file)
@@ -76,3 +76,12 @@ extern BOOL showGrid;
 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;
index b0eb560..a0f434a 100644 (file)
@@ -91,27 +91,30 @@ void insertReversible(HBITMAP hbm)
     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);
 }
index 39be55e..b0733e9 100644 (file)
@@ -18,4 +18,4 @@ void clearHistory();
 
 void insertReversible();
 
-void cropReversible(int x, int y);
+void cropReversible(int width, int height, int xOffset, int yOffset);
index 0a8e7eb..d9fa7b3 100644 (file)
@@ -26,6 +26,7 @@
 #include "palette.h"
 #include "toolsettings.h"
 #include "selection.h"
+#include "sizebox.h"
 
 /* FUNCTIONS ********************************************************/
 
@@ -107,6 +108,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)
 {
     HWND hwnd;               /* This is the handle for our window */
@@ -217,6 +227,21 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     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 @@ int WINAPI _tWinMain (HINSTANCE hThisInstance, HINSTANCE hPrevInstance, LPTSTR l
     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);
index 3c48bf8..3087df4 100644 (file)
@@ -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>
diff --git a/reactos/base/applications/paint/sizebox.c b/reactos/base/applications/paint/sizebox.c
new file mode 100644 (file)
index 0000000..8324123
--- /dev/null
@@ -0,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;
+}
diff --git a/reactos/base/applications/paint/sizebox.h b/reactos/base/applications/paint/sizebox.h
new file mode 100644 (file)
index 0000000..6329484
--- /dev/null
@@ -0,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);
index b9873e9..0160bf6 100644 (file)
@@ -198,6 +198,33 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                 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))
             {
                 long clientRectScrollbox[4];
@@ -287,8 +314,8 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                 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 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM
                         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();
                         }
                     }