Hi! Just a little piece of code for a skinned panel.... I wrote some macros for the whole wxSkin package that would allow you to use the "normal" names like wxPanel and apply wxSkinPanel later, for making "porting" to skins easier... Too bad the wxWindows list wasn't impressed at all. I'm not really sure why I did this... They stated that they needed a different set of controls with skin support, but when I told them that I wrote something like that, noone was interested.
Anyway, I hope this makes you happy :)
skinPanel.h
#ifndef __WXSKINPANEL_H
#define __WXSKINPANEL_H
#ifdef __GNUG__
#pragma interface "skinPanel.h"
#endif
#include <wx/wxprec.h>
#ifndef WX_PRECOMP
#include <wx/wx.h>
#endif
#include <wx/image.h>
class wxSkinPanel : public wxPanel
{ wxImage back;
wxColour default_background;
bool m_usedefault;
bool m_canMove;
wxPoint m_delta;
public:
wxSkinPanel();
~wxSkinPanel();
#ifdef USE_WXSKIN
wxSkinPanel(wxWindow* parent,
int id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL,
const wxString& name = "panel");
#endif
wxSkinPanel(wxWindow* parent,
const wxImage& background,
int id = -1,
const wxPoint& pos = wxDefaultPosition,
const wxSize& size = wxDefaultSize,
long style = wxTAB_TRAVERSAL,
const wxString& name = "panel");
void Init();
void UseDefault(const bool state);
void OnPaint(wxPaintEvent& WXUNUSED(event));
void OnLeftDown(wxMouseEvent& evt);
void OnLeftUp(wxMouseEvent& evt);
void OnMouseMove(wxMouseEvent& evt);
void SetCanMove(bool b);
private:
DECLARE_DYNAMIC_CLASS(wxSkinPanel)
DECLARE_EVENT_TABLE()
};
#endif
skinPanel.cpp
#ifdef __GNUG__
#pragma implementation "skinPanel.h"
#endif
#include "skinPanel.h"
#include "wxSkinDef.h"
#include <wx/image.h>
BEGIN_EVENT_TABLE(wxSkinPanel, wxPanel)
EVT_PAINT( wxSkinPanel::OnPaint)
EVT_LEFT_DOWN(wxSkinPanel::OnLeftDown)
EVT_LEFT_UP(wxSkinPanel::OnLeftUp)
EVT_MOTION(wxSkinPanel::OnMouseMove)
END_EVENT_TABLE()
IMPLEMENT_DYNAMIC_CLASS(wxSkinPanel,wxPanel)
wxSkinPanel::wxSkinPanel()
:wxPanel()
{
}
wxSkinPanel::wxSkinPanel(wxWindow* parent,
int id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
:wxPanel(parent,id,pos,size,style,name),
back( wxSkinDef::getBmp_panel_back())
{
m_canMove = true;
default_background = GetBackgroundColour();
Init();
}
wxSkinPanel::wxSkinPanel(wxWindow* parent,
const wxImage& back,
int id,
const wxPoint& pos,
const wxSize& size,
long style,
const wxString& name)
:wxPanel(parent,id,pos,size,style,name),
back(back)
{
m_canMove = true;
default_background = GetBackgroundColour();
Init();
}
void wxSkinPanel::Init()
{
SetBackgroundColour( default_background );
m_usedefault = false;
int h, w;
GetSize(&h,&w);
wxBitmap back_temp(back.Scale(h, w));
wxClientDC dc(this);
dc.DrawBitmap( back_temp, 0, 0);
}
wxSkinPanel::~wxSkinPanel()
{
}
void wxSkinPanel::UseDefault(const bool state)
{ wxClientDC dc(this);
if( state == true )
{ dc.Clear();
SetBackgroundColour( default_background );
m_usedefault = true;
}
else
{ dc.DrawBitmap( back, 0, 0);
m_usedefault = false;
}
}
void wxSkinPanel::SetCanMove(bool b)
{
m_canMove = b;
}
void wxSkinPanel::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
wxPaintDC dc(this);
int h, w;
GetSize(&h,&w);
if( m_usedefault == false )
{ wxBitmap back_temp(back.Scale(h, w));
dc.DrawBitmap( back_temp, 0, 0);
}
else
{
dc.Clear();
SetBackgroundColour( default_background );
}
}
void wxSkinPanel::OnLeftDown(wxMouseEvent& evt)
{
if(m_canMove)
{ CaptureMouse();
wxPoint pos = ClientToScreen(evt.GetPosition());
wxPoint origin = GetParent()->GetPosition();
int dx = pos.x - origin.x;
int dy = pos.y - origin.y;
m_delta = wxPoint(dx, dy);
}
}
void wxSkinPanel::OnLeftUp(wxMouseEvent& evt)
{
if (HasCapture() && m_canMove)
{
ReleaseMouse();
}
}
void wxSkinPanel::OnMouseMove(wxMouseEvent& evt)
{
if(m_canMove)
{ wxPoint pt = evt.GetPosition();
if (evt.Dragging() && evt.LeftIsDown())
{
wxPoint pos = ClientToScreen(pt);
GetParent()->Move(wxPoint(pos.x - m_delta.x, pos.y - m_delta.y));
}
}
}
upcase
upCASE ----------------------------------- If it was hard to write, it should be hard to read!- Do. Or do not. There is no try! |