hey everyone. i have a paint program but all it does is save ONE image and load that ONLY image.
is it possible to make it so when the person wants to save they can specify a name for it and when they
want to load the can chose which one to load? if so please post. here is my code:
Rem Project: PaintSplash V1
Rem Created: 1/25/2006 6:23:20 PM
Rem ***** Main Source File *****
remstart
I shall put in blue gui commands for GUI once i get it
remend
type __FloodFillType
Initialised as integer
CoverColour as integer
BitmapWidth as integer
BitmapHeight as integer
endtype
global __FloodFillGlobal as __FloodFillType
#constant __SpanListSize 15
type __FillSpan
Left as integer
Right as integer
endtype
global dim __FilledSpans() as __FillSpan
global dim __FilledSpansCount() as integer
`setup
sync on
sync rate 100
size=5
DrawColour as Dword
`Set backroud color
color backdrop 0,500
`Font
SET TEXT FONT "Arial"
`Set default color
DrawColour = rgb(0,0,255)
set display mode 640,480,16
color backdrop 0
`Set drawing variables:
draw = 1
fill = 1
`Start The Loop
do
if keystate (2)=1 then DrawColour = rgb(255,0,0)
if keystate (3)=1 then DrawColour = rgb(0,255,0)
if keystate (4)=1 then DrawColour = rgb(0,0,255)
if controlkey()=1 and bitmap exist(1)=0
load bitmap "image1.bmp",1
copy bitmap 1,0,0,bitmap width(1),bitmap height(1),0,0,0,640,480
delete bitmap 1
endif
if spacekey()=1
get image 1,0,0,640,480 : save image "image1.bmp",1 : delete image 1
endif
`print the frame around work area
ink rgb(255,255,255),0
line screen width() - screen width(),screen height(),0,0
line screen width(),screen height()-screen height(),0,0
line screen width() + screen width(),screen height(),0,479
line screen width() - screen width() + screen width(),screen height() + screen height(),639,0
MX# = mousex()
MY# = mousey()
`Start Button clicking/keystates
if mouseclick()=1 and draw = 1
ink DrawColour,0
LineTo(MX#, MY#)
endif
if mouseclick()=0
MoveTo(MX#,MY#)
endif
if escapekey()=1 then end
if mouseclick()=2 and fill = 1
floodfill(MX#,MY#,DrawColour)
endif
sync
loop
type _2D_LineTo_t
X as integer
Y as integer
endtype
global _2D_LastPoint as _2D_LineTo_t
function MoveTo(X as integer, Y as integer)
_2D_LastPoint.X = X
_2D_LastPoint.Y = Y
endfunction
function LineTo(X as integer, Y as integer)
line _2D_LastPoint.X, _2D_LastPoint.Y, X, Y
MoveTo(X,Y)
endfunction
function FilledCircle( CX as integer, CY as integer, R as integer )
local x as integer
local y as integer
local i as integer
local s as integer
` Precalculate the square of the radius - this is the hypotenuse
i=R*R
` Calculate the size of the central square
s=R*0.70710678 : ` this number is sin(45)
` Draw it
box CX-s, CY-s, CX+s+1, CY+s+1
s=s+1
` Loop through the bit we have not yet drawn
for y=s to R
x=sqrt( i-(y*y) )
` Draw top and bottom
box CX-x, CY-y, CX+x+1, CY-y+1
box CX-x, CY+y, CX+x+1, CY+y+1
` Draw left and right
box CX-y, CY-x, CX-y+1, CY+x+1
box CX+y, CY-x, CX+y+1, CY+x+1
next y
endfunction
function BoxOutline(x1 as integer, y1 as integer, x2 as integer, y2 as integer)
box x1,y1,x2+1,y1+1
box x2,y1,x2+1,y2+1
box x1,y2,x2+1,y2+1
box x1,y1,x1+1,y2+1
endfunction
function FloodFill(x,y,c)
__FloodFillGlobal.BitmapWidth=bitmap width()-1
__FloodFillGlobal.BitmapHeight=bitmap height()-1
__InitialiseFillSpan()
if x >= 0 and x <= __FloodFillGlobal.BitmapWidth
if y >= 0 and y <= __FloodFillGlobal.BitmapHeight
lock pixels
__FloodFillGlobal.CoverColour = point(x,y)
if __FloodFillGlobal.CoverColour <> c
ink c,0
__FloodLoop(x,y)
endif
unlock pixels
endif
endif
endfunction
function __FloodLoop(x as integer,y as integer)
local Left as integer
local Right as integer
local SpanSize as integer
for Left=x-1 to 0 step -1
if point(Left,y) <> __FloodFillGlobal.CoverColour then exit
next Left
inc Left
for Right=x+1 to __FloodFillGlobal.BitmapWidth
if point(Right,y) <> __FloodFillGlobal.CoverColour then exit
next Right
` draw this line
box Left,y,Right,y+1
` and remember it
__AddFillSpan(y,Left-1,Right+1)
` Fill upwards
if y > 0
dec y
x=Left
while x < Right
SpanSize=__CheckFillSpan(x,y)
if SpanSize = 0
if point(x,y) = __FloodFillGlobal.CoverColour
__FloodLoop(x,y)
endif
inc x
else
inc x,SpanSize
endif
endwhile
inc y
endif
` Fill downwards
if y < __FloodFillGlobal.BitmapHeight
inc y
x=Left
while x < Right
SpanSize=__CheckFillSpan(x,y)
if SpanSize = 0
if point(x,y) = __FloodFillGlobal.CoverColour
__FloodLoop(x,y)
endif
inc x
else
inc x,SpanSize
endif
endwhile
endif
endfunction
function __InitialiseFillSpan()
local i as integer
if __FloodFillGlobal.Initialised = 0
` First time called, create the arrays - bigger than we should ever need
undim __FilledSpans()
global dim __FilledSpans(__SpanListSize,2048) as __FillSpan
undim __FilledSpansCount()
global dim __FilledSpansCount(2048) as integer
__FloodFillGlobal.Initialised=1
else
` Subsequent call, just reset the spans we'll be using
for i=__FloodFillGlobal.BitmapHeight to 0 step -1
__FilledSpansCount(i)=0
next i
endif
endfunction
function __AddFillSpan(y as integer,Left as integer,Right as integer)
local i as integer
i=__FilledSpansCount(y)
if i < __SpanListSize
__FilledSpans(i, y).Left=Left
__FilledSpans(i, y).Right=Right
inc __FilledSpansCount(y)
endif
endfunction
function __CheckFillSpan(x as integer,y as integer)
local i as integer
for i=__FilledSpansCount(y)-1 to 0 step -1
if x >= __FilledSpans(i, y).Left
if x < __FilledSpans(i, y).Right then exitfunction __FilledSpans(i, y).Right-x
endif
next i
endfunction 0