2003-03-28 23:05:05 +00:00
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Name: shaped.cpp
|
|
|
|
// Purpose: Shaped Window sample
|
|
|
|
// Author: Robin Dunn
|
|
|
|
// Modified by:
|
|
|
|
// Created: 28-Mar-2003
|
|
|
|
// Copyright: (c) Robin Dunn
|
|
|
|
// Licence: wxWindows licence
|
|
|
|
/////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
// ============================================================================
|
|
|
|
// declarations
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// headers
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// For compilers that support precompilation, includes "wx/wx.h".
|
|
|
|
#include "wx/wxprec.h"
|
|
|
|
|
|
|
|
#ifdef __BORLANDC__
|
|
|
|
#pragma hdrstop
|
|
|
|
#endif
|
|
|
|
|
|
|
|
// for all others, include the necessary headers
|
|
|
|
#ifndef WX_PRECOMP
|
|
|
|
#include "wx/app.h"
|
|
|
|
#include "wx/log.h"
|
|
|
|
#include "wx/frame.h"
|
|
|
|
#include "wx/panel.h"
|
|
|
|
#include "wx/stattext.h"
|
|
|
|
#include "wx/menu.h"
|
|
|
|
#include "wx/layout.h"
|
|
|
|
#include "wx/msgdlg.h"
|
2003-04-30 00:39:15 +00:00
|
|
|
#include "wx/image.h"
|
2003-03-28 23:05:05 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "wx/dcclient.h"
|
2011-10-18 21:57:02 +00:00
|
|
|
#include "wx/graphics.h"
|
2003-03-28 23:56:19 +00:00
|
|
|
#include "wx/image.h"
|
2003-03-28 23:05:05 +00:00
|
|
|
|
2012-03-04 00:28:58 +00:00
|
|
|
#ifndef wxHAS_IMAGES_IN_RESOURCES
|
2009-02-08 01:01:00 +00:00
|
|
|
#include "../sample.xpm"
|
|
|
|
#endif
|
2008-05-08 21:56:26 +00:00
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// constants
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// menu ids
|
|
|
|
enum
|
|
|
|
{
|
2007-11-26 07:39:53 +00:00
|
|
|
Show_Shaped = 100,
|
2007-11-24 16:15:08 +00:00
|
|
|
Show_Transparent,
|
|
|
|
|
|
|
|
// must be consecutive and in the same order as wxShowEffect enum elements
|
|
|
|
Show_Effect_First,
|
|
|
|
Show_Effect_Roll = Show_Effect_First,
|
|
|
|
Show_Effect_Slide,
|
|
|
|
Show_Effect_Blend,
|
|
|
|
Show_Effect_Expand,
|
|
|
|
Show_Effect_Last = Show_Effect_Expand
|
2007-11-24 15:31:43 +00:00
|
|
|
};
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// private classes
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Define a new application type, each program should derive a class from wxApp
|
|
|
|
class MyApp : public wxApp
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// override base class virtuals
|
|
|
|
// ----------------------------
|
|
|
|
|
|
|
|
// this one is called on application startup and is a good place for the app
|
|
|
|
// initialization (doing it here and not in the ctor allows to have an error
|
|
|
|
// return: if OnInit() returns false, the application terminates)
|
2014-03-30 00:02:23 +00:00
|
|
|
virtual bool OnInit() wxOVERRIDE;
|
2003-03-28 23:05:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
// Main frame just contains the menu items invoking the other tests
|
|
|
|
class MainFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
MainFrame();
|
|
|
|
|
|
|
|
private:
|
|
|
|
void OnShowShaped(wxCommandEvent& event);
|
|
|
|
void OnShowTransparent(wxCommandEvent& event);
|
2007-11-24 16:15:08 +00:00
|
|
|
void OnShowEffect(wxCommandEvent& event);
|
2011-10-12 00:35:04 +00:00
|
|
|
void OnExit(wxCommandEvent& event);
|
2007-11-24 15:31:43 +00:00
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2007-11-24 15:31:43 +00:00
|
|
|
};
|
|
|
|
|
2007-10-22 21:15:04 +00:00
|
|
|
// Define a new frame type: this is going to the frame showing the
|
|
|
|
// effect of wxFRAME_SHAPED
|
2003-03-28 23:05:05 +00:00
|
|
|
class ShapedFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
// ctor(s)
|
2007-10-22 21:15:04 +00:00
|
|
|
ShapedFrame(wxFrame *parent);
|
2003-03-28 23:05:05 +00:00
|
|
|
void SetWindowShape();
|
|
|
|
|
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnDoubleClick(wxMouseEvent& evt);
|
|
|
|
void OnLeftDown(wxMouseEvent& evt);
|
|
|
|
void OnLeftUp(wxMouseEvent& evt);
|
|
|
|
void OnMouseMove(wxMouseEvent& evt);
|
|
|
|
void OnExit(wxMouseEvent& evt);
|
|
|
|
void OnPaint(wxPaintEvent& evt);
|
|
|
|
|
|
|
|
private:
|
2011-10-18 21:57:02 +00:00
|
|
|
enum ShapeKind
|
|
|
|
{
|
|
|
|
Shape_None,
|
|
|
|
Shape_Star,
|
|
|
|
#if wxUSE_GRAPHICS_CONTEXT
|
|
|
|
Shape_Circle,
|
|
|
|
#endif // wxUSE_GRAPHICS_CONTEXT
|
|
|
|
Shape_Max
|
|
|
|
} m_shapeKind;
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
wxBitmap m_bmp;
|
|
|
|
wxPoint m_delta;
|
|
|
|
|
2004-05-25 11:20:37 +00:00
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2003-03-28 23:05:05 +00:00
|
|
|
};
|
|
|
|
|
2007-10-22 21:15:04 +00:00
|
|
|
// Define a new frame type: this is going to the frame showing the
|
|
|
|
// effect of wxWindow::SetTransparent and of
|
|
|
|
// wxWindow::SetBackgroundStyle(wxBG_STYLE_TRANSPARENT)
|
|
|
|
class SeeThroughFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
2014-04-07 17:15:45 +00:00
|
|
|
void Create();
|
2007-10-22 21:15:04 +00:00
|
|
|
|
2014-04-07 17:15:45 +00:00
|
|
|
private:
|
2007-10-22 21:15:04 +00:00
|
|
|
// event handlers (these functions should _not_ be virtual)
|
|
|
|
void OnDoubleClick(wxMouseEvent& evt);
|
|
|
|
void OnPaint(wxPaintEvent& evt);
|
|
|
|
|
|
|
|
// any class wishing to process wxWidgets events must use this macro
|
2014-03-30 07:07:55 +00:00
|
|
|
wxDECLARE_EVENT_TABLE();
|
2007-10-22 21:15:04 +00:00
|
|
|
};
|
|
|
|
|
2007-11-24 16:15:08 +00:00
|
|
|
class EffectFrame : public wxFrame
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
EffectFrame(wxWindow *parent,
|
|
|
|
wxShowEffect effect,
|
|
|
|
// TODO: add menu command to the main frame to allow changing
|
|
|
|
// these parameters
|
2008-05-08 21:56:26 +00:00
|
|
|
unsigned timeout = 1000)
|
2007-11-24 16:15:08 +00:00
|
|
|
: wxFrame(parent, wxID_ANY,
|
|
|
|
wxString::Format("Frame shown with %s effect",
|
|
|
|
GetEffectName(effect)),
|
|
|
|
wxDefaultPosition, wxSize(450, 300)),
|
|
|
|
m_effect(effect),
|
2008-05-08 21:56:26 +00:00
|
|
|
m_timeout(timeout)
|
2007-11-24 16:15:08 +00:00
|
|
|
{
|
|
|
|
new wxStaticText(this, wxID_ANY,
|
|
|
|
wxString::Format("Effect: %s", GetEffectName(effect)),
|
|
|
|
wxPoint(20, 20));
|
|
|
|
new wxStaticText(this, wxID_ANY,
|
|
|
|
wxString::Format("Timeout: %ums", m_timeout),
|
|
|
|
wxPoint(20, 60));
|
|
|
|
|
2008-05-08 21:56:26 +00:00
|
|
|
ShowWithEffect(m_effect, m_timeout);
|
2007-11-24 16:15:08 +00:00
|
|
|
|
|
|
|
Connect(wxEVT_CLOSE_WINDOW, wxCloseEventHandler(EffectFrame::OnClose));
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
|
|
|
static const char *GetEffectName(wxShowEffect effect)
|
|
|
|
{
|
|
|
|
static const char *names[] =
|
|
|
|
{
|
2009-10-05 22:53:57 +00:00
|
|
|
"none",
|
2008-05-08 21:56:26 +00:00
|
|
|
"roll to left",
|
|
|
|
"roll to right",
|
|
|
|
"roll to top",
|
|
|
|
"roll to bottom",
|
|
|
|
"slide to left",
|
|
|
|
"slide to right",
|
|
|
|
"slide to top",
|
|
|
|
"slide to bottom",
|
|
|
|
"fade",
|
|
|
|
"expand",
|
2007-11-24 16:15:08 +00:00
|
|
|
};
|
|
|
|
wxCOMPILE_TIME_ASSERT( WXSIZEOF(names) == wxSHOW_EFFECT_MAX,
|
|
|
|
EffectNamesMismatch );
|
|
|
|
|
|
|
|
return names[effect];
|
|
|
|
}
|
|
|
|
|
|
|
|
void OnClose(wxCloseEvent& event)
|
|
|
|
{
|
2008-05-08 21:56:26 +00:00
|
|
|
HideWithEffect(m_effect, m_timeout);
|
2007-11-24 16:15:08 +00:00
|
|
|
|
|
|
|
event.Skip();
|
|
|
|
}
|
|
|
|
|
|
|
|
wxShowEffect m_effect;
|
|
|
|
unsigned m_timeout;
|
|
|
|
};
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
// ============================================================================
|
|
|
|
// implementation
|
|
|
|
// ============================================================================
|
|
|
|
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// the application class
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
IMPLEMENT_APP(MyApp)
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
// `Main program' equivalent: the program execution "starts" here
|
|
|
|
bool MyApp::OnInit()
|
|
|
|
{
|
2007-02-04 00:34:18 +00:00
|
|
|
if ( !wxApp::OnInit() )
|
|
|
|
return false;
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
wxInitAllImageHandlers();
|
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
new MainFrame;
|
2003-03-28 23:05:05 +00:00
|
|
|
|
|
|
|
// success: wxApp::OnRun() will be called which will enter the main message
|
2004-06-02 17:03:20 +00:00
|
|
|
// loop and the application will run. If we returned false here, the
|
2003-03-28 23:05:05 +00:00
|
|
|
// application would exit immediately.
|
2004-06-02 17:03:20 +00:00
|
|
|
return true;
|
2003-03-28 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// main frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(MainFrame, wxFrame)
|
2007-11-24 15:31:43 +00:00
|
|
|
EVT_MENU(Show_Shaped, MainFrame::OnShowShaped)
|
|
|
|
EVT_MENU(Show_Transparent, MainFrame::OnShowTransparent)
|
2007-11-24 16:15:08 +00:00
|
|
|
EVT_MENU_RANGE(Show_Effect_First, Show_Effect_Last, MainFrame::OnShowEffect)
|
2011-10-12 00:35:04 +00:00
|
|
|
EVT_MENU(wxID_EXIT, MainFrame::OnExit)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-11-24 15:31:43 +00:00
|
|
|
|
|
|
|
MainFrame::MainFrame()
|
|
|
|
: wxFrame(NULL, wxID_ANY, "wxWidgets Shaped Sample",
|
|
|
|
wxDefaultPosition, wxSize(200, 100))
|
|
|
|
{
|
2009-02-08 01:01:00 +00:00
|
|
|
SetIcon(wxICON(sample));
|
|
|
|
|
2007-11-24 15:31:43 +00:00
|
|
|
wxMenuBar * const mbar = new wxMenuBar;
|
|
|
|
wxMenu * const menuFrames = new wxMenu;
|
|
|
|
menuFrames->Append(Show_Shaped, "Show &shaped window\tCtrl-S");
|
|
|
|
menuFrames->Append(Show_Transparent, "Show &transparent window\tCtrl-T");
|
|
|
|
menuFrames->AppendSeparator();
|
2007-11-24 16:15:08 +00:00
|
|
|
menuFrames->Append(Show_Effect_Roll, "Show &rolled effect\tCtrl-R");
|
|
|
|
menuFrames->Append(Show_Effect_Slide, "Show s&lide effect\tCtrl-L");
|
|
|
|
menuFrames->Append(Show_Effect_Blend, "Show &fade effect\tCtrl-F");
|
|
|
|
menuFrames->Append(Show_Effect_Expand, "Show &expand effect\tCtrl-E");
|
|
|
|
menuFrames->AppendSeparator();
|
2007-11-24 15:31:43 +00:00
|
|
|
menuFrames->Append(wxID_EXIT, "E&xit");
|
|
|
|
|
|
|
|
mbar->Append(menuFrames, "&Show");
|
|
|
|
SetMenuBar(mbar);
|
|
|
|
|
|
|
|
Show();
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::OnShowShaped(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
ShapedFrame *shapedFrame = new ShapedFrame(this);
|
|
|
|
shapedFrame->Show(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MainFrame::OnShowTransparent(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
2014-04-07 17:15:45 +00:00
|
|
|
if (IsTransparentBackgroundSupported())
|
|
|
|
{
|
|
|
|
SeeThroughFrame *seeThroughFrame = new SeeThroughFrame;
|
|
|
|
seeThroughFrame->Create();
|
|
|
|
seeThroughFrame->Show(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
wxMessageBox(wxS("transparent window requires a composited screen"));
|
2007-11-24 15:31:43 +00:00
|
|
|
}
|
|
|
|
|
2007-11-24 16:15:08 +00:00
|
|
|
void MainFrame::OnShowEffect(wxCommandEvent& event)
|
|
|
|
{
|
2008-05-08 21:56:26 +00:00
|
|
|
int effect = event.GetId();
|
2007-11-26 07:39:53 +00:00
|
|
|
static wxDirection direction = wxLEFT;
|
|
|
|
direction = (wxDirection)(((int)direction)<< 1);
|
|
|
|
if ( direction > wxDOWN )
|
|
|
|
direction = wxLEFT ;
|
2008-05-08 21:56:26 +00:00
|
|
|
|
|
|
|
wxShowEffect eff;
|
|
|
|
switch ( effect )
|
|
|
|
{
|
|
|
|
case Show_Effect_Roll:
|
|
|
|
switch ( direction )
|
|
|
|
{
|
|
|
|
case wxLEFT:
|
|
|
|
eff = wxSHOW_EFFECT_ROLL_TO_LEFT;
|
|
|
|
break;
|
|
|
|
case wxRIGHT:
|
|
|
|
eff = wxSHOW_EFFECT_ROLL_TO_RIGHT;
|
|
|
|
break;
|
|
|
|
case wxTOP:
|
|
|
|
eff = wxSHOW_EFFECT_ROLL_TO_TOP;
|
|
|
|
break;
|
|
|
|
case wxBOTTOM:
|
|
|
|
eff = wxSHOW_EFFECT_ROLL_TO_BOTTOM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "invalid direction" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case Show_Effect_Slide:
|
|
|
|
switch ( direction )
|
|
|
|
{
|
|
|
|
case wxLEFT:
|
|
|
|
eff = wxSHOW_EFFECT_SLIDE_TO_LEFT;
|
|
|
|
break;
|
|
|
|
case wxRIGHT:
|
|
|
|
eff = wxSHOW_EFFECT_SLIDE_TO_RIGHT;
|
|
|
|
break;
|
|
|
|
case wxTOP:
|
|
|
|
eff = wxSHOW_EFFECT_SLIDE_TO_TOP;
|
|
|
|
break;
|
|
|
|
case wxBOTTOM:
|
|
|
|
eff = wxSHOW_EFFECT_SLIDE_TO_BOTTOM;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "invalid direction" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Show_Effect_Blend:
|
|
|
|
eff = wxSHOW_EFFECT_BLEND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case Show_Effect_Expand:
|
|
|
|
eff = wxSHOW_EFFECT_EXPAND;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
wxFAIL_MSG( "invalid effect" );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2009-10-05 22:53:57 +00:00
|
|
|
new EffectFrame(this, eff, 1000);
|
2007-11-24 16:15:08 +00:00
|
|
|
}
|
|
|
|
|
2011-10-12 00:35:04 +00:00
|
|
|
void MainFrame::OnExit(wxCommandEvent& WXUNUSED(event))
|
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
2007-10-22 21:15:04 +00:00
|
|
|
// shaped frame
|
2003-03-28 23:05:05 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(ShapedFrame, wxFrame)
|
2007-11-24 15:31:43 +00:00
|
|
|
EVT_LEFT_DCLICK(ShapedFrame::OnDoubleClick)
|
|
|
|
EVT_LEFT_DOWN(ShapedFrame::OnLeftDown)
|
|
|
|
EVT_LEFT_UP(ShapedFrame::OnLeftUp)
|
|
|
|
EVT_MOTION(ShapedFrame::OnMouseMove)
|
|
|
|
EVT_RIGHT_UP(ShapedFrame::OnExit)
|
|
|
|
EVT_PAINT(ShapedFrame::OnPaint)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-11-24 15:31:43 +00:00
|
|
|
|
|
|
|
|
2003-03-28 23:05:05 +00:00
|
|
|
// frame constructor
|
2007-10-22 21:15:04 +00:00
|
|
|
ShapedFrame::ShapedFrame(wxFrame *parent)
|
|
|
|
: wxFrame(parent, wxID_ANY, wxEmptyString,
|
2007-11-24 15:31:43 +00:00
|
|
|
wxDefaultPosition, wxSize(100, 100),
|
2003-04-30 00:39:15 +00:00
|
|
|
0
|
|
|
|
| wxFRAME_SHAPED
|
|
|
|
| wxSIMPLE_BORDER
|
|
|
|
| wxFRAME_NO_TASKBAR
|
|
|
|
| wxSTAY_ON_TOP
|
|
|
|
)
|
2003-03-28 23:05:05 +00:00
|
|
|
{
|
2014-06-10 00:38:42 +00:00
|
|
|
m_shapeKind = Shape_Star;
|
2009-07-23 20:30:22 +00:00
|
|
|
m_bmp = wxBitmap(wxT("star.png"), wxBITMAP_TYPE_PNG);
|
2003-03-28 23:05:05 +00:00
|
|
|
SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
|
2011-10-18 21:57:02 +00:00
|
|
|
SetToolTip(wxT("Right-click to close, double click to cycle shape"));
|
2003-03-28 23:05:05 +00:00
|
|
|
SetWindowShape();
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShapedFrame::SetWindowShape()
|
|
|
|
{
|
2011-10-18 21:57:02 +00:00
|
|
|
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;
|
|
|
|
}
|
2003-03-28 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void ShapedFrame::OnDoubleClick(wxMouseEvent& WXUNUSED(evt))
|
2003-03-28 23:05:05 +00:00
|
|
|
{
|
2011-10-18 21:57:02 +00:00
|
|
|
m_shapeKind = static_cast<ShapeKind>((m_shapeKind + 1) % Shape_Max);
|
|
|
|
SetWindowShape();
|
2003-03-28 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShapedFrame::OnLeftDown(wxMouseEvent& evt)
|
|
|
|
{
|
|
|
|
CaptureMouse();
|
|
|
|
wxPoint pos = ClientToScreen(evt.GetPosition());
|
|
|
|
wxPoint origin = GetPosition();
|
|
|
|
int dx = pos.x - origin.x;
|
|
|
|
int dy = pos.y - origin.y;
|
|
|
|
m_delta = wxPoint(dx, dy);
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void ShapedFrame::OnLeftUp(wxMouseEvent& WXUNUSED(evt))
|
2003-03-28 23:05:05 +00:00
|
|
|
{
|
|
|
|
if (HasCapture())
|
2003-04-30 00:39:15 +00:00
|
|
|
{
|
2003-03-28 23:05:05 +00:00
|
|
|
ReleaseMouse();
|
2003-09-11 12:52:20 +00:00
|
|
|
}
|
2003-03-28 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ShapedFrame::OnMouseMove(wxMouseEvent& evt)
|
|
|
|
{
|
2003-04-30 00:39:15 +00:00
|
|
|
wxPoint pt = evt.GetPosition();
|
2003-03-28 23:05:05 +00:00
|
|
|
if (evt.Dragging() && evt.LeftIsDown())
|
|
|
|
{
|
2003-04-30 00:39:15 +00:00
|
|
|
wxPoint pos = ClientToScreen(pt);
|
2003-03-28 23:05:05 +00:00
|
|
|
Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void ShapedFrame::OnExit(wxMouseEvent& WXUNUSED(evt))
|
2003-03-28 23:05:05 +00:00
|
|
|
{
|
|
|
|
Close();
|
|
|
|
}
|
|
|
|
|
2003-09-11 12:52:20 +00:00
|
|
|
void ShapedFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
|
2003-03-28 23:05:05 +00:00
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
2004-06-02 17:03:20 +00:00
|
|
|
dc.DrawBitmap(m_bmp, 0, 0, true);
|
2003-03-28 23:05:05 +00:00
|
|
|
}
|
|
|
|
|
2007-10-22 21:15:04 +00:00
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
// see-through frame
|
|
|
|
// ----------------------------------------------------------------------------
|
|
|
|
|
2014-03-30 07:07:55 +00:00
|
|
|
wxBEGIN_EVENT_TABLE(SeeThroughFrame, wxFrame)
|
2007-11-24 15:31:43 +00:00
|
|
|
EVT_LEFT_DCLICK(SeeThroughFrame::OnDoubleClick)
|
|
|
|
EVT_PAINT(SeeThroughFrame::OnPaint)
|
2014-03-30 07:07:55 +00:00
|
|
|
wxEND_EVENT_TABLE()
|
2007-11-24 15:31:43 +00:00
|
|
|
|
2014-04-07 17:15:45 +00:00
|
|
|
void SeeThroughFrame::Create()
|
2007-10-22 21:15:04 +00:00
|
|
|
{
|
|
|
|
SetBackgroundStyle(wxBG_STYLE_TRANSPARENT);
|
2014-04-07 17:15:45 +00:00
|
|
|
wxFrame::Create(NULL, wxID_ANY, "Transparency test: double click here",
|
|
|
|
wxPoint(100, 30), wxSize(300, 300),
|
|
|
|
wxDEFAULT_FRAME_STYLE |
|
|
|
|
wxFULL_REPAINT_ON_RESIZE |
|
|
|
|
wxSTAY_ON_TOP);
|
|
|
|
SetBackgroundColour(*wxWHITE);
|
2007-10-22 21:15:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Paints a grid of varying hue and alpha
|
|
|
|
void SeeThroughFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
|
|
|
|
{
|
|
|
|
wxPaintDC dc(this);
|
|
|
|
dc.SetPen(wxNullPen);
|
|
|
|
|
|
|
|
int xcount = 8;
|
|
|
|
int ycount = 8;
|
|
|
|
|
|
|
|
float xstep = 1. / xcount;
|
|
|
|
float ystep = 1. / ycount;
|
|
|
|
|
|
|
|
int width = GetClientSize().GetWidth();
|
|
|
|
int height = GetClientSize().GetHeight();
|
|
|
|
|
|
|
|
for ( float x = 0.; x < 1.; x += xstep )
|
|
|
|
{
|
|
|
|
for ( float y = 0.; y < 1.; y += ystep )
|
|
|
|
{
|
|
|
|
wxImage::RGBValue v = wxImage::HSVtoRGB(wxImage::HSVValue(x, 1., 1.));
|
|
|
|
dc.SetBrush(wxBrush(wxColour(v.red, v.green, v.blue,
|
|
|
|
(int)(255*(1. - y)))));
|
|
|
|
int x1 = (int)(x * width);
|
|
|
|
int y1 = (int)(y * height);
|
|
|
|
int x2 = (int)((x + xstep) * width);
|
|
|
|
int y2 = (int)((y + ystep) * height);
|
|
|
|
dc.DrawRectangle(x1, y1, x2 - x1, y2 - y1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void SeeThroughFrame::OnDoubleClick(wxMouseEvent& WXUNUSED(evt))
|
|
|
|
{
|
2014-04-07 17:15:45 +00:00
|
|
|
SetBackgroundStyle(wxBG_STYLE_PAINT);
|
|
|
|
SetTransparent(255);
|
|
|
|
SetTitle("Opaque");
|
2007-10-22 21:15:04 +00:00
|
|
|
|
|
|
|
Refresh();
|
|
|
|
}
|
|
|
|
|