'//////////////////////////////////////////////////////////////
'// VQB 04 - BASE CODE v.01
'// By John Onyon a.k.a Unseen Machine
'// Include library TYPE defs and CONSTANTS
'// Set root directory to load all VQB required files (icons, mouse pointers, fonts, etc...)
'// Only needed if youre using dialogs
'// You wanna use the mouse so create a MouseInfo array to handle mouse events
DIM Mouse
(1) AS MouseInfo
'// Create a screen at position at 0,0, size of 1024 * 768 and set title
VQB_Screen
0, 0, 1024, 768, _RGB32(120, 110, 100), "VQB 04 Base Code" '// Set title to whatever your program is called
'// The state of the program, generic icons and mouse pointer icons are stored in a predefined type array PROGRAM_STATE
'// The update call for this handles all window events, moving, layers and resizing.
'// so lets create the array
DIM ProgState
AS PROGRAM_STATE
'// Variables are - Use GFX Mouse, Total windows, Screen width, Screen height
VQB_PROGRAM_STATE_NEW ProgState, TRUE, 2, 1024, 768
'// Each element of your program can have it's own window (DIALOG).
'// Create the DIALOG array
'// Now set up each window
'// Set's MultiTask, X,Y,Width,height,background colour,Window title and Resize true/false
VQB_DIALOG_NEW Program
(0), FALSE
, 0, 0, 640, 480, _RGB32(0, 0, 0), "New Program", FALSE
VQB_DIALOG_NEW Program
(1), FALSE
, (ProgState.WSI
/ 2) - 320, (ProgState.HSI
/ 2) - 240, 640, 480, _RGB32(0, 0, 0), "New Program 2", FALSE
'// Create two buttons, one to launch each window
'// Set the buttons up
VQB_Button_New WndBtn
(0), 20, 20, 120, 40, _RGB(255, 0, 0), _RGB(0, 0, 0), "YOUR New App", 1VQB_Button_New WndBtn
(1), 160, 20, 120, 40, _RGB(255, 0, 0), _RGB(0, 0, 0), "Another App", 1
'###########################################################################################################################
'// get the current state iof the mouse and store it in the array
VQB_Mouse_GetInfo Mouse(0)
'// Check for button clicks
IF VQB_Button_Click
(WndBtn
(i%
), Mouse
(0)) AND NOT Mouse
(1).LMB
THEN IF Program
(i%
).Running
= FALSE
THEN '// program has not been started
New_Program Program(0), Mouse(), START_PROGRAM
New_Program_2 Program(1), Mouse(), START_PROGRAM
'// update it's position in the stack
VQB_RUN_PROGRAM ProgState, i%, Program()
ELSE '// program has been started but either closed or minimised
VQB_RUN_PROGRAM ProgState, i%, Program()
'// Draw the buttons
VQB_Button_Draw WndBtn(0)
VQB_Button_Draw WndBtn(1)
'// Check for any changes in the state of the program (switching between windows/window events)
'// Also renders opn dialog windows in order and renders GFX mouse pointers
ProgramEvent% = VQB_PROGRAM_STATE_UPDATE(ProgState, Mouse(), Program())
'// Run through open apps and update the top level window
FOR i%
= 0 TO ProgState.TotalApps
- 1
IF Program
(i%
).Running
= TRUE
THEN
IF Program
(i%
).Layer
= ProgState.CurrentLayer
- 1 THEN '// program on the top layer
New_Program Program(i%), Mouse(), UPDATE_PROGRAM
New_Program_2 Program(i%), Mouse(), UPDATE_PROGRAM
ELSE '// Not top window but need to check for multitask apps (for a future tutorial)
'// Copy mouse state for future comparisons
Mouse(1) = Mouse(0)
'// Update the display
'###########################################################################################################################
'###########################################################################################################################
SUB New_Program
(DState
AS DIALOG
, Mouse
() AS MouseInfo
, ACTION%
)
'// Any variable you need to store needs to be set as STATIC
'// These are DIM'd here
'// Handle input
'// Clone mouse data
App_Mouse(0) = Mouse(0)
'// - Make mouse position relative to window
VQB_Mouse_Adjust DState, Mouse(0), App_Mouse(0)
'// Logic here
'// Draw the output
'// Switch to dialogs image
'// Do all your rendering here
'// switch back to desktop
CASE UPDATE_PROGRAM_NO_INPUT
'// For multitask apps
App_Mouse(1) = App_Mouse(0)
'###########################################################################################################################
SUB New_Program_2
(DState
AS DIALOG
, Mouse
() AS MouseInfo
, ACTION%
)
'// Handle input
'// Clone mouse data
App_Mouse(0) = Mouse(0)
'// - Make mouse position relative to window
VQB_Mouse_Adjust DState, Mouse(0), App_Mouse(0)
'// Perform logic here
'// Draw the output
'// Switch to dialogs image
'// Do all your rendering here
'// switch back to desktop
CASE UPDATE_PROGRAM_NO_INPUT
'// For multitask apps
App_Mouse(1) = App_Mouse(0)