From: John L. <jr...@us...> - 2007-02-08 04:10:46
|
Update of /cvsroot/wxlua/wxLua/samples In directory sc8-pr-cvs9.sourceforge.net:/tmp/cvs-serv9062/wxLua/samples Modified Files: wxluasudoku.wx.lua Log Message: a little cleanup, comments, clear font cache when font changes Index: wxluasudoku.wx.lua =================================================================== RCS file: /cvsroot/wxlua/wxLua/samples/wxluasudoku.wx.lua,v retrieving revision 1.63 retrieving revision 1.64 diff -C2 -d -r1.63 -r1.64 *** wxluasudoku.wx.lua 9 Jan 2007 06:08:34 -0000 1.63 --- wxluasudoku.wx.lua 8 Feb 2007 04:10:41 -0000 1.64 *************** *** 2061,2065 **** focused_cell_id = 0, -- window id of the currently focused cell, 0 for none ! block_refresh = false, filePath = "", -- last opened filePath --- 2061,2065 ---- focused_cell_id = 0, -- window id of the currently focused cell, 0 for none ! block_refresh = false, -- temporarily block refreshing when true filePath = "", -- last opened filePath *************** *** 2172,2176 **** sudokuSolnTable = nil, -- solution to the current puzzle ! nonunique_init_puzzle = nil, -- nil for don't know, for true/false once checked possNakedTable = nil, --- 2172,2176 ---- sudokuSolnTable = nil, -- solution to the current puzzle ! nonunique_init_puzzle = nil, -- nil for don't know, is true/false once verified possNakedTable = nil, *************** *** 2251,2256 **** -- else try to fit a font size to given height/width function sudokuGUI.GetCellBestSize(cell_width, cell_height) - cell_width = cell_width or 40 - cell_height = cell_height or 40 local dc = wx.wxClientDC(sudokuGUI.frame) --- 2251,2254 ---- *************** *** 2328,2331 **** --- 2326,2330 ---- end + -- ---------------------------------------------------------------------------- -- Create one of the 81 cell windows and connect the events to it function sudokuGUI.CreateCellWindow(parent, winID, size) *************** *** 2349,2352 **** --- 2348,2353 ---- return win end + + -- ---------------------------------------------------------------------------- -- wxPaintEvent handler for all of the cell windows function sudokuGUI.OnPaintCellWindow(event) *************** *** 2364,2368 **** function sudokuGUI.PaintCell(dc, cell, width, height, valueFont, possibleFont) - -- clear the window before drawing dc:SetPen(wx.wxTRANSPARENT_PEN) --- 2365,2368 ---- *************** *** 2518,2521 **** --- 2518,2523 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.CalcPossiblePositions(width, height, possibleFont) local pos = {} *************** *** 2739,2742 **** --- 2741,2745 ---- end + -- ---------------------------------------------------------------------------- -- Set the currently focused window, refresh new and old function sudokuGUI.SetFocusWindow(cell) *************** *** 2752,2755 **** --- 2755,2760 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.OnKeyUpCellWindow(event) event:Skip() *************** *** 2871,2874 **** --- 2876,2880 ---- end + -- ---------------------------------------------------------------------------- -- Test to see if one of the possible values has been clicked on function sudokuGUI.HitTestPossibleValue(mx, my) *************** *** 2891,2894 **** --- 2897,2901 ---- end + -- ---------------------------------------------------------------------------- -- Left down click handler for the cell windows, hide the cell editor function sudokuGUI.OnLeftClickCellWindow(event) *************** *** 2978,2981 **** --- 2985,2989 ---- end + -- ---------------------------------------------------------------------------- -- Set the value of the cell from the value string function sudokuGUI.SetCellValue(cell, value) *************** *** 3020,3023 **** --- 3028,3032 ---- end + -- ---------------------------------------------------------------------------- -- Get the initial sudoku table function sudokuGUI.GetInitTable() *************** *** 3033,3036 **** --- 3042,3046 ---- end + -- ---------------------------------------------------------------------------- -- Get the current sudoku table to use function sudokuGUI.GetCurrentTable() *************** *** 3041,3044 **** --- 3051,3056 ---- sudokuGUI.sudokuTables[sudokuGUI.sudokuTables_pos] = sudokuTable end + + -- ---------------------------------------------------------------------------- -- Add a sudoku table to the list of tables, removing any past the current position, -- find possible, and refresh *************** *** 3063,3066 **** --- 3075,3079 ---- end + -- ---------------------------------------------------------------------------- -- Get the value of the cell as a printable string function sudokuGUI.GetCellValueString(cell) *************** *** 3075,3078 **** --- 3088,3093 ---- return value, false end + + -- ---------------------------------------------------------------------------- -- refresh all the grid cells function sudokuGUI.Refresh() *************** *** 3086,3089 **** --- 3101,3105 ---- end + -- ---------------------------------------------------------------------------- -- Create a new empty puzzle function sudokuGUI.NewPuzzle() *************** *** 3099,3102 **** --- 3115,3120 ---- end + -- ---------------------------------------------------------------------------- + -- Create a puzzle by hand function sudokuGUI.CreatePuzzle(init) local enableIds = *************** *** 3168,3172 **** end ! -- Generate a new puzzle function sudokuGUI.GeneratePuzzle() local keep = wx.wxGetNumberFromUser("Set the difficulty of the new puzzle by clearing cells.\n".. --- 3186,3191 ---- end ! -- ---------------------------------------------------------------------------- ! -- Generate a new puzzle automatically function sudokuGUI.GeneratePuzzle() local keep = wx.wxGetNumberFromUser("Set the difficulty of the new puzzle by clearing cells.\n".. *************** *** 3295,3298 **** --- 3314,3319 ---- end + -- ---------------------------------------------------------------------------- + -- Open a puzzle from a file function sudokuGUI.OpenPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Open file", *************** *** 3338,3341 **** --- 3359,3364 ---- end + -- ---------------------------------------------------------------------------- + -- Save the puzzle to a file function sudokuGUI.SaveAsPuzzle() local fileDialog = wx.wxFileDialog(sudokuGUI.frame, "Save puzzle", *************** *** 3365,3368 **** --- 3388,3393 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.Undo() if sudokuGUI.sudokuTables_pos > 1 then *************** *** 3378,3381 **** --- 3403,3408 ---- end + -- ---------------------------------------------------------------------------- + -- Try to fix the invalid cells if possible function sudokuGUI.FixInvalid(sudokuTable, show_dialog) local s = TableCopy(sudokuTable) *************** *** 3434,3439 **** end ! function sudokuGUI.VerifyUniquePuzzle(sudokuTable) sudokuTable = sudoku.CalcInvalidCells(sudokuTable) local invalid_count = TableCount(sudokuTable.invalid) --- 3461,3467 ---- end ! -- ---------------------------------------------------------------------------- + function sudokuGUI.VerifyUniquePuzzle(sudokuTable) sudokuTable = sudoku.CalcInvalidCells(sudokuTable) local invalid_count = TableCount(sudokuTable.invalid) *************** *** 3518,3521 **** --- 3546,3550 ---- end + -- ---------------------------------------------------------------------------- -- Use the scanning method to solve it function sudokuGUI.SolveScanning() *************** *** 3570,3573 **** --- 3599,3603 ---- end + -- ---------------------------------------------------------------------------- -- Use the brute force method to solve it function sudokuGUI.SolveBruteForce(sudokuTable) *************** *** 3663,3666 **** --- 3693,3697 ---- end + -- ---------------------------------------------------------------------------- -- Reset the grid to the original values function sudokuGUI.ResetPuzzle(dont_query_user) *************** *** 3686,3689 **** --- 3717,3722 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.UpdateTable(refresh) if refresh == nil then refresh = true end *************** *** 3729,3732 **** --- 3762,3767 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.UpdateGUI() local table_count = #sudokuGUI.sudokuTables *************** *** 3988,3991 **** --- 4023,4028 ---- sudokuGUI.possibleFont.wxfont:Delete() sudokuGUI.possibleFont.wxfont = wx.wxFontCopy(listBoxValues[sudokuGUI.POSS_VALUE_COLOUR].font) + sudokuGUI.valueFont_cache = {} -- clear cache so GetCellBestSize recreates it + sudokuGUI.possibleFont_cache = {} for winID = 1, 81 do *************** *** 4233,4236 **** --- 4270,4275 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.ConfigSave(save_prefs) local config = wx.wxConfigGet(false) *************** *** 4324,4327 **** --- 4363,4369 ---- end + sudokuGUI.valueFont_cache = {} -- clear cache in case the font has changed + sudokuGUI.possibleFont_cache = {} + -- update font size local width, height = sudokuGUI.cellWindows[1]:GetClientSize() *************** *** 4462,4465 **** --- 4504,4509 ---- end + -- ---------------------------------------------------------------------------- + function sudokuGUI.InitFontsAndColours() sudokuGUI.Colours = |