Main Menu

simple windows

Started by Alex777, March 01, 2006, 08:21:23 PM

Previous topic - Next topic

Alex777

I know there are several very good windows packages on here.  So, why am I posting another one?  Well, sometimes you just need something simple to display a bit of text or get a couple of option selections  from the user.  That's what this is - simple windows for when you don't need anything more complex.

PlayBASIC Code: [Select]
RemStart
SIMPLE WINDOWS:
Instructions: press "G" repeatedly (come on - you can handle that).
Alex Henderson
alexhenderson7@yahoo.ca
copyright: public domain
RemEnd


Constant White = RGB(255, 255, 255)
Constant Black = RGB(8, 8, 8)
Constant Trans = RGB(0, 0, 0)
Constant GrayDark = RGB(64, 64, 64)
Constant GrayMedium = RGB(128, 128, 128)
Constant GrayLight = RGB(192, 192, 192)
Constant Red = RGB(255, 0, 0)
Constant Buff = RGB(169, 212, 140)

Global FontSmall = GetFreeFont()
LoadFont "Arial", FontSmall, 18, 0
Global FontMedium = GetFreeFont()
LoadFont "Arial", FontMedium, 21, 0
Global FontMediumUnd = GetFreeFont()
LoadFont "Arial", FontMediumUnd, 21, 4
Ink Black

OpenScreen 1024, 768, 16, 2
Dim gameOptions(4)
gameOptions(2) = On
gameOptions(4) = On

; I threw in the camera to demonstrate that the routine works with it
thisCam = GetFreeCamera()
CreateCamera thisCam

Do
CaptureToScene
ClsScene
KeyCode = ScanCode()
If KeyCode = 34
; G key was pressed
FlushKeys
TestWindows()
EndIf
DrawCamera thisCam
Cls Buff ; ***
Sync
Loop

; ------------------------------------------------------------------------------

Psub TestWindows()
; demo code

Static testNum

Inc testNum
Select testNum
Case 1
message$ = "|SIMPLE WINDOWS^^You can^display text^centered^~or "
message$ = message$ + "left-justified in either of^|~2 fonts (per window)."
buttons$ = "OK"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMediumUnd)
Case 2
message$ = "|A SIMPLE TABLE^^~A{{order 1 beer^~B{{order 2^~C{{make it 3"
buttons$ = "OK^Cancel"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMedium)
Case 3
message$ = "|COMMAND BUTTONS^^~When the user left-clicks any button,^~the "
message$ = message$ + "window closes and the button no. is returned"
buttons$ = "Move^Fire^Code^Drink"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMedium)
Case 4
message$ = "You selected command button no. " + Str$(button)
buttons$ = "OK"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMedium)
Case 5
message$ = "|OPTION BOXES^^~Left-click a box to toggle its status^~the "
message$ = message$ + "status of all boxes is returned^"
message$ = message$ + "^~cancel order{{}"
message$ = message$ + "^~order beer again{}"
message$ = message$ + "^~return to coding{}"
message$ = message$ + "^~play a game{{}"
buttons$ = "OK^Cancel"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMediumUnd)
Case 6
message$ = "|Your box settings:^"
message$ = message$ + "^~Box 1{{{" + Str$(gameOptions(1))
message$ = message$ + "^~Box 2{{{" + Str$(gameOptions(2))
message$ = message$ + "^~Box 3{{{" + Str$(gameOptions(3))
message$ = message$ + "^~Box 4{{{" + Str$(gameOptions(4))
buttons$ = "OK"
button = IO_DrawWindow(message$, buttons$, gameOptions(), _
FontSmall, FontMedium)
Default
End
EndSelect

EndPsub

; ------------------------------------------------------------------------------

Psub IO_DrawWindow(message$, buttons$, gameOptions(), font1, font2)

RemStart
A simple routine to draw a text window centered on the screen.
Each string separated by "^" in message$ is a line of text.
Text will be displayed in font1 unless "|" is the 1st character in the
line, in which case it will be in font2.
Text will be centered horizontally in window unless "~" is the 1st or 2nd
character in the line, in which case it will be left-justified.
The "{" character placed anywhere in a left-justified line = a TAB stop,
of distance = tabWidth.
The "}" character placed anywhere in a left-justified line will display
a selection box.
Selection boxes are initialized according to the contents of gameOptions().
Each element in gameOptions() = On or Off.
Left-clicking a selection box will toggle the selected box on or off.
The "^", "~", "|", "{" and "}" characters are non-displayable.
Each string in buttons$ separated by "^" contains text for a button.
All buttons are displayed in a single row at the bottom, centered.
The routine calculates the window width & height for you.
Focus is restricted to window until selection is made by a left-click.
returns: buttonSelected = the index number in button$() of the button clicked.
Button 1 is the first button.
gameOptions(n) = status (On or Off) of the selections made.
gameOptions(1) is the first selection box.
RemEnd


; all these constants are in pixels
; size of 1 tab stop
Constant tabWidth = 50
; the width of the window border
Constant borderWidth = 10
; indent from window border
Constant LIndent = 40
; height of 1 line & space below it
Constant pitchY = 30
; width of a button
Constant buttWidth = 76
; height of a button
Constant buttHeight = 18
; space bewtween 2 buttons
Constant buttPitchX = 20
Login required to view complete source code



Ian Price

That's pretty good - although I'm not overly keen on the mushy-pea green colour scheme :P

I thought it was borked at first as the screen remained green - it wasn't until I read the code that I realised you had to press "G" - seems like a strange keychoice, but nevermind.

Good stuff :)
I came. I saw. I played some Nintendo.

Alex777

#2
"G" for Go.  Or, G for Green, I guess.   :rolleyes:   Anyway, thanks!

kevin


kevin

because it's so handy i've moved this to the source code forum

Alex777