Re: wxEuphoria wxBitmapButton Question

new topic     » goto parent     » topic index » view thread      » older message » newer message

Mannequin wrote:
>  
> I don't know what I had different, though. I erased what I did in frustration
> last
> night. After going through both the wxEuphoria reference manual and the
> wxWidgets reference
> manual, I was at the end of my rope. :)
> 
> One other question, if I wanted to change the bitmap of the button 'on the
> fly', so
> to speak, how would I go about doing that? (Again, some very simple code might
> do me
> some good.)
> 

I don't think there is an easy way to do this.  There should be, but the
wxBitmapButton::SetLabel function doesn't seem to work (at least under 
Windows).  Here's a modification to the earlier program that shows you 
how to do this:
-- Created using wxIDE
include wxEuphoria.e
include wxButton.e
include wxGraphics.e

global constant
bitmap = create( wxBitmap, {BM_FROM_FILE, "tiles.bmp", wxBITMAP_TYPE_BMP}),
bitmap2 = create( wxBitmap, {BM_FROM_FILE, "ship_tiny.bmp", wxBITMAP_TYPE_BMP}),
new_wxFrame_3 = create( wxFrame, {0, -1, "new_wxFrame_3" }),
new_wxPanel_1 = create( wxPanel, {new_wxFrame_3, -1, 0, 0, 299, 199 }),
new_wxBitmapButton_1 = create( wxBitmapButton, {new_wxPanel_1, -1, bitmap, 39,
34, 197, 79 })

atom current current = bitmap
procedure on_click( atom this, atom event_type, atom id, atom event )
	atom void
	sequence b
	if current = bitmap then
		current = bitmap2
	else
		current = bitmap
	end if
poke( new_wxBitmapButton_1 + sizeof_wxBitmapButton - 8 - 4 * sizeof_wxBitmap,
peek( current & sizeof_wxBitmap ))
	refresh_window( new_wxBitmapButton_1 )
end procedure
set_event_handler( new_wxBitmapButton_1, -1, wxEVT_COMMAND_BUTTON_CLICKED,
routine_id("on_click"))

wxMain( new_wxFrame_3 )

Basically, I'm going in and modifying the wxBitmapButton's data by hand.
Looking in the header file, I see the last data is:
    // the bitmaps for various states
    wxBitmap m_bmpNormal,
             m_bmpSelected,
             m_bmpFocus,
             m_bmpDisabled;

    // the margins around the bitmap
    int m_marginX,
        m_marginY;

So this is how I derive the awful looking:
poke( new_wxBitmapButton_1 + sizeof_wxBitmapButton - 8 - 4 *
sizeof_wxBitmap, peek( current & sizeof_wxBitmap ))


I start at the end of the structure by adding the size of the bitmap button
to its pointer.  Then I subtract 8 to account for the two ints.  Then I 
subtract 4 times the size of a wxBitmap to get to the start of m_bmpNormal,
which is the bitmap you want to change.  Then I just peek the data from
the appropriate bitmap, and it gets put into the right place in memory.

Alternatively, you may add the following code to the end of wxButton.e,
as it will be appearing in the next release of wxEuphoria:
include wxGraphics.e
--/topic wxBitmapButton
--/proc set_bmpbutton( atom button, atom bitmap )
--
--Sets the displayed bitmap of the bitmap button.
global procedure set_bmpbutton( atom button, atom bitmap )
	
	button += sizeof_wxBitmapButton - 8 - 4 * sizeof_wxBitmap
	poke( button, peek( bitmap & sizeof_wxBitmap )
end procedure


Matt Lewis

new topic     » goto parent     » topic index » view thread      » older message » newer message

Search



Quick Links

User menu

Not signed in.

Misc Menu