From 57acc66fd45ef77045e378967ff81e09f381d439 Mon Sep 17 00:00:00 2001 From: Dan Gudmundsson Date: Tue, 3 May 2016 13:36:28 +0200 Subject: wx: Fix warnings in example Bitmaps of size less than 1 generates asserts, and size 0 event is before window is realized. --- lib/wx/examples/demo/ex_canvas.erl | 13 ++++++++----- lib/wx/examples/demo/ex_canvas_paint.erl | 16 ++++++++++------ 2 files changed, 18 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/wx/examples/demo/ex_canvas.erl b/lib/wx/examples/demo/ex_canvas.erl index 2a95ea0777..b00ce81993 100644 --- a/lib/wx/examples/demo/ex_canvas.erl +++ b/lib/wx/examples/demo/ex_canvas.erl @@ -136,11 +136,14 @@ handle_event(#wx{event = #wxCommand{type = command_button_clicked}}, {noreply, State}; handle_event(#wx{event = #wxSize{size={W,H}}}, State = #state{bitmap=Prev, canvas=Canvas}) -> - Bitmap = wxBitmap:new(W,H), - draw(Canvas, Bitmap, fun(DC) -> wxDC:clear(DC) end), - wxBitmap:destroy(Prev), - {noreply, State#state{bitmap = Bitmap}}; - + if W > 0 andalso H > 0 -> + Bitmap = wxBitmap:new(W,H), + draw(Canvas, Bitmap, fun(DC) -> wxDC:clear(DC) end), + wxBitmap:destroy(Prev), + {noreply, State#state{bitmap = Bitmap}}; + true -> + {noreply, State} + end; handle_event(#wx{event = #wxMouse{type=left_down, x=X, y=Y}}, State) -> {noreply, State#state{pos={X,Y}}}; handle_event(#wx{event = #wxMouse{type=motion, x=X1, y=Y1}}, diff --git a/lib/wx/examples/demo/ex_canvas_paint.erl b/lib/wx/examples/demo/ex_canvas_paint.erl index aa510f5342..75eb840b04 100644 --- a/lib/wx/examples/demo/ex_canvas_paint.erl +++ b/lib/wx/examples/demo/ex_canvas_paint.erl @@ -157,10 +157,15 @@ handle_event(#wx{event = #wxMouse{type = motion, x = X, y = Y}}, {noreply, State#state{old_pos = {X,Y}}}; %% Resize event handle_event(#wx{event = #wxSize{size = {W,H}}}, State = #state{bitmap=Prev}) -> - wxBitmap:destroy(Prev), - Bitmap = wxBitmap:new(W,H), - draw(State#state.canvas, Bitmap, fun(DC) -> wxDC:clear(DC) end), - {noreply, State#state{bitmap=Bitmap}}; + case W > 0 andalso H > 0 of + true -> + wxBitmap:destroy(Prev), + Bitmap = wxBitmap:new(W,H), + draw(State#state.canvas, Bitmap, fun(DC) -> wxDC:clear(DC) end), + {noreply, State#state{bitmap=Bitmap}}; + false -> + {noreply, State} + end; handle_event(#wx{event = #wxMouse{type = left_dclick,x = X,y = Y}}, State = #state{}) -> wxPanel:connect(State#state.canvas, motion), {noreply, State#state{old_pos = {X,Y}}}; @@ -235,11 +240,10 @@ draw(Canvas, Bitmap, Fun) -> CDC = wxClientDC:new(Canvas), Fun(MemoryDC), - wxDC:blit(CDC, {0,0}, {wxBitmap:getWidth(Bitmap), wxBitmap:getHeight(Bitmap)}, MemoryDC, {0,0}), - + wxClientDC:destroy(CDC), wxMemoryDC:destroy(MemoryDC). -- cgit v1.2.3