Guidance
指路人
g.yi.org
Guidance Forums / wxWidgets (wxWindows) in C++ / Button on top of background picture

Register 
注册
Search 搜索
首页 
Home Home
Software
Upload

  
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
Message1. Button on top of background picture
#2726
Posted by: 2003-10-10 16:02:12
... how to?
The following sample does not work, even if I reverse the order of the bitmap and button object.
Thank's Markus

wxBoxSizer *sizer = new wxBoxSizer( wxVERTICAL );

button = new wxButton(parent, 220, wxT("Berlin"), wxPoint(300,135),  wxDefaultSize, 0);
sizer->Add( button, 0, wxALIGN_CENTRE|wxALL, 5 );

wxStaticBitmap *picture = new wxStaticBitmap( parent, 21, wxBitmap(wxT("germany.bmp"),wxBITMAP_TYPE_BMP), wxPoint(0,0));
sizer->Add( picture, 0, wxALIGN_CENTRE|wxALL, 5 );
Message2. Re: Button on top of background picture
#2728
Posted by: 2003-10-10 18:46:35
Hi Markus!
True, this doesn't work, or at least doesn't do what you want.
The way I got it is that you want to display a map of germany and place a button labeled "Berlin" on this image at Berlins location. In the above code you create the button and the image and put them into a sizer, which after that will display the image and below it the button (I guess).
To do what you want to do I think it would be best to write your own class for a panel, make it display the image and then place the button on this panel. To display the image you'd have to process the EVT_PAINT event and in the processing function draw the image on the panel.

e.g.

BEGIN_EVENT_TABLE(wxMyPanel, wxPanel)
   EVT_PAINT( wxMyPanel::OnPaint)
END_EVENT_TABLE()

wxMyPanel::wxMyPanel()
:wxPanel()
{
}

void wxMyPanel::OnPaint(wxPaintEvent& WXUNUSED(event) )
{
	wxPaintDC dc(this);
	
	int h, w;
	GetSize(&h,&w);
         wxBitmap back_temp(picture.Scale(h, w));
   	dc.DrawBitmap( back_temp, 0, 0);

}
This would (re)draw the image everytime there's need to do so (like when moving the window). In the example I scale the image so that it fits the panel. Maybe you don't want to do that and instead fix the panels size and let the size of the image as it is.

Hope this helps a little..

upcase
Message3. Re: Button on top of background picture
#2732
Posted by: 2003-10-13 15:33:32
THANK'S - IT WORKS!!
It took a bit to check it out, but I got it running. Sorry for the delay, but on friday I could not access this site.
Message4. Re: Button on top of background picture
#2733
Posted by: 2003-10-14 00:13:39
No prob...
Glad I could be of some help.

upcase
Forum List • Thread List • Reply • Refresh • New Topic • Search • Previous • Next First 1 Last
掌柜推荐
 
 
 
 
 
 
 
 
 
 
 
 
© Fri 2023-1-27  Guidance Laboratory Inc.
Email:webmaster1g.yi.org Hits:0