Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Keybone's GUI (04/2022 - Widget toolkit)
#1
I wrote this shortly before my latest update (04/07/2022).
Unlike that update this is a widget toolkit and not a windowing system.
It can use some work, it has some glitches, and is not pretty.
You can't do anything advanced with this but it's worth a look.

Obligatory screenshots:

[Image: toolkit1.png]

[Image: toolkit2.png]


Installation:
1) Copy blank.png and k3.bas into your qb64 folder
2) Compile and run k3.bas


blank.png:

[Image: blank.png]


k3.bas:

Code: (Select All)
Screen _NewImage(640, 480, 32)
_PrintMode _KeepBackground

Type aWindow
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    Text As String
    imageHandle As _Unsigned Long
End Type

Type anIcon
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    Text As String
    imageHandle As _Unsigned Long
End Type

Type aButton
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    Text As String
    imageHandle As _Unsigned Long
End Type

Type aCheckbox
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    isChecked As _Byte
    Text As String
    imageHandle1 As _Unsigned Long
    imageHandle2 As _Unsigned Long
End Type

Type aSwitch
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    isEnabled As _Byte
    Text As String
    imageHandle1 As _Unsigned Long
    imageHandle2 As _Unsigned Long
End Type

Type aRadiobutton
    positionX As Integer
    positionY As Integer
    sizeX As _Unsigned Integer
    sizeY As _Unsigned Integer
    groupID As _Unsigned Integer
    isSelected As _Byte
    Text As String
    imageHandle1 As _Unsigned Long
    imageHandle2 As _Unsigned Long
End Type

Type aMouse
    positionX As Integer
    positionY As Integer
    buttonLeft As _Byte
    buttonMiddle As _Byte
    buttonRight As _Byte
End Type

Type aLimit
    Minimum As _Unsigned Integer
    Current As _Unsigned Integer
    Maximum As _Unsigned Integer
End Type

Dim Shared theLimitWindows As aLimit
theLimitWindows.Minimum = 0
theLimitWindows.Current = theLimit.Minimum
theLimitWindows.Maximum = 0 - 1

Dim Shared theLimitIcons As aLimit
theLimitIcons.Minimum = 0
theLimitIcons.Current = theLimit.Minimum
theLimitIcons.Maximum = 0 - 1

Dim Shared theLimitButtons As aLimit
theLimitButtons.Minimum = 0
theLimitButtons.Current = theLimitButtons.Minimum
theLimitButtons.Maximum = 0 - 1

Dim Shared theLimitCheckboxes As aLimit
theLimitCheckboxes.Minimum = 0
theLimitCheckboxes.Current = theLimitCheckboxes.Minimum
theLimitCheckboxes.Maximum = 0 - 1

Dim Shared theLimitSwitches As aLimit
theLimitSwitches.Minimum = 0
theLimitSwitches.Current = theLimitSwitches.Minimum
theLimitSwitches.Maximum = 0 - 1

Dim Shared theLimitRadiobuttons As aLimit
theLimitRadiobuttons.Minimum = 0
theLimitRadiobuttons.Current = theLimitRadiobuttons.Minimum
theLimitRadiobuttons.Maximum = 0 - 1


ReDim Shared theWindows(theLimitWindows.Current) As aWindow
ReDim Shared theIcons(theLimitIcons.Current) As anIcon
ReDim Shared theButtons(theLimitButtons.Current) As aButton
ReDim Shared theCheckboxes(theLimitCheckboxes.Current) As aCheckbox
ReDim Shared theSwitches(theLimitSwitches.Current) As aSwitch
ReDim Shared theRadiobuttons(theLimitRadiobuttons.Current) As aRadiobutton

Dim Shared theMouse As aMouse

'initWindow 300, 200, 320, 240, "Window"
initIcon 100, 100, "blank.png", "Icon 1"
initIcon 200, 100, "blank.png", "Icon 2"
initButton 100, 200, 100, 40, "Button"
initCheckbox 100, 400, 50, -1, "Checkbox"
initSwitch 200, 150, 25, 0, "Switch"
initRadiobutton 550, 100, 50, 1, -1, "Radiobutton 1"
initRadiobutton 550, 175, 50, 1, 0, "Radiobutton 2"
initRadiobutton 550, 250, 50, 1, 0, "Radiobutton 3"

Dim Shared zoneTypeClicked As String

Do
    Line (0, 0)-(_Width, _Height), _RGBA32(127, 127, 127, 255), BF

    For i1 = 0 To theLimitButtons.Current
        _PutImage (theButtons(i1).positionX, theButtons(i1).positionY), theButtons(i1).imageHandle
    Next i1

    For i2 = 0 To theLimitIcons.Current
        _PutImage (theIcons(i2).positionX, theIcons(i2).positionY), theIcons(i2).imageHandle
    Next i2

    For i3 = 0 To theLimitWindows.Current
        _PutImage (theWindows(i3).positionX, theWindows(i3).positionY), theWindows(i3).imageHandle
    Next i3

    For i4 = 0 To theLimitCheckboxes.Current
        If theCheckboxes(i4).isChecked Then
            _PutImage (theCheckboxes(i4).positionX, theCheckboxes(i4).positionY), theCheckboxes(i4).imageHandle2
        Else
            _PutImage (theCheckboxes(i4).positionX, theCheckboxes(i4).positionY), theCheckboxes(i4).imageHandle1
        End If
    Next i4

    For i5 = 0 To theLimitSwitches.Current
        If theSwitches(i5).isEnabled Then
            _PutImage (theSwitches(i5).positionX, theSwitches(i5).positionY), theSwitches(i5).imageHandle2
        Else
            _PutImage (theSwitches(i5).positionX, theSwitches(i5).positionY), theSwitches(i5).imageHandle1
        End If
    Next i5

    For i6 = 0 To theLimitRadiobuttons.Current
        If theRadiobuttons(i6).isSelected Then
            _PutImage (theRadiobuttons(i6).positionX, theRadiobuttons(i6).positionY), theRadiobuttons(i6).imageHandle2
        Else
            _PutImage (theRadiobuttons(i6).positionX, theRadiobuttons(i6).positionY), theRadiobuttons(i6).imageHandle1
        End If
    Next i6

    probeMouse

    If theMouse.buttonLeft Then

        For i = 0 To theLimitWindows.Current
            Status1 = isZone~&(i, "window")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "window"
                GoTo skip
            End If
        Next i

        For i = 0 To theLimitIcons.Current
            Status1 = isZone~&(i, "icon")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "icon"
                GoTo skip
            End If
        Next i

        For i = 0 To theLimitButtons.Current
            Status1 = isZone~&(i, "button")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "button"
                GoTo skip
            End If
        Next i

        For i = 0 To theLimitCheckboxes.Current
            Status1 = isZone~&(i, "checkbox")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "checkbox"
                GoTo skip
            End If
        Next i

        For i = 0 To theLimitSwitches.Current
            Status1 = isZone~&(i, "switch")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "switch"
                GoTo skip
            End If
        Next i

        For i = 0 To theLimitRadiobuttons.Current
            Status1 = isZone~&(i, "radiobutton")
            If Status1 <> 0 Then
                status2 = Status1
                zoneTypeClicked = "radiobutton"
            End If
        Next i

        skip:

        zoneTypeClicked = LCase$(LTrim$(RTrim$(zoneTypeClicked)))

        Select Case zoneTypeClicked
            Case "window"
            Case "icon"
            Case "button"
            Case "checkbox"
                If theCheckboxes(status2).isChecked = -1 Then
                    theCheckboxes(status2).isChecked = 0
                Else
                    theCheckboxes(status2).isChecked = -1
                End If
            Case "switch"
                If theSwitches(status2).isEnabled = -1 Then
                    theSwitches(status2).isEnabled = 0
                Else
                    theSwitches(status2).isEnabled = -1
                End If
            Case "radiobutton"
                For i = 0 To theLimitRadiobuttons.Current
                    If theRadiobuttons(i).groupID = theRadiobuttons(status2).groupID Then
                        theRadiobuttons(i).isSelected = 0
                    End If
                Next i
                theRadiobuttons(status2).isSelected = -1
        End Select
    End If

    _Display

Loop Until Len(InKey$)


Sub initWindow (inPositionX As Integer, inPositionY As Integer, inSizeX As _Unsigned Integer, inSizeY As _Unsigned Integer, inTitle As String)
    theLimitWindows.Current = theLimitWindows.Current + 1
    ReDim _Preserve theWindows(theLimitWindows.Current) As aWindow
    theWindows(theLimitWindows.Current).positionX = inPositionX
    theWindows(theLimitWindows.Current).positionY = inPositionY
    theWindows(theLimitWindows.Current).sizeX = inSizeX
    theWindows(theLimitWindows.Current).sizeY = inSizeY
    theWindows(theLimitWindows.Current).Text = inTitle
    theWindows(theLimitWindows.Current).imageHandle = _NewImage(theWindows(theLimitWindows.Current).sizeX, theWindows(theLimitWindows.Current).sizeY, 32)
    _Dest theWindows(theLimitWindows.Current).imageHandle
    _PrintMode _KeepBackground
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(191, 191, 191, 255), BF
    _PrintString (10, 10), theWindows(theLimitWindows.Current).Text
    _Dest 0
End Sub

Sub initIcon (inPositionX As Integer, inPositionY As Integer, inIconFilename As String, inIconText As String)
    theLimitIcons.Current = theLimitIcons.Current + 1
    ReDim _Preserve theIcons(theLimitIcons.Current) As anIcon
    theIcons(theLimitIcons.Current).imageHandle = _LoadImage(inIconFilename)
    theIcons(theLimitIcons.Current).positionX = inPositionX
    theIcons(theLimitIcons.Current).positionY = inPositionY
    theIcons(theLimitIcons.Current).sizeX = _Width(theIcons(theLimitIcons.Current).imageHandle)
    theIcons(theLimitIcons.Current).sizeY = _Height(theIcons(theLimitIcons.Current).imageHandle)
    theIcons(theLimitIcons.Current).Text = inIconText
End Sub

Sub initButton (inPositionX As Integer, inPositionY As Integer, inSizeX As _Unsigned Integer, inSizeY As _Unsigned Integer, inText As String)
    theLimitButtons.Current = theLimitButtons.Current + 1
    ReDim _Preserve theButtons(theLimitButtons.Current) As aButton
    theButtons(theLimitButtons.Current).positionX = inPositionX
    theButtons(theLimitButtons.Current).positionY = inPositionY
    theButtons(theLimitButtons.Current).sizeX = inSizeX
    theButtons(theLimitButtons.Current).sizeY = inSizeY
    theButtons(theLimitButtons.Current).Text = inText
    theButtons(theLimitButtons.Current).imageHandle = _NewImage(theButtons(theLimitButtons.Current).sizeX, theButtons(theLimitButtons.Current).sizeY, 32)
    _Dest theButtons(theLimitButtons.Current).imageHandle
    _PrintMode _KeepBackground
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(0, 0, 255, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    _PrintString (5, 5), theButtons(theLimitButtons.Current).Text
    _Dest 0
End Sub

Sub initCheckbox (inPositionX As Integer, inPositionY As Integer, inSize As _Unsigned Integer, inIsChecked As _Byte, inText As String)
    theLimitCheckboxes.Current = theLimitCheckboxes.Current + 1
    ReDim _Preserve theCheckboxes(theLimitCheckboxes.Current) As aCheckbox
    theCheckboxes(theLimitCheckboxes.Current).positionX = inPositionX
    theCheckboxes(theLimitCheckboxes.Current).positionY = inPositionY
    theCheckboxes(theLimitCheckboxes.Current).sizeX = inSize
    theCheckboxes(theLimitCheckboxes.Current).sizeY = inSize
    theCheckboxes(theLimitCheckboxes.Current).isChecked = inIsChecked
    theCheckboxes(theLimitCheckboxes.Current).Text = inText
    theCheckboxes(theLimitCheckboxes.Current).imageHandle1 = _NewImage(theCheckboxes(theLimitCheckboxes.Current).sizeX, theCheckboxes(theLimitCheckboxes.Current).sizeY, 32)
    theCheckboxes(theLimitCheckboxes.Current).imageHandle2 = _NewImage(theCheckboxes(theLimitCheckboxes.Current).sizeX, theCheckboxes(theLimitCheckboxes.Current).sizeY, 32)
    _Dest theCheckboxes(theLimitCheckboxes.Current).imageHandle2
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(0, 127, 0, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    Line (2, 2)-(_Width - 3, _Height - 3), _RGBA32(255, 255, 255, 255)
    Line (2, _Height - 3)-(_Width - 3, 2), _RGBA32(255, 255, 255, 255)
    _Dest theCheckboxes(theLimitCheckboxes.Current).imageHandle1
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(0, 127, 0, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    _Dest 0
End Sub

Sub initSwitch (inPositionX As Integer, inPositionY As Integer, inSize As _Unsigned Integer, inIsEnabled As _Byte, inText As String)
    theLimitSwitches.Current = theLimitSwitches.Current + 1
    ReDim _Preserve theSwitches(theLimitSwitches.Current) As aSwitch
    theSwitches(theLimitSwitches.Current).positionX = inPositionX
    theSwitches(theLimitSwitches.Current).positionY = inPositionY
    theSwitches(theLimitSwitches.Current).sizeX = inSize
    theSwitches(theLimitSwitches.Current).sizeY = inSize * 2
    theSwitches(theLimitSwitches.Current).isEnabled = inIsEnabled
    theSwitches(theLimitSwitches.Current).Text = inText
    theSwitches(theLimitSwitches.Current).imageHandle1 = _NewImage(theSwitches(theLimitSwitches.Current).sizeX, theSwitches(theLimitSwitches.Current).sizeY, 32)
    theSwitches(theLimitSwitches.Current).imageHandle2 = _NewImage(theSwitches(theLimitSwitches.Current).sizeX, theSwitches(theLimitSwitches.Current).sizeY, 32)
    _Dest theSwitches(theLimitSwitches.Current).imageHandle2
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(0, 127, 0, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    Line (2, 2)-(_Width - 3, _Height / 2), _RGBA32(255, 255, 255, 255), BF
    _Dest theSwitches(theLimitSwitches.Current).imageHandle1
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 0, 0, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    Line (2, _Height / 2)-(_Width - 3, _Height - 3), _RGBA32(255, 255, 255, 255), BF
    _Dest 0
End Sub

Sub initRadiobutton (inPositionX As Integer, inPositionY As Integer, inSize As _Unsigned Integer, inGroupID As _Unsigned Integer, inIsSelected As _Byte, inText As String)
    theLimitRadiobuttons.Current = theLimitRadiobuttons.Current + 1
    ReDim _Preserve theRadiobuttons(theLimitRadiobuttons.Current) As aRadiobutton
    theRadiobuttons(theLimitRadiobuttons.Current).positionX = inPositionX
    theRadiobuttons(theLimitRadiobuttons.Current).positionY = inPositionY
    theRadiobuttons(theLimitRadiobuttons.Current).sizeX = inSize
    theRadiobuttons(theLimitRadiobuttons.Current).sizeY = inSize
    theRadiobuttons(theLimitRadiobuttons.Current).groupID = inGroupID
    theRadiobuttons(theLimitRadiobuttons.Current).isSelected = inIsSelected
    theRadiobuttons(theLimitRadiobuttons.Current).Text = inText
    theRadiobuttons(theLimitRadiobuttons.Current).imageHandle1 = _NewImage(theRadiobuttons(theLimitRadiobuttons.Current).sizeX, theRadiobuttons(theLimitCheckboxes.Current).sizeY, 32)
    theRadiobuttons(theLimitRadiobuttons.Current).imageHandle2 = _NewImage(theRadiobuttons(theLimitRadiobuttons.Current).sizeX, theRadiobuttons(theLimitCheckboxes.Current).sizeY, 32)
    _Dest theRadiobuttons(theLimitRadiobuttons.Current).imageHandle2
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 0, 255, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    Line (2, 2)-(_Width - 3, _Height - 3), _RGBA32(255, 255, 255, 255)
    Line (2, _Height - 3)-(_Width - 3, 2), _RGBA32(255, 255, 255, 255)
    _Dest theRadiobuttons(theLimitRadiobuttons.Current).imageHandle1
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 0, 255, 255), BF
    Line (0, 0)-(_Width - 1, _Height - 1), _RGBA32(255, 255, 255, 255), B
    _Dest 0
End Sub

Sub probeMouse
    While _MouseInput
    Wend
    theMouse.positionX = _MouseX
    theMouse.positionY = _MouseY
    theMouse.buttonLeft = _MouseButton(1)
    theMouse.buttonRight = _MouseButton(2)
    theMouse.buttonMiddle = _MouseButton(3)
End Sub

Function isZone~& (inIdentifier As _Unsigned _Integer64, inSelector As String)
    inSelector = LCase$(LTrim$(RTrim$(inSelector)))
    Select Case inSelector
        Case "window"
            If theMouse.positionX >= theWindows(inIdentifier).positionX Then
                If theMouse.positionY >= theWindows(inIdentifier).positionY Then
                    If theMouse.positionX <= theWindows(inIdentifier).positionX + theWindows(inIdentifier).sizeX Then
                        If theMouse.positionY <= theWindows(inIdentifier).positionY + theWindows(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
        Case "icon"
            If theMouse.positionX >= theIcons(inIdentifier).positionX Then
                If theMouse.positionY >= theIcons(inIdentifier).positionY Then
                    If theMouse.positionX <= theIcons(inIdentifier).positionX + theIcons(inIdentifier).sizeX Then
                        If theMouse.positionY <= theIcons(inIdentifier).positionY + theIcons(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
        Case "button"
            If theMouse.positionX >= theButtons(inIdentifier).positionX Then
                If theMouse.positionY >= theButtons(inIdentifier).positionY Then
                    If theMouse.positionX <= theButtons(inIdentifier).positionX + theButtons(inIdentifier).sizeX Then
                        If theMouse.positionY <= theButtons(inIdentifier).positionY + theButtons(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
        Case "checkbox"
            If theMouse.positionX >= theCheckboxes(inIdentifier).positionX Then
                If theMouse.positionY >= theCheckboxes(inIdentifier).positionY Then
                    If theMouse.positionX <= theCheckboxes(inIdentifier).positionX + theCheckboxes(inIdentifier).sizeX Then
                        If theMouse.positionY <= theCheckboxes(inIdentifier).positionY + theCheckboxes(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
        Case "switch"
            If theMouse.positionX >= theSwitches(inIdentifier).positionX Then
                If theMouse.positionY >= theSwitches(inIdentifier).positionY Then
                    If theMouse.positionX <= theSwitches(inIdentifier).positionX + theSwitches(inIdentifier).sizeX Then
                        If theMouse.positionY <= theSwitches(inIdentifier).positionY + theSwitches(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
        Case "radiobutton"
            If theMouse.positionX >= theRadiobuttons(inIdentifier).positionX Then
                If theMouse.positionY >= theRadiobuttons(inIdentifier).positionY Then
                    If theMouse.positionX <= theRadiobuttons(inIdentifier).positionX + theRadiobuttons(inIdentifier).sizeX Then
                        If theMouse.positionY <= theRadiobuttons(inIdentifier).positionY + theRadiobuttons(inIdentifier).sizeY Then
                            isZone~& = inIdentifier
                        End If
                    End If
                End If
            End If
    End Select
End Function
Reply




Users browsing this thread: 1 Guest(s)