lua-users home
lua-l archive

Re: primitive graphics application

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Mon, May 4, 2009 at 7:15 AM, Dave Smead <smead@amplepower.com> wrote:
> My immediate interest is using Lua to access graphics primitives such as
> draw-line, draw-circle, draw-arc, etc
wxLua is probably a good fit. A simple GUI program with graphics
primitives is really straightforward, very portable. (This was tested
using wxLua bundled with Lua For Windows)
steve d.
------------------------------------------------------------------------------------------
-- draw.wlua (based on Minimal.wx.wlua from LfW)
-- Load the wxLua module, does nothing if running from wxLua,
wxLuaFreeze, or wxLuaEdit
require("wx")
frame = nil
-- paint event handler for the frame that's called by wxEVT_PAINT
function OnPaint(event)
 -- must always create a wxPaintDC in a wxEVT_PAINT handler
 local dc = wx.wxPaintDC(panel)
 -- call some drawing functions
 dc:DrawRectangle(10, 10, 300, 300);
 dc:DrawRoundedRectangle(20, 20, 280, 280, 20);
 dc:DrawEllipse(30, 30, 260, 260);
 dc:DrawText("A test string", 50, 150);
 -- the paint DC will be automatically destroyed by the garbage collector,
 -- however on Windows 9x/Me this may be too late (DC's are
precious resource)
 -- so delete it here
 dc:delete() -- ALWAYS delete() any wxDCs created when done
end
frame = wx.wxFrame( wx.NULL, -- no parent for toplevel windows
 wx.wxID_ANY, -- don't need a wxWindow ID
 "wxLua Draw Demo", -- caption on the frame
 wx.wxDefaultPosition, -- let system place the frame
 wx.wxSize(450, 450), -- set the size of the frame
 wx.wxDEFAULT_FRAME_STYLE ) -- use default frame styles
panel = wx.wxPanel(frame, wx.wxID_ANY)
-- connect the paint event handler function with the paint event
panel:Connect(wx.wxEVT_PAINT, OnPaint)
frame:Show(true)
wx.wxGetApp():MainLoop()
---------------------------------------------------------------

AltStyle によって変換されたページ (->オリジナル) /