@@ -18,42 +18,84 @@ function PaintTool:CreateDropDownMenu()
1818 {name = " About" , action = function () pixelVisionOS :ShowAboutModal (self .toolName ) end , toolTip = " Learn about PV8." },
1919
2020 {divider = true },
21+ {name = " Undo" , action = function () self :OnUndo () end , key = Keys .Z , toolTip = " Learn about PV8." },
22+ {name = " Redo" , action = function () self :OnRedo () end , key = Keys .Y , toolTip = " Learn about PV8." },
2123
2224 {divider = true },
25+ {name = " Cut" , action = function () end , key = Keys .X , toolTip = " Learn about PV8." },
26+ {name = " Copy" , action = function () end , key = Keys .C , toolTip = " Learn about PV8." },
27+ {name = " Paste" , action = function () end , key = Keys .V , toolTip = " Learn about PV8." },
28+ {name = " Flip H" , action = function () end , key = Keys .H , toolTip = " Learn about PV8." },
29+ {name = " Flip V" , action = function () end , key = Keys .J , toolTip = " Learn about PV8." },
30+
31+ {divider = true },
32+ {name = " Line Thicker" , action = function () end , toolTip = " Learn about PV8." },
33+ {name = " Line Thinner" , action = function () end , toolTip = " Learn about PV8." },
34+ {name = " Fill" , action = function () end , toolTip = " Learn about PV8." },
35+
36+ {divider = true },
37+ {name = " Edit Color" , action = function () end , toolTip = " Learn about PV8." },
38+ {name = " Outline Color" , action = function () end , toolTip = " Learn about PV8." },
39+ {name = " Fill Color" , action = function () self :FillCanvasSelection (self .brushColor ) end , toolTip = " Learn about PV8." },
40+ {name = " BG Color" , action = function () end , toolTip = " Learn about PV8." },
41+ {name = " Mask Color" , action = function () end , toolTip = " Learn about PV8." },
42+
43+ {divider = true },
44+ {name = " Canvas Size" , action = function () end , key = Keys .I , toolTip = " Learn about PV8." },
45+ -- {name = "Color Mode", action = function() end, toolTip = "Learn about PV8."},
46+ -- {name = "Sprite Mode", action = function() end, toolTip = "Learn about PV8."},
47+ -- {name = "Flag Mode", action = function() end, toolTip = "Learn about PV8."},
48+ {name = " Toggle BG" , action = function () end , key = Keys .I , toolTip = " Learn about PV8." },
49+ -- {divider = true},
50+
51+ -- {name = "Zoom In", action = function() end, toolTip = "Learn about PV8."},
52+ -- {name = "Zoom Out", action = function() end, toolTip = "Learn about PV8."},
53+
54+ {divider = true },
55+ {name = " Export Colors" , action = function () end , toolTip = " Learn about PV8." },
56+ {name = " Export Sprites" , action = function () end , toolTip = " Learn about PV8." },
57+ {name = " Export Flags" , action = function () end , toolTip = " Learn about PV8." },
58+
59+ {divider = true },
60+ {name = " Run Game" , action = function () end , key = Keys .R , toolTip = " Learn about PV8." },
61+ {name = " Save" , action = function () end , key = Keys .S , toolTip = " Learn about PV8." },
2362 {name = " Quit" , key = Keys .Q , action = QuitCurrentTool , toolTip = " Quit the current game." }, -- Quit the current game
2463 }
2564
26- local editorMapping = pixelVisionOS :FindEditors ()
65+ self .RedoShortcut = 4
66+ self .UndoShortcut = 3
67+
68+ -- local editorMapping = pixelVisionOS:FindEditors()
2769
28- local addLastDivider = false
70+ -- local addLastDivider = false
2971
30- -- Only add these if the version of PV8 supports drawing tools
31- if (editorMapping [" colors" ] ~= nil ) then
72+ -- -- Only add these if the version of PV8 supports drawing tools
73+ -- if(editorMapping["colors"] ~= nil) then
3274
33- table.insert (menuOptions , # menuOptions , {name = " Toggle Palette" , enabled = true , action = function () debugMode = not debugMode end , toolTip = " Shows a preview of the color palette." })
75+ -- table.insert(menuOptions, #menuOptions, {name = "Toggle Palette", enabled = true, action = function() debugMode = not debugMode end, toolTip = "Shows a preview of the color palette."})
3476
35- table.insert (menuOptions , # menuOptions , {divider = true })
77+ -- table.insert(menuOptions, #menuOptions, {divider = true})
3678
37- table.insert (menuOptions , # menuOptions , {name = " Save Colors" , enabled = true , action = function () OnSavePNG (true , false , false ) end , toolTip = " Create a 'color-map.png' file." })
79+ -- table.insert(menuOptions, #menuOptions, {name = "Save Colors", enabled = true, action = function() OnSavePNG(true, false, false) end, toolTip = "Create a 'color-map.png' file."})
3880
39- addLastDivider = true
40- end
81+ -- addLastDivider = true
82+ -- end
4183
42- if (editorMapping [" sprites" ] ~= nil ) then
84+ -- if(editorMapping["sprites"] ~= nil) then
4385
44- table.insert (menuOptions , # menuOptions , {name = " Save Sprites" , enabled = true , action = function () OnSavePNG (false , true , false ) end , toolTip = " Create a 'sprite.png' file." })
45- addLastDivider = true
46- end
86+ -- table.insert(menuOptions, #menuOptions, {name = "Save Sprites", enabled = true, action = function() OnSavePNG(false, true, false) end, toolTip = "Create a 'sprite.png' file."})
87+ -- addLastDivider = true
88+ -- end
4789
48- if (editorMapping [" tilemap" ] ~= nil ) then
90+ -- if(editorMapping["tilemap"] ~= nil) then
4991
50- table.insert (menuOptions , # menuOptions , {name = " Save Tilemap" , enabled = true , action = function () OnSavePNG (false , false , true ) end , toolTip = " Create a 'tilemap.json' file." })
51- addLastDivider = true
52- end
92+ -- table.insert(menuOptions, #menuOptions, {name = "Save Tilemap", enabled = true, action = function() OnSavePNG(false, false, true) end, toolTip = "Create a 'tilemap.json' file."})
93+ -- addLastDivider = true
94+ -- end
5395
54- if (addLastDivider == true ) then
55- table.insert (menuOptions , # menuOptions , {divider = true })
56- end
96+ -- if(addLastDivider == true) then
97+ -- table.insert(menuOptions, #menuOptions, {divider = true})
98+ -- end
5799
58100 pixelVisionOS :CreateTitleBarMenu (menuOptions , " See menu options for this tool." )
59101
@@ -118,19 +160,64 @@ function PaintTool:OnQuit()
118160
119161end
120162
163+ function PaintTool :GetState ()
121164
122- function PaintTool :ToggleLineNumbers ()
165+ -- Select the correct canvas based on image or flag mode
166+ local srcCanvas = self .pickerMode == FlagMode and self .flagLayerCanvas or self .imageLayerCanvas
123167
124- if (self .codeMode == false ) then
125- return
126- end
127-
128- -- TODO need to save this value to the bios
129-
130- self .showLines = not self .showLines
131-
132- WriteBiosData (" ShowLinesInTextEditor" , self .showLines == true and " True" or " False" )
168+ -- Get the size of the canvas
169+ local width = srcCanvas .Width
170+ local height = srcCanvas .Height
171+
172+ -- Get the pixels from the canvas
173+ local pixels = srcCanvas :GetPixels ()
174+
175+
176+ -- TODO save brush state
177+
178+
179+ -- TODO save picker state
180+ local pickerMode = self .pickerMode
181+
182+ -- Save the selection rect
183+ local selection = self .selectRect
133184
134- self :InvalidateLineNumbers ()
185+ local state = {
186+
187+ Action = function ()
188+
189+ -- Restore the selection state
190+ if (selection ~= nil ) then
191+ self .selection = NewRect ( selection .X , selection .Y , selection .Width , selection .Height )
192+ end
193+
194+ -- Check the size of the image layer vs the last saved state
195+ if (srcCanvas .Width ~= width or srcCanvas .Height ~= height ) then
196+ self :ResizeCanvas (width , height )
197+ end
198+
199+ -- Restore the pixel data
200+ srcCanvas :SetPixels (pixels )
201+
202+ -- Restore picker mode
203+ self :ChangeMode (pickerMode )
204+
205+ -- Force the canvas to redraw
206+ self :InvalidateCanvas ()
207+
208+ end
209+
210+ }
211+
212+ return state
135213
136214end
215+
216+ function PaintTool :ResizeCanvas (width , height )
217+
218+ -- TODO need to resize all of the canvases
219+
220+ self .imageLayerCanvas :Resize (width , height )
221+ self .tmpLayerCanvas :Resize (width , height )
222+
223+ end
0 commit comments