Buchempfehlung
Windows System Programming
Windows System Programming
Das Kompendium liefert viele interessante Informationen zur Windows-Programmierung auf Englisch. [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!

Tutorial

Buttonologie * GUI-Programierung mit FLTK

von MitgliedKnattertonSeite 1 von 1

Inhalt

7. Buttonologie
7.1 Fl_Light_Button
7.2 Fl_Radio_Button
7.3 Fl_Repeat_Button
7.4 Fl_Return_Button
7.5 Fl_Toggle_Button
7.6 Checkbutton
7.7 Imagebutton
7.8 Toolbar
7.9 Pixmapbutton
7.10 Blinkende Glühbirne

7. Buttonologie

Wie Lothar anfangs schon erwähnte stammen von dem Objekt "Button" eine ganze Reihe verschiedener Typen ab. Aus meiner Sicht kommen vor allem Imagebutton, Toolbar und Pixmapbutton dazu.

7.1 Fl_Light_Button

7.2 Fl_Radio_Button

Radio Buttons müssen in Gruppen geordnet werden, damit der aktive Button einer Gruppe ermittelt werden kann.

' Fltk_Radio_Buttons_01.bas
' added callbacks and initial setting

#include once "fltk-c.bi"

sub RadioCB cdecl (byval self as Fl_Widget ptr)
  print "ButtonCB: " & *Fl_WidgetGetLabel(self)
end sub

var win = Fl_WindowNew(310,180,"Fltk_Radio_Buttons_01.bas (resize me ...)")

var grp1 = Fl_GroupNew(5,20,310,40,"Buttongroup")
  var rad1 = Fl_Radio_ButtonNew( 10,25,90,30,"Button A")
  var rad2 = Fl_Radio_ButtonNew(110,25,90,30,"Button B")
  var rad3 = Fl_Radio_ButtonNew(210,25,90,30,"Button C")
Fl_GroupEnd grp1

Fl_WidgetSetSelectionColor(rad1,FL_CYAN)
Fl_WidgetSetSelectionColor(rad2,FL_MAGENTA)
Fl_WidgetSetSelectionColor(rad3,FL_YELLOW)
'Fl_WidgetSetSelectionColor(rad3,FL_RED) ' shows text white

var grp2 = Fl_GroupNew(5,80,315,40,"Roundgroup")
  var rad4 = Fl_Radio_Round_ButtonNew( 10,85,90,30,"Round D")
  var rad5 = Fl_Radio_Round_ButtonNew(110,85,90,30,"Round E")
  var rad6 = Fl_Radio_Round_ButtonNew(210,85,90,30,"Round F")
Fl_GroupEnd grp2

Fl_WidgetSetSelectionColor(rad4,FL_CYAN)
Fl_WidgetSetSelectionColor(rad5,FL_MAGENTA)
Fl_WidgetSetSelectionColor(rad6,FL_YELLOW)

var grp3 = Fl_GroupNew(5,140,315,40,"Lightgroup")
  var rad7 = Fl_Radio_Light_ButtonNew( 10,145,90,30,"Light G")
  var rad8 = Fl_Radio_Light_ButtonNew(110,145,90,30,"Light H")
  var rad9 = Fl_Radio_Light_ButtonNew(210,145,90,30,"Light I")
Fl_GroupEnd grp3

Fl_WidgetSetSelectionColor(rad7,Fl_RGB_Color(164,108, 78))
Fl_WidgetSetSelectionColor(rad8,Fl_RGB_Color( 64,128,128))
Fl_WidgetSetSelectionColor(rad9,Fl_RGB_Color(177, 55,188))

  ' set callbacks
  Fl_WidgetSetCallback0 rad1,@RadioCB
  Fl_WidgetSetCallback0 rad2,@RadioCB
  Fl_WidgetSetCallback0 rad3,@RadioCB
  Fl_WidgetSetCallback0 rad4,@RadioCB
  Fl_WidgetSetCallback0 rad5,@RadioCB
  Fl_WidgetSetCallback0 rad6,@RadioCB
  Fl_WidgetSetCallback0 rad7,@RadioCB
  Fl_WidgetSetCallback0 rad8,@RadioCB
  Fl_WidgetSetCallback0 rad9,@RadioCB

  ' set initial value for each group
  Fl_ButtonSetValue(rad2,1) ' checked
  Fl_ButtonSetValue(rad5,1) ' checked
  Fl_ButtonSetValue(rad8,1) ' checked

Fl_GroupSetResizable win,win
Fl_WindowSizeRange win,240,120
Fl_WindowShow Win
Fl_Run

radio

7.3 Fl_Repeat_Button

7.4 Fl_Return_Button

7.5 Fl_Toggle_Button

7.6 Checkbutton

Checkbuttons können checked oder unchecked sein.

' Fltk_checkbox_01.bas

' in this example what i call checkbox is named checkbutton, button or widget.
' sometimes you find the needed functions in complete different places
' in Fltk-main.bi

#include once "fltk-c.bi"

sub CheckCB cdecl (byval self as FL_WIDGET ptr,byval CheckButton as any ptr)
  print *Fl_WidgetGetLabel(self) & "[" & Fl_ButtonGetValue(CheckButton) & "]"
end sub

' main
var win = Fl_WindowNew(320,40,"Fltk_Checkbox_01")

var cb1 = Fl_Check_ButtonNew( 10,10,90,30,"Test 1")
var cb2 = Fl_Check_ButtonNew(110,10,90,30,"Button 2")
var cb3 = Fl_Check_ButtonNew(210,10,90,30,"Button 3")

Fl_WidgetSetCallbackArg cb1,@CheckCB,cb1
Fl_WidgetSetCallbackArg cb2,@CheckCB,cb2
Fl_WidgetSetCallbackArg cb3,@CheckCB,cb3

'set check states (checkbox is treated as button here)
Fl_ButtonSetValue(cb1,0) ' unchecked
Fl_ButtonSetValue(cb2,1) ' checked
Fl_ButtonSetValue(cb3,0) ' unchecked

' set label(checkbox is treated as widget here)
Fl_WidgetSetLabel(cb1, "Button 1")

Fl_WindowShow Win
Fl_Run

check

7.7 Imagebutton

Ein Imagebutton ist ein Button mit einem Bild drauf. Sonst wie gehabt.

' Fltk_Imagebutton_01.bas

#include once "fltk-c.bi"

const ICONSIZE = 48' try 8,16,24,32 also

sub ButtonCB cdecl (byval button as FL_WIDGET ptr)
  ? "Button pushed"
end sub

' main
Fl_Register_Images
Fl_File_IconLoadSystemIcons

var Icon18 = Fl_File_IconNew() : Fl_File_IconLoad Icon18,"media/logo_windows_32x32.png"
var Icon19 = Fl_File_IconNew() : Fl_File_IconLoad Icon19,"media/logo_tux.png"

var win  = Fl_Double_WindowNew(320,200,"Fltk Imagebutton")
var btn1 = Fl_ButtonNew(90,80,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon18,btn1
var btn2 = Fl_ButtonNew(180,80,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon19,btn2

' connect callbacks
Fl_WidgetSetCallback0 btn1, @ButtonCB
Fl_WidgetSetCallback0 btn2, @ButtonCB

FL_WindowEnd win
Fl_WindowShow win
Fl_Run

image

7.8 Toolbar

Eine Toolbar besteht einfach aus mehreren Imagebuttons, die in einer Reihe angeordnet sind. Die einzelnen Callbacks können einfach angepasst werden. Hier wurden bereits die Bitmaps der aktuellen Version verwandt.

' Fltk_Toolbar_03.bas
' new icons of updated version
' become stretched to 48x48

#include once "fltk-c.bi"

sub ButtonCB cdecl (byval button as FL_WIDGET ptr,btn as any ptr)
  ? "Button pushed"
end sub

const ICONSIZE = 40 'try 8,16,24,32, flexible works also
Fl_Register_Images
Fl_File_IconLoadSystemIcons

' Note: you must copy the subfolder "media"  to your FastLighter folder to load the icons
var Icon01 = Fl_File_IconNew() : Fl_File_IconLoad Icon01,"media/document_32x32.png"
var Icon02 = Fl_File_IconNew() : Fl_File_IconLoad Icon02,"media/file_folder_32x32.png"
var Icon03 = Fl_File_IconNew() : Fl_File_IconLoad Icon03,"media/action_file_save_32x32.png"
var Icon04 = Fl_File_IconNew() : Fl_File_IconLoad Icon04,"media/action_file_save_as_32x32.png"

var Icon05 = Fl_File_IconNew() : Fl_File_IconLoad Icon05,"media/action_cut_32x32.png"
var Icon06 = Fl_File_IconNew() : Fl_File_IconLoad Icon06,"media/action_paste_32x32.png"
var Icon07 = Fl_File_IconNew() : Fl_File_IconLoad Icon07,"media/action_copy_32x32.png"
var Icon08 = Fl_File_IconNew() : Fl_File_IconLoad Icon08,"media/tools_32x32.png"

var Icon09 = Fl_File_IconNew() : Fl_File_IconLoad Icon09,"media/action_search_32x32.png"
var Icon10 = Fl_File_IconNew() : Fl_File_IconLoad Icon10,"media/color_palette_32x32.png"
var Icon11 = Fl_File_IconNew() : Fl_File_IconLoad Icon11,"media/msg_warning_32x32.png"
var Icon12 = Fl_File_IconNew() : Fl_File_IconLoad Icon12,"media/help_32x32.png"

var Icon13 = Fl_File_IconNew() : Fl_File_IconLoad Icon13,"media/action_view_settings_32x32.png"
var Icon14 = Fl_File_IconNew() : Fl_File_IconLoad Icon14,"media/color_fill_32x32.png"
var Icon15 = Fl_File_IconNew() : Fl_File_IconLoad Icon15,"media/coffee_pot_32x32.png"
var Icon16 = Fl_File_IconNew() : Fl_File_IconLoad Icon16,"media/book_red_32x32.png"

var Icon17 = Fl_File_IconNew() : Fl_File_IconLoad Icon17,"media/msg_stop_32x32.png"
var Icon18 = Fl_File_IconNew() : Fl_File_IconLoad Icon18,"media/msg_question_32x32.png"
var Icon19 = Fl_File_IconNew() : Fl_File_IconLoad Icon19,"media/msg_error_red_32x32.png"
var Icon20 = Fl_File_IconNew() : Fl_File_IconLoad Icon20,"media/msg_info_32x32.png"

var win  = Fl_Double_WindowNew(1024,480,"Fl_Toolbar03.bas")

' toolbar
var toolbar = Fl_GroupNew(0,32,Fl_WidgetGetW(win),ICONSIZE)
    Fl_WidgetSetBox toolbar,Boxtype(FL_UP_BOX)

    ' create buttons
    var btn01 = Fl_ButtonNew(0*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon01,btn01
    var btn02 = Fl_ButtonNew(1*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon02,btn02
    var btn03 = Fl_ButtonNew(2*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon03,btn03
    var btn04 = Fl_ButtonNew(3*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon04,btn04

    var btn05 = Fl_ButtonNew(5*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon05,btn05
    var btn06 = Fl_ButtonNew(6*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon06,btn06
    var btn07 = Fl_ButtonNew(7*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon07,btn07
    var btn08 = Fl_ButtonNew(8*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon08,btn08

    var btn09 = Fl_ButtonNew(10*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon09,btn09
    var btn10 = Fl_ButtonNew(11*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon10,btn10
    var btn11 = Fl_ButtonNew(12*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon11,btn11
    var btn12 = Fl_ButtonNew(13*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon12,btn12

    var btn13 = Fl_ButtonNew(15*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon13,btn13
    var btn14 = Fl_ButtonNew(16*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon14,btn14
    var btn15 = Fl_ButtonNew(17*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon15,btn15
    var btn16 = Fl_ButtonNew(18*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon16,btn16

    var btn17 = Fl_ButtonNew(20*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon17,btn17
    var btn18 = Fl_ButtonNew(21*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon18,btn18
    var btn19 = Fl_ButtonNew(22*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon19,btn19
    var btn20 = Fl_ButtonNew(23*ICONSIZE,32,ICONSIZE,ICONSIZE):Fl_File_IconLabel Icon20,btn20

    ' connect callbacks
    Fl_WidgetSetCallbackArg btn01,@ButtonCB,btn01
    Fl_WidgetSetCallbackArg btn02,@ButtonCB,btn02
    Fl_WidgetSetCallbackArg btn03,@ButtonCB,btn03
    Fl_WidgetSetCallbackArg btn04,@ButtonCB,btn04
    Fl_WidgetSetCallbackArg btn05,@ButtonCB,btn05
    Fl_WidgetSetCallbackArg btn06,@ButtonCB,btn06
    Fl_WidgetSetCallbackArg btn07,@ButtonCB,btn07
    Fl_WidgetSetCallbackArg btn08,@ButtonCB,btn08
    Fl_WidgetSetCallbackArg btn09,@ButtonCB,btn09
    Fl_WidgetSetCallbackArg btn10,@ButtonCB,btn10
    Fl_WidgetSetCallbackArg btn11,@ButtonCB,btn11
    Fl_WidgetSetCallbackArg btn12,@ButtonCB,btn12
    Fl_WidgetSetCallbackArg btn13,@ButtonCB,btn13
    Fl_WidgetSetCallbackArg btn14,@ButtonCB,btn14
    Fl_WidgetSetCallbackArg btn15,@ButtonCB,btn15
    Fl_WidgetSetCallbackArg btn16,@ButtonCB,btn16
    Fl_WidgetSetCallbackArg btn17,@ButtonCB,btn17
    Fl_WidgetSetCallbackArg btn18,@ButtonCB,btn18
    Fl_WidgetSetCallbackArg btn19,@ButtonCB,btn19
    Fl_WidgetSetCallbackArg btn20,@ButtonCB,btn20

Fl_GroupEnd toolbar

FL_WindowEnd win
Fl_WindowResizeable win,toolbar
Fl_WindowShow win
Fl_Run

toolbar
Vergrößern
toolbar

7.9 Pixmapbutton

Eine Pixmap ist eigentlich eine .xpm Datei, die in FB-Format umgewandelt wurde. Solche Dateien können mit Gimp erzeugt werden (Beschreibung im Thread). Diese Pixmap stammt aus einer früheren Fltk-C version.

' Fltk_Pixmap_Button_03.bas

#include once "fltk-c.bi"

dim as zstring ptr horse_xpm(...) => {@"64 64 4 1", _
@"  c #background",@".  c #000000000000",@"X    c #ffd100",@"o  c #FFFF00000000", _
@"                                                                ", _
@"                   ..........................                   ", _
@"              .....................................             ", _
@"        ............XXXXXXXXXXXXXXXXXXXXXXXX............        ", _
@"        ......XXXXXXX...XX...XXXXXXXX...XXXXXXXXXX......        ", _
@"        ..XXXXXXXXXX..X..XX..XXXX.XXXX..XXXXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..X..XX..XXX..XXXX..X...XXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XX.....XX..XX.XXXXXXXXXXX..        ", _
@"        ..XXXXXXXXX.....XXX..XXX..XXXX..X.XXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..XXXX....XXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..XXXX..X..XXXXXXXXXXX..        ", _
@"        ..XXXXXXXXXX..XXXXX..XXX..X.XX..XX..XXXXXXXXXX..        ", _
@"        ..XXXXXXXXX....XXX....XXX..XX....XX..XXXXXXXXX..        ", _
@"        ..XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX..        ", _
@"        ..XXXXXXXXX..........................XXXXXXXXX..        ", _
@"        ..XXX.......XXXXXXXXXXX...................XXXX..        ", _
@"        ......XX.XXX.XXX..XXXXX.........................        ", _
@"        ..XXXXX.XXX.XXX.XXXX.XX.........................        ", _
@"        ..XXXX.XXX.XX.......XXX.........................        ", _
@"        ..XXXX.......XXXXXX..XX..ooooooooooooooooooooo..        ", _
@"        ..X.....XXXXXXXXXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..X...XXXXXXXXXXXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..X..XXXXXXX.XX.XXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..XXXXX.XXX.XX.XXXXXXXX..ooooooooooooooooooooo..        ", _
@"        ..XXXX.XXX.XX.XX................................        ", _
@"        ..XXXX.X.........X....X.X.X.....................        ", _
@"        ..XXXX...XXXXXXX.X..X...X.X.X.X.................        ", _
@"        ..X....XXXXXXXXXX.X...X.X.X.....................        ", _
@"        ..X...XXXXXXXXXX.XXXXXXXXXXXXXX.................        ", _
@"        ..X..XXXXXX.XX.X.XXX...XXXXXXXX.................        ", _
@"        ..XXXXX.XX.XX.XX.XX.....XXXXXXX.oooooooooooooo..        ", _
@"        ..XXXX.XX.XX.XX..XX.X...XXXXX.X.oooooooooooooo..        ", _
@"        ..XXXX.X.......X.XXXX...XXXX..X.oooooooooooooo..        ", _
@"        ..X......XXXXXX..XXXX...XXXX..X.oooooooooooooo..        ", _
@"        ..X...XXXXXXXXXX.XXX.....XXX.XX.oooooooooooooo..        ", _
@"        ..X..XXXXXXXXXXX.X...........XX.oooooooooooooo..        ", _
@"        .................X.X.........XX.................        ", _
@"        .................X.X.XXXX....XX.XXXXXXXXXXXXXX..        ", _
@"        .................XXX.XXXXX.X.XX.XXX.XX.XXXXXXX..        ", _
@"         ................XXXX.XXX..X..X.XX.XX.XXX.XXX..         ", _
@"         ................XXXXXXXX.XX.XX.X.XX.XXX.XXXX..         ", _
@"         .................XXXXXX.XX.XX.X..........XXX..         ", _
@"          ..oooooooooooooo.XXXXXXXXXX....XXXXXXXX..X..          ", _
@"          ..ooooooooooooooo.XXXXXXXX....XXXXXXXXXXXX..          ", _
@"           ..ooooooooooooooo........XXXXXXX.XX.XXXX..           ", _
@"           ..oooooooooooooooooo..XXXXX.XXX.XX.XX.XX..           ", _
@"            ..ooooooooooooooooo..XXXX.XXX.XX.XX.XX..            ", _
@"            ..ooooooooooooooooo..XXX.XX........XXX..            ", _
@"             ....................XXX....XXXXXX..X..             ", _
@"              ...................XX...XXXXXXXXXXX.              ", _
@"              ...................X...XXXXXXXXXXX..              ", _
@"               ..................X..XXXX.XXXXXX..               ", _
@"                .................XXX.XX.XX.XXX..                ", _
@"                 ................XX.XX.XX.XXX..                 ", _
@"                  ..ooooooooooo..XX.......XX..                  ", _
@"                   ..oooooooooo..X...XXXX.X..                   ", _
@"                    ..ooooooooo..X..XXXXXX..                    ", _
@"                     ...ooooooo..X..XXXX...                     ", _
@"                      ....ooooo..XXXXX....                      ", _
@"                        ....ooo..XXX....                        ", _
@"                          ....o..X....                          ", _
@"                            ........                            ", _
@"                              ....                              ", _
@"                                                                "}

sub ButtonCB cdecl (byval button as FL_WIDGET ptr)
  ? "Button pushed"
end sub

  const ICONSIZE = 48' flexible
  var win = Fl_Double_WindowNew(140,140,"Fltk_Pixmap")

  var horse = Fl_PixmapNew(@horse_xpm(0))
  var btn1 = Fl_ButtonNew( 30,30,80,80)
  Fl_WidgetSetImage btn1, horse

  ' connect callbacks
  Fl_WidgetSetCallback0 btn1, @ButtonCB

Fl_WindowShow win
Fl_Run

pixmap

7.10 Blinkende Glühbirne

Buttons kann man auch animieren. As Beispiel hier eine blinkende Glühbirne. Dies kann als Message genutzt werden, etwa um auf bestimmte Ereignisse aufmerksam zu machen. Die Signale zum Blinken kommen hier in gleichen Abständen. Zum stoppen oder starten kann dann das jeweilige Signal auf 1 oder -1 gesetzt werden.

' Fltk_Bulb_Dark_Blinking.bas

' Last one of the bulb-idea. Now all dark bulbs blinking.
' Push buttons to stop blinking.

#include once "fltk-c.bi"

dim as zstring ptr bulb_clear_xpm(...) => {@"32 32 24 1", _
@"  c None",@". c #3F3924",@"+  c #414340",@"@  c #554D2D",@"#  c #6B6D6A", _
@"$ c #726E50",@"%  c #7D7F7D",@"&  c #8A865C",@"*  c #8A8C89",@"=  c #969462", _
@"- c #9C9E98",@";  c #A2A081",@">   c #B5B569",@",  c #B2B592",@"'  c #BCB988", _
@") c #BCBEBB",@"!  c #CCCECB",@"~  c #D4D3A1",@"{  c #D9D7BB",@"] c #DDDFDC", _
@"^ c #E7E9E6",@"/  c #F1F3C6",@"(  c #EFF1ED",@"_  c #F5F7F4", _
@"                                ", _
@"              %%%%              ", _
@"           *-)!]]!)-*           ", _
@"          %!!!]]^]]]]%          ", _
@"         *!!]((((((^]^-         ", _
@"        %!!^((((((((]](%        ", _
@"        )!^(((((((((^]]]        ", _
@"       *)](((((((((((]]^*       ", _
@"       -!^(((((((((((]]^-       ", _
@"       )!((((((___(((^^^!       ", _
@"       )]^((((_____(^^^^!       ", _
@"       )]](((______((^^^!       ", _
@"       -]](((_____(^(^^^)       ", _
@"       *]]^^]]]^(^]!((^(-       ", _
@"        )^^^^^^]!]]^(((]        ", _
@"        *)^^^^((((^(((]*        ", _
@"         *!((]((((](((*         ", _
@"          -((]^__^]__!          ", _
@"          %((^)(()^__-          ", _
@"           )]!-!)-)!(#          ", _
@"           %!_!]]!^^-           ", _
@"           @&;///({$            ", _
@"           @>~,;;;;=@           ", _
@"           @>_///~'$            ", _
@"           @>///~~'=@           ", _
@"           @>_///~'&@           ", _
@"           @>///~~'&@           ", _
@"            .@$&$$@.            ", _
@"              %)-#              ", _
@"              +##+              ", _
@"                                ", _
@"                                "}

dim as zstring ptr bulb_yellow_xpm(...) => {@"32 32 24 1", _
@"  c None",@". c #4B442C",@"+  c #644406",@"@  c #58471A",@"#  c #7D500A", _
@"$ c #6D6F6E",@"%  c #767152",@"&  c #928149",@"*  c #D17A23",@"=  c #A5872D", _
@"- c #FC7A0B",@";  c #AAA993",@">   c #FF9E12",@",  c #B8B469",@"'  c #CFB14B", _
@") c #BBB47F",@"!  c #FFB01D",@"~  c #F4B840",@"{  c #FFC02E",@"] c #FECD37", _
@"^ c #FFD850",@"/  c #FDE26D",@"(  c #E4E4B0",@"_  c #F4F5DA", _
@"                                ", _
@"              ++++              ", _
@"           +#**>>~=#+           ", _
@"          +*-->!{!>!'+          ", _
@"         #--!^^^^^^{!^#         ", _
@"        +--~^^^^^^^^{!/+        ", _
@"        *-~^^^^^^^^^]!!,        ", _
@"       +->^^^^^^^^^^^!!~+       ", _
@"       #-{^^^^////^^^{!{&       ", _
@"       *-]^^^///////]{{{)       ", _
@"       *>]^^^///////]{{{)       ", _
@"       *>{^^///////^^{{{)       ", _
@"       #!!^^^//////~^]{{&       ", _
@"       +!!{]>>!~^~>-^]{/+       ", _
@"        ={{{!{~>>>!{^^^(        ", _
@"        #={{{{^///{^^^(+        ", _
@"         #']^~^///~/^(+         ", _
@"          +^^''/[komm]LycnLwßß[/komm]/)          ", _
@"          @/^'&//&'//&          ", _
@"           &==@==@&&(@          ", _
@"           .,^'''=,)%           ", _
@"           %%;_(___%            ", _
@"           .,(;;;;;&.           ", _
@"           @,__((()%            ", _
@"           .,_((())&.           ", _
@"           @,__((()&.           ", _
@"           .,_((())&.           ", _
@"            ..%%%%..            ", _
@"              $;;$              ", _
@"              .$$.              ", _
@"                                ", _
@"                                "}

dim as zstring ptr bulb_red_xpm(...) => {@"32 32 24 1", _
@"  c None",@". c #4E482E",@"+  c #FF321C",@"@  c #BF5400",@"#  c #6D6F6E", _
@"$ c #FE4E4F",@"%  c #B86A1F",@"&  c #D56044",@"*  c #7F7A56",@"=  c #FE6073", _
@"- c #FD649F",@";  c #FF6B90",@">   c #EF8189",@",  c #A79B60",@"'  c #FF8BB7", _
@") c #ADAB8A",@"!  c #FF91CF",@"~  c #E2AE96",@"{  c #FFA1E2",@"] c #C7C787", _
@"^ c #FFB6FA",@"/  c #FBC5F4",@"(  c #E4DCE1",@"_  c #ECE9C3", _
@"                                ", _
@"              %%%%              ", _
@"           @%&=;;>>%@           ", _
@"          %;$+$==$+$/%          ", _
@"         %=+;!{{{{{;+>%         ", _
@"        %=+!!{{{{{{!=+/%        ", _
@"        =+!!{{{{{{{{'++(        ", _
@"       %$=!!{{{^^^{{!$+>%       ", _
@"       &+'!{{^^^^^^{!=$$%       ", _
@"       &+'!{{^^^^^^^!;=$~       ", _
@"       &+;!{^^^////^';;=~       ", _
@"       &+$!{^^/////{!';;~       ", _
@"       &++!{^^////^!{'';~       ", _
@"       %=$='$$='{'$+{!''%       ", _
@"        >=='=''$$$=;{!'(        ", _
@"        @>;'';^^/[komm]LydeXnsoJSAgICAgICAgIiwgXwpAIiAgICAgICAgIEB7JyE7Xl5eXideXiglICAgICAgICAgIiwgXwpAIiAgICAgICAgICAmYW1wO3t7LXsvL3snLwßß[/komm]/~          ", _
@"          %{{{-^^-^//~          ", _
@"           ~--$;;&-!/,          ", _
@"           *[komm]Lyc7Oy0tIS8pICAgICAgICAgICAiLCBfCkAiICAgICAgICAgICAuKilfX19fXyogICAgICAgICAgICAiLCBfCkAiICAgICAgICAgICAuLCYjeDVEOykpKSkpKi4gICAgICAgICAgICIsIF8KQCIgICAgICAgICAgIC4mI3g1RDsoX19fJiN4NUQ7KSogICAgICAgICAgICAiLCBfCkAiICAgICAgICAgICAuLF9fX18mI3g1RDsmI3g1RDssLiAgICAgICAgICAgIiwgXwpAIiAgICAgICAgICAgLiYjeDVEOyhfX18mI3g1RDssKi4gICAgICAgICAgICIsIF8KQCIgICAgICAgICAgIC4mI3g1RDtfX19fJiN4NUQ7JiN4NUQ7Ki4gICAgICAgICAgICIsIF8KQCIgICAgICAgICAgICAuLioqKiouLiAgICAgICAgICAgICIsIF8KQCIgICAgICAgICAgICAgICMoKSMgICAgICAgICAgICAgICIsIF8KQCIgICAgICAgICAgICAgIC4jIy4gICAgICAgICAgICAgICIsIF8KQCIgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICIsIF8KQCIgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICJ9CgpkaW0gYXMgenN0cmluZyBwdHIgYnVsYl9ibHVlX3hwbSguLi4pID0mZ3Q7IHtAIjMyIDMyIDI0IDEiLCBfCkAiICBjIE5vbmUiLEAiLiBjICM0MDNEMkYiLEAiKyAgYyAjNTU0RDJDIixAIkAgIGMgIzE4NjRGQSIsQCIjICBjICM3MjZFNTAiLCBfCkAiJCBjICM2RDZGNkUiLEAiJSAgYyAjMzg3OUZDIixAIiZhbXA7ICBjICM2Mjg0RDEiLEAiKiAgYyAjOEE4NjVDIixAIj0gIGMgIzY2OTJGRiIsIF8KQCItIGMgIzc1OUVGRCIsQCI7ICBjICM4REEyRDMiLEAiJmd0OyAgIGMgI0E1QTY5NyIsQCIsICBjICNBQkE5N0UiLEAiJyAgYyAjOTBBQ0ZFIiwgXwpAIikgYyAjQjVCNTY5IixAIiEgIGMgI0E0QkRGRiIsQCJöICBjICNCNkNBRkYiLEAieyAgYyAjRDJEMUEzIixAIiYjeDVEOyBjICNDMEQwRkUiLCBfCkAiXiBjICNDQUQ2RkUiLEAiLyAgYyAjRDdFMUZGIixAIiggIGMgI0U5RUJFOCIsQCJfICBjICNGMkY0QzciLCBfCkAiICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAiLCBfCkAiICAgICAgICAgICAgICBAQEBAICAgICAgICAgICAgICAiLCBfCkAiICAgICAgICAgICBAJS0nJycnLT1AICAgICAgICAgICAiLCBfCkAiICAgICAgICAgIEAnLT0tJyctJS1öQCAgICAgICAgICAiLCBfCkAiICAgICAgICAgJSctIX4mI3g1RDsmI3g1RDsmI3g1RDsmI3g1RDtöJz1öJSAgICAgICAgICIsIF8KQCIgICAgICAgIEAnLSYjeDVEO35öJiN4NUQ7JiN4NUQ7JiN4NUQ7fn5öJz1eQCAgICAgICAgIiwgXwpAIiAgICAgICAgLS1öfn4mI3g1RDsmI3g1RDsmI3g1RDsmI3g1RDsmI3g1RDsmI3g1RDtöIT09JiN4NUQ7ICAgICAgICAiLCBfCkAiICAgICAgICUtJ35öJiN4NUQ7JiN4NUQ7Xl5eXiYjeDVEOyYjeDVEO34tPSElICAgICAgICIsIF8KQCIgICAgICAgJT0hfn4mI3g1RDteXl5eXl5efictJz0gICAgICAgIiwgXwpAIiAgICAgICA9JX5öJiN4NUQ7JiN4NUQ7Xi8vLy8vXn4nJychICAgICAgICIsIF8KQCIgICAgICAgLSUhfiYjeDVEO14vLy8vLy8vfiEnJyEgICAgICAgIiwgXwpAIiAgICAgICA9PSdöJiN4NUQ7Xi8vLy8vL15öIScnISAgICAgICAiLCBfCkAiICAgICAgICU9PX4mI3g1RDteLy8vLy8vfiYjeDVEO34hIS0gICAgICAgIiwgXwpAIiAgICAgICAlLS0nIT0nJ35efi09JiN4NUQ7fiEmI3g1RDslICAgICAgICIsIF8KQCIgICAgICAgIC0nJyEnfiEtLS0nIV5öfl4gICAgICAgICIsIF8KQCIgICAgICAgIEAtISFöIV4vLy8hXl4mI3g1RDteQCAgICAgICAgIiwgXwpAIiAgICAgICAgIEBöfn4hXi8vLyEvLy8lICAgICAgICAgIiwgXwpAIiAgICAgICAgICAlXiYjeDVEOyEmI3g1RDsvL15öLy8hICAgICAgICAgICIsIF8KQCIgICAgICAgICAgQF4mI3g1RDtöJy8ß[/komm]/!//(-          ", _
@"           !!'-''='~/%          ", _
@"           &]~''''!/;           ", _
@"           +*,____{#            ", _
@"           +){,>>>,*+           ", _
@"           +)(___{,#            ", _
@"           +)___{{,*+           ", _
@"           +)(___{,*+           ", _
@"           +)___{{{*+           ", _
@"            .+#*##+.            ", _
@"              $>>$              ", _
@"              .$$.              ", _
@"                                ", _
@"                                "}

dim as zstring ptr bulb_green_xpm(...) => {@"32 32 24 1", _
@"  c None",@". c #250CB9",@"+  c #4F482D",@"@  c #B324A5",@"#  c #6D51BD", _
@"$ c #787579",@"%  c #BC5EAE",@"&  c #7E7A56",@"*  c #C998BA",@"=  c #A9AAB6", _
@"- c #B3AD8F",@";  c #B4B374",@">   c #95C78E",@",  c #9CD836",@"'  c #A0D086", _
@") c #B7D353",@"!  c #A5E261",@"~  c #B7E780",@"{  c #C4F099",@"] c #DBEEAF", _
@"^ c #EAE9C3",@"/  c #D0F4AC",@"(  c #EDE6EA",@"_  c #E4F9C8", _
@"                                ", _
@"              @@@@              ", _
@"           @@*;~~;*@@           ", _
@"          @;),!!!!,!^@          ", _
@"         @')~//////~,/@         ", _
@"        @~)/////////!,_@        ", _
@"        -){/////////{!,*        ", _
@"       @)~{/////////{!!/@       ", _
@"       %,{{////]]]//{!!!%       ", _
@"       *,{{///_____]{~!!*       ", _
@"       -,~{//]______{~~!*       ", _
@"       *,!///______/{{~~*       ", _
@"       %,!{//_____]//{~~%       ", _
@"       @~!!{,!~/]/),/{{/@       ", _
@"        =!~~!{{)!)~~//{*        ", _
@"        @*~~{~]___{///(@        ", _
@"         @-{/~/___{_](@         ", _
@"          #//{/__]/__*          ", _
@"          .//[komm]LydfXydfX14jICAgICAgICAgICIsIF8KQCIgICAgICAgICAgID17fiQnJyMnLwßß[/komm]^.          ", _
@"           .={>''>{_#           ", _
@"           &&-^^^^^&            ", _
@"           +;^-----&+           ", _
@"           +;(^_]^-&            ", _
@"           +;^^^^;;&+           ", _
@"           +;(^_^];&+           ", _
@"           +;^_^^^;&+           ", _
@"            ++&&&&++            ", _
@"              $==$              ", _
@"              +$$+              ", _
@"                                ", _
@"                                "}

dim as zstring ptr bulb_blue_xpm(...) => {@"32 32 24 1", _
@"  c None",@". c #403D2F",@"+  c #554D2C",@"@  c #1864FA",@"#  c #726E50", _
@"$ c #6D6F6E",@"%  c #3879FC",@"&  c #6284D1",@"*  c #8A865C",@"=  c #6692FF", _
@"- c #759EFD",@";  c #8DA2D3",@">   c #A5A697",@",  c #ABA97E",@"'  c #90ACFE", _
@") c #B5B569",@"!  c #A4BDFF",@"~  c #B6CAFF",@"{  c #D2D1A3",@"] c #C0D0FE", _
@"^ c #CAD6FE",@"/  c #D7E1FF",@"(  c #E9EBE8",@"_  c #F2F4C7", _
@"                                ", _
@"              @@@@              ", _
@"           @%-''''-=@           ", _
@"          @'-=-''-%-~@          ", _
@"         %'-!~]]]]~'=~%         ", _
@"        @'-]~~]]]~~~'=^@        ", _
@"        --~~~]]]]]]~!==]        ", _
@"       %-'~~]]^^^^]]~-=!%       ", _
@"       %=!~~]^^^^^^^~'-'=       ", _
@"       =%~~]]^/////^~'''!       ", _
@"       -%!~]^///////~!''!       ", _
@"       =='~]^//////^~!''!       ", _
@"       %==~]^//////~]~!!-       ", _
@"       %--'!=''~^~-=]~!]%       ", _
@"        -''!'~!---'!^~~^        ", _
@"        @-!!~!^///!^^]^@        ", _
@"         @~~~!^///!///%         ", _
@"          %^]!]//^~//!          ", _
@"          @^]~'//!//(-          ", _
@"           !!'-''='~/%          ", _
@"           &]~''''!/;           ", _
@"           +*,____{#            ", _
@"           +){,>>>,*+           ", _
@"           +)(___{,#            ", _
@"           +)___{{,*+           ", _
@"           +)(___{,*+           ", _
@"           +)___{{{*+           ", _
@"            .+#*##+.            ", _
@"              $>>$              ", _
@"              .$$.              ", _
@"                                ", _
@"                                "}


dim shared as any ptr bulb_clear, bulb_yellow, bulb_red, bulb_blue, bulb_green

  bulb_clear = Fl_PixmapNew(@bulb_clear_xpm(0))
  bulb_yellow = Fl_PixmapNew(@bulb_yellow_xpm(0))
  bulb_red = Fl_PixmapNew(@bulb_red_xpm(0))
  bulb_green = Fl_PixmapNew(@bulb_green_xpm(0))
  bulb_blue = Fl_PixmapNew(@bulb_blue_xpm(0))

var win = Fl_Double_WindowNew(310,200,"Fltk Bulb Dark Blinking Pixmaps")

var box1 = Fl_BoxExNew(50+45*0,32,32,32)
Fl_WidgetSetImage box1,bulb_clear
var box2 = Fl_BoxExNew(50+45*1,32,32,32)
Fl_WidgetSetImage box2,bulb_yellow
var box3 = Fl_BoxExNew(50+45*2,32,32,32)
Fl_WidgetSetImage box3,bulb_red
var box4 = Fl_BoxExNew(50+45*3,32,32,32)
Fl_WidgetSetImage box4,bulb_green
var box5 = Fl_BoxExNew(50+45*4,32,32,32)
Fl_WidgetSetImage box5,bulb_blue

dim shared as byte signal1,signal2,signal3,signal4,signal5

dim shared as any ptr btn1
btn1 = Fl_ButtonNew( 42+45*0,100,40,40)
Fl_WidgetSetImage btn1,bulb_clear
dim shared as any ptr btn2
btn2 = Fl_ButtonNew( 42+45*1,100,40,40)
Fl_WidgetSetImage btn2,bulb_clear
dim shared as any ptr btn3
btn3 = Fl_ButtonNew( 42+45*2,100,40,40)
Fl_WidgetSetImage btn3,bulb_clear
dim shared as any ptr btn4
btn4 = Fl_ButtonNew( 42+45*3,100,40,40)
Fl_WidgetSetImage btn4,bulb_clear
dim shared as any ptr btn5
btn5 = Fl_ButtonNew( 42+45*4,100,40,40)
Fl_WidgetSetImage btn4,bulb_clear

sub ButtonCB cdecl (byval button as FL_WIDGET ptr)
  ? "Button pushed"
  Fl_WidgetSetImage button, bulb_clear
  if button = btn1 then signal1 = -1
  if button = btn2 then signal2 = -1
  if button = btn3 then signal3 = -1
  if button = btn4 then signal4 = -1
  if button = btn5 then signal5 = -1
end sub

' connect callbacks
Fl_WidgetSetCallback0 btn1, @ButtonCB
Fl_WidgetSetCallback0 btn2, @ButtonCB
Fl_WidgetSetCallback0 btn3, @ButtonCB
Fl_WidgetSetCallback0 btn4, @ButtonCB
Fl_WidgetSetCallback0 btn5, @ButtonCB

sub TimeoutHandler1 cdecl (byval btn as any ptr)
   select case signal1
      case 0
        signal1 = 1
        Fl_WidgetSetImage btn,bulb_yellow
      case 1
        signal1 = 0
        Fl_WidgetSetImage btn,bulb_red
    end select
    Fl_ReDraw()
  ' reapeat the timer
  Fl_RepeatTimeout(0.2, @TimeoutHandler1,btn)
end sub

sub TimeoutHandler2 cdecl (byval btn as any ptr)
    select case signal2
      case 0
        signal2 = 1
        Fl_WidgetSetImage btn,bulb_clear
      case 1
        signal2 = 0
        Fl_WidgetSetImage btn,bulb_yellow
    end select
    Fl_ReDraw()
  ' reapeat the timer
  Fl_RepeatTimeout(0.4, @TimeoutHandler2,btn)
end sub

sub TimeoutHandler3 cdecl (byval btn as any ptr)
    select case signal3
      case 0
        signal3 = 1
        Fl_WidgetSetImage btn,bulb_clear
      case 1
        signal3 = 0
        Fl_WidgetSetImage btn,bulb_red
    end select
    Fl_ReDraw()
  ' reapeat the timer
  Fl_RepeatTimeout(0.1, @TimeoutHandler3,btn)
end sub

sub TimeoutHandler4 cdecl (byval btn as any ptr)
    select case signal4
      case 0
        signal4 = 1
        Fl_WidgetSetImage btn,bulb_clear
      case 1
        signal4 = 0
        Fl_WidgetSetImage btn,bulb_green
    end select
    Fl_ReDraw()
  ' reapeat the timer
  Fl_RepeatTimeout(0.7, @TimeoutHandler4,btn)
end sub

sub TimeoutHandler5 cdecl (byval btn as any ptr)
    select case signal5
      case 0
        signal5 = 1
        Fl_WidgetSetImage btn,bulb_red
      case 1
        signal5 = 0
        Fl_WidgetSetImage btn,bulb_blue
    end select
    Fl_ReDraw()
  ' reapeat the timer
  Fl_RepeatTimeout(0.5, @TimeoutHandler5,btn)
end sub

Fl_WindowShow win
Fl_AddTimeout 0, @TimeoutHandler1,btn1
Fl_AddTimeout 0, @TimeoutHandler2,btn2
Fl_AddTimeout 0, @TimeoutHandler3,btn3
Fl_AddTimeout 0, @TimeoutHandler4,btn4
Fl_AddTimeout 0, @TimeoutHandler5,btn5
Fl_Run

(Diese "komm-Tags" erscheinen offenbar irrtümlich. Beim Editieren sieht man sie nicht einmal. Bitte die Tags komplett aus dem Code entfernen, sodass alle Bild-Zeilen gleich lang sind)


button_blinking


* Der Begriff "Buttonologie" wurde von mir erfunden.

 

Zusätzliche Informationen und Funktionen
  • Das Tutorial wurde am 01.10.2019 von MitgliedKnatterton angelegt.
  • Die aktuellste Version wurde am 13.10.2019 von MitgliedKnatterton gespeichert.
  Bearbeiten Bearbeiten  

  Versionen Versionen