lots and lots of lots
This commit is contained in:
parent
827afeb19a
commit
6af399f587
1 changed files with 127 additions and 48 deletions
173
pixler.bas
173
pixler.bas
|
|
@ -2,6 +2,9 @@ type statetype
|
||||||
tool as long
|
tool as long
|
||||||
fcolor as long
|
fcolor as long
|
||||||
bcolor as long
|
bcolor as long
|
||||||
|
offsetX as single
|
||||||
|
offsetY as single
|
||||||
|
zoom as single
|
||||||
end type
|
end type
|
||||||
|
|
||||||
type layertype
|
type layertype
|
||||||
|
|
@ -20,6 +23,7 @@ dim shared mouseclicked as integer
|
||||||
dim shared mousedown as integer
|
dim shared mousedown as integer
|
||||||
dim shared rmouseclicked as integer
|
dim shared rmouseclicked as integer
|
||||||
dim shared rmousedown as integer
|
dim shared rmousedown as integer
|
||||||
|
|
||||||
$resize:on
|
$resize:on
|
||||||
screen _newimage(750,480,32)
|
screen _newimage(750,480,32)
|
||||||
_delay 0.1
|
_delay 0.1
|
||||||
|
|
@ -32,31 +36,82 @@ layers(1).ihandle=_newimage(640,350,32)
|
||||||
_dest layers(0).ihandle
|
_dest layers(0).ihandle
|
||||||
line (0,0)-(_width-1,_height-1),_rgb32(255),bf
|
line (0,0)-(_width-1,_height-1),_rgb32(255),bf
|
||||||
_dest 0
|
_dest 0
|
||||||
|
state.tool = 1
|
||||||
|
state.fcolor = 1
|
||||||
|
state.bcolor = 2
|
||||||
|
state.zoom = 1.0
|
||||||
|
state.offsetX = 70 + 20 ' To the right of the toolbox
|
||||||
|
state.offsetY = 20
|
||||||
|
dim lastMX, lastMY
|
||||||
|
dim diffX as integer
|
||||||
|
dim diffY as integer
|
||||||
|
dim oldWidth as integer
|
||||||
|
dim oldHeight as integer
|
||||||
|
|
||||||
|
oldWidth=_width
|
||||||
|
oldHeight=_height
|
||||||
do
|
do
|
||||||
|
if CheckResize(_source) = -1 THEN
|
||||||
|
diffX = _width - oldWidth
|
||||||
|
diffY = _height - oldHeight
|
||||||
|
state.offsetX = state.offsetX + (diffX / 2)
|
||||||
|
state.offsetY = state.offsetY + (diffY / 2)
|
||||||
|
oldWidth = _width
|
||||||
|
oldHeight = _height
|
||||||
|
end if
|
||||||
|
|
||||||
|
cls
|
||||||
line (0,0)-(_width-1,_height-1),backgroundcolor1,bf
|
line (0,0)-(_width-1,_height-1),backgroundcolor1,bf
|
||||||
IF CheckResize(_SOURCE) = -1 then rem 'whatever, maybe some day somthing needs changing if the window is resized'
|
while _mouseinput:mw=mw+_mousewheel:wend
|
||||||
while _mouseinput:wend
|
|
||||||
mouseclicked=0
|
' --- Global Mouse Handling (Left & Right) ---
|
||||||
rmouseclicked=0
|
mouseclicked = 0
|
||||||
if mousedown=-1 and _mousebutton(1)=0 then mouseclicked=-1
|
rmouseclicked = 0
|
||||||
if rmousedown=-1 and _mousebutton(2)=0 then rmouseclicked=-1
|
if mousedown = -1 and _mousebutton(1) = 0 then mouseclicked = -1
|
||||||
mousedown=_mousebutton(1)
|
if rmousedown = -1 and _mousebutton(2) = 0 then rmouseclicked = -1
|
||||||
rmousedown=_mousebutton(2)
|
mousedown = _mousebutton(1)
|
||||||
|
rmousedown = _mousebutton(2)
|
||||||
|
|
||||||
|
' Panning (Middle Mouse)
|
||||||
|
if _mousebutton(3) then
|
||||||
|
state.offsetX = state.offsetX + (_mousex - lastMX)
|
||||||
|
state.offsetY = state.offsetY + (_mousey - lastMY)
|
||||||
|
end if
|
||||||
|
lastMX = _mousex: lastMY = _mousey
|
||||||
|
|
||||||
|
' Zooming
|
||||||
|
if mw <> 0 then
|
||||||
|
state.zoom = state.zoom + (mw * 0.1)
|
||||||
|
if state.zoom < 0.1 then state.zoom = 0.1
|
||||||
|
mw=0
|
||||||
|
end if
|
||||||
|
'state.zoom=mw/100
|
||||||
|
canvas ' Uses mousedown and rmousedown for drawing/erasing
|
||||||
toolbox
|
toolbox
|
||||||
colorpicker
|
colorpicker ' Uses rmouseclicked for bcolor
|
||||||
canvas
|
|
||||||
locate 10,10: print state.tool
|
|
||||||
locate 11,10: color state.fcolor: print state.fcolor
|
|
||||||
locate 12,10: color state.bcolor: print state.bcolor
|
|
||||||
_limit 30
|
_limit 30
|
||||||
_display
|
_display
|
||||||
loop
|
loop
|
||||||
|
|
||||||
sub toolbox
|
sub toolbox
|
||||||
dim x,y
|
dim i, x, y
|
||||||
if imagebutton(0,0,32,32,icon(0)) then state.tool=1
|
dim btnSize : btnSize = 32
|
||||||
if imagebutton(32,0,32,32,icon(1)) then state.tool=2
|
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
|
||||||
|
state.tool = i + 1
|
||||||
|
end if
|
||||||
|
next
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
sub colorpicker
|
sub colorpicker
|
||||||
|
|
@ -78,51 +133,75 @@ sub colorpicker
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
sub canvas
|
sub canvas
|
||||||
' 1. Define the box boundaries
|
|
||||||
dim boxX1 as integer: boxX1 = 70
|
dim boxX1 as integer: boxX1 = 70
|
||||||
dim boxWidth as integer: boxWidth = _width - 1 - boxX1
|
dim boxWidth as integer: boxWidth = _width - 1 - boxX1
|
||||||
dim boxHeight as integer: boxHeight = _height - 20
|
dim boxHeight as integer: boxHeight = _height - 20
|
||||||
|
|
||||||
' 2. Draw the background box
|
' Workspace background
|
||||||
line (boxX1, 0)-(_width - 1, boxHeight), _rgb32(64), bf
|
line (boxX1, 0)-(_width - 1, boxHeight), _rgb32(32), bf
|
||||||
|
|
||||||
' 3. Loop through layers and calculate centering for each
|
' Render Layers with Zoom/Offset[cite: 4]
|
||||||
|
dim i as integer
|
||||||
for i = 0 to ubound(layers)
|
for i = 0 to ubound(layers)
|
||||||
dim imgW as integer: imgW = _width(layers(i).ihandle)
|
dim w as integer: w = _width(layers(i).ihandle) * state.zoom
|
||||||
|
dim h as integer: h = _height(layers(i).ihandle) * state.zoom
|
||||||
' Calculate X to center the image relative to the box
|
_putimage (state.offsetX, state.offsetY)-(state.offsetX + w, state.offsetY + h), layers(i).ihandle
|
||||||
' We take the box start (70) and add half of the remaining whitespace
|
|
||||||
dim drawX as integer
|
|
||||||
drawX = boxX1 + (boxWidth - imgW) / 2
|
|
||||||
|
|
||||||
' If you also want it centered vertically:
|
|
||||||
dim imgH as integer: imgH = _height(layers(i).ihandle)
|
|
||||||
dim drawY as integer
|
|
||||||
drawY = (boxHeight - imgH) / 2
|
|
||||||
|
|
||||||
_putimage (drawX, drawY), layers(i).ihandle
|
|
||||||
next
|
next
|
||||||
|
|
||||||
|
' --- Drawing Logic (Multi-Button) ---
|
||||||
|
if (mousedown or rmousedown) and _mousex > boxX1 then
|
||||||
|
' Translate to Canvas Space
|
||||||
|
dim canX as integer: canX = (_mousex - state.offsetX) / state.zoom
|
||||||
|
dim canY as integer: canY = (_mousey - state.offsetY) / state.zoom
|
||||||
|
|
||||||
|
' Boundary Check
|
||||||
|
if canX >= 0 and canX < _width(layers(0).ihandle) then
|
||||||
|
if canY >= 0 and canY < _height(layers(0).ihandle) then
|
||||||
|
_dest layers(0).ihandle
|
||||||
|
|
||||||
|
' Select color based on button pressed
|
||||||
|
dim drawCol as _unsigned long
|
||||||
|
if mousedown then drawCol = state.fcolor else drawCol = state.bcolor
|
||||||
|
|
||||||
|
' Apply Tool
|
||||||
|
if state.tool = 1 then
|
||||||
|
pset (canX, canY), drawCol
|
||||||
|
elseif state.tool = 2 then
|
||||||
|
' Example: Square brush
|
||||||
|
line (canX - 1, canY - 1)-(canX + 1, canY + 1), drawCol, bf
|
||||||
|
end if
|
||||||
|
|
||||||
|
_dest 0
|
||||||
|
end if
|
||||||
|
end if
|
||||||
|
end if
|
||||||
end sub
|
end sub
|
||||||
|
|
||||||
function icon(index as long)
|
function icon (index as long)
|
||||||
static init as integer
|
static init as integer
|
||||||
static icons() as long
|
static icons() as long
|
||||||
if not init then
|
if not init then
|
||||||
dim icons(5) as long
|
redim icons(19) as long ' Room for 20 icons
|
||||||
icons(0)=_newimage(32,32,32)
|
|
||||||
_dest icons(0)
|
|
||||||
line (5,27)-(27,5)
|
|
||||||
icons(1)=_newimage(32,32,32)
|
|
||||||
_dest icons(1)
|
|
||||||
circle (15,15),13
|
|
||||||
icons(2)=_newimage(32,32,32)
|
|
||||||
_dest icons(2)
|
|
||||||
|
|
||||||
_dest 0
|
' Define your specific tool icons here
|
||||||
init = -1
|
icons(0) = _newimage(32, 32, 32): _dest icons(0): line (5, 27)-(27, 5): _dest 0
|
||||||
|
icons(1) = _newimage(32, 32, 32): _dest icons(1): circle (15, 15), 13: _dest 0
|
||||||
|
icons(2) = _newimage(32, 32, 32): _dest icons(2): line (5, 5)-(27, 27), , b: _dest 0
|
||||||
|
|
||||||
|
' Fill the remaining slots with blank 32x32 images
|
||||||
|
dim j as integer
|
||||||
|
for j = 3 to 19
|
||||||
|
if icons(j) = 0 then icons(j) = _newimage(32, 32, 32)
|
||||||
|
next
|
||||||
|
|
||||||
|
init = -1
|
||||||
end if
|
end if
|
||||||
if (index>=lbound(icons)) and (index<=ubound(icons)) then
|
|
||||||
icon=icons(index)
|
' Bounds checking to prevent returning 0 or crashing
|
||||||
|
if index >= 0 and index <= 19 then
|
||||||
|
icon = icons(index)
|
||||||
|
else
|
||||||
|
icon = icons(0)
|
||||||
end if
|
end if
|
||||||
end function
|
end function
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue