From: John L. <jr...@us...> - 2007-02-26 05:17:34
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv16333/wxLua/samples Modified Files: scribble.wx.lua Log Message: rem out debugging code in wxlbind.cpp only measure the text height once for the stack window make scribble faster by drawing to the window first Index: scribble.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/scribble.wx.lua,v retrieving revision 1.13 retrieving revision 1.14 diff -C2 -d -r1.13 -r1.14 *** scribble.wx.lua 22 Nov 2006 21:13:56 -0000 1.13 --- scribble.wx.lua 26 Feb 2007 05:17:30 -0000 1.14 *************** *** 2,6 **** -- Name: scribble.wx.lua -- Purpose: 'Scribble' wxLua sample ! -- Author: J Winwood -- Modified by: Thanks to Peter Prade and Nick Trout for fixing -- the bug in the for loop in DrawPoints() --- 2,6 ---- -- Name: scribble.wx.lua -- Purpose: 'Scribble' wxLua sample ! -- Author: J Winwood, John Labenski -- Modified by: Thanks to Peter Prade and Nick Trout for fixing -- the bug in the for loop in DrawPoints() *************** *** 19,23 **** isModified = false -- has the drawing been modified redrawRequired = true -- redraw the image ! lastDrawn = 0 -- last point that was drawn or 0 to redraw all fileName = "" -- filename to save to ID_SAVEBITMAP = wx.wxID_HIGHEST + 1 --- 19,23 ---- isModified = false -- has the drawing been modified redrawRequired = true -- redraw the image ! lastDrawn = 0 -- last segment that was drawn or 0 to redraw all fileName = "" -- filename to save to ID_SAVEBITMAP = wx.wxID_HIGHEST + 1 *************** *** 45,53 **** local point = listValue[1] ! local last_x, last_y = point.x, point.y for point_index = 2, #listValue do point = listValue[point_index] ! drawDC:DrawLine(last_x, last_y, point.x, point.y) ! last_x, last_y = point.x, point.y end end --- 45,53 ---- local point = listValue[1] ! local last_point = point for point_index = 2, #listValue do point = listValue[point_index] ! drawDC:DrawLine(last_point.x, last_point.y, point.x, point.y) ! last_point = point end end *************** *** 57,64 **** --- 57,78 ---- end + function DrawLastPoint(drawDC) + if #pointsList < 1 then return end + local listValue = pointsList[#pointsList] + if #listValue < 2 then return end + + drawDC:SetPen(pens[listValue.penColour]) + local pt1 = listValue[#listValue-1] + local pt2 = listValue[#listValue] + + drawDC:DrawLine(pt1.x, pt1.y, pt2.x, pt2.y) + end + function DrawBitmap(bmp) local memDC = wx.wxMemoryDC() -- create off screen dc to draw on memDC:SelectObject(bmp) -- select our bitmap to draw into + DrawPoints(memDC) + memDC:SelectObject(wx.wxNullBitmap) -- always release bitmap memDC:Delete() -- ALWAYS Delete() any wxDCs created when done *************** *** 83,88 **** function OnLeftDown(event) - frame:SetStatusText(penColours[itemColour], 1) - local pointItem = {penColour = itemColour, {x = event:GetX(), y = event:GetY()}} table.insert(pointsList, pointItem) --- 97,100 ---- *************** *** 96,101 **** mouseDown = true isModified = true - redrawRequired = true - panel:Refresh() end --- 108,111 ---- *************** *** 127,132 **** mouseDown = true ! redrawRequired = true ! panel:Refresh() elseif panel:HasCapture() then -- just in case we lost focus somehow panel:ReleaseMouse() --- 137,145 ---- mouseDown = true ! ! -- draw directly on the panel, we'll draw on the bitmap in OnLeftUp ! local drawDC = wx.wxClientDC(panel) ! DrawLastPoint(drawDC) ! drawDC:Delete() elseif panel:HasCapture() then -- just in case we lost focus somehow panel:ReleaseMouse() *************** *** 258,261 **** --- 271,277 ---- fileMenu:Append(wx.wxID_EXIT, "E&xit", "Quit the program") + local editMenu = wx.wxMenu() + editMenu:Append(wx.wxID_UNDO, "&Undo\tCtrl-Z", "Undo last drawn segment") + local helpMenu = wx.wxMenu() helpMenu:Append(wx.wxID_ABOUT, "&About...", "About the wxLua Scribble Application") *************** *** 263,266 **** --- 279,283 ---- local menuBar = wx.wxMenuBar() menuBar:Append(fileMenu, "&File") + menuBar:Append(editMenu, "&Edit") menuBar:Append(helpMenu, "&Help") frame:SetMenuBar(menuBar) *************** *** 366,369 **** --- 383,400 ---- end ) + frame:Connect(wx.wxID_UNDO, wx.wxEVT_COMMAND_MENU_SELECTED, + function (event) + if #pointsList then + pointsList[#pointsList] = nil + lastDrawn = 0 + redrawRequired = true + panel:Refresh() + end + + if #pointsList == 0 then + isModified = false + end + end ) + frame:Connect(wx.wxID_ABOUT, wx.wxEVT_COMMAND_MENU_SELECTED, function (event) |