space saving

This commit is contained in:
visionmercer 2026-05-27 11:08:49 +02:00
commit fb5935e4b9

View file

@ -120,12 +120,12 @@ do
' Keyboarding ' Keyboarding
keyin=inkey$ keyin=inkey$
select case keyin select case keyin
case "+": state.brushsize=state.brushsize+1: addcommand"brushsize ("+tst(state.brushsize)+")" case "+":state.brushsize=state.brushsize+1:addcommand"brushsize ("+tst(state.brushsize)+")"
case "-": if state.brushsize>1 then state.brushsize=state.brushsize-1: addcommand"brushsize ("+tst(state.brushsize)+")" case "-":if state.brushsize>1 then state.brushsize=state.brushsize-1:addcommand"brushsize ("+tst(state.brushsize)+")"
case "h": state.zoom=1: state.offsetx=(_width/2)-(_width(layers(0).ihandle)/2): state.offsety=(_height/2)-(_height(layers(0).ihandle)/2) case "h":state.zoom=1:state.offsetx=(_width/2)-(_width(layers(0).ihandle)/2):state.offsety=(_height/2)-(_height(layers(0).ihandle)/2)
case "t": showtoolbox=not showtoolbox case "t":showtoolbox=not showtoolbox
case "c": showcolorpicker=not showcolorpicker case "c":showcolorpicker=not showcolorpicker
case "l": showcommands=not showcommands case "l":showcommands=not showcommands
end select end select
' 4. Draw everything using the freshly updated math ' 4. Draw everything using the freshly updated math
@ -281,12 +281,7 @@ sub toolbox
dim spacing:spacing=1 dim spacing:spacing=1
for i=0 to 19 for i=0 to 19
' Force integer math to keep columns locked at 2
' x will only ever be 0 or 33
x=(i mod 2)*(btnsize+spacing) x=(i mod 2)*(btnsize+spacing)
' y will only increase every 2 buttons
' Use Int() if your language doesn't support the \ operator
y=int(i/2)*(btnsize+spacing) y=int(i/2)*(btnsize+spacing)
if imagebutton(x,y,btnsize,btnsize,icon(i)) then if imagebutton(x,y,btnsize,btnsize,icon(i)) then
@ -345,30 +340,30 @@ sub canvas
if showcolorpicker then viewy2=_height-20 else viewy2=_height-1 if showcolorpicker then viewy2=_height-20 else viewy2=_height-1
_dest 0 _dest 0
' 2. Render Layers (Let QB64 handle the viewport clipping natively) ' 2. Render Layers (Let QB64 handle the viewport clipping natively)
dim i as integer dim i as integer
for i = 0 to ubound(layers) for i=0 to ubound(layers)
dim img as long: img = layers(i).ihandle dim img as long:img=layers(i).ihandle
dim imgw as integer: imgw = _width(img) dim imgw as integer:imgw=_width(img)
dim imgh as integer: imgh = _height(img) dim imgh as integer:imgh=_height(img)
' Calculate the absolute unclipped destination positions ' Calculate the absolute unclipped destination positions
drawx1 = state.offsetx drawx1=state.offsetx
drawy1 = state.offsety drawy1=state.offsety
drawx2 = state.offsetx + (imgw * state.zoom) drawx2=state.offsetx+(imgw*state.zoom)
drawy2 = state.offsety + (imgh * state.zoom) drawy2=state.offsety+(imgh*state.zoom)
' Direct 1:1 mapping of the entire source asset ' Direct 1:1 mapping of the entire source asset
srcx1 = 0 srcx1=0
srcy1 = 0 srcy1=0
srcx2 = imgw srcx2=imgw
srcy2 = imgh srcy2=imgh
' Only draw if the asset is within the general view window range ' Only draw if the asset is within the general view window range
if drawx2 > viewx1 and drawx1 < viewx2 and drawy2 > viewy1 and drawy1 < viewy2 then if drawx2>viewx1 and drawx1<viewx2 and drawy2>viewy1 and drawy1<viewy2 then
_putimage (drawx1, drawy1)-(drawx2, drawy2), img, 0, (srcx1, srcy1)-(srcx2, srcy2) _putimage (drawx1,drawy1)-(drawx2,drawy2),img,0,(srcx1,srcy1)-(srcx2,srcy2)
end if end if
next next
_dest layers(2).ihandle:cls,0:_dest 0 _dest layers(2).ihandle:cls,0:_dest 0
' 2.5 if the mouse is in ui thats all we need ' 2.5 if the mouse is in ui thats all we need
if showtoolbox then if showtoolbox then
@ -387,14 +382,14 @@ sub canvas
end if end if
end if end if
' 3. Calculate Canvas Coordinates (Center-aligned to the zoom block) ' 3. Calculate Canvas Coordinates (Center-aligned to the zoom block)
dim canx as long dim canx as long
dim cany as long dim cany as long
' Add half a zoomed pixel block to align the mouse tip to the block center ' Add half a zoomed pixel block to align the mouse tip to the block center
canx = int((_mousex - state.offsetx + (state.zoom \ 2)) / state.zoom) canx=int((_mousex-state.offsetx+(state.zoom \ 2))/state.zoom)
cany = int((_mousey - state.offsety + (state.zoom \ 2)) / state.zoom) cany=int((_mousey-state.offsety+(state.zoom \ 2))/state.zoom)
static drawcol static drawcol
if _mousebutton(1) then drawcol=state.fcolor if _mousebutton(1) then drawcol=state.fcolor
if _mousebutton(2) then drawcol=state.bcolor if _mousebutton(2) then drawcol=state.bcolor
@ -487,27 +482,27 @@ sub do.circle (sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
dim x as long,y as long,r as long dim x as long,y as long,r as long
if state.isdrawing then if state.isdrawing then
osource=_source osource=_source
odest=_dest odest=_dest
if _keydown(100303) or _keydown(100304) then if _keydown(100303) or _keydown(100304) then
' --- Shift Held: Locked Edge Diameter Mode --- ' --- Shift Held: Locked Edge Diameter Mode ---
' Calculate the full distance from the start click to the mouse pointer ' Calculate the full distance from the start click to the mouse pointer
dim diameter as single dim diameter as single
diameter = sqr((ex - sx) ^ 2 + (ey - sy) ^ 2) diameter=sqr((ex-sx) ^ 2+(ey-sy) ^ 2)
r = _round(diameter / 2) r=_round(diameter/2)
' The center is the exact midpoint between the click and the cursor ' The center is the exact midpoint between the click and the cursor
x = _round((sx + ex) / 2) x=_round((sx+ex)/2)
y = _round((sy + ey) / 2) y=_round((sy+ey)/2)
else else
' --- No Shift: Default Center-Radius Mode --- ' --- No Shift: Default Center-Radius Mode ---
x = sx x=sx
y = sy y=sy
r = _round(sqr((ex - sx) ^ 2 + (ey - sy) ^ 2)) r=_round(sqr((ex-sx) ^ 2+(ey-sy) ^ 2))
end if end if
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
@ -527,27 +522,27 @@ sub do.fcircle (sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
dim x as long,y as long,r as long dim x as long,y as long,r as long
if state.isdrawing then if state.isdrawing then
osource=_source osource=_source
odest=_dest odest=_dest
if _keydown(100303) or _keydown(100304) then if _keydown(100303) or _keydown(100304) then
' --- Shift Held: Locked Edge Diameter Mode --- ' --- Shift Held: Locked Edge Diameter Mode ---
' Calculate the full distance from the start click to the mouse pointer ' Calculate the full distance from the start click to the mouse pointer
dim diameter as single dim diameter as single
diameter = sqr((ex - sx) ^ 2 + (ey - sy) ^ 2) diameter=sqr((ex-sx) ^ 2+(ey-sy) ^ 2)
r = _round(diameter / 2) r=_round(diameter/2)
' The center is the exact midpoint between the click and the cursor ' The center is the exact midpoint between the click and the cursor
x = _round((sx + ex) / 2) x=_round((sx+ex)/2)
y = _round((sy + ey) / 2) y=_round((sy+ey)/2)
else else
' --- No Shift: Default Center-Radius Mode --- ' --- No Shift: Default Center-Radius Mode ---
x = sx x=sx
y = sy y=sy
r = _round(sqr((ex - sx) ^ 2 + (ey - sy) ^ 2)) r=_round(sqr((ex-sx) ^ 2+(ey-sy) ^ 2))
end if end if
if mouseclicked or rmouseclicked then if mouseclicked or rmouseclicked then
@ -566,26 +561,26 @@ end sub
sub do.box (sx as long,sy as long,ex as long,ey as long,col as long) sub do.box (sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isdrawing then
osource=_source osource=_source
odest=_dest odest=_dest
' --- Shift Held: Perfect Square Constraint --- ' --- Shift Held: Perfect Square Constraint ---
if _keydown(100303) or _keydown(100304) then if _keydown(100303) or _keydown(100304) then
dim dx as long: dx = ex - sx dim dx as long:dx=ex-sx
dim dy as long: dy = ey - sy dim dy as long:dy=ey-sy
' Determine the longest side to use as the square dimensions ' Determine the longest side to use as the square dimensions
dim size as long dim size as long
if abs(dx) > abs(dy) then size = abs(dx) else size = abs(dy) if abs(dx)>abs(dy) then size=abs(dx) else size=abs(dy)
' Shift coordinates relative to the direction of the drag ' Shift coordinates relative to the direction of the drag
dim signx as long: if dx >= 0 then signx = 1 else signx = -1 dim signx as long:if dx>=0 then signx=1 else signx=-1
dim signy as long: if dy >= 0 then signy = 1 else signy = -1 dim signy as long:if dy>=0 then signy=1 else signy=-1
ex = sx + (size * signx) ex=sx+(size*signx)
ey = sy + (size * signy) ey=sy+(size*signy)
end if end if
' --------------------------------------------- ' ---------------------------------------------
@ -605,26 +600,26 @@ end sub
sub do.fbox (sx as long,sy as long,ex as long,ey as long,col as long) sub do.fbox (sx as long,sy as long,ex as long,ey as long,col as long)
dim osource as long dim osource as long
dim odest as long dim odest as long
if state.isdrawing then if state.isdrawing then
osource=_source osource=_source
odest=_dest odest=_dest
' --- Shift Held: Perfect Square Constraint --- ' --- Shift Held: Perfect Square Constraint ---
if _keydown(100303) or _keydown(100304) then if _keydown(100303) or _keydown(100304) then
dim dx as long: dx = ex - sx dim dx as long:dx=ex-sx
dim dy as long: dy = ey - sy dim dy as long:dy=ey-sy
' Determine the longest side to use as the square dimensions ' Determine the longest side to use as the square dimensions
dim size as long dim size as long
if abs(dx) > abs(dy) then size = abs(dx) else size = abs(dy) if abs(dx)>abs(dy) then size=abs(dx) else size=abs(dy)
' Shift coordinates relative to the direction of the drag ' Shift coordinates relative to the direction of the drag
dim signx as long: if dx >= 0 then signx = 1 else signx = -1 dim signx as long:if dx>=0 then signx=1 else signx=-1
dim signy as long: if dy >= 0 then signy = 1 else signy = -1 dim signy as long:if dy>=0 then signy=1 else signy=-1
ex = sx + (size * signx) ex=sx+(size*signx)
ey = sy + (size * signy) ey=sy+(size*signy)
end if end if
' --------------------------------------------- ' ---------------------------------------------