Friday, August 14, 2009

wxErlang in Action -- Listing 1.3

This decorates the previous frame with an image. The prototype used the wxPython logo, so for this version, I used the Erlang logo as found here:

-module('hello').
-export([start/0]).
-include_lib("wx/include/wx.hrl").
start() ->
_WX = wx:new(),
% There is no wxImage:convertToBitmap (there is a wxBitmap:convertToImage if required)
Image = wxBitmap:new("erlanglogo.jpg", [{type, ?wxBITMAP_TYPE_JPEG}]),
% this is the whole image size
Size = {wxBitmap:getWidth(Image), wxBitmap:getHeight(Image)},
% this seems to be sizing the whole non-client area to the image size
Frame = wxFrame:new(wx:null(), ?wxID_ANY, "Hello, wxErlang!", [{pos, ?wxDefaultPosition}, {size, Size}]),
% and this seems to vertically centre the image over the client area
wxStaticBitmap:new(Frame, ?wxID_ANY, Image),
wxFrame:connect(Frame, close_window),
wxFrame:show(Frame),
% No obvious equivalent to wxApp.SetTopWindow(Frame) found in wxErlang 0.98.2
loop(Frame),
wx:destroy().
loop(Frame) ->
receive
#wx{event=#wxClose{type=close_window}} ->
ok % NOT wxWindow:close(Frame,[])
end.
view raw gistfile1.erl hosted with ❤ by GitHub

And this is what the application looks like when superposed on the stand-alone image; the comments in the code give my interpretation of what is going on here.

No comments :