hey everyone!
whenever i run my program none of the buttons work. like when i hit save and load a save/load dialog is supposed to come up. here is my code: please help!
`Project: Blue gui style
`Created: 02/05/06
`=================
`Main Source File
rem End of loop
sync on
sync rate 0
`Global Variables
global mainMenu
global fileMenu
global editMenu
global brushsmenu
global toolsmenu
global colormenu
global button1
global colorp
`Constants
#constant MENU_FILE 1
#constant MENU_FILE_EXIT 2
startBlue "***","******"
`Create user interface
mainMenu=createMenu(0)
addMenuItem mainMenu,"File",1
addMenuItem mainMenu,"Edit",2
addMenuItem mainMenu,"Brush-Size",3
addMenuItem mainMenu,"Tools",4
addMenuItem mainMenu,"Color Picker",5
fileMenu=createSubMenu(mainMenu,1)
addMenuItem fileMenu,"New",22
addMenuSplitter fileMenu
addMenuItem fileMenu,"Open",9
addMenuItem fileMenu,"Save",10
addMenuSplitter fileMenu
addMenuItem fileMenu,"Save as",23
addMenuSplitter fileMenu
addMenuItem fileMenu,"Exit",11
editMenu=createSubMenu(mainMenu,2)
addMenuItem editMenu,"Undo",12
addMenuItem editMenu,"Redo",13
brushsMenu=createSubMenu(mainMenu,3)
addMenuItem brushsMenu,"Increase (Keypad +)",14
addMenuItem brushsMenu,"Decrease (Keypad -)", 15
toolsMenu=createSubMenu(mainMenu,4)
addMenuItem toolsmenu,"Pencil (D)",18
addMenuItem toolsmenu,"Spray paint",19
addMenuItem toolsmenu,"Fill (F)",20
addMenuItem toolsmenu,"Eye Dropper (I)",24
addMenuItem toolsmenu,"Text (T)",17
addMenuSplitter toolsmenu
addMenuItem toolsmenu,"Font selector",16
colorMenu=createSubMenu(mainMenu,5)
addMenuItem colormenu,"Color Picker",21
`Set default color
DrawColour = rgb(255,255,255)
`Set drawing variables:
draw = 1
size = 2
SizePlus# = 0
atext = 0
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
`Main Loop
do
`Get information about gadget events
getEvent
if eventType()=MENU_CLICK
select eventData()
case 11 : `Exit
savebeforeclose = questionmessage ("Would you like to save?", "Save before you exit")
if savebeforeclose = 0 then end
if savebeforeclose = 1 then savebeforeyouexit = 1
endcase
case 14
size = size + 1
endcase
case 15
size = size - 1
endcase
case 16
SelectFont = (fontDialog())
endcase
case 18
draw = 1 : spray = 0 : fill = 0 : eyedrop = 0 : atext = 0
endcase
case 17
atext = 1 : draw = 0 : spray = 0 : fill = 0 : eyedrop = 0
endcase
case 19
message "Notice","Spray feature not implemented yet"
endcase
case 20
fill = 1 : draw = 0 : spray = 0 : eyedrop = 0 : atext = 0
endcase
case 21
DrawColour=colorDialog()
endcase
case 10
save = 1
endcase
case 9
load = 1
endcase
case 22
CLS
size = 2
draw = 1 : spray = 0 : fill = 0 : eyedrop = 0 : atext = 0
DrawColour = rgb(255,255,255)
endcase
case 23
saveas=1
endcase
case 24
eyedrop = 1 : fill = 0 : draw = 0 : spray = 0 : atext = 0
endcase
endselect
endif
`if + key is pressed
if keystate(74)=1 and Sizeminus#=0
SizeminusTime#=timer()
size = size - 1
Sizeminus#=1
endif
`if + key was pressed
if Sizeminus#=1
if timer()=>SizeminusTime#+500 then Sizeminus#=0
endif
`if + key is pressed
if keystate(78)=1 and SizePlus#=0
SizePlusTime#=timer()
size = size + 1
SizePlus#=1
endif
`if + key was pressed
if SizePlus#=1
if timer()=>SizePlusTime#+500 then SizePlus#=0
endif
`Set smallest brush size
if size <= .1 then size = .1
`Set shortcuts to drawing tools
If keystate(32)=1 then draw = 1 : spray = 0 : fill = 0 : eyedrop = 0
If keystate(23)=1 then eyedrop = 1 : fill = 0 : draw = 0 : spray = 0
If keystate(33)=1 then fill = 1 : draw = 0 : spray = 0 : eyedrop = 0
`Get backround color at start
`Text
if atext = 1
eyedrop = 0 : fill = 0 : draw = 0 : spray = 0
addtextpanel = createpanel(220,150,300,300,0)
addtext = createedit(50,50,200,75,1,addtextpanel)
addtextbutton = createbutton (115,250,75,30,"Accept",0,addtextpanel)
endif
if save = 1
file$=saveDialog("Save List","jpg. files (*.jpg)|*.jpg")
get image 1,0,0,screen width(),screen height() : save image file$+".jpg",1 : delete image 1
save = 0
endif
if saveas = 1
file$=saveDialog("Save list","jpg. files (*.jpg)|*.jpg")
get image 1,0,0,800,600 : save image file$+".jpg",1 : delete image 1
saveas = 0
endif
if load = 1
lfile$=openDialog("Load list","jpg. files (*.jpg)|*.jpg")
CLS
load bitmap lfile$,1
copy bitmap 1,0,0,bitmap width(1),bitmap height(1),0,0,0,screen width(),screen height()
delete bitmap 1
load = 0
endif
if savebeforeyouexit = 1
file$=saveDialog("Save Before closing","jpg. files (*.jpg)|*.jpg")
get image 1,0,0,800,600 : save image file$+".jpg",1 : delete image 1
savebeforeyouexit = 0
end
endif
MX# = mousex()
MY# = mousey()
`Start Button clicking/keystates
if mouseclick()=1 and draw = 1
ink DrawColour,0
x=mousex() : y=mousey()
if mousedown=0
mousedown=1
else
dx=x-mx : dy=y-my
d=abs(dx) : if abs(dy) > abs(dx) then d=abs(dy)
for f=1 to d
bx=mx+(dx*f/(d*1.0))
by=my+(dy*f/(d*1.0))
box bx-size,by-size,bx+size+1,by+size+1
next f
endif
mx=x : my=y
box x-size,y-size,x+size+1,y+size+1
LineTo(x,y)
else
mousedown=0
endif
if mouseclick()=1 and eyedrop = 1
DrawColour=POINT(MX#,MY#)
endif
if mouseclick()=0
MoveTo(MX#,MY#)
endif
if mouseclick()=1 and fill = 1
ink DrawColor,0
floodfill(MX#,MY#,DrawColour)
endif
sync
loop
`Main User Interface Function
function processEvents()
`Handle menu events
if eventType()=MENU_CLICK
eventMenu(eventData())
endif
endfunction
`Process menu selections
function eventMenu(id)
select id
`insert case statements here to respond to each menu item click in turn
case MENU_FILE_EXIT
end
endcase
endselect
endfunction
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