diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/wx/examples/demo/demo.erl | 33 | ||||
-rw-r--r-- | lib/wx/examples/demo/ex_gl.erl | 46 | ||||
-rw-r--r-- | lib/wx/test/wx_opengl_SUITE.erl | 16 | ||||
-rw-r--r-- | lib/wx/test/wx_xtra_SUITE.erl | 27 |
4 files changed, 92 insertions, 30 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, diff --git a/lib/wx/test/wx_opengl_SUITE.erl b/lib/wx/test/wx_opengl_SUITE.erl index 089036e47c..f351bc93ed 100644 --- a/lib/wx/test/wx_opengl_SUITE.erl +++ b/lib/wx/test/wx_opengl_SUITE.erl @@ -98,7 +98,8 @@ canvas(Config) -> ?WX_GL_MIN_GREEN,8, ?WX_GL_MIN_BLUE,8, ?WX_GL_DEPTH_SIZE,24,0]}], - Canvas = ?mt(wxGLCanvas, wxGLCanvas:new(Frame, Attrs)), + Canvas = ?mt(wxGLCanvas, wxGLCanvas:new(Frame, [{style,?wxFULL_REPAINT_ON_RESIZE}| + Attrs])), wxFrame:connect(Frame, show), ?m(true, wxWindow:show(Frame)), @@ -142,11 +143,20 @@ canvas(Config) -> %% This may fail when window is deleted catch draw_loop(2,Data,Canvas) end), + %% Needed on mac with wx-2.9 + wxGLCanvas:connect(Canvas, paint, + [{callback, fun(_,_) -> + wxGLCanvas:setCurrent(Canvas), + DC= wxPaintDC:new(Canvas), + wxPaintDC:destroy(DC) + end}]), + + ?m_receive(works), ?m([], flush()), io:format("Undef func ~p ~n", [catch gl:uniform1d(2, 0.75)]), timer:sleep(500), - ?m([], flush()), + flush(), wx_test_lib:wx_destroy(Frame, Config). flush() -> @@ -161,6 +171,8 @@ flush(Collected) -> draw_loop(Deg,Data,Canvas) -> timer:sleep(15), + {NW,NH} = wxGLCanvas:getClientSize(Canvas), + gl:viewport(0,0,NW,NH), drawBox(Deg,Data), ?m(ok, wxGLCanvas:swapBuffers(Canvas)), draw_loop(Deg+1, Data,Canvas). diff --git a/lib/wx/test/wx_xtra_SUITE.erl b/lib/wx/test/wx_xtra_SUITE.erl index ad0049a9a5..a2d4c26319 100644 --- a/lib/wx/test/wx_xtra_SUITE.erl +++ b/lib/wx/test/wx_xtra_SUITE.erl @@ -192,8 +192,12 @@ menu_item_debug(Config) -> wxFrame:connect(Frame, close_window), wxPanel:new(Frame), - create_menus(Frame), + MenuBar = create_menus(Frame), wxWindow:show(Frame), + N = wxMenuBar:getMenuCount(MenuBar), + io:format("No of menus ~p~n",[N]), + [io:format("Menu ~p ~p~n",[Id, wxMenuBar:getLabelTop(MenuBar, Id)]) + || Id <- lists:seq(0, N-1)], wx_test_lib:wx_destroy(Frame,Config). @@ -225,14 +229,15 @@ create_menus(Frame) -> || Id <- lists:seq(600, 620)], ?m(ok,wxFrame:connect(Frame, command_menu_selected)), - ?m(true, wxMenuBar:append(MenuBar, File, "&File")), - ?m(true, wxMenuBar:append(MenuBar, Help, "&Help")), - ?m(true, wxMenuBar:append(MenuBar, T1, "T1")), - ?m(true, wxMenuBar:append(MenuBar, T2, "T2")), - ?m(true, wxMenuBar:append(MenuBar, T3, "T3")), - ?m(true, wxMenuBar:append(MenuBar, T4, "T4")), - ?m(true, wxMenuBar:append(MenuBar, T5, "T5")), - ?m(true, wxMenuBar:append(MenuBar, T6, "T6")), - - ?m(ok, wxFrame:setMenuBar(Frame,MenuBar)). + ?m(true, wxMenuBar:insert(MenuBar, 0,File, "&File")), + ?m(true, wxMenuBar:insert(MenuBar, 1,Help, "&Help")), + ?m(true, wxMenuBar:insert(MenuBar, 2,T1, "T1")), + ?m(true, wxMenuBar:insert(MenuBar, 3,T2, "T2")), + ?m(true, wxMenuBar:insert(MenuBar, 4,T3, "T3")), + ?m(true, wxMenuBar:insert(MenuBar, 5,T4, "T4")), + ?m(true, wxMenuBar:insert(MenuBar, 6,T5, "T5")), + ?m(true, wxMenuBar:insert(MenuBar, 7,T6, "T6")), + + ?m(ok, wxFrame:setMenuBar(Frame,MenuBar)), + MenuBar. |