aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/examples/demo/ex_canvas_paint.erl
diff options
context:
space:
mode:
authorDan Gudmundsson <[email protected]>2016-05-03 13:36:28 +0200
committerDan Gudmundsson <[email protected]>2016-05-03 13:36:28 +0200
commit57acc66fd45ef77045e378967ff81e09f381d439 (patch)
treec489cfa5230cc2df035ba43e7c7563ed36936848 /lib/wx/examples/demo/ex_canvas_paint.erl
parent6e88e68dba5b608c824d592367a2f39af8c082b9 (diff)
downloadotp-57acc66fd45ef77045e378967ff81e09f381d439.tar.gz
otp-57acc66fd45ef77045e378967ff81e09f381d439.tar.bz2
otp-57acc66fd45ef77045e378967ff81e09f381d439.zip
wx: Fix warnings in example
Bitmaps of size less than 1 generates asserts, and size 0 event is before window is realized.
Diffstat (limited to 'lib/wx/examples/demo/ex_canvas_paint.erl')
-rw-r--r--lib/wx/examples/demo/ex_canvas_paint.erl16
1 files changed, 10 insertions, 6 deletions
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).