]> git.saurik.com Git - wxWidgets.git/commitdiff
added and documented wxDC::DrawCheckMark()
authorVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Feb 2000 12:53:36 +0000 (12:53 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Thu, 17 Feb 2000 12:53:36 +0000 (12:53 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@6109 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

docs/latex/wx/dc.tex
include/wx/dc.h
include/wx/gtk/dcclient.h
include/wx/gtk1/dcclient.h
include/wx/msw/dc.h
samples/drawing/drawing.cpp
src/common/dcbase.cpp
src/msw/dc.cpp

index b704196331a39ef09cc181f11ee526751c0bf8a9..ea39bed045db97f67da969b2d941d049d55eb82e 100644 (file)
@@ -179,6 +179,14 @@ of the bitmap (all bits set to 1), and the current text background colour to dra
 (all bits set to 0). See also \helpref{SetTextForeground}{wxdcsettextforeground},
 \helpref{SetTextBackground}{wxdcsettextbackground} and \helpref{wxMemoryDC}{wxmemorydc}.
 
+\membersection{wxDC::DrawCheckMark}\label{wxdcdrawcheckmark}
+
+\func{void}{DrawCheckMark}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}}
+
+\func{void}{DrawCheckMark}{\param{const wxRect \&}{rect}}
+
+Draws a check mark inside the given rectangle.
+
 \membersection{wxDC::DrawEllipse}\label{wxdcdrawellipse}
 
 \func{void}{DrawEllipse}{\param{wxCoord}{ x}, \param{wxCoord}{ y}, \param{wxCoord}{ width}, \param{wxCoord}{ height}}
index b49bbaacca9bc47ac14f6cca600af7529d6034b0..1c2ddf548f16799820a99601f0e32d8eb120cf19 100644 (file)
@@ -43,8 +43,6 @@ WXDLLEXPORT_DATA(extern int) wxPageNumber;
 
 class WXDLLEXPORT wxDCBase : public wxObject
 {
-    DECLARE_ABSTRACT_CLASS(wxDCBase)
-
 public:
     wxDCBase()
     {
@@ -112,6 +110,12 @@ public:
     void DrawArc(const wxPoint& pt1, const wxPoint& pt2, const wxPoint& centre)
         { DoDrawArc(pt1.x, pt1.y, pt2.x, pt2.y, centre.x, centre.y); }
 
+    void DrawCheckMark(wxCoord x, wxCoord y,
+                       wxCoord width, wxCoord height)
+        { DoDrawCheckMark(x, y, width, height); }
+    void DrawCheckMark(const wxRect& rect)
+        { DoDrawCheckMark(rect.x, rect.y, rect.width, rect.height); }
+
     void DrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                          double sa, double ea)
         { DoDrawEllipticArc(x, y, w, h, sa, ea); }
@@ -261,7 +265,7 @@ public:
 
     virtual wxCoord GetCharHeight() const = 0;
     virtual wxCoord GetCharWidth() const = 0;
-    
+
     void GetTextExtent(const wxString& string,
                        wxCoord *x, wxCoord *y,
                        wxCoord *descent = NULL,
@@ -453,13 +457,13 @@ public:
             *y = y2;
     }
     void GetClippingBox(long *x, long *y, long *w, long *h) const
-    { 
-       wxCoord xx,yy,ww,hh;
-       DoGetClippingBox(&xx, &yy, &ww, &hh);
-       if (x) *x = xx;
-       if (y) *y = yy;
-       if (w) *w = ww;
-       if (h) *h = hh;
+    {
+        wxCoord xx,yy,ww,hh;
+        DoGetClippingBox(&xx, &yy, &ww, &hh);
+        if (x) *x = xx;
+        if (y) *y = yy;
+        if (w) *w = ww;
+        if (h) *h = hh;
     }
 #endif // !Win16
 
@@ -485,6 +489,8 @@ protected:
     virtual void DoDrawArc(wxCoord x1, wxCoord y1,
                            wxCoord x2, wxCoord y2,
                            wxCoord xc, wxCoord yc) = 0;
+    virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
+                                 wxCoord width, wxCoord height);
     virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                                    double sa, double ea) = 0;
 
@@ -605,6 +611,7 @@ protected:
 
 private:
     DECLARE_NO_COPY_CLASS(wxDCBase);
+    DECLARE_ABSTRACT_CLASS(wxDCBase)
 };
 
 // ----------------------------------------------------------------------------
index 0142e694c7297c2b1721a93b138b6660b6eb4fa1..acc3896336f08abe1b31f41b686d13bab9b99771 100644 (file)
@@ -40,6 +40,7 @@ public:
     virtual bool CanDrawBitmap() const { return TRUE; }
     virtual bool CanGetTextExtent() const { return TRUE; }
 
+//protected:
     virtual void DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, int style=wxFLOOD_SURFACE );
     virtual bool DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const;
 
@@ -121,7 +122,7 @@ public:
     void ComputeScaleAndOrigin();
 
     GdkWindow *GetWindow() { return m_window; }
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxWindowDC)
 };
@@ -135,7 +136,7 @@ class wxPaintDC : public wxWindowDC
 public:
     wxPaintDC();
     wxPaintDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxPaintDC)
 };
@@ -149,7 +150,7 @@ class wxClientDC : public wxWindowDC
 public:
     wxClientDC();
     wxClientDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxClientDC)
 };
index 0142e694c7297c2b1721a93b138b6660b6eb4fa1..acc3896336f08abe1b31f41b686d13bab9b99771 100644 (file)
@@ -40,6 +40,7 @@ public:
     virtual bool CanDrawBitmap() const { return TRUE; }
     virtual bool CanGetTextExtent() const { return TRUE; }
 
+//protected:
     virtual void DoFloodFill( wxCoord x, wxCoord y, const wxColour& col, int style=wxFLOOD_SURFACE );
     virtual bool DoGetPixel( wxCoord x1, wxCoord y1, wxColour *col ) const;
 
@@ -121,7 +122,7 @@ public:
     void ComputeScaleAndOrigin();
 
     GdkWindow *GetWindow() { return m_window; }
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxWindowDC)
 };
@@ -135,7 +136,7 @@ class wxPaintDC : public wxWindowDC
 public:
     wxPaintDC();
     wxPaintDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxPaintDC)
 };
@@ -149,7 +150,7 @@ class wxClientDC : public wxWindowDC
 public:
     wxClientDC();
     wxClientDC( wxWindow *win );
-    
+
 private:
     DECLARE_DYNAMIC_CLASS(wxClientDC)
 };
index d9479093ea593ba06460f7eb889070fe98c8a602..2bf3643789f51b432b70850f50588608a186bf79 100644 (file)
@@ -153,6 +153,8 @@ protected:
     virtual void DoDrawArc(wxCoord x1, wxCoord y1,
                            wxCoord x2, wxCoord y2,
                            wxCoord xc, wxCoord yc);
+    virtual void DoDrawCheckMark(wxCoord x, wxCoord y,
+                                 wxCoord width, wxCoord height);
     virtual void DoDrawEllipticArc(wxCoord x, wxCoord y, wxCoord w, wxCoord h,
                                    double sa, double ea);
 
index 47a069d5d0d229141c50ca5b08ac5a32a190772c..06f587a9a33809a2a5656efe93d12643e7dbff91 100644 (file)
@@ -574,22 +574,31 @@ void MyCanvas::DrawDefault(wxDC& dc)
 
     dc.DrawIcon( wxICON(mondrian), 40, 40 );
 
+    dc.DrawCheckMark(5, 80, 15, 15);
+    dc.DrawCheckMark(25, 80, 30, 30);
+    dc.DrawCheckMark(60, 80, 60, 60);
+
     // this is the test for "blitting bitmap into DC damages selected brush"
     // bug
+    wxIcon icon = wxTheApp->GetStdIcon(wxICON_INFORMATION);
+    wxCoord rectSize = icon.GetWidth() + 10;
+    wxCoord x = 100;
     dc.SetPen(*wxTRANSPARENT_PEN);
     dc.SetBrush( *wxGREEN_BRUSH );
-    dc.DrawRectangle(100, 10, 40, 40);
-    dc.DrawBitmap(wxTheApp->GetStdIcon(wxICON_INFORMATION), 102, 12, TRUE);
-    dc.DrawRectangle(150, 10, 40, 40);
-    dc.DrawIcon(wxTheApp->GetStdIcon(wxICON_INFORMATION), 152, 12);
-    dc.DrawRectangle(200, 10, 40, 40);
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
+    dc.DrawBitmap(icon, x + 5, 15, TRUE);
+    x += rectSize + 10;
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
+    dc.DrawIcon(wxTheApp->GetStdIcon(wxICON_INFORMATION), x + 5, 15);
+    x += rectSize + 10;
+    dc.DrawRectangle(x, 10, rectSize, rectSize);
 
     // test for "transparent" bitmap drawing (it intersects with the last
     // rectangle above)
     //dc.SetBrush( *wxTRANSPARENT_BRUSH );
     #include "../image/smile.xpm"
     wxBitmap bmp(smile_xpm);
-    dc.DrawBitmap(bmp, 210, 30, TRUE);
+    dc.DrawBitmap(bmp, x + rectSize - 20, rectSize - 10, TRUE);
 
     dc.SetBrush( *wxBLACK_BRUSH );
     dc.DrawRectangle( 0, 160, 1000, 300 );
@@ -722,9 +731,9 @@ void MyCanvas::DrawDefault(wxDC& dc)
 
     memdc2.DrawRectangle(0, 0, totalWidth, totalHeight);
 
-    memdc2.SelectObject(wxNullBitmap);
     memdc2.SetPen(wxNullPen);
     memdc2.SetBrush(wxNullBrush);
+    memdc2.SelectObject(wxNullBitmap);
 
     dc.DrawBitmap(bitmap2, 500, 270);
 }
index a95db6adcca844f52bf34685f1a06fd72ace51a3..e625e91d072de0ad739c22b1a26ccce09eba6a75 100644 (file)
 
 #include "wx/dc.h"
 
+void wxDCBase::DoDrawCheckMark(wxCoord x1, wxCoord y1,
+                               wxCoord width, wxCoord height)
+{
+    wxCHECK_RET( Ok(), wxT("invalid window dc") );
+
+    wxCoord x2 = x1 + width,
+            y2 = y1 + height;
+
+    // this is to yield width of 3 for width == height == 10
+    SetPen(wxPen(GetTextForeground(), (width + height + 1) / 7, wxSOLID));
+
+    // we're drawing a scaled version of wx/generic/tick.xpm here
+    wxCoord x3 = x1 + (4*width) / 10,   // x of the tick bottom
+            y3 = y1 + height / 2;       // y of the left tick branch
+    DoDrawLine(x1, y3, x3, y2);
+    DoDrawLine(x3, y2, x2, y1);
+
+    CalcBoundingBox(x1, y1);
+    CalcBoundingBox(x2, y2);
+}
+
 void wxDCBase::DrawLines(const wxList *list, wxCoord xoffset, wxCoord yoffset)
 {
     int n = list->Number();
index a3bbadbeec809d9ffc81343e160b33f96d8be9d6..f339b4dafe12aab7a8b210d7885d80808b4a8c42 100644 (file)
@@ -409,6 +409,41 @@ void wxDC::DoDrawArc(wxCoord x1,wxCoord y1,wxCoord x2,wxCoord y2, wxCoord xc, wx
     CalcBoundingBox((wxCoord)(xc+radius), (wxCoord)(yc+radius));
 }
 
+void wxDC::DoDrawCheckMark(wxCoord x1, wxCoord y1,
+                           wxCoord width, wxCoord height)
+{
+    wxCoord x2 = x1 + width,
+            y2 = y1 + height;
+
+#if defined(__WIN32__) && !defined(__SC__)
+    RECT rect;
+    rect.left   = x1;
+    rect.top    = y1;
+    rect.right  = x2;
+    rect.bottom = y2;
+
+    DrawFrameControl(GetHdc(), &rect, DFC_MENU, DFCS_MENUCHECK);
+#else // Win16
+    // In WIN16, draw a cross
+    HPEN blackPen = ::CreatePen(PS_SOLID, 1, RGB(0, 0, 0));
+    HPEN whiteBrush = (HPEN)::GetStockObject(WHITE_BRUSH);
+    HPEN hPenOld = (HPEN)::SelectObject(hdcMem, blackPen);
+    HPEN hBrushOld = (HPEN)::SelectObject(hdcMem, whiteBrush);
+    ::SetROP2(GetHdc(), R2_COPYPEN);
+    Rectangle(GetHdc(), x1, y1, x2, y2);
+    MoveTo(GetHdc(), x1, y1);
+    LineTo(GetHdc(), x2, y2);
+    MoveTo(GetHdc(), x2, y1);
+    LineTo(GetHdc(), x1, y2);
+    ::SelectObject(GetHdc(), hPenOld);
+    ::SelectObject(GetHdc(), hBrushOld);
+    ::DeleteObject(blackPen);
+#endif // Win32/16
+
+    CalcBoundingBox(x1, y1);
+    CalcBoundingBox(x2, y2);
+}
+
 void wxDC::DoDrawPoint(wxCoord x, wxCoord y)
 {
     COLORREF color = 0x00ffffff;