1. wxEuphoria graphics
- Posted by buzzo Nov 20, 2014
- 1083 views
This code does not display as expected..
simply want to color wxStaticBox and print in color
include wxeud.e constant HelloFrame = create( wxFrame, {0, -1, "My First Message", -1, -1, 500, 800} ), HelloWin = create( wxPanel, {HelloFrame}), HelloBox = create(wxStaticBox,{HelloWin, -1,"",50,40,400,400,0}) constant BrightRed = create( wxColour, {255,0,0}) , BrightGreen = create( wxColour, {0,255,0}) , BrightBlue = create( wxColour, {0,0,255}) , RedPen = create( wxPen, {BrightRed, 1, wxSOLID}) , GreenPen = create( wxPen, {BrightGreen, 1, wxSOLID}) , BluePen = create( wxPen, {BrightBlue, 1, wxSOLID}) , RedBrush = create( wxBrush, {BrightRed, wxSOLID}) , GreenBrush = create( wxBrush, {BrightGreen, wxSOLID}) , TransBrush = create( wxBrush, {BrightGreen, wxTRANSPARENT}) , BlueBrush = create( wxBrush, {BrightBlue, wxSOLID}) constant Arial = create( wxFont, {30,wxDEFAULT,wxNORMAL,wxNORMAL,0,"Arial",wxFONTENCODING_DEFAULT}) set_font(HelloWin, Arial) set_font(HelloBox, Arial) procedure onPaint_HelloWin( atom this, atom event, atom it, atom event_type ) atom dc dc = create(wxClientDC,{HelloWin}) begin_drawing( dc ) set_pen( dc, BrightBlue) set_brush( dc,BlueBrush) draw_rectangle(dc,50,40,400,400) -- does not change the color at HelloBox set_pen( dc, BrightRed) set_brush( dc,RedBrush) draw_rectangle(dc,100,100,40,40) -- does not appear anywhere set_font(dc, Arial) -- does not draw the size at create set_text_color ( dc, BrightRed ) -- does not draw in this color wx_puts( {HelloWin,10,10}, "Hello, World!") -- not 30 points; not per set_text_color end_drawing( dc ) delete_instance( dc ) end procedure set_event_handler( HelloWin, get_id(HelloWin), wxEVT_PAINT, routine_id( "onPaint_HelloWin" )) wxMain( HelloFrame )
Help appreciated
Buzzo
2. Re: wxEuphoria graphics
- Posted by ghaberek (admin) Nov 20, 2014
- 1084 views
When performing paint events, you have to create a wxPaintDC. The wxClientDC is for painting outside of a paint event. Changing wxClientDC to wxPaintDC in your code technically fixes all of the issues with nothing showing up. If you comment out all references to HelloBox, you will see your graphics painted on HelloWin as you would expect. The HelloBox was just covering them up. You have to capture the paint event for HelloBox and perform painting against that to see things there. Also, you need to provide a dc parameter to wx_puts() in order for it to pick up the wxPaintDC options (e.g. color).
Here is an updated example that works as I believe you would expect.
include wxeud.e constant HelloFrame = create( wxFrame, {0, -1, "My First Message", -1, -1, 500, 800} ), HelloWin = create( wxPanel, {HelloFrame}), HelloBox = create(wxStaticBox,{HelloWin, -1,"",50,40,400,400,0}) constant BrightRed = create( wxColour, {255,0,0}) , BrightGreen = create( wxColour, {0,255,0}) , BrightBlue = create( wxColour, {0,0,255}) , RedPen = create( wxPen, {BrightRed, 1, wxSOLID}) , GreenPen = create( wxPen, {BrightGreen, 1, wxSOLID}) , BluePen = create( wxPen, {BrightBlue, 1, wxSOLID}) , RedBrush = create( wxBrush, {BrightRed, wxSOLID}) , GreenBrush = create( wxBrush, {BrightGreen, wxSOLID}) , TransBrush = create( wxBrush, {BrightGreen, wxTRANSPARENT}) , BlueBrush = create( wxBrush, {BrightBlue, wxSOLID}) constant Arial = create( wxFont, {30,wxDEFAULT,wxNORMAL,wxNORMAL,0,"Arial",wxFONTENCODING_DEFAULT}) -- set_font(HelloWin, Arial) -- I don't think these are necessary, we set fonts in the paint event -- set_font(HelloBox, Arial) procedure onPaint_HelloWin( atom this, atom event, atom it, atom event_type ) atom dc dc = create(wxPaintDC,{this}) -- should always use 'this' parameter here begin_drawing( dc ) set_font(dc, Arial) set_text_color ( dc, BrightRed ) wx_puts( {HelloWin,10,10,dc}, "Hello, World!") -- add 'dc' parameter here to get color end_drawing( dc ) delete_instance( dc ) end procedure set_event_handler( HelloWin, get_id(HelloWin), wxEVT_PAINT, routine_id( "onPaint_HelloWin" )) procedure onPaint_HelloBox( atom this, atom event, atom it, atom event_type ) atom dc dc = create(wxPaintDC,{this}) -- should always use 'this' parameter here begin_drawing( dc ) set_pen( dc, BrightBlue) set_brush( dc,BlueBrush) draw_rectangle(dc,0,0,400,400) -- needs to start at 0,0 (relative to HelloBox) set_pen( dc, BrightRed) set_brush( dc,RedBrush) draw_rectangle(dc,100,100,40,40) end_drawing( dc ) delete_instance( dc ) end procedure set_event_handler( HelloBox, get_id(HelloBox), wxEVT_PAINT, routine_id( "onPaint_HelloBox" )) wxMain( HelloFrame )
-Greg
3. Re: wxEuphoria graphics
- Posted by buzzo Nov 20, 2014
- 1047 views
reading the code and your comments gives me a better understanding of the paint event(s)..
Again, thanks Greg
Buzzo