aboutsummaryrefslogtreecommitdiffstats
path: root/lib/wx/examples
diff options
context:
space:
mode:
Diffstat (limited to 'lib/wx/examples')
-rw-r--r--lib/wx/examples/demo/demo.erl53
-rw-r--r--lib/wx/examples/demo/ex_aui.erl22
-rw-r--r--lib/wx/examples/demo/ex_button.erl10
-rw-r--r--lib/wx/examples/demo/ex_canvas.erl5
-rw-r--r--lib/wx/examples/demo/ex_canvas_paint.erl25
-rw-r--r--lib/wx/examples/demo/ex_choices.erl6
-rw-r--r--lib/wx/examples/demo/ex_cursor.erl4
-rw-r--r--lib/wx/examples/demo/ex_dialogs.erl4
-rw-r--r--lib/wx/examples/demo/ex_frame_utils.erl4
-rw-r--r--lib/wx/examples/demo/ex_gauge.erl4
-rw-r--r--lib/wx/examples/demo/ex_gl.erl61
-rw-r--r--lib/wx/examples/demo/ex_graphicsContext.erl42
-rw-r--r--lib/wx/examples/demo/ex_grid.erl4
-rw-r--r--lib/wx/examples/demo/ex_htmlWindow.erl4
-rw-r--r--lib/wx/examples/demo/ex_listCtrl.erl8
-rw-r--r--lib/wx/examples/demo/ex_notebook.erl4
-rw-r--r--lib/wx/examples/demo/ex_pickers.erl4
-rw-r--r--lib/wx/examples/demo/ex_popupMenu.erl4
-rw-r--r--lib/wx/examples/demo/ex_radioBox.erl4
-rw-r--r--lib/wx/examples/demo/ex_sashWindow.erl4
-rw-r--r--lib/wx/examples/demo/ex_sizers.erl4
-rw-r--r--lib/wx/examples/demo/ex_slider.erl4
-rw-r--r--lib/wx/examples/demo/ex_splitterWindow.erl4
-rw-r--r--lib/wx/examples/demo/ex_static.erl4
-rw-r--r--lib/wx/examples/demo/ex_textCtrl.erl24
-rw-r--r--lib/wx/examples/demo/ex_treeCtrl.erl4
-rw-r--r--lib/wx/examples/simple/menu.erl4
-rw-r--r--lib/wx/examples/simple/minimal.erl6
-rw-r--r--lib/wx/examples/sudoku/sudoku_board.erl46
-rw-r--r--lib/wx/examples/sudoku/sudoku_gui.erl25
30 files changed, 264 insertions, 137 deletions
diff --git a/lib/wx/examples/demo/demo.erl b/lib/wx/examples/demo/demo.erl
index 61e71af021..2f560096f5 100644
--- a/lib/wx/examples/demo/demo.erl
+++ b/lib/wx/examples/demo/demo.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -32,6 +32,21 @@
-record(state, {win, demo, example, selector, log, code}).
+%% For wx-2.9 usage
+-ifndef(wxSTC_ERLANG_COMMENT_FUNCTION).
+-define(wxSTC_ERLANG_COMMENT_FUNCTION, 14).
+-define(wxSTC_ERLANG_COMMENT_MODULE, 15).
+-define(wxSTC_ERLANG_COMMENT_DOC, 16).
+-define(wxSTC_ERLANG_COMMENT_DOC_MACRO, 17).
+-define(wxSTC_ERLANG_ATOM_QUOTED, 18).
+-define(wxSTC_ERLANG_MACRO_QUOTED, 19).
+-define(wxSTC_ERLANG_RECORD_QUOTED, 20).
+-define(wxSTC_ERLANG_NODE_NAME_QUOTED, 21).
+-define(wxSTC_ERLANG_BIFS, 22).
+-define(wxSTC_ERLANG_MODULES, 23).
+-define(wxSTC_ERLANG_MODULES_ATT, 24).
+-endif.
+
start() ->
start([]).
@@ -78,6 +93,7 @@ init(Options) ->
wxFrame:setMenuBar(Frame,MB),
wxFrame:connect(Frame, command_menu_selected),
+ wxFrame:connect(Frame, close_window),
_SB = wxFrame:createStatusBar(Frame,[]),
@@ -179,6 +195,8 @@ create_subwindow(Parent, BoxLabel, Funs) ->
%% Handled as in normal gen_server callbacks
handle_info({'EXIT',_, wx_deleted}, State) ->
{noreply,State};
+handle_info({'EXIT',_, shutdown}, State) ->
+ {noreply,State};
handle_info({'EXIT',_, normal}, State) ->
{noreply,State};
handle_info(Msg, State) ->
@@ -197,13 +215,13 @@ handle_cast(Msg, State) ->
handle_event(#wx{event=#wxCommand{type=command_listbox_selected, cmdString=Ex}},
State = #state{demo={_,DemoSz}, example=Example, code=Code}) ->
case Ex of
- [] ->
+ [] ->
{noreply, State};
_ ->
wxSizer:detach(DemoSz, Example),
- wxWindow:destroy(Example),
+ wx_object:call(Example, shutdown),
unload_code(Code),
- NewExample = load_example(Ex, State),
+ NewExample = load_example(Ex, State),
wxSizer:add(DemoSz, NewExample, [{proportion,1}, {flag, ?wxEXPAND}]),
wxSizer:layout(DemoSz),
{noreply, State#state{example=NewExample}}
@@ -247,9 +265,9 @@ handle_event(#wx{id = Id,
?wxICON_INFORMATION bor
?wxSTAY_ON_TOP},
{caption, "About"}])),
- {noreply, State};
+ {noreply, State};
?wxID_EXIT ->
- wx_object:get_pid(State#state.example) ! stop,
+ wx_object:call(State#state.example, shutdown),
{stop, normal, State};
_ ->
{noreply, State}
@@ -265,9 +283,9 @@ handle_event(Ev,State) ->
code_change(_, _, State) ->
{stop, not_yet_implemented, State}.
-terminate(_Reason, State) ->
- wx_object:get_pid(State#state.example) ! stop,
- timer:sleep(200), %% Give the example process some time to cleanup.
+terminate(_Reason, State = #state{win=Frame}) ->
+ catch wx_object:call(State#state.example, shutdown),
+ wxFrame:destroy(Frame),
wx:destroy().
%%%%%%%%%%%%%%%%% Internals %%%%%%%%%%
@@ -275,8 +293,6 @@ terminate(_Reason, State) ->
load_example(Ex, #state{demo={DemoPanel,DemoSz}, log=EvCtrl, code=Code}) ->
ModStr = "ex_" ++ Ex,
Mod = list_to_atom(ModStr),
-%% WxDir = code:lib_dir(wx),
-%% ModFile = filename:join([WxDir, "examples","demo", ModStr ++ ".erl"]),
ModFile = ModStr ++ ".erl",
load_code(Code, file:read_file(ModFile)),
find(Code),
@@ -312,7 +328,20 @@ code_area(Parent) ->
{?wxSTC_ERLANG_MACRO, {40,144,170}},
{?wxSTC_ERLANG_RECORD, {40,100,20}},
{?wxSTC_ERLANG_SEPARATOR,{0,0,0}},
- {?wxSTC_ERLANG_NODE_NAME,{0,0,0}}],
+ {?wxSTC_ERLANG_NODE_NAME,{0,0,0}},
+ %% Optional 2.9 stuff
+ {?wxSTC_ERLANG_COMMENT_FUNCTION, {160,53,35}},
+ {?wxSTC_ERLANG_COMMENT_MODULE, {160,53,35}},
+ {?wxSTC_ERLANG_COMMENT_DOC, {160,53,35}},
+ {?wxSTC_ERLANG_COMMENT_DOC_MACRO, {160,53,35}},
+ {?wxSTC_ERLANG_ATOM_QUOTED, {0,0,0}},
+ {?wxSTC_ERLANG_MACRO_QUOTED, {40,144,170}},
+ {?wxSTC_ERLANG_RECORD_QUOTED, {40,100,20}},
+ {?wxSTC_ERLANG_NODE_NAME_QUOTED, {0,0,0}},
+ {?wxSTC_ERLANG_BIFS, {130,40,172}},
+ {?wxSTC_ERLANG_MODULES, {64,102,244}},
+ {?wxSTC_ERLANG_MODULES_ATT, {64,102,244}}
+ ],
SetStyle = fun({Style, Color}) ->
?stc:styleSetFont(Ed, Style, FixedFont),
?stc:styleSetForeground(Ed, Style, Color)
diff --git a/lib/wx/examples/demo/ex_aui.erl b/lib/wx/examples/demo/ex_aui.erl
index 50f077638d..70372caad8 100644
--- a/lib/wx/examples/demo/ex_aui.erl
+++ b/lib/wx/examples/demo/ex_aui.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -32,7 +32,8 @@
-record(state,
{
parent,
- config
+ config,
+ aui
}).
start(Config) ->
@@ -47,12 +48,10 @@ init(Config) ->
do_init(Config) ->
Parent = proplists:get_value(parent, Config),
Panel = wxPanel:new(Parent, []),
-
%% Setup sizers
MainSizer = wxBoxSizer:new(?wxVERTICAL),
- Manager = wxAuiManager:new([{managed_wnd, Panel}
- ]),
+ Manager = wxAuiManager:new([{managed_wnd, Panel}]),
Pane = ?pi:new(),
?pi:closeButton(Pane),
@@ -79,8 +78,8 @@ do_init(Config) ->
wxAuiManager:connect(Manager, aui_pane_button, [{skip,true}]),
wxAuiManager:connect(Manager, aui_pane_maximize, [{skip,true}]),
wxAuiManager:update(Manager),
-
- {Panel, #state{parent=Panel, config=Config}}.
+ process_flag(trap_exit, true),
+ {Panel, #state{parent=Panel, config=Config, aui=Manager}}.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% Callbacks handled as normal gen_server callbacks
@@ -88,6 +87,12 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel, aui=Manager}) ->
+ wxAuiManager:unInit(Manager),
+ wxAuiManager:destroy(Manager),
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
@@ -134,11 +139,10 @@ handle_event(Ev = #wx{}, State) ->
io:format("~p\n", [Ev]),
{noreply, State}.
-
code_change(_, _, State) ->
{stop, ignore, State}.
-terminate(_Reason, _State) ->
+terminate(_Reason, _) ->
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/lib/wx/examples/demo/ex_button.erl b/lib/wx/examples/demo/ex_button.erl
index 0dd0363933..41bf34e572 100644
--- a/lib/wx/examples/demo/ex_button.erl
+++ b/lib/wx/examples/demo/ex_button.erl
@@ -25,7 +25,8 @@
-include_lib("wx/include/wx.hrl").
-behaviour(wx_object).
--export([start/1, init/1, terminate/2, code_change/3,
+-export([start/1, init/1,
+ terminate/2, code_change/3,
handle_info/2, handle_call/3, handle_cast/2, handle_event/2]).
-record(state,
@@ -120,6 +121,7 @@ do_init(Config) ->
wxWindow:connect(Panel, command_button_clicked),
wxWindow:setSizer(Panel, Sz),
wxSizer:layout(Sz),
+ wxWindow:refresh(Panel),
wxScrolledWindow:setScrollRate(Panel, 5, 5),
{Panel, #state{parent=Panel, config=Config}}.
@@ -149,6 +151,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p~n",[Msg]),
{noreply,State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p~n",[Msg]),
{reply,ok,State}.
@@ -160,7 +166,7 @@ handle_cast(Msg, State) ->
code_change(_, _, State) ->
{stop, ignore, State}.
-terminate(_Reason, _State) ->
+terminate(_Reason, _) ->
ok.
%%%%% a copy from wxwidgets samples.
diff --git a/lib/wx/examples/demo/ex_canvas.erl b/lib/wx/examples/demo/ex_canvas.erl
index 1ec4760f40..1f1d260276 100644
--- a/lib/wx/examples/demo/ex_canvas.erl
+++ b/lib/wx/examples/demo/ex_canvas.erl
@@ -140,6 +140,9 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
@@ -151,7 +154,7 @@ handle_cast(Msg, State) ->
code_change(_, _, State) ->
{stop, ignore, State}.
-terminate(_Reason, _State) ->
+terminate(_Reason, _) ->
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/lib/wx/examples/demo/ex_canvas_paint.erl b/lib/wx/examples/demo/ex_canvas_paint.erl
index 9bc083766a..6873724655 100644
--- a/lib/wx/examples/demo/ex_canvas_paint.erl
+++ b/lib/wx/examples/demo/ex_canvas_paint.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -207,6 +207,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
@@ -218,7 +222,7 @@ handle_cast(Msg, State) ->
code_change(_, _, State) ->
{stop, ignore, State}.
-terminate(_Reason, _State) ->
+terminate(_Reason, _) ->
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -239,14 +243,17 @@ draw(Canvas, Bitmap, Fun) ->
wxMemoryDC:destroy(MemoryDC).
redraw(DC, Bitmap) ->
- MemoryDC = wxMemoryDC:new(Bitmap),
+ try
+ MemoryDC = wxMemoryDC:new(Bitmap),
- wxDC:blit(DC, {0,0},
- {wxBitmap:getWidth(Bitmap), wxBitmap:getHeight(Bitmap)},
- MemoryDC, {0,0}),
-
- wxMemoryDC:destroy(MemoryDC).
+ wxDC:blit(DC, {0,0},
+ {wxBitmap:getWidth(Bitmap), wxBitmap:getHeight(Bitmap)},
+ MemoryDC, {0,0}),
+ wxMemoryDC:destroy(MemoryDC)
+ catch error:{{badarg,_},_} -> %% Bitmap have been deleted
+ ok
+ end.
-getPageInfo(_This) ->
+getPageInfo(_This) ->
{1,1,1,1}.
diff --git a/lib/wx/examples/demo/ex_choices.erl b/lib/wx/examples/demo/ex_choices.erl
index 2e456ae249..b4418293c1 100644
--- a/lib/wx/examples/demo/ex_choices.erl
+++ b/lib/wx/examples/demo/ex_choices.erl
@@ -143,6 +143,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply, {error,nyi}, State}.
@@ -154,7 +158,7 @@ handle_cast(Msg, State) ->
code_change(_, _, State) ->
{stop, ignore, State}.
-terminate(_Reason, _State) ->
+terminate(_Reason, _) ->
ok.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
diff --git a/lib/wx/examples/demo/ex_cursor.erl b/lib/wx/examples/demo/ex_cursor.erl
index c1a558541b..2f1eaaf7c7 100644
--- a/lib/wx/examples/demo/ex_cursor.erl
+++ b/lib/wx/examples/demo/ex_cursor.erl
@@ -131,6 +131,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_dialogs.erl b/lib/wx/examples/demo/ex_dialogs.erl
index b39344f8b1..5c47b51271 100644
--- a/lib/wx/examples/demo/ex_dialogs.erl
+++ b/lib/wx/examples/demo/ex_dialogs.erl
@@ -149,6 +149,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_frame_utils.erl b/lib/wx/examples/demo/ex_frame_utils.erl
index a90642b355..4a59bb3a68 100644
--- a/lib/wx/examples/demo/ex_frame_utils.erl
+++ b/lib/wx/examples/demo/ex_frame_utils.erl
@@ -98,6 +98,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_gauge.erl b/lib/wx/examples/demo/ex_gauge.erl
index ffc667ff05..c53dfb807b 100644
--- a/lib/wx/examples/demo/ex_gauge.erl
+++ b/lib/wx/examples/demo/ex_gauge.erl
@@ -114,6 +114,10 @@ handle_info(pulse, State=#state{undeterminate_gauge = Gauge=#gauge{obj = Obj}})
Timer = erlang:send_after(300, self(), pulse),
{noreply, State#state{undeterminate_gauge = Gauge#gauge{timer = Timer}}}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply,ok, State}.
diff --git a/lib/wx/examples/demo/ex_gl.erl b/lib/wx/examples/demo/ex_gl.erl
index 72dad2cf9d..6bb2d12dff 100644
--- a/lib/wx/examples/demo/ex_gl.erl
+++ b/lib/wx/examples/demo/ex_gl.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -20,7 +20,8 @@
-behaviour(wx_object).
--export([init/1, code_change/3, handle_info/2, handle_event/2,
+-export([init/1, code_change/3, handle_info/2,
+ handle_sync_event/3, handle_event/2,
handle_call/3, handle_cast/2, terminate/2,
start/1]).
@@ -34,6 +35,7 @@
config,
gl,
canvas,
+ image,
timer,
time
}).
@@ -58,7 +60,7 @@ do_init(Config) ->
%% Setup sizer
Sizer = wxStaticBoxSizer:new(?wxHORIZONTAL, Panel, [{label, "wxGLCanvas"}]),
- Opts = [{size, {300,300}}, {style, ?wxSUNKEN_BORDER}],
+ Opts = [{style, ?wxFULL_REPAINT_ON_RESIZE}],
GLAttrib = [{attribList, [?WX_GL_RGBA,
?WX_GL_DOUBLEBUFFER,
?WX_GL_MIN_RED,8,
@@ -67,34 +69,48 @@ do_init(Config) ->
?WX_GL_DEPTH_SIZE,24,0]}],
Canvas = wxGLCanvas:new(Panel,Opts ++ GLAttrib),
wxGLCanvas:connect(Canvas, size),
+ wxGLCanvas:connect(Canvas, paint, [callback]),
- wxGLCanvas:setCurrent(Canvas),
Image = wxImage:scale(wxImage:new("image.jpg"), 128,128),
- GL = setup_gl(Canvas,Image),
- Timer = timer:send_interval(20, self(), update),
%% Add to sizers
wxSizer:add(Sizer, Canvas, [{flag, ?wxEXPAND},{proportion, 1}]),
wxWindow:setSizer(Panel,Sizer),
wxSizer:layout(Sizer),
+ Timer = timer:send_interval(20, self(), update),
{Panel, #state{parent = Panel, config = Config,
- canvas = Canvas,
- gl = GL, timer = Timer}}.
+ canvas = Canvas, image=Image,
+ timer = Timer}}.
%% Event handling
-handle_event(#wx{event = #wxSize{size = {W,H}}}, State) ->
- case W =:= 0 orelse H =:= 0 of
- true -> skip;
- _ ->
+handle_sync_event(_PaintEvent, _, #state{canvas=Canvas}) ->
+ %% Sync events are called from a temporary process,
+ %% we need to setup the gl canvas on cocoa for some reason
+ %% We do not really have to do anything, the timer event will refresh the painting
+ wxGLCanvas:setCurrent(Canvas),
+ DC= wxPaintDC:new(Canvas),
+ wxPaintDC:destroy(DC),
+ ok.
+
+handle_event(#wx{event = #wxSize{size = {W,H}}}, State = #state{gl=GL}) ->
+ if
+ GL =:= undefined ->
+ #state{canvas=Canvas, image=Image} = State,
+ wxGLCanvas:setCurrent(Canvas),
+ {noreply, State#state{gl=setup_gl(Canvas,Image)}};
+ W =:= 0, H =:= 0 -> {noreply, State};
+ true ->
gl:viewport(0,0,W,H),
gl:matrixMode(?GL_PROJECTION),
gl:loadIdentity(),
gl:ortho( -2.0, 2.0, -2.0*H/W, 2.0*H/W, -20.0, 20.0),
gl:matrixMode(?GL_MODELVIEW),
- gl:loadIdentity()
- end,
- {noreply, State}.
+ gl:loadIdentity(),
+ {noreply, State}
+ end.
+handle_info(update, State=#state{gl=undefined}) ->
+ {noreply, State};
handle_info(update, State) ->
S1 = update_rotation(State),
GL = S1#state.gl,
@@ -113,7 +129,13 @@ handle_info(stop, State) ->
timer:cancel(State#state.timer),
catch wxGLCanvas:destroy(State#state.canvas),
{stop, normal, State}.
-
+
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ catch wxGLCanvas:destroy(State#state.canvas),
+ timer:cancel(State#state.timer),
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
io:format("Got Call ~p~n",[Msg]),
{reply,ok,State}.
@@ -125,11 +147,8 @@ handle_cast(Msg, State) ->
code_change(_, _, State) ->
{stop, not_yet_implemented, State}.
-terminate(_Reason, State) ->
- catch wxGLCanvas:destroy(State#state.canvas),
- timer:cancel(State#state.timer),
- timer:sleep(300).
-
+terminate(_Reason, _State) ->
+ ok.
-define(VS, {{-0.5, -0.5, -0.5}, %1
diff --git a/lib/wx/examples/demo/ex_graphicsContext.erl b/lib/wx/examples/demo/ex_graphicsContext.erl
index c356500d99..59bfe7ff64 100644
--- a/lib/wx/examples/demo/ex_graphicsContext.erl
+++ b/lib/wx/examples/demo/ex_graphicsContext.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -25,8 +25,8 @@
%% wx_object callbacks
-export([init/1, terminate/2, code_change/3,
- handle_info/2, handle_call/3,
-handle_cast/2, handle_event/2, handle_sync_event/3]).
+ handle_info/2, handle_call/3,handle_cast/2,
+ handle_event/2, handle_sync_event/3]).
-include_lib("wx/include/wx.hrl").
@@ -57,11 +57,9 @@ do_init(Config) ->
[{label, "wxGrapicsContext"}]),
Win = wxPanel:new(Panel, []),
- Pen = wxPen:new(),
- Brush = wxBrush:new(?wxBLACK),
- Font = wxFont:new(),
- wxFont:setWeight(Font, ?wxBOLD),
-
+ Pen = ?wxBLACK_PEN,
+ Brush = wxBrush:new({30, 175, 23, 127}),
+ Font = ?wxITALIC_FONT,
wxPanel:connect(Win, paint, [callback]),
%% Add to sizers
@@ -94,6 +92,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
@@ -112,36 +114,26 @@ terminate(_Reason, _State) ->
%% Local functions
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-draw(Win, Pen0, _Brush0, Font0) ->
+draw(Win, Pen, Brush, Font) ->
try
Canvas = wxGraphicsContext:create(Win),
- Pen = wxGraphicsContext:createPen(Canvas, Pen0),
wxGraphicsContext:setPen(Canvas, Pen),
- Brush = wxGraphicsContext:createLinearGradientBrush(Canvas, 0.0,0.0, 30.0,30.0,
- {200,50,50,50},
- {200,50,50,200}),
wxGraphicsContext:setBrush(Canvas, Brush),
- Font = wxGraphicsContext:createFont(Canvas, Font0),
- wxGraphicsContext:setFont(Canvas, Font),
+ wxGraphicsContext:setFont(Canvas, Font, {0, 0, 50}),
wxGraphicsContext:drawRoundedRectangle(Canvas, 35.0,35.0, 100.0, 50.0, 10.0),
- wxGraphicsContext:drawText(Canvas, "Welcome", 60.0, 55.0),
+ wxGraphicsContext:drawText(Canvas, "This text should be antialised", 60.0, 55.0),
Path = wxGraphicsContext:createPath(Canvas),
wxGraphicsPath:addCircle(Path, 0.0, 0.0, 40.0),
wxGraphicsPath:closeSubpath(Path),
- wxGraphicsContext:translate(Canvas, 100.0, 100.0),
-
- Brush2 = wxGraphicsContext:createLinearGradientBrush(Canvas, 0.0,0.0, 30.0,30.0,
- {50,200,50,50},
- {50,50,200,50}),
- wxGraphicsContext:setBrush(Canvas, Brush2),
+ wxGraphicsContext:translate(Canvas, 100.0, 250.0),
- F = fun(_) ->
+ F = fun(N) ->
wxGraphicsContext:scale(Canvas, 1.1, 1.1),
- wxGraphicsContext:translate(Canvas, 3.0,3.0),
+ wxGraphicsContext:translate(Canvas, 15.0,-1.0*N),
wxGraphicsContext:drawPath(Canvas, Path)
end,
- wx:foreach(F, lists:seq(1,5)),
+ wx:foreach(F, lists:seq(1,10)),
ok
catch _:{not_supported, _} ->
Err = "wxGraphicsContext not available in this build of wxwidgets",
diff --git a/lib/wx/examples/demo/ex_grid.erl b/lib/wx/examples/demo/ex_grid.erl
index d1a9952ab2..e284836d5b 100644
--- a/lib/wx/examples/demo/ex_grid.erl
+++ b/lib/wx/examples/demo/ex_grid.erl
@@ -78,6 +78,10 @@ handle_event(#wx{event = #wxGrid{type = grid_cell_change,
handle_info(_Msg, State) ->
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(_Msg, _From, State) ->
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_htmlWindow.erl b/lib/wx/examples/demo/ex_htmlWindow.erl
index 564c790e48..af3d4c71f5 100644
--- a/lib/wx/examples/demo/ex_htmlWindow.erl
+++ b/lib/wx/examples/demo/ex_htmlWindow.erl
@@ -77,6 +77,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_listCtrl.erl b/lib/wx/examples/demo/ex_listCtrl.erl
index 13096dfa52..2c62ac9d5f 100644
--- a/lib/wx/examples/demo/ex_listCtrl.erl
+++ b/lib/wx/examples/demo/ex_listCtrl.erl
@@ -58,8 +58,8 @@ do_init(Config) ->
IL = wxImageList:new(16,16),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_COPY", [{size, {16,16}}])),
wxImageList:add(IL, wxArtProvider:getBitmap("wxART_MISSING_IMAGE", [{size, {16,16}}])),
- wxImageList:add(IL, wxArtProvider:getBitmap("wxART_TICK_MARK", [{size, {16,16}}])),
- wxImageList:add(IL, wxArtProvider:getBitmap("wxART_CROSS_MARK", [{size, {16,16}}])),
+ wxImageList:add(IL, wxArtProvider:getBitmap("wxART_QUESTION", [{size, {16,16}}])),
+ wxImageList:add(IL, wxArtProvider:getBitmap("wxART_WARNING", [{size, {16,16}}])),
wxListCtrl:assignImageList(ListCtrl2, IL, ?wxIMAGE_LIST_SMALL),
Fun =
fun(Item) ->
@@ -143,6 +143,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply,State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply,ok,State}.
diff --git a/lib/wx/examples/demo/ex_notebook.erl b/lib/wx/examples/demo/ex_notebook.erl
index fc38fdae08..5edcc65082 100644
--- a/lib/wx/examples/demo/ex_notebook.erl
+++ b/lib/wx/examples/demo/ex_notebook.erl
@@ -129,6 +129,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply,State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply,ok,State}.
diff --git a/lib/wx/examples/demo/ex_pickers.erl b/lib/wx/examples/demo/ex_pickers.erl
index 8013a5ba32..54f8c7a8e5 100644
--- a/lib/wx/examples/demo/ex_pickers.erl
+++ b/lib/wx/examples/demo/ex_pickers.erl
@@ -120,6 +120,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_popupMenu.erl b/lib/wx/examples/demo/ex_popupMenu.erl
index d6778c5dc5..f48b00963d 100644
--- a/lib/wx/examples/demo/ex_popupMenu.erl
+++ b/lib/wx/examples/demo/ex_popupMenu.erl
@@ -86,6 +86,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_radioBox.erl b/lib/wx/examples/demo/ex_radioBox.erl
index ab7685f41f..17a11d1054 100644
--- a/lib/wx/examples/demo/ex_radioBox.erl
+++ b/lib/wx/examples/demo/ex_radioBox.erl
@@ -103,6 +103,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply, {error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_sashWindow.erl b/lib/wx/examples/demo/ex_sashWindow.erl
index d8a8958f28..9eb3b9b27e 100644
--- a/lib/wx/examples/demo/ex_sashWindow.erl
+++ b/lib/wx/examples/demo/ex_sashWindow.erl
@@ -112,6 +112,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_sizers.erl b/lib/wx/examples/demo/ex_sizers.erl
index 7b9e8eb37f..ecd539cd62 100644
--- a/lib/wx/examples/demo/ex_sizers.erl
+++ b/lib/wx/examples/demo/ex_sizers.erl
@@ -97,6 +97,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_slider.erl b/lib/wx/examples/demo/ex_slider.erl
index 612543ff26..4979e8b4f4 100644
--- a/lib/wx/examples/demo/ex_slider.erl
+++ b/lib/wx/examples/demo/ex_slider.erl
@@ -97,6 +97,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply, {error, nyi},State}.
diff --git a/lib/wx/examples/demo/ex_splitterWindow.erl b/lib/wx/examples/demo/ex_splitterWindow.erl
index 4f25b73293..ac2fbe0113 100644
--- a/lib/wx/examples/demo/ex_splitterWindow.erl
+++ b/lib/wx/examples/demo/ex_splitterWindow.erl
@@ -86,6 +86,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_static.erl b/lib/wx/examples/demo/ex_static.erl
index 013bd5ac35..8cf477b55a 100644
--- a/lib/wx/examples/demo/ex_static.erl
+++ b/lib/wx/examples/demo/ex_static.erl
@@ -101,6 +101,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_textCtrl.erl b/lib/wx/examples/demo/ex_textCtrl.erl
index d82884f30b..57088ad878 100644
--- a/lib/wx/examples/demo/ex_textCtrl.erl
+++ b/lib/wx/examples/demo/ex_textCtrl.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -51,27 +51,23 @@ do_init(Config) ->
Sizer3 = wxStaticBoxSizer:new(?wxVERTICAL, Panel,
[{label, "wxTextCtrl multiline"}]),
- TextCtrl = wxTextCtrl:new(Panel, 1, [{value, "This is a single line wxTextCtrl"},
+ TextCtrl = wxTextCtrl:new(Panel, 1, [{value, "This is a single line wxTextCtrl"},
{style, ?wxDEFAULT}]),
TextCtrl2 = wxTextCtrl:new(Panel, 2, [{value, "password"},
- {style, ?wxDEFAULT bor
- ?wxTE_PASSWORD}]),
- TextCtrl3 = wxTextCtrl:new(Panel, 3, [{value, "This is a\n"
- "multiline\n"
- "wxTextCtrl"},
- {style, ?wxDEFAULT bor
- ?wxTE_MULTILINE}]),
+ {style, ?wxDEFAULT bor ?wxTE_PASSWORD}]),
+ TextCtrl3 = wxTextCtrl:new(Panel, 3, [{value, "This is a\nmultiline\nwxTextCtrl"},
+ {style, ?wxDEFAULT bor ?wxTE_MULTILINE}]),
%% Add to sizers
- wxSizer:add(Sizer, TextCtrl, [{flag, ?wxEXPAND}]),
+ wxSizer:add(Sizer, TextCtrl, [{flag, ?wxEXPAND}]),
wxSizer:add(Sizer2, TextCtrl2, []),
- wxSizer:add(Sizer3, TextCtrl3, [{flag, ?wxEXPAND}]),
+ wxSizer:add(Sizer3, TextCtrl3, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxSizer:add(MainSizer, Sizer, [{flag, ?wxEXPAND}]),
wxSizer:addSpacer(MainSizer, 10),
wxSizer:add(MainSizer, Sizer2, [{flag, ?wxEXPAND}]),
wxSizer:addSpacer(MainSizer, 10),
- wxSizer:add(MainSizer, Sizer3, [{flag, ?wxEXPAND}]),
+ wxSizer:add(MainSizer, Sizer3, [{flag, ?wxEXPAND}, {proportion, 1}]),
wxPanel:setSizer(Panel, MainSizer),
{Panel, #state{parent=Panel, config=Config}}.
@@ -88,6 +84,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n",[Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config,"Got Call ~p\n",[Msg]),
{reply, {error,nyi}, State}.
diff --git a/lib/wx/examples/demo/ex_treeCtrl.erl b/lib/wx/examples/demo/ex_treeCtrl.erl
index 611904500a..7698ab1f00 100644
--- a/lib/wx/examples/demo/ex_treeCtrl.erl
+++ b/lib/wx/examples/demo/ex_treeCtrl.erl
@@ -105,6 +105,10 @@ handle_info(Msg, State) ->
demo:format(State#state.config, "Got Info ~p\n", [Msg]),
{noreply, State}.
+handle_call(shutdown, _From, State=#state{parent=Panel}) ->
+ wxPanel:destroy(Panel),
+ {stop, normal, ok, State};
+
handle_call(Msg, _From, State) ->
demo:format(State#state.config, "Got Call ~p\n", [Msg]),
{reply,{error, nyi}, State}.
diff --git a/lib/wx/examples/simple/menu.erl b/lib/wx/examples/simple/menu.erl
index 0025a0b027..9e6b28b46b 100644
--- a/lib/wx/examples/simple/menu.erl
+++ b/lib/wx/examples/simple/menu.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -105,7 +105,7 @@ create_frame(Wx) ->
Frame = wxFrame:new(Wx, -1, "wxErlang menu sample", [{size, {600,400}}]),
Path = filename:dirname(code:which(?MODULE)),
- wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"))),
+ wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"), [{type, ?wxBITMAP_TYPE_XPM}])),
wxFrame:createStatusBar(Frame,[]),
wxFrame:connect(Frame, close_window),
diff --git a/lib/wx/examples/simple/minimal.erl b/lib/wx/examples/simple/minimal.erl
index bdff66e217..4782745dfc 100644
--- a/lib/wx/examples/simple/minimal.erl
+++ b/lib/wx/examples/simple/minimal.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -41,8 +41,8 @@ start() ->
create_window(Wx) ->
Frame = wxFrame:new(Wx, -1, "Minimal wxErlang App", [{size, {600,400}}]),
- Path = filename:dirname(code:which(?MODULE)),
- wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"))),
+ Path = filename:dirname(code:which(?MODULE)),
+ wxFrame:setIcon(Frame, wxIcon:new(filename:join(Path,"sample.xpm"), [{type, ?wxBITMAP_TYPE_XPM}])),
wxFrame:createStatusBar(Frame,[]),
wxFrame:connect(Frame, close_window),
diff --git a/lib/wx/examples/sudoku/sudoku_board.erl b/lib/wx/examples/sudoku/sudoku_board.erl
index 4b26ff97da..ed9c62b7c8 100644
--- a/lib/wx/examples/sudoku/sudoku_board.erl
+++ b/lib/wx/examples/sudoku/sudoku_board.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -27,7 +27,7 @@
-export([new/1, setup_board/2, clear_board/1, left/1,
get_board_data/1,set_board_data/2,
set_butt/3, butt_correct/3,
- draw/3,
+ get_state/1, redraw/3,
%% Callbacks
init/1, handle_sync_event/3,
handle_event/2, handle_info/2, handle_call/3, handle_cast/2,
@@ -69,9 +69,8 @@ get_board_data(Board) ->
set_board_data(Board, List) ->
wx_object:call(Board, {set_board_data, List}).
-
-draw(Board, DC, Size) ->
- wx_object:call(Board, {draw, DC, Size}).
+get_state(Board) ->
+ wx_object:call(Board, get_state).
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -85,26 +84,29 @@ init([ParentObj, ParentPid]) ->
wxWindow:connect(Win, erase_background, []),
wxWindow:connect(Win, key_up, [{skip, true}]),
wxWindow:connect(Win, left_down, [{skip, true}]),
- wxWindow:connect(Win, enter_window, [{skip, true}]),
+ wxWindow:connect(Win, enter_window, [{skip, true}]),
%% Init pens and fonts
Pen = wxPen:new({0,0,0}, [{width, 3}]),
Fs0 = [{Sz,wxFont:new(Sz, ?wxSWISS, ?wxNORMAL, ?wxNORMAL,[])} ||
Sz <- [8,9,10,11,12,13,14,16,18,20,22,24,26,28,30,34,38,42,44,46]],
- TestDC = wxClientDC:new(Win),
+ TestDC = wxMemoryDC:new(),
+ Bitmap = wxBitmap:new(256,256),
+ wxMemoryDC:selectObject(TestDC, Bitmap),
+ true = wxDC:isOk(TestDC),
CW = fun({Sz,Font},Acc) ->
case wxFont:ok(Font) of
- true ->
+ true ->
wxDC:setFont(TestDC, Font),
- CH = wxDC:getCharHeight(TestDC),
+ CH = wxDC:getCharHeight(TestDC),
[{CH,Sz,Font} | Acc];
false ->
Acc
end
end,
Fs = lists:foldl(CW, [], Fs0),
- wxClientDC:destroy(TestDC),
- {Win, #state{win=Win, board=[], pen=Pen, fonts=Fs, parent=ParentPid}}.
+ wxMemoryDC:destroy(TestDC),
+ {Win, #state{win=Win, board=[], pen=Pen, fonts=Fs,parent=ParentPid}}.
handle_sync_event(#wx{event=#wxPaint{}}, _Obj, State = #state{win=Win}) ->
%% io:format("EPaint~n",[]),
@@ -119,22 +121,17 @@ handle_sync_event(#wx{event=#wxPaint{}}, _Obj, State = #state{win=Win}) ->
handle_event(#wx{event=#wxMouse{type=enter_window}}, State = #state{win=Win}) ->
wxWindow:setFocus(Win), %% Get keyboard focus
{noreply,State};
-handle_event(#wx{event=#wxKey{keyCode=KeyC, x=X,y=Y}},
+handle_event(#wx{event=#wxKey{keyCode=KeyC}},
S = #state{parent=Pid, win=Win}) ->
Val = if KeyC > 47, KeyC < 58 -> KeyC - $0;
KeyC > 325, KeyC < 336 -> KeyC - 326; %% NUM LOCK
true -> 0
end,
- case get_butt(X,Y,S) of
- error -> %% Mac don't get correct coordinates.
- Global = wx_misc:getMousePosition(),
- {CX,CY} = wxWindow:screenToClient(Win, Global),
- case get_butt(CX,CY,S) of
- error -> ignore;
- Id -> Pid ! {set_val,Id,Val}
- end;
- Id ->
- Pid ! {set_val,Id,Val}
+ Global = wx_misc:getMousePosition(),
+ {CX,CY} = wxWindow:screenToClient(Win, Global),
+ case get_butt(CX,CY,S) of
+ error -> ignore;
+ Id -> Pid ! {set_val,Id,Val}
end,
{noreply, S};
handle_event(#wx{event=#wxMouse{type=left_down,x=X,y=Y}},
@@ -205,9 +202,8 @@ handle_call({set_board_data, B},_From, S0) ->
handle_call(left,_From, S = #state{board=B}) ->
Res = 81 - length([ok || #sq{correct=C} <- B, C /= false]),
{reply, Res, S};
-handle_call({draw, DC, Size},_From, S) ->
- redraw(DC,Size,S),
- {reply, ok, S}.
+handle_call(get_state, _From, S) ->
+ {reply, {ok,S}, S}.
handle_cast(Msg, State) ->
io:format("Got cast ~p~n",[Msg]),
diff --git a/lib/wx/examples/sudoku/sudoku_gui.erl b/lib/wx/examples/sudoku/sudoku_gui.erl
index 3d0c95ffa7..5f3f1a2621 100644
--- a/lib/wx/examples/sudoku/sudoku_gui.erl
+++ b/lib/wx/examples/sudoku/sudoku_gui.erl
@@ -1,7 +1,7 @@
%%
%% %CopyrightBegin%
%%
-%% Copyright Ericsson AB 2009-2011. All Rights Reserved.
+%% Copyright Ericsson AB 2009-2012. All Rights Reserved.
%%
%% The contents of this file are subject to the Erlang Public License,
%% Version 1.1, (the "License"); you may not use this file except in
@@ -307,19 +307,19 @@ dialog(?PRINT_PAGE_SETUP, S = #gs{frame=Frame, print_psdd=PsDD0, print_d=PD0}) -
wxPageSetupDialogData:destroy(PsDD0),
wxPrintData:destroy(PD0),
S#gs{print_psdd=PsDD, print_d=PD};
-dialog(?PRINT_PRE, S = #gs{frame=Frame, print_d=PD}) ->
+dialog(?PRINT_PRE, S = #gs{frame=Frame, print_d=PD, board=Board}) ->
+ {ok, BoardS} = sudoku_board:get_state(Board),
PDD = wxPrintDialogData:new(PD),
- Printout1 = wxPrintout:new("Print", fun(This,Page) -> printout(This,Page,S) end,
+ Printout1 = wxPrintout:new("Print 1", fun(This,Page) -> printout(This,Page,BoardS, S) end,
[{getPageInfo, fun getPageInfo/1}]),
- Printout2 = wxPrintout:new("Print", fun(This,Page) -> printout(This,Page,S) end,
+ Printout2 = wxPrintout:new("Print 2", fun(This,Page) -> printout(This,Page,BoardS, S) end,
[{getPageInfo, fun getPageInfo/1}]),
- Preview = wxPrintPreview:new(Printout1, [{printoutForPrinting,Printout2},{data,PDD}]),
+ Preview = wxPrintPreview:new(Printout1, [{printoutForPrinting,Printout2},{data,PDD}]),
case wxPrintPreview:isOk(Preview) of
true ->
PF = wxPreviewFrame:new(Preview, Frame, [{title, "Print Preview"}]),
wxPreviewFrame:centre(PF, [{dir, ?wxBOTH}]),
wxPreviewFrame:initialize(PF),
- wxPreviewFrame:centre(PF),
wxPreviewFrame:show(PF);
false ->
io:format("Could not create preview window.\n"
@@ -327,10 +327,11 @@ dialog(?PRINT_PRE, S = #gs{frame=Frame, print_d=PD}) ->
wxPrintPreview:destroy(Preview)
end,
S;
-dialog(?PRINT, S = #gs{frame=Frame, print_d=PD}) ->
+dialog(?PRINT, S = #gs{frame=Frame, print_d=PD, board=Board}) ->
+ {ok, BoardS} = sudoku_board:get_state(Board),
PDD = wxPrintDialogData:new(PD),
Printer = wxPrinter:new([{data,PDD}]),
- Printout = wxPrintout:new("Print", fun(This,Page) -> printout(This,Page,S) end,
+ Printout = wxPrintout:new("Print", fun(This,Page) -> printout(This,Page,BoardS,S) end,
[{getPageInfo, fun getPageInfo/1}]),
case wxPrinter:print(Printer, Frame, Printout, [{prompt,true}]) of
@@ -374,16 +375,14 @@ init_printer(S) ->
getPageInfo(_This) ->
{1,1,1,1}.
-printout(This, _Page, #gs{board=Board, print_psdd=PsDD}) ->
+printout(This, _Page, Board, #gs{print_psdd=PsDD}) ->
MX = MY = 500,
wxPrintout:fitThisSizeToPageMargins(This, {MX,MY}, PsDD),
-
+
_DBG = {_X,_Y,W,H} = wxPrintout:getLogicalPageMarginsRect(This, PsDD),
wxPrintout:offsetLogicalOrigin(This,(W-MX) div 2, (H-MY) div 2),
-%% io:format("~p ->{~p,~p} ~n", [_DBG, (W-MX) div 2, (H-MY) div 2]),
-
DC = wxPrintout:getDC(This),
- sudoku_board:draw(Board, DC, {500,500}),
+ sudoku_board:redraw(DC, {500,500}, Board),
true.
set_val(Id, Val, Board, G) ->