start of a menu.
This commit is contained in:
parent
d727c75fea
commit
7f9e6ea5e9
1 changed files with 58 additions and 40 deletions
98
pixler.bas
98
pixler.bas
|
|
@ -69,9 +69,9 @@ do
|
|||
oldWidth = _width
|
||||
oldHeight = _height
|
||||
end if
|
||||
|
||||
|
||||
line (0,0)-(_width-1,_height-1),backgroundcolor1,bf
|
||||
|
||||
|
||||
'Mouse Handling
|
||||
while _mouseinput:mw=mw+_mousewheel:wend
|
||||
mouseclicked = 0
|
||||
|
|
@ -80,7 +80,7 @@ do
|
|||
if rmousedown = -1 and _mousebutton(2) = 0 then rmouseclicked = -1
|
||||
mousedown = _mousebutton(1)
|
||||
rmousedown = _mousebutton(2)
|
||||
|
||||
|
||||
' Panning (Middle Mouse)
|
||||
if _mousebutton(3) then
|
||||
state.offsetX = int(state.offsetX + (_mousex - lastMX))
|
||||
|
|
@ -93,23 +93,23 @@ do
|
|||
' 1. Capture current world position
|
||||
dim mouseWorldX as single: mouseWorldX = (_mousex - state.offsetX) / state.zoom
|
||||
dim mouseWorldY as single: mouseWorldY = (_mousey - state.offsetY) / state.zoom
|
||||
|
||||
|
||||
' 2. Calculate the new zoom level (Snap to whole numbers)
|
||||
if mw > 0 then
|
||||
state.zoom = state.zoom + 1
|
||||
else
|
||||
state.zoom = state.zoom - 1
|
||||
end if
|
||||
|
||||
|
||||
' 3. Constrain zoom (Min 1, Max 20)
|
||||
if state.zoom < 1 then state.zoom = 1
|
||||
if state.zoom > 20 then state.zoom = 20
|
||||
|
||||
|
||||
' 4. Adjust offsets and LOCK them to integers
|
||||
' This prevents the canvas from sitting "between" screen pixels
|
||||
state.offsetX = _mousex - (mouseWorldX * state.zoom)
|
||||
state.offsetY = _mousey - (mouseWorldY * state.zoom)
|
||||
|
||||
|
||||
mw = 0
|
||||
end if
|
||||
|
||||
|
|
@ -123,7 +123,7 @@ do
|
|||
case chr$(19) ' ctrl+s
|
||||
'TODO: save logic
|
||||
case chr$(27)' esc
|
||||
'TODO: main menu
|
||||
menu
|
||||
case "h"
|
||||
state.zoom = 1.0
|
||||
state.offsetX = (_width / 2) - (_width(layers(0).ihandle) / 2)
|
||||
|
|
@ -132,12 +132,12 @@ do
|
|||
showtoolbox=not showtoolbox
|
||||
case "c"
|
||||
showcolorpicker=not showcolorpicker
|
||||
end select
|
||||
end select
|
||||
|
||||
canvas
|
||||
if showtoolbox then toolbox
|
||||
if showcolorpicker then colorpicker
|
||||
|
||||
|
||||
_limit 30
|
||||
_display
|
||||
loop
|
||||
|
|
@ -146,16 +146,16 @@ sub toolbox
|
|||
dim i, x, y
|
||||
dim btnSize : btnSize = 32
|
||||
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
|
||||
|
|
@ -175,13 +175,13 @@ sub colorpicker
|
|||
state.fcolor=pal(i)
|
||||
case -2
|
||||
state.bcolor=pal(i)
|
||||
end select
|
||||
end select
|
||||
next i
|
||||
_freeimage img
|
||||
end sub
|
||||
|
||||
sub canvas
|
||||
|
||||
|
||||
' 1. Define the Viewport (The "Window" on your screen)
|
||||
dim viewX1 as integer
|
||||
if showtoolbox then viewX1 = 70 else viewX1 = 0
|
||||
|
|
@ -191,7 +191,7 @@ sub canvas
|
|||
if showcolorpicker then viewY2 = _height - 20 else viewY2 = _height - 1
|
||||
|
||||
_dest 0
|
||||
|
||||
|
||||
' 2. Render Layers with Clipping
|
||||
dim srcX1 as long
|
||||
dim srcY1 as long
|
||||
|
|
@ -201,7 +201,7 @@ sub canvas
|
|||
dim drawY1 as long
|
||||
dim drawX2 as long
|
||||
dim drawY2 as long
|
||||
|
||||
|
||||
dim i as integer
|
||||
for i = 0 to ubound(layers)
|
||||
dim img as long: img = layers(i).ihandle
|
||||
|
|
@ -254,15 +254,15 @@ sub canvas
|
|||
dim canY as integer: canY = int((_mousey - state.offsetY) / state.zoom)
|
||||
|
||||
|
||||
static polypoints(200) as single
|
||||
static polypoints(200) as single
|
||||
static pointCount as integer
|
||||
|
||||
static drawCol
|
||||
if _mousebutton(1) then drawCol = state.fcolor
|
||||
if _mousebutton(2) then drawCol = state.bcolor
|
||||
|
||||
|
||||
' 4. Interaction Logic
|
||||
if _mousex > boxX1 then
|
||||
'if _mousex > boxX1 then
|
||||
' Start Drawing Logic
|
||||
if state.tool = 9 and (mouseclicked or rmouseclicked) then
|
||||
_dest layers(1).ihandle
|
||||
|
|
@ -304,12 +304,12 @@ sub canvas
|
|||
state.isDrawing = -1
|
||||
end if
|
||||
end if
|
||||
|
||||
|
||||
if state.isDrawing then
|
||||
' We use Layer 2 as the temporary preview "rubber-band" layer
|
||||
_dest layers(2).ihandle
|
||||
cls , 0
|
||||
|
||||
_dest layers(2).ihandle
|
||||
cls , 0
|
||||
|
||||
select case state.tool
|
||||
case 1 ' Pencil
|
||||
_dest layers(1).ihandle
|
||||
|
|
@ -338,7 +338,7 @@ sub canvas
|
|||
thickline polypoints((pointCount - 1) * 2), polypoints((pointCount - 1) * 2 + 1), canX, canY, state.fcolor
|
||||
end if
|
||||
end select
|
||||
|
||||
|
||||
' 5. Commit Logic
|
||||
dim commit as integer: commit = 0
|
||||
if state.tool = 7 or state.tool = 8 then
|
||||
|
|
@ -355,15 +355,15 @@ sub canvas
|
|||
if state.tool =8 then filledPolygon finalP(), state.fcolor else Polygon finalP(), state.fcolor
|
||||
else
|
||||
' Merge the preview into the drawing layer
|
||||
_putimage , layers(2).ihandle, layers(1).ihandle
|
||||
_putimage , layers(2).ihandle, layers(1).ihandle
|
||||
end if
|
||||
|
||||
_dest layers(2).ihandle: cls , 0
|
||||
|
||||
_dest layers(2).ihandle: cls , 0
|
||||
state.isDrawing = 0
|
||||
pointCount = 0
|
||||
pointCount = 0
|
||||
end if
|
||||
end if
|
||||
end if
|
||||
'end if
|
||||
_dest 0 ' Ensure we return to main screen
|
||||
end sub
|
||||
|
||||
|
|
@ -372,7 +372,7 @@ function icon (index as long)
|
|||
static icons() as long
|
||||
if not init then
|
||||
redim icons(19) as long ' Room for 20 icons
|
||||
|
||||
|
||||
' Define your specific tool icons here
|
||||
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
|
||||
|
|
@ -380,7 +380,7 @@ function icon (index as long)
|
|||
icons(6) = _newimage(32,32,32): _dest icons(6)
|
||||
line (5,15)-(15,5):line -(25,15):line -(20,25): line -(10,25):line -(5,15)
|
||||
_dest 0
|
||||
|
||||
|
||||
icons(7) = _newimage(32, 32, 32): _dest icons(7)
|
||||
' Draw a small filled shape for the filled polygon icon
|
||||
for fy = 10 to 20: line (10, fy)-(22, fy): next
|
||||
|
|
@ -395,7 +395,7 @@ function icon (index as long)
|
|||
for j = 0 to 19
|
||||
if icons(j) = 0 then icons(j) = _newimage(32, 32, 32)
|
||||
next
|
||||
|
||||
|
||||
init = -1
|
||||
end if
|
||||
|
||||
|
|
@ -432,7 +432,7 @@ function __internaluiicon&(index as long,imagehandle as long,mode as integer)
|
|||
static init as integer
|
||||
static icons() as long
|
||||
if not init or mode=3 then
|
||||
if mode<3 then
|
||||
if mode<3 then
|
||||
redim icons(3) as long
|
||||
else
|
||||
_freeimage icons(0)
|
||||
|
|
@ -443,23 +443,23 @@ function __internaluiicon&(index as long,imagehandle as long,mode as integer)
|
|||
icons(0)=_newimage(23,23,32) 'Up arrow'
|
||||
_dest icons(0)
|
||||
color textcolor
|
||||
|
||||
|
||||
icons(1)=_newimage(23,23,32) 'Down arrow'
|
||||
_dest icons(1)
|
||||
color textcolor
|
||||
|
||||
|
||||
icons(2)=_newimage(23,23,32) 'Left arrow'
|
||||
_dest icons(2)
|
||||
color textcolor
|
||||
|
||||
|
||||
icons(3)=_newimage(23,23,32) 'Right arrow'
|
||||
_dest icons(3)
|
||||
_dest icons(3)
|
||||
color textcolor
|
||||
|
||||
|
||||
_dest 0
|
||||
init=-1
|
||||
end if
|
||||
|
||||
|
||||
select case mode
|
||||
case 1
|
||||
redim _preserve icons(ubound(icons)+1)
|
||||
|
|
@ -487,3 +487,21 @@ FUNCTION CheckResize (CurrentScreen AS _UNSIGNED LONG) 'pulled straight out of t
|
|||
END IF
|
||||
|
||||
END FUNCTION
|
||||
|
||||
|
||||
sub menu()
|
||||
Line (0,0)-(_width-1,_height-1),_rgb32(0,1),bf
|
||||
do until done
|
||||
k$=inkey$
|
||||
while _mouseinput:wend
|
||||
mouseclicked=mbd and not _mousebutton(1)
|
||||
mbd=_mousebutton(1)
|
||||
if button(10,10,60,23,"open") then system
|
||||
if button(10,34,60,23,"save") then system
|
||||
if button(10,56,60,23,"exit") then system
|
||||
|
||||
if k$=chr$(27) then done=-1
|
||||
_limit 30
|
||||
_display
|
||||
loop
|
||||
end sub
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue