X Tutup
Skip to content
This repository was archived by the owner on Jan 4, 2023. It is now read-only.

Commit 607a4db

Browse files
committed
Added support for resizing sprites in the Paint Tool.
1 parent 24d5552 commit 607a4db

File tree

211 files changed

+479
-395
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

211 files changed

+479
-395
lines changed

Disks/PixelVisionOS/System/Libs/pixel-vision-os-message-modal-v5.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ function MessageModal:Configure(title, message, width, buttons)
4141
-- Need to calculate the height ahead of time
4242
local wrap = WordWrap(message, (width / 4) - 4)
4343
self.lines = SplitLines(wrap)
44-
height = #self.lines * 8 + 42
44+
local height = #self.lines * 8 + 42
4545

4646
-- Make sure width and height are on the grid
4747
width = math.floor(width / 8) * 8

Disks/PixelVisionOS/System/Tools/PaintTool/Src/drop-down-menu.lua

Lines changed: 87 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ function PaintTool:CreateDropDownMenu()
1414
-- create a variable for the edit color modal
1515
self.editColorModal = EditColorModal:Init()
1616

17+
-- self.resizeModal = ResizeModal:Init()
18+
1719
-- Create a table with all of the menu options
1820
local menuOptions =
1921
{
@@ -40,7 +42,7 @@ function PaintTool:CreateDropDownMenu()
4042
{name = "Mask Color", action = function() self:OnEditColor(self.maskColor) end, enabled = false, toolTip = "Learn about PV8."},
4143

4244
{divider = true},
43-
{name = "Canvas Size", action = function() end, enabled = false, key = Keys.I, toolTip = "Learn about PV8."},
45+
{name = "Canvas Size", action = function() self:OnResize() end, enabled = true, key = Keys.I, toolTip = "Learn about PV8."},
4446
{name = "Toggle BG", action = function() self:ToggleBackground() end, key = Keys.B, toolTip = "Learn about PV8."},
4547
{name = "Toggle Grid", action = function() self:ToggleGrid() end, key = Keys.G, toolTip = "Learn about PV8."},
4648

@@ -120,6 +122,90 @@ function PaintTool:Cut()
120122
-- Delete the selection
121123
self:Delete()
122124

125+
end
126+
127+
function PaintTool:OnResize()
128+
129+
pixelVisionOS:RemoveUI("OnUpdateToolbar")
130+
131+
local title = "Resize"
132+
local message = "Do you want to resize the current canvas? This process can not be undone."
133+
local width = 160
134+
local buttons =
135+
{
136+
{
137+
name = "modalyesbutton",
138+
action = function(target)
139+
140+
target.onParentClose()
141+
end,
142+
key = Keys.Y,
143+
tooltip = "Press 'y' to resize the canvas"
144+
},
145+
{
146+
name = "modalnobutton",
147+
action = function(target)
148+
target.onParentClose()
149+
end,
150+
key = Keys.N,
151+
tooltip = "Press 'n' to cancel making changes"
152+
}
153+
}
154+
155+
-- Look to see if the modal exists
156+
if(self.resizeModal == nil) then
157+
158+
-- Create the model
159+
self.resizeModal = ResizeModal:Init(title, message, width, buttons, self.imageLayerCanvas.Width, self.imageLayerCanvas.Height)
160+
161+
-- Pass a reference of the editorUI to the modal
162+
self.resizeModal.editorUI = self.editorUI
163+
-- end
164+
else
165+
-- If the modal exists, configure it with the new values
166+
self.resizeModal:Configure(title, message, width, buttons, self.imageLayerCanvas.Width, self.imageLayerCanvas.Height)--showCancel, okButtonSpriteName, cancelButtonSpriteName)
167+
end
168+
169+
self:CancelCanvasSelection()
170+
171+
-- TODO need to clear undo history
172+
pixelVisionOS:ResetUndoHistory(self)
173+
174+
pixelVisionOS:UpdateHistoryButtons(self)
175+
176+
-- Open the modal
177+
pixelVisionOS:OpenModal(self.resizeModal, function()
178+
179+
pixelVisionOS:RegisterUI({name = "OnUpdateToolbar"}, "UpdateToolbar", self, true)
180+
181+
local newWidth = tonumber(self.resizeModal.colInputData.text) * 8
182+
local newHeight = tonumber(self.resizeModal.rowInputData.text) * 8
183+
184+
if(self.imageLayerCanvas.Width == newWidth and self.imageLayerCanvas.Height == newHeight) then
185+
return
186+
end
187+
188+
self.imageLayerCanvas:Resize(newWidth, newHeight, true)
189+
190+
self.backgroundLayerCanvas:Resize(newWidth, newHeight)
191+
self.tmpLayerCanvas:Resize(newWidth, newHeight)
192+
self.flagLayerCanvas:Resize(newWidth, newHeight)
193+
self.gridCanvas:Resize(newWidth, newHeight)
194+
195+
self:InvalidateBackground()
196+
self:InvalidateGrid()
197+
self:InvalidateCanvas()
198+
199+
self:ChangeScale( self.scaleValues[self.scaleMode])
200+
201+
end
202+
)
203+
204+
end
205+
206+
function PaintTool:UpdateResize()
207+
208+
123209
end
124210

125211
function PaintTool:OnExportColors()

Disks/PixelVisionOS/System/Tools/PaintTool/Src/paint-tool.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ LoadScript("index-colors" )
2222
LoadScript("index-flags" )
2323
LoadScript("selection" )
2424
LoadScript("color-editor-modal" )
25+
LoadScript("resize-modal" )
2526
LoadScript("pixel-vision-os-option-modal-v1" )
2627
LoadScript("import-colors" )
2728

Disks/PixelVisionOS/System/Tools/PaintTool/Src/picker-panel.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ function PaintTool:DrawPickerPanel()
288288
if(self.fillColor > -1 and self.fill == true) then
289289
pos = CalculatePosition( self.fillColor, 16 )
290290

291-
DrawMetaSprite( "iconmask", (pos.X * 8) + self.pickerPanelRect.X, (pos.Y * 8) + self.pickerPanelRect.Y, false, false, DrawMode.SpriteAbove )
291+
DrawMetaSprite( "iconfill", (pos.X * 8) + self.pickerPanelRect.X, (pos.Y * 8) + self.pickerPanelRect.Y, false, false, DrawMode.SpriteAbove )
292292
end
293293

294294
end
Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
ResizeModal = {}
2+
ResizeModal.__index = ResizeModal
3+
4+
function ResizeModal:Init(title, message, width, buttons, imageWidth, imageHeight)
5+
6+
local _resizeModal = {} -- our new object
7+
setmetatable(_resizeModal, ResizeModal) -- make Account handle lookup
8+
9+
_resizeModal:Configure(title, message, width, buttons, imageWidth, imageHeight)
10+
11+
return _resizeModal
12+
13+
end
14+
15+
function ResizeModal:Configure(title, message, width, buttons, imageWidth, imageHeight)
16+
17+
18+
self.imageWidth = math.ceil(imageWidth / 8)
19+
self.imageHeight = math.ceil(imageHeight / 8)
20+
21+
if(buttons == nil) then
22+
buttons =
23+
{
24+
{
25+
name = "modalokbutton",
26+
action = function(target)
27+
28+
-- if(target.onParentClose ~= nil) then
29+
target.onParentClose()
30+
-- end
31+
32+
end,
33+
key = Keys.Enter,
34+
size = NewPoint(32, 16),
35+
tooltip = "Press 'enter' to close",
36+
}
37+
}
38+
end
39+
40+
-- Reset the modal so it redraws correctly when opened
41+
self.firstRun = true
42+
43+
width = width or 96
44+
45+
-- Need to calculate the height ahead of time
46+
local wrap = WordWrap(message, (width / 4) - 4)
47+
self.lines = SplitLines(wrap)
48+
local height = #self.lines * 8 + 42 + 8
49+
50+
-- Make sure width and height are on the grid
51+
width = math.floor(width / 8) * 8
52+
height = math.floor(height / 8) * 8 + 24
53+
54+
-- Create the canvas for the modal background
55+
self.canvas = NewCanvas(width, height)
56+
57+
self.title = title or "Message Modal"
58+
59+
self.rect = {
60+
x = math.floor(((Display().X - self.canvas.Width) * .5) / 8) * 8,
61+
y = math.floor(((Display().Y - self.canvas.Height) * .5) / 8) * 8,
62+
w = width,
63+
h = height
64+
}
65+
66+
-- self.selectionValue = false
67+
68+
self.buttonData = {}
69+
70+
local tmpButton = nil
71+
72+
local total = #buttons
73+
74+
local bX = self.rect.w
75+
local btnPadding = 8
76+
77+
-- If total is 1, just center the button
78+
if(total == 1) then
79+
80+
local width = buttons.size == nil and 32 or buttons[1].size.x
81+
82+
bX = ((bX - width) * .5) + (width + btnPadding)
83+
84+
end
85+
86+
for i = 1, total do
87+
88+
-- Get a reference to the button properties
89+
tmpButton = buttons[i]
90+
91+
-- Make sure there is a default button size
92+
if(tmpButton.size == nil) then
93+
tmpButton.size = {x = 32, y = 16}
94+
end
95+
96+
bX = bX - (tmpButton.size.x + btnPadding)
97+
98+
-- Fix the button to the bottom of the window
99+
local bY = math.floor(((self.rect.y + self.rect.h) - tmpButton.size.y - 8) / 8) * 8
100+
101+
local tmpBtnData = editorUI:CreateButton({x = bX + self.rect.x, y = bY}, tmpButton.name, tmpButton.tooltip or "")
102+
103+
if(tmpButton.key ~= nil and tmpButton.action ~= nil) then
104+
105+
tmpBtnData.key = tmpButton.key
106+
tmpBtnData.onAction = function() buttons[i].action(self) end
107+
108+
end
109+
110+
table.insert(self.buttonData, tmpBtnData)
111+
112+
end
113+
114+
end
115+
116+
function ResizeModal:Open()
117+
118+
if(self.firstRun == true) then
119+
120+
pixelVisionOS:CreateModalChrome(self.canvas, self.title, self.lines)
121+
122+
local offset = #self.lines * 8 + 12
123+
self.canvas:DrawMetaSprite("resizemodal", 32, offset, false, false)
124+
125+
-- TODO need to get the size of the image
126+
self.colInputData = editorUI:CreateInputField({x = self.rect.x + 40, y = self.rect.y + offset + 16, w = 24}, tostring(self.imageWidth), "Width of canvas in columns.", "number")
127+
128+
self.colInputData.min = 1
129+
self.colInputData.max = 256 -- TODO should this be limited to 128 to help with performance?
130+
131+
-- TODO need to get the size of the image
132+
self.rowInputData = editorUI:CreateInputField({x = self.rect.x + 88 , y = self.rect.y + offset + 16, w = 24}, tostring(self.imageHeight), "Height of canvas in rows.", "number")
133+
134+
self.rowInputData.min = 1
135+
self.rowInputData.max = 256 -- TODO should this be limited to 128 to help with performance?
136+
137+
self.firstRun = false;
138+
139+
end
140+
141+
for i = 1, #self.buttonData do
142+
editorUI:Invalidate(self.buttonData[i])
143+
end
144+
145+
self.canvas:DrawPixels(self.rect.x, self.rect.y, DrawMode.TilemapCache)
146+
147+
end
148+
149+
function ResizeModal:Update(timeDelta)
150+
151+
local tmpBtn = nil
152+
153+
for i = 1, #self.buttonData do
154+
155+
tmpBtn = self.buttonData[i]
156+
157+
editorUI:UpdateButton(tmpBtn)
158+
editorUI:UpdateInputField(self.colInputData)
159+
editorUI:UpdateInputField(self.rowInputData)
160+
161+
if(tmpBtn.key ~= nil and tmpBtn.onAction ~= nil and Key(tmpBtn.key, InputState.Released) == true ) then
162+
tmpBtn.onAction(self)
163+
end
164+
165+
end
166+
167+
end
333 Bytes
Loading

0 commit comments

Comments
 (0)
X Tutup