fb:porticula NoPaste
ScrollBar.bi
Uploader: | OneCypher |
Datum/Zeit: | 13.10.2009 11:11:35 |
Hinweis: Dieser Quelltext ist Bestandteil des Projekts GuiPtr, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.
#include once "GuiPtr.bi"
type ScrollBar
Object as GuiObject ptr
MinValue as double = 0
MaxValue as double = 100
Value as double = 0
dValue as double = 0
TmpPtr as any ptr
declare constructor (l as integer, t as integer, w as integer, h as integer)
end type
Sub DragScrollBar(GO as any ptr, e as EventParameter)
dim s as ScrollBar ptr = GO
dim size as integer
Dim TmpVal as integer = s->Value
with *s->Object
if .width > .height then
size = .height
if e.mx > size and e.mx < .width - size then
s->Value = s->MinValue+ ((e.mx - size) / (.width - 2*size)) * (s->MaxValue - s->MinValue)
end if
else
size = .width
if e.my > size and e.my < .height - size then
s->Value = s->MinValue+ ((e.my - size) / (.height - 2*size)) * (s->MaxValue - s->MinValue)
end if
end if
's->Value = int(s->TmpValue)
s->dValue = TmpVal - s->Value
end with
end sub
Sub DrawScrollBar(GO as any ptr)
dim s as ScrollBar ptr = GO
dim XPos as integer
Dim YPos as integer
dim Size as integer
with *s->Object
line .buffer,(.left,.top)-(.left+.width, .top + .height),RGB(255,255,255),BF
line .buffer,(.left,.top)-(.left+.width, .top + .height),RGB(0,0,0),B
if .width > .height then
size = .height: YPos = .top: XPos = .left + size + ((.width - (3*size)) * ((s->value -s->MinValue)/ (s->MaxValue - s->MinValue)))
line .buffer,(.left,.top)-(.left + size, .top + size),RGB(0,0,0),BF 'Einen schritt nach links
line .buffer,(.left+.width,.top)-(.left + .width - size, .top + size),RGB(0,0,0),BF 'Einen schritt nach rechts
else
size = .width: XPos = .left: YPos = .top + size + ((.height - (3*size)) * ((s->value -s->MinValue)/ (s->MaxValue - s->MinValue)))
line .buffer,(.left,.top)-(.left + size, .top + size),RGB(0,0,0),BF 'Einen schritt nach oben
line .buffer,(.left,.top+.height)-(.left+size, .top + .height- size),RGB(0,0,0),BF 'einen schritt nach unten
end if
line .Buffer, (Xpos,YPos)-(XPos + size, YPos + Size),RGB(128,128,128),BF
end with
end sub
Sub ClickScrollbar(GO as any ptr,e as EventParameter)
dim s as ScrollBar ptr = GO
dim size as integer
with *s->Object
if .width > .height then
size = .height
if e.mx < size and s->value > s->MinValue then s->value -= 1
if e.mx > .width - size and s->value < s->MaxValue then s->value += 1
else
size = .width
if e.my < size and s->value > s->MinValue then s->value -= 1
if e.my > .height - size and s->value < s->MaxValue then s->value += 1
end if
end with
end sub
Constructor ScrollBar(l as integer, t as integer, w as integer, h as integer)
Object = new GuiObject(@This)
with *object
.name = "ScrollBar"
.left = l: .top = t
.width = w: .height = h
.PrivateEvents = new Events
with *.PrivateEvents
.OnDraw = @DrawScrollBar
.SingleClick = @ClickScrollbar
.OnMouseDrag = @DragScrollbar
end with
end with
end constructor