02-18-2026, 11:16 PM
(This post was last modified: 02-18-2026, 11:18 PM by Unseen Machine.)
Its defo not a UDT thing as this is the basis of my entire Qb64 life!
AS youll see the params passed to the function work as a defacto
It does not matter how much you embed the core (w/h) values, it will always work! and also as my code is
SCREEN System_State.Screen_Handle
and then uses a predefined newimage...none of the errors will exisit!
Unseen
AS youll see the params passed to the function work as a defacto
Code: (Select All)
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'///////////////////////////////////////////// Low Brow Libs ///////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// ---- Part 1. Basic Type definitions and their Functions -----
'//
'// Using/creating a set of basic UDT's (User Defined Types) is the best way to start.
'// You can use these UDT's in your future programs to make coding obvious and easier.
'// Think of these as the foundations on which you build your programs.
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// I will be using a Main Function to act as the main loop as i code in C/C++ and this is common practice I think people should
'// Learn from day 1 to make transistioning to modern languages easier later on
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// Global shared variables
DIM SHARED Sys_State AS System_State '// This contains our basic program data, screen handle, input and timers
'// Whilst you can define this in your Main function, for other subs and functions to access it without
'// needing to have it passed as a parameter, i find this method more logical.
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
Main '// Call the program
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SUB Main
'// First we set up using the system_state_new function. This creates our screen, initialises the input data and timers
System_State_New Sys_State, 0, 0, 800, 600, "Low Brow Dev"
DO
_LIMIT 144 '// 144 fps is the modern default as most modern screens have this refresh rate
'// Logic first
System_State_Update Sys_State '// Update the system data (timers and input) - later we can add screen resizing etc...
'// Graphics
CLS '// Clear the screen
PRINT "Mouse info"
PRINT
PRINT "X : " + STR$(Sys_State.Mouse.Position.X)
PRINT "Y : " + STR$(Sys_State.Mouse.Position.Y)
PRINT
PRINT "LB : " + STR$(Sys_State.Mouse.LB)
PRINT "RB : " + STR$(Sys_State.Mouse.RB)
PRINT "MB : " + STR$(Sys_State.Mouse.MB)
PRINT "MW : " + STR$(Sys_State.Mouse.MW)
_DISPLAY '// Update the display
LOOP UNTIL _EXIT '// Loop until the eXit button is pressed
'// Here you would free any memory youve allocated to avoid memory leaks
SYSTEM '// End the program
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SUB Core_UDTS
'// A position in 2d space
TYPE Vector_2
X AS DOUBLE
Y AS DOUBLE
END TYPE
'// A rectangle
TYPE Rect
XY AS Vector_2 '// Top left corner
WH AS Vector_2 '// Width/Height of the rectangle
END TYPE
'// With those two UDT's, Screen position and resolution, Buttons, Mouse pointer position and more can be created
'// Next is the most basic of input devices, the mouse.
TYPE Mouse_State
LB AS _BYTE '// Left button
RB AS _BYTE '// Right Button
MB AS _BYTE '// Middle button
MW AS _BYTE '// Mouse wheel value
Position AS Vector_2 '// Current position
END TYPE
'// Next is the core of your program, the System_State. This should hold the resolution settings, input data and what ever else
'// you decide is a standard requirment
TYPE System_State
Screen_Handle AS LONG '// The handle returned by Screen _newimage
Screen_Rect AS Rect '// The dimensions and position of the screen
Screen_Title AS STRING * 32 '// the title of your program
Mouse AS Mouse_State '// Current input data
Old_Mouse AS Mouse_State '// Last input data - You can then compare the current vs this for just clicked or just released info
Time AS DOUBLE '// Created at the start of your program
Delta_Time AS DOUBLE '// The time since the the program was started
END TYPE
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'// Now we have those defined we can start to use them. For specific things like the mouse and system we make
'// functions to update/create them.
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SUB System_State_New (System_State AS System_State, x#, y#, w#, h#, ScreenTitle$)
'// Screen dimension and position
System_State.Screen_Rect.XY.X = x#
System_State.Screen_Rect.XY.Y = y#
System_State.Screen_Rect.WH.X = w#
System_State.Screen_Rect.WH.Y = h#
'// Now we create the screen, set its position and set the title
System_State.Screen_Handle = _NEWIMAGE(w#, h#, 32)
SCREEN System_State.Screen_Handle
_TITLE ScreenTitle$
System_State.Screen_Title = ScreenTitle$
_SCREENMOVE x#, y# '// If you add full screen flag parameter you may wish to add an if clause here
'// set the system timers
System_State.Time = TIMER(.001)
System_State.Delta_Time = System_State.Time
'// Init input handlers
Mouse_State_Update System_State.Mouse
System_State.Old_Mouse = System_State.Mouse
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SUB System_State_Update (System_State AS System_State)
System_State.Old_Mouse = System_State.Mouse '// Copy the old mouse data
Mouse_State_Update System_State.Mouse '// Get the new mouse data
'// Update the timers
System_State.Time = TIMER(.001)
System_State.Delta_Time = System_State.Time - System_State.Delta_Time
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
SUB Mouse_State_Update (Mouse_State AS Mouse_State)
DO WHILE _MOUSEINPUT
Mouse_State.LB = _MOUSEBUTTON(1)
Mouse_State.RB = _MOUSEBUTTON(2)
Mouse_State.MB = _MOUSEBUTTON(3)
Mouse_State.Position.X = _MOUSEX
Mouse_State.Position.Y = _MOUSEY
Mouse_State.MW = Mouse_State.MW + _MOUSEWHEEL
LOOP
END SUB
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
'/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
It does not matter how much you embed the core (w/h) values, it will always work! and also as my code is
SCREEN System_State.Screen_Handle
and then uses a predefined newimage...none of the errors will exisit!
Unseen

