; Module/File: Pixbuf_ScaleSimple.pb ; Function: Scale Pixbuf to size: w & h - Linux ; Author: Omi ; Date: Jun. 18, 2016 ; Version: 0.1 ; Target Compiler: PureBasic 5.22/5.31/5.4 ; Target OS: Linux: (X/K/L)ubuntu, Mint, 32/64, Ascii/Uni ;-------------------------------------------------------------- ;System icon are loaded by name as pixbufs (same as ImageID(#Image) and can be used everywhere, ImageID(#Image) is used. ;If Icon doesn't exist, '0' is returned and no Image is used -> NO CRASH !!! :-) EnableExplicit ;UsePNGImageDecoder(); :-) ImportC "" gtk_icon_theme_load_icon(*icon_theme.GtkIconTheme, icon_name.p-utf8, size, flags, *error.GError); gtk2.4+ gdk_pixbuf_scale_simple(*srcpixbuf, dest_width, dest_height, interp_type) EndImport Enumeration GtkIconLookupFlags #GTK_ICON_LOOKUP_ALL = 0; Not gtk-defined, own constant to clearify #GTK_ICON_LOOKUP_NO_SVG = 1 #GTK_ICON_LOOKUP_FORCE_SVG = 2 #GTK_ICON_LOOKUP_USE_BUILTIN = 4 #GTK_ICON_LOOKUP_GENERIC_FALLBACK = 8 #GTK_ICON_LOOKUP_FORCE_SIZE = 16 EndEnumeration Enumeration GdkInterpType; see https://developer.gnome.org/gdk-pixbuf/unstable/gdk-pixbuf-Scaling.html#GdkInterpType #GDK_INTERP_NEAREST #GDK_INTERP_TILES #GDK_INTERP_BILINEAR #GDK_INTERP_HYPER EndEnumeration ; Object constants #Win_Main = 0 Global.i gEvent, gEventWin, gQuit Global *gPixbuf Procedure IconTheme_LoadIconFromName(icon_name.s, icon_size, flags) Protected *error.GError Protected *pixbuf= gtk_icon_theme_load_icon(gtk_icon_theme_get_default_(), icon_name, icon_size, flags, @*error) If *error : Debug icon_name + ": " + PeekS(*error\message, -1, #PB_UTF8) : EndIf ProcedureReturn *pixbuf EndProcedure Procedure GdkPixbuf_Scale2wh(*srcpixbuf, w, h, interp_type, unref) Protected *pixbuf= gdk_pixbuf_scale_simple(*srcpixbuf, w, h, interp_type) If unref g_object_unref_(*srcpixbuf) EndIf ProcedureReturn *pixbuf EndProcedure Procedure Create_WinMain() If OpenWindow(#Win_Main, 300, 200, 550, 240, "System-scale pixbufs...", #PB_Window_SystemMenu | #PB_Window_ScreenCentered) SetWindowColor (#Win_Main, $CFFFFF) *gPixbuf= IconTheme_LoadIconFromName("find", 32, #GTK_ICON_LOOKUP_ALL) TextGadget (#PB_Any, 5, 5, 250, 22, "Scale Pixbuf from System icon 'find' ...") TextGadget (#PB_Any, 5, 30, 190, 22, "ImageGadget x 0.5:" + #LF$ + " Interp.: bilinear") ImageGadget (0, 200, 30, 16, 16, GdkPixbuf_Scale2wh(*gPixbuf, 16, 16, #GDK_INTERP_BILINEAR, #False)) TextGadget (#PB_Any, 5, 65, 190, 22, "ImageGadget x 1.0:" + #LF$ + " Orig. pixbuf!") ImageGadget (1, 200, 55, 32, 32, *gPixbuf, #PB_Image_Border) TextGadget (#PB_Any, 5, 100, 190, 22, "ButtonImageGadget x 1.5:" + #LF$ + " Interp.: tiles") ButtonImageGadget(2, 200, 95, 48, 48, GdkPixbuf_Scale2wh(*gPixbuf, 48, 48, #GDK_INTERP_TILES, #False)) TextGadget (#PB_Any, 5, 165, 190, 65, "ButtonImageGadget x 2.0" + #LF$ + " Interp.: nearest, tiles, " + #LF$ + " bilinear + hyper" + #LF$ + "See quality") ButtonImageGadget(3, 200, 160, 64, 64, GdkPixbuf_Scale2wh(*gPixbuf, 64, 64, #GDK_INTERP_NEAREST, #False)) ButtonImageGadget(4, 280, 160, 64, 64, GdkPixbuf_Scale2wh(*gPixbuf, 64, 64, #GDK_INTERP_TILES, #False)) ButtonImageGadget(5, 360, 160, 64, 64, GdkPixbuf_Scale2wh(*gPixbuf, 64, 64, #GDK_INTERP_BILINEAR, #False)) ButtonImageGadget(6, 440, 160, 64, 64, GdkPixbuf_Scale2wh(*gPixbuf, 64, 64, #GDK_INTERP_HYPER, #True)); now free *gPixbuf with #True EndIf EndProcedure Create_WinMain() Repeat gEvent= WaitWindowEvent() Select gEvent Case #PB_Event_CloseWindow gQuit= #True EndSelect Until gQuit ; IDE Options = PureBasic 5.44 LTS (Linux - x86) ; CursorPosition = 39 ; FirstLine = 9 ; Folding = - ; EnableUnicode ; EnableXP