]> git.saurik.com Git - wxWidgets.git/commitdiff
Added a simple example of semi-transparent window to the erase sample.
authorVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Mar 2011 22:33:25 +0000 (22:33 +0000)
committerVadim Zeitlin <vadim@wxwidgets.org>
Sun, 20 Mar 2011 22:33:25 +0000 (22:33 +0000)
Show how to create a custom control with transparent background.

Notice that this doesn't work in wxGTK currently.

git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@67267 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

samples/erase/erase.cpp

index 554c989f2a9daffadfae0607be6e55e1db5997d3..138b3fa2bc328cd8dfa58259d61763aa20ee35a1 100644 (file)
@@ -139,6 +139,34 @@ private:
     DECLARE_EVENT_TABLE()
 };
 
+class ControlWithTransparency : public wxWindow
+{
+public:
+    ControlWithTransparency(wxWindow *parent,
+                            const wxPoint& pos,
+                            const wxSize& size)
+        : wxWindow(parent, wxID_ANY, pos, size, wxBORDER_NONE)
+    {
+        Connect(wxEVT_PAINT,
+                wxPaintEventHandler(ControlWithTransparency::OnPaint));
+    }
+
+    virtual bool HasTransparentBackground() { return true; }
+
+private:
+    void OnPaint( wxPaintEvent& WXUNUSED(event) )
+    {
+        wxPaintDC dc(this);
+
+        dc.SetPen(*wxRED_PEN);
+        dc.SetBrush(*wxTRANSPARENT_BRUSH);
+        dc.DrawRectangle(GetClientSize());
+
+        dc.SetTextForeground(*wxBLUE);
+        dc.SetBackgroundMode(wxTRANSPARENT);
+        dc.DrawText("This is custom control with transparency", 0, 2);
+    }
+};
 
 // ----------------------------------------------------------------------------
 // constants
@@ -299,6 +327,8 @@ MyCanvas::MyCanvas(wxFrame *parent)
                      "right one drawn directly",
                      wxPoint(150, 20));
 
+    new ControlWithTransparency(this, wxPoint(65, 125), wxSize(300, 22));
+
     SetFocusIgnoringChildren();
     SetBackgroundColour(*wxCYAN);
 }