Please run this code in a 960x720 windowed resolution as it was intended !
Ok...this code will show you how to create a 2D right click menu with full functioning commands!It will also show the implementation of 2D Shape Focus(on 2D Boxes anyway)!
Rem ***** Main Source File *****
set text size 20
set text font "MV Boli"
print "I'll use this project to build a replica of win 3.11 graphics(the windows anyway) but i told myself it would be funny to add all the 2d"
print "shapes that DBP suports and make a Snippet so here it is..."
print "This will show you how to create a right click menu and to make 'objects' with 2D graphics,objects that have proprieties."
print "Such a (custom)propriety is the `>Move<` comand in the right click menu."
print "When the move command is selected you will be able to move a RECTANGLE on the screen.Also the focus will be set to the first"
print "rectangle that you intend to move!"
print "<<<<<>>>>>"
Print "Shortcut keys: 1>>elipse 2>>Rectangle 3>>Circle 4>>line 5>>Resets the color buffer! Delete>>Deletes the last created object!"
Print "You can also select these command from the custom made right click menu! N_JOY!"
print "Press any key to begin..."
wait key
sync on:sync rate 60
#constant max_shapes 40
global Shapes_Boarder_Color as dword
Shapes_Boarder_Color=RGB(0,0,255)
global menu_width#
global menu_height#
global menu_force_close
global menu_separator_width#
global dim shapeIndex(max_shapes) as integer
global dim shapeInitX(max_shapes) as integer
global dim shapeInitY(max_shapes) as integer
global dim shapeFinX(max_shapes) as integer
global dim shapeFinY(max_shapes) as integer
global dim options(5) as integer
global x:global y `mouse coordnates(for the menu)
global dim red(max_shapes) as byte
global dim green(max_shapes) as byte
global dim blue(max_shapes) as byte
`maintains the current "object" that we are processing
global var3=1
global option_temp
`initially sets the color of all shapes to white
for var=1 to max_shapes
red(var)=255
green(var)=255
blue(var)=255
next
time#=timer()
repeat
cls
gosub Process_Options
gosub Mouse_Actions
gosub Keyboard_Actions
gosub Mouse_Move_Option
ink RGB(255,255,255),0
print "Current Shape Index: "+str$(var3)
`print "Shape:"+str$(ShapeIndex(var3))
`print "Option_temp: "+str$(option_temp)
for var=0 to 5
if options(var)=1 then
`print "Selectie: "+Str$(var)
next
sync
until escapekey()=1
function draw_rectangle(startx,starty)
ink rgb(red(var3),green(var3),blue(var3)),0
if mousex()<startx
box mousex(),mousey(),startx,starty
endif
if mousex()>startx then
box startx,starty,mousex(),mousey()
if mousey()<starty then
box startx,mousey(),mousex(),starty
if mousey()>starty then
box mousex(),starty,startx,mousey()
`creates the rectangle boarders
ink Shapes_Boarder_Color,0
line startx,mousey(),mousex(),mousey()
line mousex(),starty,mousex(),mousey()
line startx,starty,startx,mousey()
line startx,starty,mousex(),starty
endfunction
function draw_line(startx,starty)
ink rgb(red(var3),green(var3),blue(var3)),0
line startx,starty,mousex(),mousey()
ink Shapes_Boarder_Color,0
line startx+1,starty+1,mousex()+1,mousey()+1
endfunction
function draw_circle(startx,starty)
ink rgb(red(var3),green(var3),blue(var3)),0
if mousex()>startx
circle startx,starty,mousex()-startx
ink Shapes_Boarder_Color,0
circle startx,starty,mousex()-startx-1
else
circle startx,starty,startx-mousex()
ink Shapes_Boarder_Color,0
circle startx,starty,startx-mousex()-1
endif
endfunction
function draw_ellipse(startx,starty)
ink rgb(red(var3),green(var3),blue(var3)),0
ellipse startx,starty,mousex()-startx,mousey()-starty
ink Shapes_Boarder_Color,0
ellipse startx,starty,mousex()-startx-1,mousey()-starty-1
endfunction
function show_menu()
ink RGB(215,251,179),0
box x,y,x+menu_width#,y+menu_height#
if menu_width#<92.5
menu_width#=menu_width#+2,5
else
`prints the options text
for var=0 to 5
if var=0 then
button_text$="CollorPalette"
if var=1 then
button_text$=" >Move<"
if var=2 then
button_text$=" Elipse"
if var=3 then
button_text$=" Rectangle"
if var=4 then
button_text$=" Circle"
if var=5 then
button_text$=" Line"
if mousex()>x and mousex()<=x+menu_width# and mousey()>y+var*14.5 and mousey()<=y+var*14.5+10
if mouseclick()=1
for var2=0 to 5
options(var)=1
if var<>var2 and options(var2)=1
option_temp=var2
`holds the preselected option:
options(var2)=0
endif
next
menu_force_close=1
endif
ink RGB(255,0,0),0
else
ink RGB(0,0,0),0
endif
text x,y+var*14.5,button_text$
next
endif
if menu_height#<90 then
menu_height#=menu_height#+5.0
if menu_height#=90 and menu_width#=94
ink RGB(0,0,255),0
for var=5 to 1 step -1
line x,y+menu_height#-15*var,x+menu_separator_width#,y+menu_height#-15*var
if menu_separator_width#<menu_width#-1 then
menu_separator_width#=menu_separator_width#+2
next
endif
endfunction
Mouse_Actions:
if mouseclick()=2 and menu_exist=0
x=mousex()
y=mousey()
menu_exist=1
endif
if menu_exist=1 then
show_menu()
if mouseclick()=1 or menu_force_close=1
if mousex()<x or mousex()>x+menu_width# or mousey()<y or mousey()>y+menu_height# or menu_force_close=1
menu_exist=0
menu_force_close=0
menu_height#=0
menu_width#=0
menu_separator_width#=0
x=0
y=0
endif
for var=2 to 5
if options(var)=1 and var3<max_shapes` and options(2
if shapeexist=0 and shapeIndex(var3)=0
shapeIndex(var3)=var
shapeInitX(var3)=mousex()
shapeInitY(var3)=mousey()
shapeexist=1
endif
if var=3 then
draw_rectangle(shapeInitX(var3),shapeInitY(var3))
if var=5 then
draw_line(shapeInitX(var3),shapeInitY(var3))
if var=4 then
draw_circle(shapeInitX(var3),shapeInitY(var3))
If var=2 then
draw_ellipse(shapeInitX(var3),shapeInitY(var3))
endif
next
`if rgb picker was choosen then
if options(0)=1
ColorBox2 "Pick a color for the IndexShape "+str$(var3-1)+"!"
for var2=var3 to max_shapes
red(var2-1)=GetRed()
green(var2-1)=GetGreen()
blue(var2-1)=GetBlue()
next
options(0)=0
options(option_temp)=1
endif
else
shapeexist=0
if ShapeFinX(var3)=0 and (shapeInitY(var3)<>0 or shapeInitX(var3)<>0) and var3<max_shapes and ShapeFinX(var3)<>ShapeInitX(var3) and ShapeFinY(var3)<>ShapeInitY(var3)
shapeFinX(var3)=mousex()
shapeFinY(var3)=mousey()
inc var3
endif
endif
return
Process_Options:
for var=1 to max_shapes
if ShapeIndex(var)<>0
ink rgb(red(var),green(var),blue(var)),0
if ShapeIndex(var)=3
if ShapeInitX(var)>ShapeFinX(var) and ShapeInitY(var)<ShapeFinY(var) then
box shapeFinX(var),ShapeInitY(var),ShapeInitX(var),ShapeFinY(var)
if ShapeInitY(var)>ShapeFinY(var) and ShapeInitX(var)<ShapeFinX(var) then
box shapeInitX(var),ShapeFinY(var),ShapeFinX(var),ShapeInitY(var)
if ShapeInitY(var)>ShapeFinY(var) and ShapeInitX(var)>ShapeFinX(var) and shapeFinX(var)<>0 then
box shapeFinX(var),ShapeFinY(var),ShapeInitX(var),ShapeInitY(var)
if ShapeInitY(var)<ShapeFinY(var) and ShapeInitX(var)<ShapeFinX(var) then
box shapeInitX(var),ShapeInitY(var),ShapeFinX(var),ShapeFinY(var)
`creates the rectangles boarders
if shapeFinx(var)<>0
ink Shapes_Boarder_Color,0
line ShapeInitX(var),ShapeFinY(var),ShapeFinX(var),ShapeFinY(var)
line ShapeFinX(var),ShapeInitY(var),ShapeFinX(var),ShapeFinY(var)
line ShapeInitX(var),ShapeInitY(var),ShapeInitX(var),ShapeFinY(var)
line ShapeInitX(var),ShapeInitY(var),ShapeFinX(var),ShapeInitY(var)
endif
endif
if ShapeIndex(var)=5 and shapeFinX(var)<>0
line ShapeInitX(var),ShapeInitY(var),ShapeFinX(var),ShapeFinY(var)
`creates the line boarders
ink Shapes_Boarder_Color,0
line ShapeInitX(var)+1,ShapeInitY(var)+1,ShapeFinX(var)+1,ShapeFinY(var)+1
endif
if ShapeIndex(var)=4
if ShapeFinx(var)>ShapeInitX(var)
circle shapeInitX(var),ShapeInitY(var),ShapeFinX(var)-shapeInitX(var)
`creates the boarders for the circle
ink Shapes_Boarder_Color,0
circle shapeInitX(var),ShapeInitY(var),ShapeFinX(var)-shapeInitX(var)-1
else
if ShapeFinX(var)<>0
circle ShapeInitX(var),ShapeInitY(var),ShapeInitX(var)-ShapeFinX(var)
`creates the boarders for the circle
ink Shapes_Boarder_Color,0
circle ShapeInitX(var),ShapeInitY(var),ShapeInitX(var)-ShapeFinX(var)-1
endif
endif
endif
if ShapeIndex(var)=2 and shapeFinX(var)<>0
ellipse shapeInitX(var),ShapeInitY(var),ShapeFinX(var)-shapeInitX(var),shapeFinY(var)-ShapeInitY(var)
ink Shapes_Boarder_Color,0
ellipse shapeInitX(var),ShapeInitY(var),ShapeFinX(var)-shapeInitX(var)-1,shapeFinY(var)-ShapeInitY(var)-1
endif
endif
next
return
Keyboard_Actions:
`if delete key pressed..deletes the last made shape
if keystate(211)=1 and time#+200<timer()
time#=timer()
shapeIndex(var3-1)=0
shapeInitX(var3-1)=0
shapeInitY(var3-1)=0
shapeFinX(var3-1)=0
shapeFinY(var3-1)=0
if var3>1 then
dec var3
endif
`shortcut keys for drawing
for var=2 to 5
if keystate(var)=1
for var2=0 to 5
options(var)=1
if var<>var2 then
options(var2)=0
next
endif
next
`empty the color array
if keystate(6)=1 then
for var=1 to max_shapes
red(var)=255
green(var)=255
blue(var)=255
next
return
Mouse_Move_Option:
if move_click=0
x2=mousex()
y2=mousey()
endif
if options(1)=1 and mouseclick()=1
move_click=1
for object_move=max_shapes to 1 step -1
if shapeIndex(object_move)=3 then
gosub Move_Rectangle
next
else
move_click=0
sort_after_click_move=0
endif
return
Move_Rectangle:
if (ShapeInitX(object_move)>ShapeFinX(object_move) and ShapeInitY(object_move)<ShapeFinY(object_move) and mousex()<ShapeInitX(object_move) and mousex()>ShapeFinX(object_move) and mousey()>ShapeInitY(object_move) and mousey()<ShapeFinY(object_move)) or (ShapeInitX(object_move)<ShapeFinX(object_move) and ShapeInitY(object_move)>ShapeFinY(object_move) and mousex()>ShapeInitX(object_move) and mousex()<ShapeFinX(object_move) and mousey()<ShapeInitY(object_move) and mousey()>ShapeFinY(object_move)) or (ShapeInitX(object_move)>ShapeFinX(object_move) and ShapeInitY(object_move)>ShapeFinY(object_move) and mousex()<ShapeInitX(object_move) and mousex()>ShapeFinX(object_move) and mousey()<ShapeInitY(object_move) and mousey()>ShapeFinY(object_move)) or (ShapeInitX(object_move)<ShapeFinX(object_move) and ShapeInitY(object_move)<ShapeFinY(object_move) and mousex()>ShapeInitX(object_move) and mousex()<ShapeFinX(object_move) and mousey()>ShapeInitY(object_move) and mousey()<ShapeFinY(object_move))
print "Moved Shape Index: "+Str$(object_move)
if sort_after_click_move=0
sort_after_click_move=1
for var=object_move to max_shapes-1
if ShapeIndex(var+1)<>0
aux_move=ShapeIndex(var)
ShapeIndex(var)=ShapeIndex(var+1)
ShapeIndex(var+1)=aux_move
aux_move=ShapeInitX(var)
ShapeInitX(var)=ShapeInitX(var+1)
ShapeInitX(var+1)=aux_move
aux_move=ShapeInitY(var)
ShapeInitY(var)=ShapeInitY(var+1)
ShapeInitY(var+1)=aux_move
aux_move=ShapeFinX(var)
ShapeFinX(var)=ShapeFinX(var+1)
ShapeFinX(var+1)=aux_move
aux_move=ShapeFinY(var)
ShapeFinY(var)=ShapeFinY(var+1)
ShapeFinY(var+1)=aux_move
endif
next
endif
ShapeInitX(object_move)=ShapeInitX(object_move)+mousex()-x2
ShapeFinX(object_move)= ShapeFinX(object_move)+mousex()-x2
ShapeInitY(object_move) = ShapeInitY(object_move)+mousey()-y2
ShapeFinY(object_move)= ShapeFinY(object_move)+mousey()-y2
x2=mousex()
y2=mousey()
endif
return
Knowledge belongs to the world...but not this time