Discussion:
Adding common controls to shaped window
leo.zhou
2014-06-16 04:53:11 UTC
Permalink
Hi guys,
I've been testing shaped window recently on Mac. When I add one button to
the shaped window, it isn't displayed with correct size and position.
Furthermore, the mouse pointer always goes to the top left corner when I
drag the window. I use a white bitmap(100*100 pixels) with rounded corners
as the background, This is my code:

ShapedFrame::ShapedFrame(wxFrame *parent)

: wxFrame(parent, wxID_ANY, wxEmptyString,

wxDefaultPosition, wxSize(100, 100),

0

| wxFRAME_SHAPED

| wxSIMPLE_BORDER

| wxFRAME_NO_TASKBAR

| wxSTAY_ON_TOP

)

{

m_shapeKind = Shape_Star;

m_bmp = wxBitmap(wxT("window.bmp"), wxBITMAP_TYPE_BMP );

SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));

SetWindowShape();



m_Button = new wxButton( this, wxID_ANY, "Click me!", wxPoint(30, 30),
wxSize(30, 15) );

}


Regards,

Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
leo.zhou
2014-06-19 04:14:51 UTC
Permalink
Can anyone help? If I create a wxStaticText like this, the control will
show up on the top left corner of the window. Ridiculous!
m_pStaticText = new wxStaticText(this, wxID_ANY, _("Hello World!"), wxPoint(
100, 100), wxSize(50, 25));

Regards,
Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
leo.zhou
2014-06-23 03:14:21 UTC
Permalink
Hi,
I solved this problem by creating a wxPanel first and adding all controls
to the panel. I modified the shaped sample and moved mouse capture code to
my panel class. Everything seems to work great. But when I add a button to
the panel, something trange happens.
1. The button size is not what I specify in my code. It should be the same
size as static text control.
2. If I click the button once, then drag the window, the button's
background will become transparent.
Here's my code:
ShapedPanel::ShapedPanel(wxWindow *parent)
: wxPanel(parent, wxID_ANY)
{
}

void ShapedPanel::OnLeftDown(wxMouseEvent& evt)
{
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 ShapedPanel::OnLeftUp(wxMouseEvent& WXUNUSED(evt))
{
if (HasCapture())
{
ReleaseMouse();
}
}

void ShapedPanel::OnMouseMove(wxMouseEvent& evt)
{
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));
}
}

ShapedFrame::ShapedFrame(wxWindow *parent)
: wxFrame(parent, wxID_ANY, wxEmptyString,
wxDefaultPosition, wxSize(360, 360),
0
| wxFRAME_SHAPED
| wxSIMPLE_BORDER
| wxFRAME_NO_TASKBAR
| wxSTAY_ON_TOP
)
{
m_bmp = wxBitmap(wxT("window.bmp"), wxBITMAP_TYPE_BMP);
SetSize(wxSize(m_bmp.GetWidth(), m_bmp.GetHeight()));
SetWindowShape();

ShapedPanel *panel = new ShapedPanel(this);

m_pStaticText = new wxStaticText(panel, wxID_ANY, wxT("Hello World!"),
wxPoint(100, 100), wxSize(70, 25));
m_pBtn = new wxButton(panel, wxID_ANY, wxT("Click me!"), wxPoint(100,
120), wxSize(70, 25));
}

void ShapedFrame::SetWindowShape()
{
wxColour color(46, 49, 146, 255);
SetShape(wxRegion(m_bmp, color));
}

void ShapedFrame::OnExit(wxMouseEvent& WXUNUSED(evt))
{
Close();
}

void ShapedFrame::OnPaint(wxPaintEvent& WXUNUSED(evt))
{
wxPaintDC dc(this);
dc.DrawBitmap(m_bmp, 0, 0, true);
}

Can anybody help? Thanks!

Regards,
Leo
--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.

To unsubscribe, send email to wx-users+***@googlegroups.com
or visit http://groups.google.com/group/wx-users
Loading...