ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

selection.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     PAINT for ReactOS
00003  * LICENSE:     LGPL
00004  * FILE:        base/applications/paint/selection.c
00005  * PURPOSE:     Window procedure of the selection window
00006  * PROGRAMMERS: Benedikt Freisen
00007  */
00008 
00009 /* INCLUDES *********************************************************/
00010 
00011 #include "precomp.h"
00012 
00013 /* FUNCTIONS ********************************************************/
00014 
00015 LPCTSTR cursors[9] = { IDC_SIZEALL, IDC_SIZENWSE, IDC_SIZENS, IDC_SIZENESW,
00016     IDC_SIZEWE, IDC_SIZEWE, IDC_SIZENESW, IDC_SIZENS, IDC_SIZENWSE
00017 };
00018 
00019 BOOL moving = FALSE;
00020 int action = 0;
00021 short xPos;
00022 short yPos;
00023 short xFrac;
00024 short yFrac;
00025 
00026 int
00027 identifyCorner(short x, short y, short w, short h)
00028 {
00029     if (y < 3)
00030     {
00031         if (x < 3)
00032             return 1;
00033         if ((x < w / 2 + 2) && (x >= w / 2 - 1))
00034             return 2;
00035         if (x >= w - 3)
00036             return 3;
00037     }
00038     if ((y < h / 2 + 2) && (y >= h / 2 - 1))
00039     {
00040         if (x < 3)
00041             return 4;
00042         if (x >= w - 3)
00043             return 5;
00044     }
00045     if (y >= h - 3)
00046     {
00047         if (x < 3)
00048             return 6;
00049         if ((x < w / 2 + 2) && (x >= w / 2 - 1))
00050             return 7;
00051         if (x >= w - 3)
00052             return 8;
00053     }
00054     return 0;
00055 }
00056 
00057 LRESULT CALLBACK
00058 SelectionWinProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
00059 {
00060     switch (message)
00061     {
00062         case WM_PAINT:
00063         {
00064             if (!moving)
00065             {
00066                 HDC hDC = GetDC(hwnd);
00067                 DefWindowProc(hwnd, message, wParam, lParam);
00068                 SelectionFrame(hDC, 1, 1, rectSel_dest[2] * zoom / 1000 + 5,
00069                                rectSel_dest[3] * zoom / 1000 + 5);
00070                 ReleaseDC(hwnd, hDC);
00071             }
00072             break;
00073         }
00074         case WM_LBUTTONDOWN:
00075             xPos = LOWORD(lParam);
00076             yPos = HIWORD(lParam);
00077             SetCapture(hwnd);
00078             if (action != 0)
00079                 SetCursor(LoadCursor(NULL, cursors[action]));
00080             moving = TRUE;
00081             break;
00082         case WM_MOUSEMOVE:
00083             if (moving)
00084             {
00085                 TCHAR sizeStr[100];
00086                 int xDelta;
00087                 int yDelta;
00088                 resetToU1();
00089                 xFrac += (short)LOWORD(lParam) - xPos;
00090                 yFrac += (short)HIWORD(lParam) - yPos;
00091                 if (zoom < 1000)
00092                 {
00093                     xDelta = xFrac * 1000 / zoom;
00094                     xFrac = 0;
00095                     yDelta = yFrac * 1000 / zoom;
00096                     yFrac = 0;
00097                 }
00098                 else
00099                 {
00100                     xDelta = xFrac * 1000 / zoom;
00101                     xFrac -= (xFrac * 1000 / zoom) * zoom / 1000;
00102                     yDelta = yFrac * 1000 / zoom;
00103                     yFrac -= (yFrac * 1000 / zoom) * zoom / 1000;
00104                 }
00105                 switch (action)
00106                 {
00107                     case 0:
00108                         rectSel_dest[0] += xDelta;
00109                         rectSel_dest[1] += yDelta;
00110                         break;
00111                     case 1:
00112                         rectSel_dest[0] += xDelta;
00113                         rectSel_dest[1] += yDelta;
00114                         rectSel_dest[2] -= xDelta;
00115                         rectSel_dest[3] -= yDelta;
00116                         break;
00117                     case 2:
00118                         rectSel_dest[1] += yDelta;
00119                         rectSel_dest[3] -= yDelta;
00120                         break;
00121                     case 3:
00122                         rectSel_dest[2] += xDelta;
00123                         rectSel_dest[1] += yDelta;
00124                         break;
00125                     case 4:
00126                         rectSel_dest[0] += xDelta;
00127                         rectSel_dest[2] -= xDelta;
00128                         break;
00129                     case 5:
00130                         rectSel_dest[2] += xDelta;
00131                         break;
00132                     case 6:
00133                         rectSel_dest[0] += xDelta;
00134                         rectSel_dest[2] -= xDelta;
00135                         rectSel_dest[3] += yDelta;
00136                         break;
00137                     case 7:
00138                         rectSel_dest[3] += yDelta;
00139                         break;
00140                     case 8:
00141                         rectSel_dest[2] += xDelta;
00142                         rectSel_dest[3] += yDelta;
00143                         break;
00144                 }
00145 
00146                 _stprintf(sizeStr, _T("%d x %d"), rectSel_dest[2], rectSel_dest[3]);
00147                 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) sizeStr);
00148 
00149                 if (action != 0)
00150                     StretchBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
00151                 else
00152                 if (transpBg == 0)
00153                     MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
00154                             hSelDC, 0, 0, hSelMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
00155                 else
00156                 {
00157                     HBITMAP tempMask;
00158                     HBRUSH oldBrush;
00159                     HDC tempDC;
00160                     tempMask = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL);
00161                     oldBrush = SelectObject(hSelDC, CreateSolidBrush(bgColor));
00162                     tempDC = CreateCompatibleDC(hSelDC);
00163                     SelectObject(tempDC, tempMask);
00164                     MaskBlt(tempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0, hSelMask, 0, 0,
00165                             MAKEROP4(NOTSRCCOPY, BLACKNESS));
00166                     DeleteDC(tempDC);
00167                     DeleteObject(SelectObject(hSelDC, oldBrush));
00168 
00169                     MaskBlt(hDrawingDC, rectSel_dest[0], rectSel_dest[1], rectSel_dest[2], rectSel_dest[3],
00170                             hSelDC, 0, 0, tempMask, 0, 0, MAKEROP4(SRCCOPY, SRCAND));
00171                     DeleteObject(tempMask);
00172                 }
00173                 SendMessage(hImageArea, WM_PAINT, 0, 0);
00174                 xPos = LOWORD(lParam);
00175                 yPos = HIWORD(lParam);
00176                 //SendMessage(hwnd, WM_PAINT, 0, 0);
00177             }
00178             else
00179             {
00180                 int w = rectSel_dest[2] * zoom / 1000 + 6;
00181                 int h = rectSel_dest[3] * zoom / 1000 + 6;
00182                 xPos = LOWORD(lParam);
00183                 yPos = HIWORD(lParam);
00184                 SendMessage(hStatusBar, SB_SETTEXT, 2, (LPARAM) NULL);
00185                 action = identifyCorner(xPos, yPos, w, h);
00186                 if (action != 0)
00187                     SetCursor(LoadCursor(NULL, cursors[action]));
00188             }
00189             break;
00190         case WM_LBUTTONUP:
00191             if (moving)
00192             {
00193                 moving = FALSE;
00194                 ReleaseCapture();
00195                 if (action != 0)
00196                 {
00197                     HDC hTempDC;
00198                     HBITMAP hTempBm;
00199                     hTempDC = CreateCompatibleDC(hSelDC);
00200                     hTempBm = CreateDIBWithProperties(rectSel_dest[2], rectSel_dest[3]);
00201                     SelectObject(hTempDC, hTempBm);
00202                     SelectObject(hSelDC, hSelBm);
00203                     StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0,
00204                                GetDIBWidth(hSelBm), GetDIBHeight(hSelBm), SRCCOPY);
00205                     DeleteObject(hSelBm);
00206                     hSelBm = hTempBm;
00207                     hTempBm = CreateBitmap(rectSel_dest[2], rectSel_dest[3], 1, 1, NULL);
00208                     SelectObject(hTempDC, hTempBm);
00209                     SelectObject(hSelDC, hSelMask);
00210                     StretchBlt(hTempDC, 0, 0, rectSel_dest[2], rectSel_dest[3], hSelDC, 0, 0,
00211                                GetDIBWidth(hSelMask), GetDIBHeight(hSelMask), SRCCOPY);
00212                     DeleteObject(hSelMask);
00213                     hSelMask = hTempBm;
00214                     SelectObject(hSelDC, hSelBm);
00215                     DeleteDC(hTempDC);
00216                 }
00217                 placeSelWin();
00218                 ShowWindow(hSelection, SW_HIDE);
00219                 ShowWindow(hSelection, SW_SHOW);
00220             }
00221             break;
00222         default:
00223             return DefWindowProc(hwnd, message, wParam, lParam);
00224     }
00225 
00226     return 0;
00227 }

Generated on Sat May 26 2012 04:16:04 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.