Pastey A Graph Dialog Demo

-- test2.ex --------------------------------------------------------------------
include wxeu/wxeud.e 
include graph.ew 
 
constant 
    NULL        =  0, 
    wxID_ANY    = -1, 
    wxID_TIMER1 = new_id(), 
$ 
 
constant 
    myFrame     = create( wxFrame, {NULL, wxID_ANY, "", -1, -1, 400, 300} ), 
    myPanel     = create( wxPanel, {myFrame} ), 
    myTimer     = create( wxTimer, {myFrame, wxID_TIMER1} ), 
    myButton    = create( wxButton, {myPanel, wxID_ANY, "GRAPH", 10, 10, 90, 30} ), 
$ 
 
procedure myButton_OnClick( atom this, atom event_type, atom id, atom event ) 
     
    sequence message = "" 
    integer result = show_graph( myFrame, {} ) 
     
    if result = wxOK then 
        message = "User clicked the OK button" 
    else 
        message = "User closed the window" 
    end if 
     
    message_box( message, "", wxICON_INFORMATION ) 
     
end procedure 
set_event_handler( myButton, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("myButton_OnClick") ) 
 
wxMain( myFrame ) 
 
-- graph.ew -------------------------------------------------------------------- 
include wxeu/wxeud.e 
 
atom myDialog, myBuffer, myButton 
 
constant BLACK = create( wxColour, {"BLACK"} ) 
constant GREEN = create( wxColour, {"GREEN"} ) 
constant WHITE = create( wxColour, {"WHITE"} ) 
 
procedure draw_values( atom bmp, sequence values ) 
     
    atom dc = create( wxMemoryDC, {bmp} ) 
    -- begin drawing here 
         
        atom pen = create( wxPen, {GREEN,1,wxSOLID} ) 
        atom brush = create( wxBrush, {WHITE,wxSOLID} ) 
        sequence size = get_dc_size( dc ) 
         
        set_pen( dc, pen ) 
        set_back_brush( dc, brush ) 
        set_text_color( dc, BLACK ) 
         
        -- fill the DC with a rectangle 
        draw_rectangle( dc, 0, 0, size[1], size[2] ) 
         
        -- draw some text 
        wx_puts( {bmp,10,size[2]-24,dc}, "Graph" ) 
         
        -- cleanup our objects 
        delete_instance( brush ) 
        delete_instance( pen ) 
         
    -- end drawing here 
    delete_instance( dc ) 
     
end procedure 
 
procedure myDialog_OnPaint( atom this, atom event_type, atom id, atom event ) 
     
    atom dc = create( wxPaintDC, {this} ) 
    begin_drawing( dc ) 
    -- begin drawing here 
         
        -- draw the buffer to the screen 
        draw_bitmap( dc, myBuffer, 10, 10, wxFalse ) 
         
    -- end drawing here 
    end_drawing( dc ) 
    delete_instance( dc ) 
     
end procedure 
 
procedure myButton_OnClick( atom this, atom event_type, atom id, atom event ) 
     
    -- OK button was clicked 
    end_modal( myDialog, wxOK ) 
     
end procedure 
 
public function show_graph( atom parent, sequence values ) 
     
    -- get the current location of the parent 
    sequence rect = get_rect( parent ) 
     
    -- create the dialog, slightly offset from the parent window 
    myDialog = create( wxDialog, {parent, -1, "Graph", rect[1]+20, rect[2]+20, 400, 300} ), 
    set_event_handler( myDialog, -1, wxEVT_PAINT, routine_id("myDialog_OnPaint") ) 
     
    -- create the bitmap 
    sequence size = get_client_size( myDialog ) 
    myBuffer = create( wxBitmap, {BM_IN_MEMORY, size[1]-20, size[2]-60} ) 
     
    -- create the "OK" button 
    myButton = create( wxButton, {myDialog, -1, "OK", size[1]-100, size[2]-40, 90, 30} ) 
    set_event_handler( myButton, -1, wxEVT_COMMAND_BUTTON_CLICKED, routine_id("myButton_OnClick") ) 
     
    -- draw the values to the buffer 
    draw_values( myBuffer, values ) 
     
    -- show the dialog 
    integer result = show_modal( myDialog ) 
     
    -- destroy the dialog 
    destroy( myDialog ) 
     
    return result 
end function