Buchempfehlung
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Mikrocomputertechnik mit Controllern der Atmel AVR-RISC-Familie
Umfassend, aber leicht verständlich führt dieses Buch in die Programmierung von ATMEL AVR Mikrocontrollern ein. [Mehr Infos...]
FreeBASIC-Chat
Es sind Benutzer im FreeBASIC-Chat online.
(Stand:  )
FreeBASIC bei Twitter
Twitter FreeBASIC-Nachrichten jetzt auch über Twitter erhalten. Follow us!

fb:porticula NoPaste

Info
Info / Hilfe
Liste
Übersicht / Liste
Neu
Datei hochladen
Suche
Quellcode suchen
Download
Dateidownload

Scrollbar.bi

Uploader:MitgliedOneCypher
Datum/Zeit:20.09.2009 17:07:35
Hinweis: Dieser Quelltext ist Bestandteil des Projekts GuiPtr, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.
Warnung: Es steht bereits eine neuere Version des Quelltexts zur Verfügung. Die hier vorliegende alte Version könnte Fehler enthalten, die in der neuen Version vielleicht ausgebessert wurden.

type ScrollBar
    Object as GuiObject ptr
    MinValue as integer = 0
    MaxValue as integer = 100
    Value as integer = 0
    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
    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)
    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