space saving
This commit is contained in:
parent
e3054bdb79
commit
fb5935e4b9
1 changed files with 81 additions and 86 deletions
107
pixler.bas
107
pixler.bas
|
|
@ -120,12 +120,12 @@ do
|
|||
' Keyboarding
|
||||
keyin=inkey$
|
||||
select case keyin
|
||||
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 "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 "c": showcolorpicker=not showcolorpicker
|
||||
case "l": showcommands=not showcommands
|
||||
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 "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 "c":showcolorpicker=not showcolorpicker
|
||||
case "l":showcommands=not showcommands
|
||||
end select
|
||||
|
||||
' 4. Draw everything using the freshly updated math
|
||||
|
|
@ -281,12 +281,7 @@ sub toolbox
|
|||
dim spacing:spacing=1
|
||||
|
||||
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)
|
||||
|
||||
' y will only increase every 2 buttons
|
||||
' Use Int() if your language doesn't support the \ operator
|
||||
y=int(i/2)*(btnsize+spacing)
|
||||
|
||||
if imagebutton(x,y,btnsize,btnsize,icon(i)) then
|
||||
|
|
@ -347,26 +342,26 @@ sub canvas
|
|||
|
||||
' 2. Render Layers (Let QB64 handle the viewport clipping natively)
|
||||
dim i as integer
|
||||
for i = 0 to ubound(layers)
|
||||
dim img as long: img = layers(i).ihandle
|
||||
dim imgw as integer: imgw = _width(img)
|
||||
dim imgh as integer: imgh = _height(img)
|
||||
for i=0 to ubound(layers)
|
||||
dim img as long:img=layers(i).ihandle
|
||||
dim imgw as integer:imgw=_width(img)
|
||||
dim imgh as integer:imgh=_height(img)
|
||||
|
||||
' Calculate the absolute unclipped destination positions
|
||||
drawx1 = state.offsetx
|
||||
drawy1 = state.offsety
|
||||
drawx2 = state.offsetx + (imgw * state.zoom)
|
||||
drawy2 = state.offsety + (imgh * state.zoom)
|
||||
drawx1=state.offsetx
|
||||
drawy1=state.offsety
|
||||
drawx2=state.offsetx+(imgw*state.zoom)
|
||||
drawy2=state.offsety+(imgh*state.zoom)
|
||||
|
||||
' Direct 1:1 mapping of the entire source asset
|
||||
srcx1 = 0
|
||||
srcy1 = 0
|
||||
srcx2 = imgw
|
||||
srcy2 = imgh
|
||||
srcx1=0
|
||||
srcy1=0
|
||||
srcx2=imgw
|
||||
srcy2=imgh
|
||||
|
||||
' 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
|
||||
_putimage (drawx1, drawy1)-(drawx2, drawy2), img, 0, (srcx1, srcy1)-(srcx2, srcy2)
|
||||
if drawx2>viewx1 and drawx1<viewx2 and drawy2>viewy1 and drawy1<viewy2 then
|
||||
_putimage (drawx1,drawy1)-(drawx2,drawy2),img,0,(srcx1,srcy1)-(srcx2,srcy2)
|
||||
end if
|
||||
next
|
||||
_dest layers(2).ihandle:cls,0:_dest 0
|
||||
|
|
@ -387,13 +382,13 @@ sub canvas
|
|||
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 cany as long
|
||||
|
||||
' 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)
|
||||
cany = int((_mousey - state.offsety + (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)
|
||||
|
||||
static drawcol
|
||||
if _mousebutton(1) then drawcol=state.fcolor
|
||||
|
|
@ -496,18 +491,18 @@ sub do.circle (sx as long,sy as long,ex as long,ey as long,col as long)
|
|||
' --- Shift Held: Locked Edge Diameter Mode ---
|
||||
' Calculate the full distance from the start click to the mouse pointer
|
||||
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
|
||||
x = _round((sx + ex) / 2)
|
||||
y = _round((sy + ey) / 2)
|
||||
x=_round((sx+ex)/2)
|
||||
y=_round((sy+ey)/2)
|
||||
else
|
||||
' --- No Shift: Default Center-Radius Mode ---
|
||||
x = sx
|
||||
y = sy
|
||||
r = _round(sqr((ex - sx) ^ 2 + (ey - sy) ^ 2))
|
||||
x=sx
|
||||
y=sy
|
||||
r=_round(sqr((ex-sx) ^ 2+(ey-sy) ^ 2))
|
||||
end if
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
|
|
@ -536,18 +531,18 @@ sub do.fcircle (sx as long,sy as long,ex as long,ey as long,col as long)
|
|||
' --- Shift Held: Locked Edge Diameter Mode ---
|
||||
' Calculate the full distance from the start click to the mouse pointer
|
||||
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
|
||||
x = _round((sx + ex) / 2)
|
||||
y = _round((sy + ey) / 2)
|
||||
x=_round((sx+ex)/2)
|
||||
y=_round((sy+ey)/2)
|
||||
else
|
||||
' --- No Shift: Default Center-Radius Mode ---
|
||||
x = sx
|
||||
y = sy
|
||||
r = _round(sqr((ex - sx) ^ 2 + (ey - sy) ^ 2))
|
||||
x=sx
|
||||
y=sy
|
||||
r=_round(sqr((ex-sx) ^ 2+(ey-sy) ^ 2))
|
||||
end if
|
||||
|
||||
if mouseclicked or rmouseclicked then
|
||||
|
|
@ -573,19 +568,19 @@ sub do.box (sx as long,sy as long,ex as long,ey as long,col as long)
|
|||
|
||||
' --- Shift Held: Perfect Square Constraint ---
|
||||
if _keydown(100303) or _keydown(100304) then
|
||||
dim dx as long: dx = ex - sx
|
||||
dim dy as long: dy = ey - sy
|
||||
dim dx as long:dx=ex-sx
|
||||
dim dy as long:dy=ey-sy
|
||||
|
||||
' Determine the longest side to use as the square dimensions
|
||||
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
|
||||
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 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
|
||||
|
||||
ex = sx + (size * signx)
|
||||
ey = sy + (size * signy)
|
||||
ex=sx+(size*signx)
|
||||
ey=sy+(size*signy)
|
||||
end if
|
||||
' ---------------------------------------------
|
||||
|
||||
|
|
@ -612,19 +607,19 @@ sub do.fbox (sx as long,sy as long,ex as long,ey as long,col as long)
|
|||
|
||||
' --- Shift Held: Perfect Square Constraint ---
|
||||
if _keydown(100303) or _keydown(100304) then
|
||||
dim dx as long: dx = ex - sx
|
||||
dim dy as long: dy = ey - sy
|
||||
dim dx as long:dx=ex-sx
|
||||
dim dy as long:dy=ey-sy
|
||||
|
||||
' Determine the longest side to use as the square dimensions
|
||||
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
|
||||
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 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
|
||||
|
||||
ex = sx + (size * signx)
|
||||
ey = sy + (size * signy)
|
||||
ex=sx+(size*signx)
|
||||
ey=sy+(size*signy)
|
||||
end if
|
||||
' ---------------------------------------------
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue