without warning include wxEuphoria.e include wxGraphics.e include wxStatusBar.e include tiles.e include wxButton.e integer FLAG, isDragging, isDrawing, currPen, currPenSize FLAG = 1 isDragging = wxFalse isDrawing = wxFalse sequence origin origin = {0,0} constant Win = create( wxFrame,{0, -1, "Tile Window", -1, -1, 240, 260, wx_or_all({wxDEFAULT_FRAME_STYLE,wxCLIP_CHILDREN}) } ), blankBMP = create( wxBitmap, {BM_IN_MEMORY, 2000, 2000}), canvasBMP = create( wxBitmap, {BM_IN_MEMORY, 2000, 2000}), drawWin = create( wxPanel, Win ), -- {Win, -1, -1, -1, -1, -1, wxCLIP_CHILDREN} ), drawDC = create( wxMemoryDC, blankBMP ), canvasDC = create( wxMemoryDC, canvasBMP ), Red = create( wxColour, {255,0,0}), Green = create( wxColour, {0,255,0}), Blue = create( wxColour, {0,0,255}), penRed = create( wxPen, {Red,1,wxSOLID} ), penGreen = create( wxPen, {Green,1,wxSOLID} ), penBlue = create( wxPen, {Blue,1,wxSOLID} ) currPen = penBlue currPenSize = 1 function pick( sequence s ) return s[ rand(length(s)) ] end function procedure no_erase(atom this, atom id, atom event_type, atom event ) -- this helps eliminate the flicker end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_ERASE_BACKGROUND, routine_id("no_erase")) procedure create_bitmaps() atom bmp sequence extent for i = 0 to 2000 by 23 do for j = 0 to 2000 by 23 do bmp = pick( {Block,Question,Check,Mine} ) draw_bitmap( drawDC, bmp, i, j, 0 ) end for end for clear_dc( canvasDC ) end procedure create_bitmaps() procedure Paint( atom this, atom id, atom event_type, atom event ) atom bmp sequence extent atom windc windc = create( wxPaintDC, this) extent = get_client_size( this ) blit( windc, 0, 0, drawDC, origin[1], origin[2], extent[1], extent[2], wxCOPY ) delete_instance( windc ) end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_PAINT, routine_id("Paint")) sequence clickOrigin procedure left_down( atom this, atom id, atom event_type, atom event ) integer pressedShift clickOrigin = mouse_event_position(event) if mouse_event_shiftdown( event ) then -- wants to move pic isDragging = wxTrue else -- wants to draw isDrawing = wxTrue end if capture_mouse( drawWin ) end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_LEFT_DOWN, routine_id("left_down")) procedure mouse_motion( atom this, atom id, atom event_type, atom event ) sequence currPos, newPos, canvasSize currPos = mouse_event_position(event) canvasSize = get_client_size( drawWin ) if isDragging then origin = origin - ( currPos - clickOrigin ) if origin[1] < 0 then origin[1] = 0 end if if origin[2] < 0 then origin[2] = 0 end if if origin[1] + canvasSize[1] > 2000 then origin[1] = 2000 - canvasSize[1] end if if origin[2] + canvasSize[2] > 2000 then origin[2] = 2000 - canvasSize[2] end if clickOrigin = currPos refresh_window( this ) elsif isDrawing then draw_line( drawDC, (clickOrigin + origin) & (currPos + origin) ) clickOrigin = currPos refresh_window( this ) end if end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_MOTION, routine_id("mouse_motion")) procedure left_up( atom this, atom id, atom event_type, atom event ) release_mouse( drawWin ) isDragging = wxFalse isDrawing = wxFalse end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_LEFT_UP, routine_id("left_up")) procedure key_down( atom this, atom id, atom event_type, atom event ) integer keycode, shifted sequence ins object junk keycode = get_key_code(event) shifted = key_event_shiftdown( event ) if keycode = WXK_F1 then ins = "Click + Drag - Draw\nShift+Click+Drag - Move palette\n1 - Change to red pen\n2 - Change to blue pen\n3 - Change to green pen\n" & "! - 1-pt pen thickness\n@ - 3-pt pen thickness\n# - 7-pt pen thickness\n" & "F1 - This help dialog\nESC - Exit" junk = message_box(ins,"Bitmap Manipulation Help",wxOK) elsif keycode = WXK_ESCAPE then exit_main() elsif keycode = '1' then if shifted then currPenSize = 1 else currPen = penRed end if set_pen_size( currPen, currPenSize ) set_pen( drawDC, currPen ) elsif keycode = '2' then if shifted then currPenSize = 3 else currPen = penBlue end if set_pen_size( currPen, currPenSize ) set_pen( drawDC, currPen ) elsif keycode = '3' then if shifted then currPenSize = 7 else currPen = penGreen end if set_pen_size( currPen, currPenSize ) set_pen( drawDC, currPen ) end if end procedure set_event_handler( drawWin, get_id(drawWin), wxEVT_KEY_DOWN, routine_id("key_down")) wxMain( Win )