` -------------------------
` ----------TYPES----------
` -------------------------
 
` Line
type toolLine
   activeTool as boolean : ` 1 = active; 0 = unactive
   startX as integer
   startY as integer
   endX as integer
   endY as integer
endtype
 
` Pencil
type toolPencil
   activeTool as boolean
   curX as integer
   curY as integer
endtype
 
type toolCircle
   activeTool as boolean
   X as integer
   Y as integer
   radius as integer
endtype
 
dim toolLine(0) as toolLine
dim toolPencil(0) as toolPencil
dim toolCircle(0) as toolCircle
 
` Window settings
set window on : set window size 640,480 : set window title "Paint Program by Halo Man"
 
` Text Settings
set text size 20 : set text font "Arial"
 
` Make the GUI
gosub CreateGUI
 
` Make the menu text and variables
gosub MakeMenu
 
` Declare color variables
rColor = 0
gColor = 0
bColor = 0
 
` -----------------------------
` ----------Main Loop----------
` -----------------------------
DO
 
   ` Check if a button is being pressed and change the
   ` tool properties based on what button was clicked
   gosub CheckButtons
 
   ` Show current mouse positions
   ink rgb(0,0,0),rgb(255,255,255)
   set text opaque
   text screen width()-70,420,"X:  "+str$(mouseX())+"   "
   text screen width()-70,440,"Y:  "+str$(mouseY())+"   "
 
   ` Check current color
   text screen width()-165,410,"R: "+str$(rColor)+"  "
   text screen width()-165,430,"G: "+str$(gColor)+"  "
   text screen width()-165,450,"B: "+str$(bColor)+"  "
   box screen width()-115,410,screen width()-80,475,rgb(rColor,gColor,bColor),rgb(rColor,gColor,bColor),rgb(rColor,gColor,bColor),rgb(rColor,gColor,bColor)
 
   ` rColor
   if mouseX()>=screen width()-165 and mouseX()<=screen width()-165+text width("R: ")
      if mouseY()>=410 and mouseY()<=410+text height("R: ")
         if mouseclick()=1
               inc rColor
               if rColor > 255
                  rColor = 255
               endif
         endif
 
         if mouseclick()=2
               dec rColor
               if rColor < 0
                  rColor = 0
               endif
         endif
      endif
   endif
 
   ` gColor
   if mouseX()>=screen width()-165 and mouseX()<=screen width()-165+text width("G: ")
      if mouseY()>=430 and mouseY()<=430+text height("G: ")
         if mouseclick()=1
               inc gColor
               if gColor > 255
                  gColor = 255
               endif
         endif
 
         if mouseclick()=2
               dec gColor
               if gColor < 0
                  gColor = 0
               endif
         endif
      endif
   endif
 
   ` bColor
   if mouseX()>=screen width()-165 and mouseX()<=screen width()-165+text width("B: ")
      if mouseY()>=450 and mouseY()<=450+text height("B: ")
         if mouseclick()=1
               inc bColor
               if bColor > 255
                  bColor = 255
               endif
         endif
         if mouseclick()=2
               dec bColor
               if bColor < 0
                  bColor = 0
               endif
         endif
      endif
   endif
 
   ` Pencil
   if toolPencil(0).activeTool = 1
      if mouseX()<sizeX and mouseX()>=0
         if mouseY()<sizeY and mouseY()>=0
            if mouseclick()=1
               ink rgb(rColor,gColor,bColor),rgb(255,255,255)
               repeat
                  toolPencil(0).curX = mouseX()
                  toolPencil(0).curY = mouseY()
                  if toolPencil(0).curX < sizeX and toolPencil(0).curX >= 0 and toolPencil(0).curY < sizeY and toolPencil(0).curY >= 0
                     dot toolPencil(0).curX,toolPencil(0).curY
                  endif
               until mouseclick()=0
            endif
         endif
      endif
   else
      ink rgb(0,0,0),rgb(255,255,255)
      text 120,410,pencil$
   endif
 
   ` Making Lines
   if toolLine(0).activeTool = 1
      if mouseX()<=sizeX and mouseX()>=0
         if mouseY()<=sizeY and mouseY()>=0
            if mouseclick()=1
               ink rgb(rColor,gColor,bColor),rgb(255,255,255)
               toolLine(0).startX = mouseX()
               toolLine(0).startY = mouseY()
 
               repeat
                  toolLine(0).endX = mouseX()
                  toolLine(0).endY = mouseY()
               until mouseclick()=0 and toolLine(0).endX<=sizeX and toolLine(0).endX >= 0 and toolLine(0).endY <= sizeY and toolLine(0).endY >= 0
 
               line toolLine(0).startX,toolLine(0).startY,toolLine(0).endX,toolLine(0).endY
            endif
         endif
      endif
   else
      ink rgb(0,0,0),rgb(255,255,255)
      text 120,450,line$
   endif
 
   ` Circle
   if toolCircle(0).activeTool = 1
      if mouseX()<=sizeX and mouseX()>=0
         if mouseY()<=sizeY and mouseY()>=0
            if mouseclick()=1
               ink rgb(rColor,gColor,bColor),rgb(255,255,255)
               toolCircle(0).X = mouseX()
               toolCircle(0).Y = mouseY()
               oldmx = mouseX()
               repeat
                  if mouseX() <> oldmx
                     inc toolCircle(0).radius
                  endif
 
                  oldmx = mouseX()
               until mouseclick()=0
               circle toolCircle(0).X,toolCircle(0).Y,toolCircle(0).radius
               toolCircle(0).radius = 0
            endif
         endif
      endif
   else
      ink rgb(0,0,0),rgb(255,255,255)
      text 200,410,circle$
   endif
 
 
 
 
LOOP
` -------------------------------
` ----------End of Loop----------
` -------------------------------
 
 
` Breakpoint code
wait key
end
 
` -----------------------------
` ----------FUNCTIONS----------
` -----------------------------
function ResetActiveTool()
   toolLine(0).activeTool = 0
   toolPencil(0).activeTool = 0
   toolCircle(0).activeTool = 0
endfunction
 
` --------------------------
` ----------GOSUBS----------
` --------------------------
 
` Create the GUI(messy code)
CreateGUI:
   box 0,0,screen width(),screen height()-75,rgb(128,128,128),rgb(128,128,128),rgb(128,128,128),rgb(128,128,128)
   ink rgb (0,0,255),rgb(0,0,255)
   line 0,screen height()-75,screen width(),screen height()-75
   x = -1
   for n = 1 to 255 step 3
      x = x + 1
      ink rgb(n,n,255),rgb(255,255,255)
      line x,screen height()-74,x,screen height()
   next n
   box 85,screen height()-74,screen width(),screen height()
   ink rgb(0,0,0),rgb(128,128,128)
   set cursor screen width()/2-60,screen height()/2-75
   INPUT "Drawing Size X:  ",sizeX
   if str$(sizeX)=""
      sizeX = 0
   endif
   if sizeX > screen width()
      sizeX = screen width()
   endif
   if sizeX < 0
      sizeX = 0
   endif
   set cursor screen width()/2-60,screen height()/2-55
   INPUT "Drawing Size Y:  ",sizeY
   if str$(sizeY)=""
      sizeY = 0
   endif
   if sizeY > screen height()-75
      sizeY = screen height()-75
   endif
   if sizeY < 0
      sizeY = 0
   endif
   ink rgb(0,0,255),rgb(255,255,255)
   line screen width()-75,screen height()-75,screen width()-75,screen height()
   line screen width()-175,screen height()-75,screen width()-175,screen height()
   box 0,0,screen width(),screen height()-75,rgb(128,128,128),rgb(128,128,128),rgb(128,128,128),rgb(128,128,128)
   box 0,0,sizeX,sizeY,rgb(255,255,255),rgb(255,255,255),rgb(255,255,255),rgb(255,255,255)
 
` Makes the menu
MakeMenu:
   ` Global Text Color
   ink rgb(0,0,0),rgb(255,255,255)
 
   ` Line Button
   pencil$ = "Pencil"
   text 120,410,pencil$
 
   ` Pencil Button
   line$ = "Line"
   text 120,450,line$
 
   ` Box Button
   circle$ = "Circle"
   text 200,410,circle$
 
return
 
 
` Checks the buttons
CheckButtons:
 
   ` Pencil Button
   if mouseX()>=120 and mouseX()<=120+text width(pencil$)
      if mouseY()>=410 and mouseY()<=410+text height(pencil$)
         if mouseclick()=1
            ResetActiveTool()
            ink rgb(255,0,0),rgb(255,255,255)
            text 120,410,pencil$
            toolPencil(0).activeTool = 1
         endif
      endif
   endif
 
   ` Line Button
   if mouseX()>=120 and mouseX()<=120+text width(line$)
      if mouseY()>=450 and mouseY()<=450+text height(line$)
         if mouseclick()=1
            ResetActiveTool()
            ink rgb(255,0,0),rgb(255,255,255)
            text 120,450,line$
            toolLine(0).activeTool = 1
         endif
      endif
   endif
 
 
   ` Circle Button
   if mouseX()>=200 and mouseX()<=200+text width(circle$)
      if mouseY()>=410 and mouseY()<=410+text height(circle$)
         if mouseclick()=1
            ResetActiveTool()
            ink rgb(255,0,0),rgb(255,255,255)
            text 200,410,circle$
            toolCircle(0).activeTool = 1
         endif
      endif
   endif
 
 
 
 
return