From: John L. <jr...@us...> - 2008-01-04 05:36:12
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv29155/samples Modified Files: scribble.wx.lua Log Message: Make scribble a little nicer with a scrolled window and allow setting the size Index: scribble.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/scribble.wx.lua,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** scribble.wx.lua 22 Jul 2007 04:38:30 -0000 1.23 --- scribble.wx.lua 4 Jan 2008 05:36:07 -0000 1.24 *************** *** 12,16 **** frame = nil -- the main wxFrame ! panel = nil -- the child wxPanel in the wxFrame to draw on mouseDown = false -- left mouse button is down pointsList = {} -- list of the points added to the drawing --- 12,17 ---- frame = nil -- the main wxFrame ! scrollwin = nil -- the child of the frame ! panel = nil -- the child wxPanel of the wxScrolledWindow to draw on mouseDown = false -- left mouse button is down pointsList = {} -- list of the points added to the drawing *************** *** 310,314 **** -- Create the menubar local fileMenu = wx.wxMenu() ! fileMenu:Append(wx.wxID_NEW, "&New\tCtrl+N", "Begin a new drawing") fileMenu:Append(wx.wxID_OPEN, "&Open...\tCtrl+O", "Open an existing drawing") fileMenu:AppendSeparator() --- 311,315 ---- -- Create the menubar local fileMenu = wx.wxMenu() ! fileMenu:Append(wx.wxID_NEW, "&New...\tCtrl+N", "Begin a new drawing") fileMenu:Append(wx.wxID_OPEN, "&Open...\tCtrl+O", "Open an existing drawing") fileMenu:AppendSeparator() *************** *** 320,325 **** local editMenu = wx.wxMenu() ! editMenu:Append(ID_PENCOLOUR, "Set pen &Color\tCtrl+R", "Set the color of the pen to draw with") ! editMenu:Append(ID_PENWIDTH, "Set pen &Width\tCtrl+T", "Set width of the pen to draw with") -- Styles really only work for long lines, when you change direction the styles -- blur into each other and just look like a solid line. --- 321,326 ---- local editMenu = wx.wxMenu() ! editMenu:Append(ID_PENCOLOUR, "Set pen &color\tCtrl+R", "Set the color of the pen to draw with") ! editMenu:Append(ID_PENWIDTH, "Set pen &width\tCtrl+T", "Set width of the pen to draw with") -- Styles really only work for long lines, when you change direction the styles -- blur into each other and just look like a solid line. *************** *** 356,360 **** penWidthSpinCtrl = wx.wxSpinCtrl(toolBar, ID_PENWIDTH_SPINCTRL, "3", wx.wxDefaultPosition, wx.wxDefaultSize, ! wx.wxSP_ARROW_KEYS, 1, 100, 3) local w, h = penWidthSpinCtrl:GetSizeWH() penWidthSpinCtrl:SetSize(3*h, -1) --- 357,361 ---- penWidthSpinCtrl = wx.wxSpinCtrl(toolBar, ID_PENWIDTH_SPINCTRL, "3", wx.wxDefaultPosition, wx.wxDefaultSize, ! wx.wxSP_ARROW_KEYS, 1, 100, currentPen:GetWidth()) local w, h = penWidthSpinCtrl:GetSizeWH() penWidthSpinCtrl:SetSize(3*h, -1) *************** *** 363,369 **** toolBar:AddSeparator() ! colourPicker = wx.wxColourPickerCtrl(toolBar, ID_PENCOLOUR, wx.wxBLACK, wx.wxDefaultPosition, toolBmpSize:op_sub(wx.wxSize(2,2)), wx.wxCLRP_DEFAULT_STYLE) colourPicker:SetToolTip("Choose pen color") colourPicker:Connect(wx.wxEVT_COMMAND_COLOURPICKER_CHANGED, --- 364,372 ---- toolBar:AddSeparator() ! local c = currentPen:GetColour() ! colourPicker = wx.wxColourPickerCtrl(toolBar, ID_PENCOLOUR, c, wx.wxDefaultPosition, toolBmpSize:op_sub(wx.wxSize(2,2)), wx.wxCLRP_DEFAULT_STYLE) + c:delete() colourPicker:SetToolTip("Choose pen color") colourPicker:Connect(wx.wxEVT_COMMAND_COLOURPICKER_CHANGED, *************** *** 389,392 **** --- 392,396 ---- "white", "light grey", "tan", "pink", "yellow", "turquoise", "sky blue", "maroon" } + -- Note: this bitmap is local, but is used in the event handlers local colourWinBmp = wx.wxBitmap(4*colourWin_height, colourWin_height) do *************** *** 454,459 **** frame:SetStatusText("Welcome to wxLua Scribble.") ! -- Create a wxPanel to draw on, always a good idea, it will fill the frame ! panel = wx.wxPanel(frame, wx.wxID_ANY) panel:Connect(wx.wxEVT_PAINT, OnPaint) --- 458,469 ---- frame:SetStatusText("Welcome to wxLua Scribble.") ! -- Create a wxScrolledWindow to hold drawing window, it will fill the frame ! scrollwin = wx.wxScrolledWindow(frame, wx.wxID_ANY) ! scrollwin:SetScrollbars(1, 1, bitmap:GetWidth(), bitmap:GetHeight()) ! ! -- Create the panel that's the correct size of the bitmap on the scrolled ! -- window so we don't have to worry about calculating the scrolled position ! -- for drawing and the mouse position. ! panel = wx.wxPanel(scrollwin, wx.wxID_ANY, wx.wxDefaultPosition, wx.wxSize(bitmap:GetWidth(), bitmap:GetHeight())) panel:Connect(wx.wxEVT_PAINT, OnPaint) *************** *** 472,475 **** --- 482,511 ---- end + local w, h = bitmap:GetWidth(), bitmap:GetHeight() + + local ok = true + repeat + local s = wx.wxGetTextFromUser("Enter the image size to use as 'width height'", "Set new image size", + string.format("%d %d", bitmap:GetWidth(), bitmap:GetHeight()), frame) + if (#s == 0) then + return -- they canceled the dialog + end + w, h = string.match(s, "(%d+) (%d+)") + + w = tonumber(w) + h = tonumber(h) + if (w == nil) or (h == nil) or (w < 2) or (h < 2) or (w > 10000) or (h > 10000) then + wx.wxMessageBox("Please enter two positive numbers for the width and height separated by a space", + "Invalid image width or height", wx.wxOK + wx.wxCENTRE + wx.wxICON_ERROR, frame) + ok = false + end + until ok + + -- resize all the drawing objects + bitmap:delete() + bitmap = wx.wxBitmap(w, h) + panel:SetSize(w, h) + scrollwin:SetScrollbars(1, 1, w, h) + fileName = "" frame:SetTitle("wxLua Scribble") *************** *** 633,640 **** "Save changes before exiting?", "Save Changes?", ! wx.wxYES_NO + wx.wxCENTRE + wx.wxICON_QUESTION ) local result = dialog:ShowModal() dialog:Destroy() ! if result == wx.wxID_YES then isOkToClose = SaveChanges() end --- 669,678 ---- "Save changes before exiting?", "Save Changes?", ! wx.wxYES_NO + wx.wxCANCEL + wx.wxCENTRE + wx.wxICON_QUESTION ) local result = dialog:ShowModal() dialog:Destroy() ! if result == wx.wxID_CANCEL then ! return ! elseif result == wx.wxID_YES then isOkToClose = SaveChanges() end *************** *** 649,652 **** --- 687,693 ---- end ) + -- delete all locals vars like the temporary wxArtProvider bitmaps + collectgarbage("collect") + frame:Show(true) end |