1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98
| ;======================================================================
; Module/File: Button_AddImage.pb
; Function: Button: Add loaded or stock-imaged to pb-Button with alignment - Linux
; Author: Omi
; Date: Oct. 14, 2014
; Version: 0.3, updt. utf8-handling, activate images in Buttons
; Target Compiler: PureBasic 5.22/5.30
; Target OS: (X/K)ubuntu 32/64, Ascii/Uni
; License: Free, unrestricted, no warranty
;======================================================================
EnableExplicit
ImportC ""
gtk_button_set_image(*button.GtkButton, *image.GtkWidget)
gtk_button_set_image_position(*button.GtkButton, position)
gtk_button_set_label(*button.GtkButton, label.p-utf8)
gtk_image_clear(*image.GtkWidget)
gtk_button_set_alignment(*button.GtkButton, xalign.f, yalign.f)
gtk_image_new_from_stock(stock_id.p-utf8, size)
gtk_image_new_from_file(filename.p-utf8)
g_object_set(*object.GObject, property_name.p-utf8, *data, v= 0)
EndImport
#MainWin= 0
Enumeration
#myButton1
#myButton2
#myButton3
#myButton4
#myButton5
EndEnumeration
Global.i gEvent, gQuit
Global *image1, *image2, *image3, *image4
Procedure ButtonImages_Activate(Show)
g_object_set(gtk_settings_get_default_(), "gtk-button-images", Show, #Null)
EndProcedure
Procedure ButtonGadget_AddImage(Gadget, *Pic, Label.s, Alignment)
gtk_button_set_image(GadgetID(Gadget), *Pic)
gtk_button_set_label(GadgetID(Gadget), Label)
gtk_button_set_image_position(GadgetID(Gadget), Alignment)
EndProcedure
If OpenWindow(#MainWin, #PB_Ignore, #PB_Ignore, 250, 250, "Linux-Test Button with image")
;if icons are not shown, uncomment the following line ...
; ButtonImages_Activate(#True)
;for loading icons choose your own image-adresses ...
; *image1= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Back.png")
; *image2= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Find.png")
; *image3= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Previous.png")
; *image4= gtk_image_new_from_file("/home/charly-xubuntu/Programming/PBSource/Icons/Own/Stop sign.png")
;or use stock-images ...
*image1= gtk_image_new_from_stock("gtk-go-back", #GTK_ICON_SIZE_MENU); #GTK_ICON_SIZE_BUTTON
*image2= gtk_image_new_from_stock("gtk-find", #GTK_ICON_SIZE_MENU)
*image3= gtk_image_new_from_stock("gtk-goto-first", #GTK_ICON_SIZE_MENU)
*image4= gtk_image_new_from_stock("gtk-stop", #GTK_ICON_SIZE_MENU)
ButtonGadget(#myButton1, 5, 5, 200, 30, " Button with image", #PB_Button_Toggle)
ButtonGadget_AddImage(#myButton1, *image1, "1. Button with image", #GTK_POS_LEFT)
ButtonGadget(#myButton2, 5, 40, 200, 30, " Button with image")
ButtonGadget_AddImage(#myButton2, *image2, "2. Button with image", #GTK_POS_RIGHT)
ButtonGadget(#myButton3, 5, 75, 200, 50, " Button with image")
ButtonGadget_AddImage(#myButton3, *image3, "3. Button with image", #GTK_POS_TOP)
ButtonGadget(#myButton4, 5, 130, 200, 50, " Button with image")
ButtonGadget_AddImage(#myButton4, *image4, "4. Button with image", #GTK_POS_BOTTOM)
ButtonGadget(#myButton5, 5, 185, 200, 50, "Button with alignment", #PB_Button_Right)
gtk_button_set_alignment(GadgetID(#myButton5), 1.0, 1.0); geht nur über ImportC
Else
End
EndIf
Repeat
gEvent = WaitWindowEvent()
If EventWindow()= #MainWin
Select gEvent
Case #PB_Event_CloseWindow
gQuit= #True
EndSelect
EndIf
Until gQuit
;free image-memory...
gtk_image_clear(*image1)
gtk_image_clear(*image2)
gtk_image_clear(*image3)
gtk_image_clear(*image4)
End |
Partager