2D-Drawing Vollbildoberfläche (Buttons)
Verfasst: 11.04.2008 15:16
Programmier grad daran:
Eine Vollbildoberfläche für PBs Vollbildmodus.
Eine Vollbildoberfläche für PBs Vollbildmodus.
Code: Alles auswählen
InitSprite()
InitKeyboard()
InitMouse()
; Desktopauflösung ermitteln
Global deskw.l,deskh.l
ExamineDesktops()
deskw = DesktopWidth(0)
deskh = DesktopHeight(0)
Structure gadget
id.l
posx.l
posy.l
width.l
height.l
title.s
group.l
state.l
mode.b
EndStructure
Global NewList buttons.gadget()
Global xmouse.l, ymouse.l, lbutton.b, presslbutton.b, presslgroup.l, bmarked.l
Procedure CheckMouse()
xmouse = MouseX()
ymouse = MouseY()
lbutton = MouseButton(#PB_MouseButton_Left)
EndProcedure
Procedure DisplayCursor()
StartDrawing(ScreenOutput())
FrontColor(0)
Line(xmouse+1,ymouse-5,0,13)
Line(xmouse-5,ymouse+1,13,0)
FrontColor(RGB(255,255,255))
Line(xmouse,ymouse-6,0,13)
Line(xmouse-6,ymouse,13,0)
StopDrawing()
EndProcedure
Procedure.l NewButton(id.l, posx.l,posy.l,width.l,height.l,title$,group.l,state.l,mode.b)
adr.l = AddElement(buttons())
buttons()\id = id
buttons()\posx = posx
buttons()\posy = posy
buttons()\width = width
buttons()\height = height
buttons()\title = title$
buttons()\group = group
buttons()\state = state
buttons()\mode = mode
ProcedureReturn adr
EndProcedure
Procedure RenderButton(posx.l,posy.l,width.l, height.l, text$, mode.b, marked.b)
Box(posx,posy,width,height,RGB(150,150,150))
If mode = 0
FrontColor(RGB(255,255,255))
Else
FrontColor(RGB(50,50,50))
EndIf
Line(posx,posy,width,0)
Line(posx,posy,0,height)
If mode = 0
FrontColor(RGB(50,50,50))
Else
FrontColor(RGB(255,255,255))
EndIf
Line(posx,posy+height-1,width,0)
Line(posx+width-1,posy,0,height)
If marked
DrawingMode(#PB_2DDrawing_Outlined)
Box(posx+2,posy+2,width-4,height-4,RGB(210,210,210))
EndIf
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(posx+4,posy+height/2-9,text$,0)
DrawText(posx+5,posy+height/2-8,text$,RGB(255,255,255))
EndProcedure
Procedure DisplayButtons()
lcount.l = CountList(buttons())
StartDrawing(ScreenOutput())
If lcount > 0
FirstElement(buttons())
For n = 0 To lcount-1
mark.b = 0
If buttons()\id = bmarked
mark = 1
EndIf
RenderButton(buttons()\posx,buttons()\posy,buttons()\width, buttons()\height, buttons()\title, buttons()\state, mark)
NextElement(buttons())
Next
EndIf
StopDrawing()
EndProcedure
Procedure.l ButtonEvent()
ret.l = -1
lcount.l = CountList(buttons())
If lcount > 0
FirstElement(buttons())
For n = 0 To lcount-1
If xmouse > buttons()\posx And xmouse < buttons()\posx + buttons()\width And ymouse > buttons()\posy And ymouse < buttons()\posy + buttons()\height
highlighted.b = 1
If presslbutton = 0 Or buttons()\group <> presslgroup
bmarked = buttons()\id
If buttons()\mode = 0
buttons()\state = 0
EndIf
Else
If buttons()\mode = 0
buttons()\state = 1
EndIf
bmarked = -1
EndIf
If lbutton = 0 And presslbutton = 1
If presslgroup = buttons()\group
If buttons()\mode = 1
If buttons()\state = 1
buttons()\state = 0
Else
buttons()\state = 1
EndIf
EndIf
ret = buttons()\id
presslbutton = 0
Else
presslbutton = 0
EndIf
ElseIf lbutton = 1 And presslbutton = 0
presslbutton = 1
presslgroup = buttons()\group
EndIf
ElseIf buttons()\mode = 0
buttons()\state = 0
EndIf
NextElement(buttons())
Next
EndIf
If ret = -1 And lbutton = 0
presslbutton = 0
EndIf
If highlighted = 0
bmarked = -1
EndIf
ProcedureReturn ret
EndProcedure
Procedure.b KillButtonID(buttonid.l)
KillIDAgain:
lcount.l = CountList(buttons())
If lcount > 0
FirstElement(buttons())
For n = 0 To lcount-1
If buttons()\id = buttonid
DeleteElement(buttons())
If CountList(buttons()) > 0
Goto KillIDAgain
EndIf
EndIf
NextElement(buttons())
Next
EndIf
EndProcedure
Procedure.b KillButtonGroup(buttongroup.l)
KillGroupAgain:
lcount.l = CountList(buttons())
If lcount > 0
FirstElement(buttons())
For n = 0 To lcount-1
If buttons()\group = buttongroup
DeleteElement(buttons())
If CountList(buttons()) > 0
Goto KillGroupAgain
EndIf
EndIf
NextElement(buttons())
Next
EndIf
EndProcedure
; ****Beispiel 1****
; bc.l = -1
; For x = 0 To 15:For y = 0 To 15
; bc + 1
; NewButton(bc,x*32,y*32,30,30,Chr(bc),x,0,1)
; Next:Next
; ****Beipiel 2****
; Ein Menü in einer Buttongroup
NewButton(0,20,100,100,20,"Neu",1, 0,0)
NewButton(2,20,120,100,20,"Öffnen",1,0,0)
NewButton(3,20,140,100,20,"Speichern",1,0,0)
NewButton(4,20,160,100,20,"Beenden",1,0,0)
; Einzelne Toggle Buttons
NewButton(5,0,deskh-120,100,40,"Nehmen",5, 0,1)
NewButton(6,0,deskh-80,100,40,"Öffnen",6, 0,1)
NewButton(7,0,deskh-40,100,40,"Benutzen",7, 0,1)
NewButton(8,100,deskh-120,100,40,"Werfen",8, 1,1)
NewButton(9,100,deskh-80,100,40,"Inventar",9, 0,1)
NewButton(10,100,deskh-40,100,40,"Pause",10, 0,1)
NewButton(0,200,200,220,220,"Neu zum zweiten mal",28, 1,1)
OpenScreen(deskw,deskh,32,"Small Full Screen GUI v1.0")
Repeat
ExamineKeyboard()
ExamineMouse()
CheckMouse() ; Mauschecken
bevent.l = ButtonEvent()
If bevent <> -1
texto$ = Str(bevent)
; KillButtonID(bevent)
EndIf
StartDrawing(ScreenOutput())
DrawText(500,0,"EventID = "+ texto$)
StopDrawing()
DisplayButtons() ;Knöpfe darstellen
DisplayCursor() ;Mauszeiger darstellen
FlipBuffers()
ClearScreen(0)
Until KeyboardPushed(#PB_Key_Escape)
CloseScreen()