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

drawing.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:     PAINT for ReactOS
00003  * LICENSE:     LGPL
00004  * FILE:        base/applications/paint/drawing.c
00005  * PURPOSE:     The drawing functions used by the tools
00006  * PROGRAMMERS: Benedikt Freisen
00007  */
00008 
00009 /* INCLUDES *********************************************************/
00010 
00011 #include "precomp.h"
00012 
00013 /* FUNCTIONS ********************************************************/
00014 
00015 void
00016 Line(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, int thickness)
00017 {
00018     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, color));
00019     MoveToEx(hdc, x1, y1, NULL);
00020     LineTo(hdc, x2, y2);
00021     DeleteObject(SelectObject(hdc, oldPen));
00022 }
00023 
00024 void
00025 Rect(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg,  COLORREF bg, int thickness, int style)
00026 {
00027     HBRUSH oldBrush;
00028     LOGBRUSH logbrush;
00029     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
00030     logbrush.lbStyle = (style == 0) ? BS_HOLLOW : BS_SOLID;
00031     logbrush.lbColor = (style == 2) ? fg : bg;
00032     logbrush.lbHatch = 0;
00033     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00034     Rectangle(hdc, x1, y1, x2, y2);
00035     DeleteObject(SelectObject(hdc, oldBrush));
00036     DeleteObject(SelectObject(hdc, oldPen));
00037 }
00038 
00039 void
00040 Ellp(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg,  COLORREF bg, int thickness, int style)
00041 {
00042     HBRUSH oldBrush;
00043     LOGBRUSH logbrush;
00044     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
00045     logbrush.lbStyle = (style == 0) ? BS_HOLLOW : BS_SOLID;
00046     logbrush.lbColor = (style == 2) ? fg : bg;
00047     logbrush.lbHatch = 0;
00048     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00049     Ellipse(hdc, x1, y1, x2, y2);
00050     DeleteObject(SelectObject(hdc, oldBrush));
00051     DeleteObject(SelectObject(hdc, oldPen));
00052 }
00053 
00054 void
00055 RRect(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg,  COLORREF bg, int thickness, int style)
00056 {
00057     LOGBRUSH logbrush;
00058     HBRUSH oldBrush;
00059     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
00060     logbrush.lbStyle = (style == 0) ? BS_HOLLOW : BS_SOLID;
00061     logbrush.lbColor = (style == 2) ? fg : bg;
00062     logbrush.lbHatch = 0;
00063     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00064     RoundRect(hdc, x1, y1, x2, y2, 16, 16);
00065     DeleteObject(SelectObject(hdc, oldBrush));
00066     DeleteObject(SelectObject(hdc, oldPen));
00067 }
00068 
00069 void
00070 Poly(HDC hdc, POINT * lpPoints, int nCount,  COLORREF fg,  COLORREF bg, int thickness, int style, BOOL closed)
00071 {
00072     LOGBRUSH logbrush;
00073     HBRUSH oldBrush;
00074     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, fg));
00075     logbrush.lbStyle = (style == 0) ? BS_HOLLOW : BS_SOLID;
00076     logbrush.lbColor = (style == 2) ? fg : bg;
00077     logbrush.lbHatch = 0;
00078     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00079     if (closed)
00080         Polygon(hdc, lpPoints, nCount);
00081     else
00082         Polyline(hdc, lpPoints, nCount);
00083     DeleteObject(SelectObject(hdc, oldBrush));
00084     DeleteObject(SelectObject(hdc, oldPen));
00085 }
00086 
00087 void
00088 Bezier(HDC hdc, POINT p1, POINT p2, POINT p3, POINT p4, COLORREF color, int thickness)
00089 {
00090     HPEN oldPen;
00091     POINT fourPoints[4];
00092     fourPoints[0] = p1;
00093     fourPoints[1] = p2;
00094     fourPoints[2] = p3;
00095     fourPoints[3] = p4;
00096     oldPen = SelectObject(hdc, CreatePen(PS_SOLID, thickness, color));
00097     PolyBezier(hdc, fourPoints, 4);
00098     DeleteObject(SelectObject(hdc, oldPen));
00099 }
00100 
00101 void
00102 Fill(HDC hdc, LONG x, LONG y, COLORREF color)
00103 {
00104     HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
00105     ExtFloodFill(hdc, x, y, GetPixel(hdc, x, y), FLOODFILLSURFACE);
00106     DeleteObject(SelectObject(hdc, oldBrush));
00107 }
00108 
00109 void
00110 Erase(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, LONG radius)
00111 {
00112     short a;
00113     HPEN oldPen;
00114     HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
00115     oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
00116     for(a = 0; a <= 100; a++)
00117         Rectangle(hdc, (x1 * (100 - a) + x2 * a) / 100 - radius + 1,
00118                   (y1 * (100 - a) + y2 * a) / 100 - radius + 1, (x1 * (100 - a) + x2 * a) / 100 + radius + 1,
00119                   (y1 * (100 - a) + y2 * a) / 100 + radius + 1);
00120     DeleteObject(SelectObject(hdc, oldBrush));
00121     DeleteObject(SelectObject(hdc, oldPen));
00122 }
00123 
00124 void
00125 Replace(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF fg, COLORREF bg, LONG radius)
00126 {
00127     LONG a, x, y;
00128     
00129     for(a = 0; a <= 100; a++)
00130         for(y = (y1 * (100 - a) + y2 * a) / 100 - radius + 1;
00131             y < (y1 * (100 - a) + y2 * a) / 100 + radius + 1; y++)
00132             for(x = (x1 * (100 - a) + x2 * a) / 100 - radius + 1;
00133                 x < (x1 * (100 - a) + x2 * a) / 100 + radius + 1; x++)
00134                 if (GetPixel(hdc, x, y) == fg)
00135                     SetPixel(hdc, x, y, bg);
00136 }
00137 
00138 void
00139 Airbrush(HDC hdc, LONG x, LONG y, COLORREF color, LONG r)
00140 {
00141     LONG a, b;
00142     
00143     for(b = -r; b <= r; b++)
00144         for(a = -r; a <= r; a++)
00145             if ((a * a + b * b <= r * r) && (rand() % 4 == 0))
00146                 SetPixel(hdc, x + a, y + b, color);
00147 }
00148 
00149 void
00150 Brush(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2, COLORREF color, COLORREF style)
00151 {
00152     HPEN oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, color));
00153     HBRUSH oldBrush = SelectObject(hdc, CreateSolidBrush(color));
00154     short a;
00155     switch (style)
00156     {
00157         case 0:
00158             for(a = 0; a <= 100; a++)
00159                 Ellipse(hdc, (x1 * (100 - a) + x2 * a) / 100 - 3, (y1 * (100 - a) + y2 * a) / 100 - 3,
00160                         (x1 * (100 - a) + x2 * a) / 100 + 4, (y1 * (100 - a) + y2 * a) / 100 + 4);
00161             break;
00162         case 1:
00163             for(a = 0; a <= 100; a++)
00164                 Ellipse(hdc, (x1 * (100 - a) + x2 * a) / 100 - 1, (y1 * (100 - a) + y2 * a) / 100 - 1,
00165                         (x1 * (100 - a) + x2 * a) / 100 + 3, (y1 * (100 - a) + y2 * a) / 100 + 3);
00166             break;
00167         case 2:
00168             MoveToEx(hdc, x1, y1, NULL);
00169             LineTo(hdc, x2, y2);
00170             SetPixel(hdc, x2, y2, color);
00171             break;
00172         case 3:
00173             for(a = 0; a <= 100; a++)
00174                 Rectangle(hdc, (x1 * (100 - a) + x2 * a) / 100 - 3, (y1 * (100 - a) + y2 * a) / 100 - 3,
00175                           (x1 * (100 - a) + x2 * a) / 100 + 5, (y1 * (100 - a) + y2 * a) / 100 + 5);
00176             break;
00177         case 4:
00178             for(a = 0; a <= 100; a++)
00179                 Rectangle(hdc, (x1 * (100 - a) + x2 * a) / 100 - 2, (y1 * (100 - a) + y2 * a) / 100 - 2,
00180                           (x1 * (100 - a) + x2 * a) / 100 + 3, (y1 * (100 - a) + y2 * a) / 100 + 3);
00181             break;
00182         case 5:
00183             for(a = 0; a <= 100; a++)
00184                 Rectangle(hdc, (x1 * (100 - a) + x2 * a) / 100 - 1, (y1 * (100 - a) + y2 * a) / 100 - 1,
00185                           (x1 * (100 - a) + x2 * a) / 100 + 1, (y1 * (100 - a) + y2 * a) / 100 + 1);
00186             break;
00187         case 6:
00188             for(a = 0; a <= 100; a++)
00189             {
00190                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 3, (y1 * (100 - a) + y2 * a) / 100 + 5, NULL);
00191                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 5, (y1 * (100 - a) + y2 * a) / 100 - 3);
00192             }
00193             break;
00194         case 7:
00195             for(a = 0; a <= 100; a++)
00196             {
00197                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 2, (y1 * (100 - a) + y2 * a) / 100 + 3, NULL);
00198                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 3, (y1 * (100 - a) + y2 * a) / 100 - 2);
00199             }
00200             break;
00201         case 8:
00202             for(a = 0; a <= 100; a++)
00203             {
00204                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 1, (y1 * (100 - a) + y2 * a) / 100 + 1, NULL);
00205                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 1, (y1 * (100 - a) + y2 * a) / 100 - 1);
00206             }
00207             break;
00208         case 9:
00209             for(a = 0; a <= 100; a++)
00210             {
00211                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 3, (y1 * (100 - a) + y2 * a) / 100 - 3, NULL);
00212                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 5, (y1 * (100 - a) + y2 * a) / 100 + 5);
00213             }
00214             break;
00215         case 10:
00216             for(a = 0; a <= 100; a++)
00217             {
00218                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 2, (y1 * (100 - a) + y2 * a) / 100 - 2, NULL);
00219                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 3, (y1 * (100 - a) + y2 * a) / 100 + 3);
00220             }
00221             break;
00222         case 11:
00223             for(a = 0; a <= 100; a++)
00224             {
00225                 MoveToEx(hdc, (x1 * (100 - a) + x2 * a) / 100 - 1, (y1 * (100 - a) + y2 * a) / 100 - 1, NULL);
00226                 LineTo(hdc, (x1 * (100 - a) + x2 * a) / 100 + 1, (y1 * (100 - a) + y2 * a) / 100 + 1);
00227             }
00228             break;
00229     }
00230     DeleteObject(SelectObject(hdc, oldBrush));
00231     DeleteObject(SelectObject(hdc, oldPen));
00232 }
00233 
00234 void
00235 RectSel(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
00236 {
00237     HBRUSH oldBrush;
00238     LOGBRUSH logbrush;
00239     HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
00240     logbrush.lbStyle = BS_HOLLOW;
00241     logbrush.lbColor = 0;
00242     logbrush.lbHatch = 0;
00243     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00244     Rectangle(hdc, x1, y1, x2, y2);
00245     DeleteObject(SelectObject(hdc, oldBrush));
00246     DeleteObject(SelectObject(hdc, oldPen));
00247 }
00248 
00249 void
00250 SelectionFrame(HDC hdc, LONG x1, LONG y1, LONG x2, LONG y2)
00251 {
00252     HBRUSH oldBrush;
00253     LOGBRUSH logbrush;
00254     HPEN oldPen = SelectObject(hdc, CreatePen(PS_DOT, 1, 0x00000000));
00255     logbrush.lbStyle = BS_HOLLOW;
00256     logbrush.lbColor = 0;
00257     logbrush.lbHatch = 0;
00258     oldBrush = SelectObject(hdc, CreateBrushIndirect(&logbrush));
00259     Rectangle(hdc, x1, y1, x2, y2);
00260     DeleteObject(SelectObject(hdc, oldBrush));
00261     DeleteObject(SelectObject(hdc, oldPen));
00262     oldPen = SelectObject(hdc, CreatePen(PS_SOLID, 1, 0x00000000));
00263     oldBrush = SelectObject(hdc, CreateSolidBrush(0x00000000));
00264     Rectangle(hdc, x1 - 1, y1 - 1, x1 + 2, y1 + 2);
00265     Rectangle(hdc, x2 - 2, y1 - 1, x2 + 2, y1 + 2);
00266     Rectangle(hdc, x1 - 1, y2 - 2, x1 + 2, y2 + 1);
00267     Rectangle(hdc, x2 - 2, y2 - 2, x2 + 2, y2 + 1);
00268     Rectangle(hdc, (x1 + x2) / 2 - 1, y1 - 1, (x1 + x2) / 2 + 2, y1 + 2);
00269     Rectangle(hdc, (x1 + x2) / 2 - 1, y2 - 2, (x1 + x2) / 2 + 2, y2 + 1);
00270     Rectangle(hdc, x1 - 1, (y1 + y2) / 2 - 1, x1 + 2, (y1 + y2) / 2 + 2);
00271     Rectangle(hdc, x2 - 2, (y1 + y2) / 2 - 1, x2 + 1, (y1 + y2) / 2 + 2);
00272     DeleteObject(SelectObject(hdc, oldBrush));
00273     DeleteObject(SelectObject(hdc, oldPen));
00274 }

Generated on Sun May 27 2012 04:17: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.