DEFINT A-Z '$STATIC '$INCLUDE: 'future.bi' 'Routines for buttons: DECLARE FUNCTION CreateButton (BYVAL Xpos, BYVAL Ypos, BYVAL XSize, BYVAL YSize, BYVAL Style, Caption AS STRING) DECLARE SUB DestroyButton (BYVAL ButID) DECLARE SUB DrawButton (BYVAL ButID, BYVAL Mode) DECLARE SUB ButtonSystem () 'Set up button data. TYPE ButtonData Xpos AS INTEGER 'Xpos and Ypos are Ypos AS INTEGER ' button coordinates on the screen XSize AS INTEGER 'XSize and YSize are YSize AS INTEGER ' button X and Y size Status AS INTEGER 'Button status flag Style AS INTEGER 'specifies the button style Caption AS STRING * 10 'Name END TYPE 'Button Status table: ' 0 - Button does not exist. ' 1 - Button is in normal mode. ' 2 - Mouse cursor is over the button. ' 3 - Button is pressed down. ' 4 - Button has been clicked. CONST NumberOfButtons = 100 DIM SHARED MouseOnButton DIM SHARED ButtonTemp DIM SHARED ButtonClicked DIM SHARED ButtonPressed DIM SHARED Button(1 TO NumberOfButtons) AS ButtonData DIM SHARED OldMouseX, OldMouseY, OldMouseB DIM SHARED MouseX, MouseY, MouseB 'NB! This demo whows using buttons and such with Future.Library ' However you may change it to work with anything you like. Set640x480 8 Future.CLS 200 ExitButton = CreateButton(100, 100, 80, 14, 0, "Exit") But1 = CreateButton(100, 125, 80, 14, 0, "Button 1") but2 = CreateButton(100, 150, 80, 14, 0, "Button 1") But3 = CreateButton(100, 175, 80, 14, 0, "Button 1") Future.MouseON 'These button routined must be between constant cycle. DO IF ButtonClicked = ExitButton THEN EXIT DO END IF ButtonSystem Future.UpdateMouse LOOP UNTIL INKEY$ > "" ReSetScreen SUB ButtonSystem 'This sub is the place where main button handling is done. 'NB! The following mouse routines are Future.Library specific. ' If you use some other library or your own mouse routines then ' you probably need to change these. MouseX = Future.MouseX MouseY = Future.MouseY MouseB = Future.MouseB 'If some button is already pressed down '--------------------------------------- IF ButtonTemp > 0 THEN 'If yes then check where is mouse cursor. '--------------------------------------- IF MouseX >= Button(ButtonTemp).Xpos THEN IF MouseY >= Button(ButtonTemp).Ypos THEN IF MouseX <= Button(ButtonTemp).Xpos + Button(ButtonTemp).XSize THEN IF MouseY <= Button(ButtonTemp).Ypos + Button(ButtonTemp).YSize THEN 'mouse cursor is on the button. 'Now check for mousebutton status. '--------------------------------------- IF MouseB = 0 THEN 'if not pressed down then it means it has been 'released. so The button was clicked. Button(ButtonTemp).Status = 4 ButtonClicked = ButtonTemp Future.MouseOFF DrawButton ButtonTemp, 1 Future.MouseON ButtonPressed = 0 ButtonTemp = 0 EXIT SUB ELSE 'if mousebutton is held down then check is the 'button drawn in pressed state or not. IF ButtonPressed = 0 THEN 'If not then do so MouseOnButton = ButtonTemp ButtonPressed = ButtonTemp Button(ButtonTemp).Status = 3 Future.MouseOFF DrawButton ButtonTemp, 3 Future.MouseON END IF EXIT SUB END IF END IF END IF END IF END IF 'if mouse cursor is not on the button then check if 'the button is drawn in pressed state IF ButtonPressed > 0 THEN 'If is then draw normal button ButtonPressed = 0 Button(ButtonTemp).Status = 1 Future.MouseOFF DrawButton ButtonTemp, 1 Future.MouseON END IF MouseOnButton = 0 'Also check if the mousebutton is pressed or not. 'If is then just exit the sub IF MouseB > 0 THEN EXIT SUB 'If not then release button and zero ButtonTemp variable END IF ButtonClicked = 0 ButtonTemp = 0 'Find on what button(if at all) mouse cursor is FOR Check = 1 TO NumberOfButtons IF Button(Check).Status > 0 THEN IF MouseX >= Button(Check).Xpos THEN IF MouseY >= Button(Check).Ypos THEN IF MouseX <= Button(Check).Xpos + Button(Check).XSize THEN IF MouseY <= Button(Check).Ypos + Button(Check).YSize THEN 'If it makes here, then mouse cursor is on the button. 'Check if some button is already pressed. MouseOnButton = Check IF MouseB = 0 THEN Button(Check).Status = 2 EXIT SUB END IF ButtonTemp = Check ButtonPressed = Check Button(Check).Status = 3 Future.MouseOFF DrawButton Check, 3 Future.MouseON EXIT SUB END IF END IF END IF END IF END IF NEXT Check IF MouseOnButton > 0 THEN Button(MouseOnButton).Status = 1 MouseOnButton = 0 END IF END SUB FUNCTION CreateButton (BYVAL Xpos, BYVAL Ypos, BYVAL XSize, BYVAL YSize, BYVAL Style, Caption AS STRING) 'This function creates a new button, saves variables and returns button ID 'Find free button ID. If there's non function returns 0 FOR Search = 1 TO NumberOfButtons IF Button(Search).Status = 0 THEN 'Free button ID found. 'If button exists then Status is > 0, else 'Status = 0 ButID = Search EXIT FOR END IF NEXT 'if no free button socket was found in previous for...next cucle, then 'ButID is 0. So exit the function. IF ButID = 0 THEN EXIT FUNCTION 'Now that we have a button ID we can save button information. Button(ButID).Xpos = Xpos Button(ButID).Ypos = Ypos Button(ButID).XSize = XSize Button(ButID).YSize = YSize Button(ButID).Style = Style Button(ButID).Status = 1 Button(ButID).Caption = Caption 'Now draw the button DrawButton ButID, 1 'Return the ID number CreateButton = ButID END FUNCTION SUB DestroyButton (BYVAL ButID) END SUB SUB DrawButton (BYVAL ButID, BYVAL Mode) 'This routine just draws the button. 'Let's for simplicity assign some variables. DIM Xpos, Ypos, X1pos, Y1pos, TextX, TextY, Caption AS STRING Xpos = Button(ButID).Xpos Ypos = Button(ButID).Ypos X1pos = Xpos + Button(ButID).XSize Y1pos = Ypos + Button(ButID).YSize Caption$ = RTRIM$(Button(ButID).Caption) TextX = (Button(ButID).XSize / 2 + Xpos) - LEN(Caption$) * 4 TextY = (Button(ButID).YSize / 2 + Ypos) - 7 'As we have style variable then we can draw many different style buttons. SELECT CASE Button(ButID).Style CASE 0 'Standard button. Let's make it look like windows 95. Simple 'NB! the following Gfx routine are part of Future.Library. You can change ' them to fit your needs. IF Mode = 1 THEN 'Draw ordinary not pressed button to the screen. Future.FillBox Xpos, Ypos, X1pos, Y1pos, 7 Future.LINE Xpos, Ypos, X1pos, Ypos, 15, -1 Future.LINE Xpos, Ypos, Xpos, Y1pos, 15, -1 Future.LINE Xpos, Y1pos, X1pos, Y1pos, 0, -1 Future.LINE X1pos, Ypos, X1pos, Y1pos, 0, -1 Future.PRINT TextX, TextY, Caption$, 0, -1 EXIT SUB ELSEIF Mode = 3 THEN 'Draw pressed button Future.FillBox Xpos, Ypos, X1pos, Y1pos, 7 Future.LINE Xpos, Ypos, X1pos, Ypos, 8, -1 Future.LINE Xpos, Ypos, Xpos, Y1pos, 8, -1 Future.LINE Xpos, Y1pos, X1pos, Y1pos, 7, -1 Future.LINE X1pos, Ypos, X1pos, Y1pos, 7, -1 Future.PRINT TextX + 1, TextY + 1, Caption$, 0, -1 EXIT SUB END IF END SELECT END SUB