Buchempfehlung
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
Windows-Programmierung. Das Entwicklerhandbuch zur WIN32-API
"Der" Petzold, das über 1000 Seiten starke Standardwerk zum Win32-API - besonders nützlich u. a. bei der GUI-Programmierung in FreeBASIC! [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

Button.bi

Uploader:MitgliedOneCypher
Datum/Zeit:13.10.2009 10:58:00
Hinweis: Dieser Quelltext ist Bestandteil des Projekts GuiPtr, zu dem es auf FreeBASIC-Portal.de eine Projektseite gibt.

#include once "GuiPtr.bi"

type Button
    Object as GuiObject ptr
    Caption as string
    Pressed as ubyte
    declare constructor(left as integer, top as integer, w as integer, h as integer, GWindowtitle as string)
    declare constructor overload (left as integer, top as integer, GWindowtitle as string)
    declare constructor overload (Descriptor as string, ButtonCaption as string)
end type

sub DrawButton(ButtonPTR as any ptr)
    dim b as Button ptr = ButtonPTR
    with *b
        select case .pressed
        case 0
            with *.object
                line .buffer, (.left, .top)-(.left + .width, .top + .height),RGB(212,208,200),BF
                line .buffer, (.left, .top)-(.left + .width, .top + .height),RGB(64,64,64),B
                line .buffer, (.left, .top)-(.left, .top + .height),RGB(255,255,255)
                line .buffer, (.left, .top)-(.left + .width, .top),RGB(255,255,255)
                Draw string .buffer, (.left + ((.width /2) - ((len(b->caption)*8)/2)), .top + ((.height / 2) - 7)),b->caption, RGB(0,0,0)
            end with
        case 1
            with *.object
                line .buffer, (.left, .top)-(.left + .width, .top + .height),RGB(212,208,200),BF
                line .buffer, (.left, .top)-(.left + .width, .top + .height),RGB(255,255,255),B
                line .buffer, (.left, .top)-(.left, .top + .height),RGB(64,64,64)
                line .buffer, (.left, .top)-(.left + .width, .top),RGB(64,64,64)
                Draw string .buffer, (1+.left + ((.width /2) - ((len(b->caption)*8)/2)), 1+.top + ((.height / 2) - 7)),b->caption, RGB(0,0,0)
            end with
        end select
    end with
end sub

sub DrawButtonPressed(ButtonPTR as any ptr,e as EventParameter)
    dim b as Button ptr = ButtonPTR
    b->pressed = 1
    b->object->root->redraw
end sub

sub DrawButtonReleased(ButtonPTR as any ptr,e as EventParameter)
    dim b as Button ptr = ButtonPTR
    b->pressed = 0
    b->object->root->redraw
end sub

constructor Button(left as integer, top as integer, w as integer, h as integer, ButtonCaption as string)
    'Objectconstruction
    Object = new GuiObject(@This)
    with *Object
        .ClassName = "Button"
        .left = left
        .top = top
        .width = w
        .height = h
        .PrivateEvents = new Events
        with *.PrivateEvents
            .OnDraw = @DrawButton
            .OnMouseDown = @DrawButtonPressed
            .OnMouseUp = @DrawButtonReleased
        end with
    end with
    'Controlelements
    Caption = ButtonCaption
end constructor

constructor Button overload (left as integer, top as integer, ButtonCaption as string)
    'Objectconstruction
    Object = new GuiObject(@This)
    with *Object
        .ClassName = "Button"
        .left = left
        .top = top
        .width = len(ButtonCaption) * 8 + 24
        .height = 26
        .PrivateEvents = new Events
        with *.PrivateEvents
            .OnDraw = @DrawButton
            .OnMouseDown = @DrawButtonPressed
            .OnMouseUp = @DrawButtonReleased
        end with
    end with
    'Controlelements
    Caption = ButtonCaption
end constructor

constructor Button overload (Descriptor as string, ButtonCaption as string)
    'Objectconstruction
    Object = new GuiObject(@This, Descriptor)
    with *Object
        .ClassName = "Button"
        .PrivateEvents = new Events
        with *.PrivateEvents
            .OnDraw = @DrawButton
            .OnMouseDown = @DrawButtonPressed
            .OnMouseUp = @DrawButtonReleased
        end with
    end with
    'Controlelements
    Caption = ButtonCaption
end constructor