1. wxEuphoria wxBitmapButton Question

Hi all!

I'm new to Euphoria, but working to plunge right in!

I have a question about wxBitmapButtons in wxEuphoria. Could anyone post a
simple working example of a wxBitmapButton for me? I'm cannot get it to work, so
I'm thinking I might have the wrong idea about it.

On a side note, I'm thinking about trying to port the Euphoria interpreter to
PowerPC / Linux. (I'm running Debian PPC Linux / testing on an Apple PowerBook G3
Pismo.) I haven't bought the source yet, but I'm seriously considering whether I
should go for it or not. Does anyone have any experience with porting it over to
a different architecture? Any advise?

Thanks in advance!
-Mannequin

new topic     » topic index » view message » categorize

2. Re: wxEuphoria wxBitmapButton Question

Mannequin wrote:
> 
> Hi all!
> 
> I'm new to Euphoria, but working to plunge right in!
> 
> I have a question about wxBitmapButtons in wxEuphoria. Could anyone post a
> simple working
> example of a wxBitmapButton for me? I'm cannot get it to work, so I'm thinking
> I might
> have the wrong idea about it.

Here's a really simple example:
-- 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}),
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 })

wxMain( new_wxFrame_3 )

 
Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

3. Re: wxEuphoria wxBitmapButton Question

Matt Lewis wrote:
> 
> Mannequin wrote:
> > 
> > Hi all!
> > 
> > I'm new to Euphoria, but working to plunge right in!
> > 
> > I have a question about wxBitmapButtons in wxEuphoria. Could anyone post a
> > simple working
> > example of a wxBitmapButton for me? I'm cannot get it to work, so I'm
> > thinking I might
> > have the wrong idea about it.
> 
> Here's a really simple example:
> }}}
<eucode>
> -- 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}),
> 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 })
> 
> wxMain( new_wxFrame_3 )
> <font color="#330033"></eucode>
{{{
</font>
>  
> Matt Lewis
> 

That works great. Thanks!

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.)

Thanks again!
-Mannequin.

new topic     » goto parent     » topic index » view message » categorize

4. Re: wxEuphoria wxBitmapButton Question

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 message » categorize

5. Re: wxEuphoria wxBitmapButton Question

Matt Lewis wrote:
> 
> Alternatively, you may add the following code to the end of wxButton.e,
> as it will be appearing in the next release of wxEuphoria:

Sorry, hit send too soon.  The new code will be:
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 )
	atom ptr
	ptr = button + sizeof_wxBitmapButton - 8 - 4 * sizeof_wxBitmap
	poke( ptr, peek( bitmap & sizeof_wxBitmap ) )
	refresh_window( button )
end procedure


Matt lewis

new topic     » goto parent     » topic index » view message » categorize

6. Re: wxEuphoria wxBitmapButton Question

Matt Lewis wrote:
> 
> Matt Lewis wrote:
> > 
> > Alternatively, you may add the following code to the end of wxButton.e,
> > as it will be appearing in the next release of wxEuphoria:
> 
> Sorry, hit send too soon.  The new code will be:
> }}}
<eucode>
> 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 )
> 	atom ptr
> 	ptr = button + sizeof_wxBitmapButton - 8 - 4 * sizeof_wxBitmap
> 	poke( ptr, peek( bitmap & sizeof_wxBitmap ) )
> 	refresh_window( button )
> end procedure
> </eucode>
{{{

> 
> Matt lewis
> 

That seems to be the trick I need. :)  Thank you, once again.

So... When do you think the next release will be? ;)

By the way, do you think that it would be better to include the procedure in the
program until the next version of wxEuphoria is released?

Thanks again,
-Mannequin.

new topic     » goto parent     » topic index » view message » categorize

7. Re: wxEuphoria wxBitmapButton Question

Mannequin wrote:
> 
> 
> That seems to be the trick I need. :)  Thank you, once again.
> 
> So... When do you think the next release will be? ;)

Probably at least a couple of weeks away, unfortunately, unless I manage to
get it out by this weekend.  RL is keeping me pretty busy these days, and
I'll be out of town all next week.
 
> By the way, do you think that it would be better to include the procedure in
> the program
> until the next version of wxEuphoria is released?

If you plan to distribute it, then it probably would be better to put it in
your program (and even rename it so there won't be any name conflicts if 
someone happens to use it with a newer version of wxEuphoria before you 
update).  Otherwise, you'd need to distribute the wxButton.e file[s] so
other people could run with v0.7.x.

Matt Lewis

new topic     » goto parent     » topic index » view message » categorize

8. Re: wxEuphoria wxBitmapButton Question

Matt Lewis wrote:
> 
> Mannequin wrote:
...
> > By the way, do you think that it would be better to include the procedure in
> > the program
> > until the next version of wxEuphoria is released?
> 
> If you plan to distribute it, then it probably would be better to put it in
> your program (and even rename it so there won't be any name conflicts if 
> someone happens to use it with a newer version of wxEuphoria before you 
> update).  Otherwise, you'd need to distribute the wxButton.e file[s] so
> other people could run with v0.7.x.

Okay, I've put the procedure in the program, and renamed it. Thanks for all of
your help.

I should have a nice little dice game out in the next few days using wxEuphoria.
Not too shabby a learning curve for my first 'true' program in Euphoria.

I'm pretty impressed with Euphoria so far. It's very easy to learn, and I've
built a nice little game with it only after a little over a week of being
introduced to it. So, to Rob and anyone else who has contributed, my hat's off to
you. :)

-Mannequin.

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu