diff options
Diffstat (limited to 'lib/wx/examples')
-rw-r--r-- | lib/wx/examples/demo/demo.erl | 33 | ||||
-rw-r--r-- | lib/wx/examples/demo/ex_gl.erl | 46 |
2 files changed, 62 insertions, 17 deletions
diff --git a/lib/wx/examples/demo/demo.erl b/lib/wx/examples/demo/demo.erl index 76ebc804bb..2f560096f5 100644 --- a/lib/wx/examples/demo/demo.erl +++ b/lib/wx/examples/demo/demo.erl @@ -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([]). @@ -268,8 +283,9 @@ handle_event(Ev,State) -> code_change(_, _, State) -> {stop, not_yet_implemented, State}. -terminate(_Reason, State) -> +terminate(_Reason, State = #state{win=Frame}) -> catch wx_object:call(State#state.example, shutdown), + wxFrame:destroy(Frame), wx:destroy(). %%%%%%%%%%%%%%%%% Internals %%%%%%%%%% @@ -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_gl.erl b/lib/wx/examples/demo/ex_gl.erl index 0e656071b3..6bb2d12dff 100644 --- a/lib/wx/examples/demo/ex_gl.erl +++ b/lib/wx/examples/demo/ex_gl.erl @@ -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), - %% Demo window is already shown so we can setCurrent directly - wxGLCanvas:setCurrent(Canvas), + wxGLCanvas:connect(Canvas, paint, [callback]), + 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, |