]> git.saurik.com Git - wxWidgets.git/blobdiff - samples/shaped/shaped.cpp
Fixed mismatch in amount of format specifiers in Japanese translation for i18n sample.
[wxWidgets.git] / samples / shaped / shaped.cpp
index 9ebf3e697c74fb3ed4e4e02c047eb545a16172eb..9b05903463163b08954b8f1ad95c5afff270f378 100644 (file)
 #endif
 
 #include "wx/dcclient.h"
+#include "wx/graphics.h"
 #include "wx/image.h"
 
+#ifndef __WXMSW__
+    #include "../sample.xpm"
+#endif
 
 // ----------------------------------------------------------------------------
 // constants
@@ -88,6 +92,7 @@ private:
     void OnShowShaped(wxCommandEvent& event);
     void OnShowTransparent(wxCommandEvent& event);
     void OnShowEffect(wxCommandEvent& event);
+    void OnExit(wxCommandEvent& event);
 
     DECLARE_EVENT_TABLE()
 };
@@ -110,7 +115,16 @@ public:
     void OnPaint(wxPaintEvent& evt);
 
 private:
-    bool     m_hasShape;
+    enum ShapeKind
+    {
+        Shape_None,
+        Shape_Star,
+#if wxUSE_GRAPHICS_CONTEXT
+        Shape_Circle,
+#endif // wxUSE_GRAPHICS_CONTEXT
+        Shape_Max
+    } m_shapeKind;
+
     wxBitmap m_bmp;
     wxPoint  m_delta;
 
@@ -178,6 +192,7 @@ private:
     {
         static const char *names[] =
         {
+            "none",
             "roll to left",
             "roll to right",
             "roll to top",
@@ -240,12 +255,15 @@ BEGIN_EVENT_TABLE(MainFrame, wxFrame)
     EVT_MENU(Show_Shaped, MainFrame::OnShowShaped)
     EVT_MENU(Show_Transparent, MainFrame::OnShowTransparent)
     EVT_MENU_RANGE(Show_Effect_First, Show_Effect_Last, MainFrame::OnShowEffect)
+    EVT_MENU(wxID_EXIT, MainFrame::OnExit)
 END_EVENT_TABLE()
 
 MainFrame::MainFrame()
          : wxFrame(NULL, wxID_ANY, "wxWidgets Shaped Sample",
                    wxDefaultPosition, wxSize(200, 100))
 {
+    SetIcon(wxICON(sample));
+
     wxMenuBar * const mbar = new wxMenuBar;
     wxMenu * const menuFrames = new wxMenu;
     menuFrames->Append(Show_Shaped, "Show &shaped window\tCtrl-S");
@@ -341,7 +359,12 @@ void MainFrame::OnShowEffect(wxCommandEvent& event)
             return;
     }
 
-    new EffectFrame(this, eff,1000);
+    new EffectFrame(this,  eff, 1000);
+}
+
+void MainFrame::OnExit(wxCommandEvent& WXUNUSED(event))
+{
+    Close();
 }
 
 // ----------------------------------------------------------------------------
@@ -369,29 +392,46 @@ ShapedFrame::ShapedFrame(wxFrame *parent)
                   | wxSTAY_ON_TOP
             )
 {
-    m_hasShape = false;
-    m_bmp = wxBitmap(_T("star.png"), wxBITMAP_TYPE_PNG);
+    m_shapeKind = Shape_None;
+    m_bmp = wxBitmap(wxT("star.png"), wxBITMAP_TYPE_PNG);
     SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
-    SetToolTip(wxT("Right-click to close"));
+    SetToolTip(wxT("Right-click to close, double click to cycle shape"));
     SetWindowShape();
 }
 
 void ShapedFrame::SetWindowShape()
 {
-    wxRegion region(m_bmp, *wxWHITE);
-    m_hasShape = SetShape(region);
+    switch ( m_shapeKind )
+    {
+        case Shape_None:
+            SetShape(wxRegion());
+            break;
+
+        case Shape_Star:
+            SetShape(wxRegion(m_bmp, *wxWHITE));
+            break;
+
+#if wxUSE_GRAPHICS_CONTEXT
+        case Shape_Circle:
+            {
+                wxGraphicsPath
+                    path = wxGraphicsRenderer::GetDefaultRenderer()->CreatePath();
+                path.AddCircle(m_bmp.GetWidth()/2, m_bmp.GetHeight()/2, 30);
+                SetShape(path);
+            }
+            break;
+#endif // wxUSE_GRAPHICS_CONTEXT
+
+        case Shape_Max:
+            wxFAIL_MSG( "invalid shape kind" );
+            break;
+    }
 }
 
 void ShapedFrame::OnDoubleClick(wxMouseEvent& WXUNUSED(evt))
 {
-    if (m_hasShape)
-    {
-        wxRegion region;
-        SetShape(region);
-        m_hasShape = false;
-    }
-    else
-        SetWindowShape();
+    m_shapeKind = static_cast<ShapeKind>((m_shapeKind + 1) % Shape_Max);
+    SetWindowShape();
 }
 
 void ShapedFrame::OnLeftDown(wxMouseEvent& evt)