diff --git a/pixler.bas b/pixler.bas index 541e3e9..ea71359 100644 --- a/pixler.bas +++ b/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 @@ -345,30 +340,30 @@ sub canvas if showcolorpicker then viewy2=_height-20 else viewy2=_height-1 _dest 0 - ' 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) - - ' Calculate the absolute unclipped destination positions - 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 - - ' 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) - end if - next + ' 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) + + ' Calculate the absolute unclipped destination positions + 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 + + ' Only draw if the asset is within the general view window range + if drawx2>viewx1 and drawx1viewy1 and drawy1 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 - - ex = sx + (size * signx) - ey = sy + (size * signy) + 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) 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) dim osource as long dim odest as long - + if state.isdrawing then osource=_source odest=_dest - + ' --- 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 - - ex = sx + (size * signx) - ey = sy + (size * signy) + 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) end if ' ---------------------------------------------