There isn't much to this yet, as it is just really buttons for now.
The plan is to add features slowly but steadily building up the framework in the areas people need.
This is purely a button interface, with limited options. Right not it just creates text buttons. What I plan on doing is making this in DB/P, creating everything I need in the language; right now it handled 100 Entities (Rendering, Collision Check and Activity Callback) without any slow-downs.
While it is a fairly small number of objects and graphics, this includes the slow DB/P text routine. This will be changed later to something that can provide much more speed and control.
RemStart
// Project: UserInterface Framework v0.1
// Author: Raven
// Version: 0.1.0000
// Copyright 2005 Liandri. All Rights Reserved.
// There will be an LGPL here later.. sorry but for now
// it's closed source, in relation to what your allowed
// to do with it. Not that there is enough to warrent
// nicking it yet. ;)
RemEnd
#Constant uiVersionMajor = 0
#Constant uiVersionMinor = 1
#Constant uiVersionBuild = 0
#Constant uiDefault = 0x01
#Constant uiTrue = 0x01
#Constant uiFalse = 0x00
#Constant COLORBLACK = 0x000000
#Constant COLORWHITE = 0xffffff
#Constant MOUSELMB = 0x01
#Constant MOUSERMB = 0x02
#Constant MOUSEMMB = 0x04
#Constant OnOut = 0x00
#Constant OnOver = 0x01
#Constant OnClick = 0x02
`/ Add these to the start of your main file .. bug with DB/P /
`/ Colours / Remember to put these in as a loadable palette later
Global COLOR1 As Integer = 0xE5E5D7 ` Shadow
Global COLOR2 As Integer = 0xFAFAF7 ` Highlight
Global COLOR3 As Integer = 0xF3F3EF ` Base
Global COLOR4 As Integer = 0x8a867a ` Button Outline
Global COLOR5 As Integer = 0x000000 ` Text Color
Global COLOR6 As Integer = 0xc1d2ee ` Menu Highlight Background
Global COLOR7 As Integer = 0x316ac5 ` Menu Highlight Edge
Global COLOR8 As Integer = 0xfcfcf9 ` Menu Background
Global COLOR9 As Integer = 0x8a867a ` Menu Outline
Type EventType
Selected As Integer
Event As Integer
EndType
Type PointType
X As Integer
Y As Integer
EndType
Type RectType
Left As Integer
Top As Integer
Right As Integer
Bottom As Integer
EndType
Type ButtonType
Caption As String
X As Integer
Y As Integer
Width As Integer
Height As Integer
EndType
Global Dim uiButton(0) As ButtonType
Global uiActive As EventType
Global _UI_DEBUG_ As Boolean = uiFalse
`/ End of Add /
Function uiSync()
Local Index As Integer
Local Width As Integer ; Width = Screen Width()
Local Height As Integer ; Height = Screen Height()
Lock Pixels
Box 0, 0, Width, Height, COLOR1, COLOR1, COLOR2, COLOR2
UnLock Pixels
For Index = uiDefault To Array Count(uiButton(0))
uiButton_OnPaint(Index)
Next Index
EndFunction
Function uiButton_OnCreate(X As Integer, Y As Integer, Caption As String)
Local Ref As Integer
Local Width As Integer
Array Insert At Bottom uiButton(0)
Ref = Array Count(uiButton(0))
Width = Text Width(Caption)
uiButton(Ref).Caption = Caption
uiButton(Ref).X = X - 12
uiButton(Ref).Y = Y - 8
If Width < 100
uiButton(Ref).Width = 100
Else
uiButton(Ref).Width = Width + 12
EndIf
uiButton(Ref).Height = Text Height(Caption) + 8
EndFunction Ref
Function uiButton_OnPaint(Ref As Integer)
Local Area As RectType
Area.Left = uiButton(Ref).X
Area.Top = uiButton(Ref).Y
Area.Right = uiButton(Ref).X + uiButton(Ref).Width
Area.Bottom = uiButton(Ref).Y + uiButton(Ref).Height
Local Put As PointType
Put.X = Area.Left + Int((Area.Right - Area.Left) / 2)
Put.Y = Area.Top + Int((Area.Bottom - Area.Top) / 4)
Lock Pixels
Ink COLOR1, COLORBLACK
Box Area.Left - 1, Area.Top - 1, Area.Right + 1, Area.Bottom
Ink COLOR2, COLORBLACK
Line Area.Left, Area.Bottom + 1, Area.Right, Area.Bottom + 1
Local Action As Integer = null
Action = uiButton_OnCollision(Ref)
Select Action
Case OnOver
Local OutlineColor As Integer = COLOR7
Ink COLOR6, COLORBLACK
Box Area.Left, Area.Top, Area.Right, Area.Bottom
EndCase
Case OnClick
Local OutlineColor As Integer = COLOR7
Ink COLOR1, COLORBLACK
Box Area.Left, Area.Top + 2, Area.Right, Area.Bottom - 1
EndCase
Case Default
Local OutlineColor As Integer = COLOR9
Ink COLOR3, COLORBLACK
Box Area.Left, Area.Top + 2, Area.Right, Area.Bottom - 2
EndCase
EndSelect
Ink OutlineColor, COLORBLACK
Line Area.Left + 1, Area.Top + 1, Area.Right + 1, Area.Top + 1
Line Area.Left + 1, Area.Top + 1, Area.Left + 1, Area.Bottom + 1
Line Area.Left + 1, Area.Bottom + 1, Area.Right + 1, Area.Bottom + 1
Line Area.Right + 1, Area.Top + 1, Area.Right + 1, Area.Bottom + 1
Ink COLOR5, COLORBLACK
Center Text Put.X, Put.Y, uiButton(Ref).Caption
UnLock Pixels
EndFunction
Function uiButton_OnCollision(Ref As Integer)
Local Mouse As PointType
Mouse.X = MouseX()
Mouse.Y = MouseY()
Local Area As RectType
Area.Left = uiButton(Ref).X
Area.Top = uiButton(Ref).Y
Area.Right = uiButton(Ref).X + uiButton(Ref).Width
Area.Bottom = uiButton(Ref).Y + uiButton(Ref).Height
If Mouse.X > Area.Left And Mouse.X < Area.Right
If Mouse.Y > Area.Top And Mouse.Y < Area.Bottom
uiActive.Selected = Ref
If MouseClick() = MOUSELMB
uiActive.Event = Ref
ExitFunction OnClick
EndIf
ExitFunction OnOver
EndIF
EndIf
uiActive.Selected = 0
uiActive.Event = 0
EndFunction OnOut
Function uiButton_Debug()
`/ Known Bug - For some reason only buttons 11+ are debuged when uiActive.Selected is reset
` when nothing is selected. Can't actually figure out why so feel free to tinker. /
If uiActive.Selected
Local Ref As Integer = uiActive.Selected
Local Height As Integer
Height = Text Height("Test")
Text 10, Height * 1, "Button ID [" + STR$(Ref) + "]"
Text 10, Height * 2, "Button String [" + uiButton(Ref).Caption + "]"
Text 10, Height * 3, "Button X [" + STR$(uiButton(Ref).X) + "]"
Text 10, Height * 4, "Button Y [" + STR$(uiButton(Ref).Y) + "]"
Text 10, Height * 5, "Button Width [" + STR$(uiButton(Ref).Width) + "]"
Text 10, Height * 6, "Button Height [" + STR$(uiButton(Ref).Height) + "]"
EndIf
EndFunction
I want to make it to allow for a lot of quick customisability.
So people who use it can simply create thier own OnPaint() functions without worrying about the complex handling of all the entities and such. Yet leave in enough complexity to allow people who need it to use information directly.
Have a little play and let me know what you think of this though.
Here's an exmaple of how to use it:
`<--/ #Include "UserInterfaceFramework.dba" /-->
`/ Example Source / -------------------------------------------
Sync On : Sync Rate 0
Backdrop On
_UI_DEBUG_ = uiTrue
Set Text Font "Tahoma"
Set Text Size 14
Global PrintHello As Integer
Global ExitButton AS Integer
`/ uiButton_OnCreate(X Position, Y Position, Display String)
PrintHello = uiButton_OnCreate(10, 26 * 2, "Press me to say hello!")
ExitButton = uiButton_OnCreate(100, Screen Height() - 26, "Exit")
Repeat
uiSync() `/ I'd recommend always drawing the UI first
If uiActive.Event = PrintHello
Text (Screen Width() / 2), (Screen Height() / 2), "Hiya!"
EndIf
` If _UI_DEBUG_ Then uiButton_Debug() `/ Debug is bugged.. heh
Sync
Until EscapeKey() Or uiActive.Event = ExitButton
`/ End Example / ----------------------------------------------
These whole section will be completely recoded, I'm still not sure on the naming convention; but the best part of Alpha's is you can tinker without worrying about compatibility ^_^
What I will work on next now I'm happy understanding what can and can't be done with DB/P is the Window System, this includes the Main Window itself.
Now don't get exciting, as I won't be making external windows (that would be too much of a pain in the arse to achieve) but you will have full internal window control.