From: John L. <jr...@us...> - 2006-05-14 07:48:13
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv1343/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: Add classinfo to the encapsulated classes for showing what they are in stacktree show the tracked class types in the stack tree use long for memory pointers not int in AddToTrackedMemory Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.45 retrieving revision 1.46 diff -C2 -d -r1.45 -r1.46 *** wxluasudoku.wx.lua 13 May 2006 17:20:52 -0000 1.45 --- wxluasudoku.wx.lua 14 May 2006 07:48:09 -0000 1.46 *************** *** 1851,1854 **** --- 1851,1857 ---- sudokuSolnTable = nil, -- solution to the current puzzle + possNakedTable = nil, + possHiddenTable = nil, + pencilMarks = {}, -- pencilMarks[cell][value] = true/nil pencilMarksNakedTable = nil, *************** *** 2034,2043 **** -- clear the window before drawing dc:SetPen(wx.wxTRANSPARENT_PEN) ! local bgColour = sudokuGUI.Colours[sudokuGUI.FOCUS_CELL_COLOUR] if sudokuGUI.focused_cell_id ~= cell then ! bgColour = sudokuGUI.cellWindows[cell]:GetBackgroundColour() end ! dc:SetBrush(wx.wxBrush(bgColour, wx.wxSOLID)) dc:DrawRectangle(0, 0, width, height) local sudokuTable = sudokuGUI.GetCurrentGrid() --- 2037,2054 ---- -- clear the window before drawing dc:SetPen(wx.wxTRANSPARENT_PEN) ! local bgColour if sudokuGUI.focused_cell_id ~= cell then ! if math.fmod(sudoku.CellToBlock(cell), 2) ~= 0 then ! bgColour = sudokuGUI.Colours[sudokuGUI.BACKGROUND_COLOUR] ! else ! bgColour = sudokuGUI.Colours[sudokuGUI.ODD_BACKGROUND_COLOUR] ! end ! else ! bgColour = sudokuGUI.Colours[sudokuGUI.FOCUS_CELL_COLOUR] end ! local brush = wx.wxBrush(bgColour, wx.wxSOLID) ! dc:SetBrush(brush) dc:DrawRectangle(0, 0, width, height) + brush:Delete() local sudokuTable = sudokuGUI.GetCurrentGrid() *************** *** 2081,2086 **** end ! local naked = sudokuTable.nakedTable ! local hidden = sudokuTable.hiddenTable if show_possible_user then naked = sudokuGUI.pencilMarksNakedTable --- 2092,2097 ---- end ! local naked = sudokuGUI.possNakedTable ! local hidden = sudokuGUI.possHiddenTable if show_possible_user then naked = sudokuGUI.pencilMarksNakedTable *************** *** 2107,2128 **** -- draw pair marker last so it's on top of the others if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENQUADS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_QUADS_COLOUR], 1, wx.wxSOLID), 4, hidden.quads.cells[cell]) end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDQUADS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_QUADS_COLOUR], 1, wx.wxSOLID), 4, naked.quads.cells[cell]) end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENTRIPLETS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_TRIPLETS_COLOUR], 1, wx.wxSOLID), 3, hidden.triplets.cells[cell]) end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDTRIPLETS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_TRIPLETS_COLOUR], 1, wx.wxSOLID), 3, naked.triplets.cells[cell]) end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENPAIRS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_PAIRS_COLOUR], 1, wx.wxSOLID), 2, hidden.pairs.cells[cell]) end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDPAIRS) then ! draw_nakedhidden(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_PAIRS_COLOUR], 1, wx.wxSOLID), 2, naked.pairs.cells[cell]) end end --- 2118,2151 ---- -- draw pair marker last so it's on top of the others if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENQUADS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_QUADS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 4, hidden.quads.cells[cell]) ! pen:Delete() end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDQUADS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_QUADS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 4, naked.quads.cells[cell]) ! pen:Delete() end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENTRIPLETS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_TRIPLETS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 3, hidden.triplets.cells[cell]) ! pen:Delete() end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDTRIPLETS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_TRIPLETS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 3, naked.triplets.cells[cell]) ! pen:Delete() end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_HIDDENPAIRS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.HIDDEN_PAIRS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 2, hidden.pairs.cells[cell]) ! pen:Delete() end if sudokuGUI.IsCheckedMenuItem(sudokuGUI.ID_SHOW_NAKEDPAIRS) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.NAKED_PAIRS_COLOUR], 1, wx.wxSOLID) ! draw_nakedhidden(pen, 2, naked.pairs.cells[cell]) ! pen:Delete() end end *************** *** 2144,2148 **** (sudoku.GetCellValue(cell, sudokuGUI.sudokuSolnTable) ~= sudoku.GetCellValue(cell, sudokuTable)) then ! dc:SetPen(wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.INVALID_VALUE_COLOUR], 1, wx.wxSOLID)) dc:DrawLine(0, 0, width, height) end --- 2167,2173 ---- (sudoku.GetCellValue(cell, sudokuGUI.sudokuSolnTable) ~= sudoku.GetCellValue(cell, sudokuTable)) then ! local pen = wx.wxPenFromColour(sudokuGUI.Colours[sudokuGUI.INVALID_VALUE_COLOUR], 1, wx.wxSOLID) ! dc:SetPen(pen) ! pen:Delete() dc:DrawLine(0, 0, width, height) end *************** *** 2151,2160 **** -- Draw the set value, if any if string.len(value_str) then if is_init then ! dc:SetTextForeground(sudokuGUI.Colours[sudokuGUI.INIT_VALUE_COLOUR]) else ! dc:SetTextForeground(sudokuGUI.Colours[sudokuGUI.VALUE_COLOUR]) end dc:SetFont(valueFont.wxfont) dc:DrawText(value_str, width/2 - valueFont.width/2, --- 2176,2188 ---- -- Draw the set value, if any if string.len(value_str) then + local fgColour if is_init then ! fgColour = sudokuGUI.Colours[sudokuGUI.INIT_VALUE_COLOUR] else ! fgColour = sudokuGUI.Colours[sudokuGUI.VALUE_COLOUR] end + dc:SetTextForeground(fgColour) + dc:SetFont(valueFont.wxfont) dc:DrawText(value_str, width/2 - valueFont.width/2, *************** *** 2299,2303 **** local borders = { [1]=true, [4]=true, [7]=true, [10]=true } for i = 1, 10 do ! dc:SetPen(wx.wxPenFromColour(wx.wxColour(0, 0, 0), iff(borders[i], 4, 2), wx.wxSOLID)) dc:DrawLine(ColOrigin(1), RowOrigin(i), ColOrigin(10), RowOrigin(i)) dc:DrawLine(ColOrigin(i), RowOrigin(1), ColOrigin(i), RowOrigin(10)) --- 2327,2333 ---- local borders = { [1]=true, [4]=true, [7]=true, [10]=true } for i = 1, 10 do ! local pen = wx.wxPenFromColour(wx.BLACK, iff(borders[i], 4, 2), wx,SOLID) ! dc:SetPen(pen) ! pen:Delete() dc:DrawLine(ColOrigin(1), RowOrigin(i), ColOrigin(10), RowOrigin(i)) dc:DrawLine(ColOrigin(i), RowOrigin(1), ColOrigin(i), RowOrigin(10)) *************** *** 2668,2671 **** --- 2698,2712 ---- table.remove(sudokuGUI.sudokuTables) end + + -- clear calculated values to save memory + for n = 2, sudokuGUI.sudokuTables_pos do + sudokuGUI.sudokuTables[n].possible = {} + sudokuGUI.sudokuTables[n].row_values = {} + sudokuGUI.sudokuTables[n].col_values = {} + sudokuGUI.sudokuTables[n].block_values = {} + sudokuGUI.sudokuTables[n].possible = {} + sudokuGUI.sudokuTables[n].invalid = {} + end + table.insert(sudokuGUI.sudokuTables, sudokuTable) sudokuGUI.sudokuTables_pos = sudokuGUI.sudokuTables_pos + 1 *************** *** 2945,2952 **** end - function sudokuGUI.SolveInitPuzzle() - - end - function sudokuGUI.FixInvalid(sudokuTable, show_dialog) local s = TableCopy(sudokuTable) --- 2986,2989 ---- *************** *** 3119,3125 **** local s, count, changed_cells = sudoku.SolveScan(s) - s.nakedTable = nil -- slows things down - s.hiddenTable = nil - local s, g = sudoku.SolveBruteForce(s) --- 3156,3159 ---- *************** *** 3187,3191 **** sudokuTable.possible = p else ! sudokuTable.nakedTable, sudokuTable.hiddenTable = sudoku.FindAllNakedHiddenGroups(true, sudokuTable) end end --- 3221,3225 ---- sudokuTable.possible = p else ! sudokuGUI.possNakedTable, sudokuGUI.possHiddenTable = sudoku.FindAllNakedHiddenGroups(true, sudokuTable) end end *************** *** 3310,3314 **** c = listBoxValues[sel].colour end ! dc:SetBrush(wx.wxBrush(c, wx.wxSOLID)) dc:DrawRectangle(0, 0, width, height) --- 3344,3350 ---- c = listBoxValues[sel].colour end ! local brush = wx.wxBrush(c, wx.wxSOLID) ! dc:SetBrush(brush) ! brush:Delete() dc:DrawRectangle(0, 0, width, height) *************** *** 3338,3356 **** dc:SetBrush(wx.wxTRANSPARENT_BRUSH) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_PAIRS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[1].x, pos[1].y, font_width, font_height) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_TRIPLETS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[4].x, pos[4].y, font_width, font_height) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_QUADS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[7].x, pos[7].y, font_width, font_height) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_PAIRS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[3].x, pos[3].y, font_width, font_height) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_TRIPLETS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[6].x, pos[6].y, font_width, font_height) ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_QUADS_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawRectangle(pos[9].x, pos[9].y, font_width, font_height) -- draw invalid marker ! dc:SetPen(wx.wxPenFromColour(listBoxValues[sudokuGUI.INVALID_VALUE_COLOUR].colour, 1, wx.wxSOLID)) dc:DrawLine(0, 0, width, height) --- 3374,3400 ---- dc:SetBrush(wx.wxTRANSPARENT_BRUSH) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_PAIRS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[1].x, pos[1].y, font_width, font_height) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_TRIPLETS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[4].x, pos[4].y, font_width, font_height) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.NAKED_QUADS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[7].x, pos[7].y, font_width, font_height) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_PAIRS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[3].x, pos[3].y, font_width, font_height) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_TRIPLETS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[6].x, pos[6].y, font_width, font_height) ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.HIDDEN_QUADS_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen); pen:Delete() dc:DrawRectangle(pos[9].x, pos[9].y, font_width, font_height) -- draw invalid marker ! local pen = wx.wxPenFromColour(listBoxValues[sudokuGUI.INVALID_VALUE_COLOUR].colour, 1, wx.wxSOLID) ! dc:SetPen(pen) ! pen:Delete() dc:DrawLine(0, 0, width, height) *************** *** 3387,3392 **** --- 3431,3439 ---- f = wx.wxGetFontFromUser(panel, f) if f:Ok() then + listBoxValues[sel].font:Delete() listBoxValues[sel].font = f reset_fonts = true + else + f:Delete() end sampleWin:Refresh(false) *************** *** 3398,3403 **** --- 3445,3453 ---- c = wx.wxGetColourFromUser(panel, c) if c:Ok() then + listBoxValues[sel].colour:Delete() listBoxValues[sel].colour = c colourButton:SetForegroundColour(c) + else + c:Delete() end sampleWin:Refresh(false) *************** *** 3415,3429 **** --- 3465,3485 ---- if ret == wx.wxYES then for n = 1, sudokuGUI.COLOUR_MAX do + listBoxValues[n].colour:Delete() listBoxValues[n].colour = wx.wxColourCopy(sudokuGUI.Colours_[n]) end + listBoxValues[sudokuGUI.VALUE_COLOUR].font:Delete() + listBoxValues[sudokuGUI.POSS_VALUE_COLOUR].font:Delete() listBoxValues[sudokuGUI.VALUE_COLOUR].font = wx.wxFontCopy(sudokuGUI.valueFont_wxfont_) listBoxValues[sudokuGUI.POSS_VALUE_COLOUR].font = wx.wxFontCopy(sudokuGUI.possibleFont_wxfont_) elseif ret == wx.wxNO then + listBoxValues[sel].colour:Delete() listBoxValues[sel].colour = wx.wxColourCopy(sudokuGUI.Colours_[sel]) if (sel == sudokuGUI.VALUE_COLOUR) then + listBoxValues[sel].font:Delete() listBoxValues[sel].font = wx.wxFontCopy(sudokuGUI.valueFont_wxfont_) elseif (sel == sudokuGUI.POSS_VALUE_COLOUR) then + listBoxValues[sel].font:Delete() listBoxValues[sel].font = wx.wxFontCopy(sudokuGUI.possibleFont_wxfont_) end *************** *** 3437,3445 **** --- 3493,3504 ---- function sudokuGUI.PreferencesDialogPageUI.Apply() for n = 1, sudokuGUI.COLOUR_MAX do + sudokuGUI.Colours[n]:Delete() sudokuGUI.Colours[n] = wx.wxColourCopy(listBoxValues[n].colour) end -- copy the fonts since when applied their size will change + sudokuGUI.valueFont.wxfont:Delete() sudokuGUI.valueFont.wxfont = wx.wxFontCopy(listBoxValues[sudokuGUI.VALUE_COLOUR].font) + sudokuGUI.possibleFont.wxfont:Delete() sudokuGUI.possibleFont.wxfont = wx.wxFontCopy(listBoxValues[sudokuGUI.POSS_VALUE_COLOUR].font) *************** *** 3457,3460 **** --- 3516,3526 ---- end + function sudokuGUI.PreferencesDialogPageUI.Destroy() + for n = 1, sudokuGUI.COLOUR_MAX do + listBoxValues[n].colour:Delete() + if listBoxValues[n].font then listBoxValues[n].font:Delete() end + end + end + return panel end *************** *** 3536,3539 **** --- 3602,3608 ---- end + function sudokuGUI.PreferencesDialogPageShow.Destroy() + end + return panel end *************** *** 3615,3618 **** --- 3684,3690 ---- end + function sudokuGUI.PreferencesDialogPageSolve.Destroy() + end + return panel end *************** *** 3662,3667 **** dialog:ConnectEvent(wx.wxID_OK, wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) ! local sel = notebook:GetSelection() ! if sel >= 0 then notebookPages[sel+1].Apply() end event:Skip() -- wxDialog will cancel automatically end) --- 3734,3750 ---- dialog:ConnectEvent(wx.wxID_OK, wx.wxEVT_COMMAND_BUTTON_CLICKED, function (event) ! for n = 1, 3 do ! notebookPages[n].Apply() ! notebookPages[n].Destroy() ! end ! ! event:Skip() -- wxDialog will cancel automatically ! end) ! dialog:ConnectEvent(wx.wxID_CANCEL, wx.wxEVT_COMMAND_BUTTON_CLICKED, ! function (event) ! for n = 1, 3 do ! notebookPages[n].Destroy() ! end ! event:Skip() -- wxDialog will cancel automatically end) |