diff options
| author | Tomas Bzatek <tbzatek@redhat.com> | 2024-12-24 12:41:48 +0100 |
|---|---|---|
| committer | Tomas Bzatek <tbzatek@redhat.com> | 2025-11-27 19:39:51 +0100 |
| commit | 1b2b4bb4f3ecc034a6e9364d8768e50b167a9680 (patch) | |
| tree | 065ddde53b64f7957a30b7dc9d83a748f309868c /libgtk_kylix/GTKPixbuf.pas | |
| parent | b9703b29819b619037cc282d719c187e51bacd30 (diff) | |
| download | tuxcmd-1b2b4bb4f3ecc034a6e9364d8768e50b167a9680.tar.xz | |
Rough GTK3 port
Diffstat (limited to 'libgtk_kylix/GTKPixbuf.pas')
| -rw-r--r-- | libgtk_kylix/GTKPixbuf.pas | 47 |
1 files changed, 19 insertions, 28 deletions
diff --git a/libgtk_kylix/GTKPixbuf.pas b/libgtk_kylix/GTKPixbuf.pas index c296add..c199ac4 100644 --- a/libgtk_kylix/GTKPixbuf.pas +++ b/libgtk_kylix/GTKPixbuf.pas @@ -1,6 +1,5 @@ (* GTK-Kylix Library: GTKPixbuf - Image handling routines - Version 0.6.2 (last updated 2003-03-30) Copyright (C) 2003 Tomas Bzatek <tbzatek@users.sourceforge.net> This library is free software; you can redistribute it and/or @@ -24,7 +23,7 @@ unit GTKPixbuf; interface -uses lazglib2, gdk2pixbuf, gtk2, Classes, GTKControls, GTKStdCtrls; +uses lazglib2, lazgobject2, lazgdk3, lazgtk3, lazgdkpixbuf2, Classes, GTKControls; type TGTKIconSize = (isInvalid, isMenu, isSmallToolbar, isLargeToolbar, isButton, isDND, isDialog); @@ -39,16 +38,14 @@ type public FPixbuf: PGdkPixbuf; constructor Create(AOwner: TComponent); override; - constructor CreateNew(AOwner: TComponent; const Width, Height, BPP: integer; const HasAlpha: boolean); destructor Destroy; override; function LoadFromFile(const FileName: string): boolean; - function LoadFromXPM(const Data: PPChar): boolean; - function LoadFromInline(Data: Pointer): boolean; + function LoadFromResource(ResourcePath: string): boolean; + function LoadFromIconTheme(IconName: string; IconSize: Integer): boolean; procedure Fill(const Pixel: Cardinal); procedure ScaleSimple(const DestWidth, DestHeight: integer); function Copy: PGdkPixbuf; procedure CopyArea(Source: TGDKPixbuf; SourceX, SourceY, SourceWidth, SourceHeight, DestX, DestY: integer); - procedure SetFromStock(Stock_ID: string; IconSize: TGTKIconSize); published property Width: integer read GetWidth; property Height: integer read GetHeight; @@ -56,7 +53,7 @@ type end; (****************************************** TGTKIMAGE ***************************************************************************) - TGTKImage = class(TGTKMisc) + TGTKImage = class(TGTKControl) private protected public @@ -66,7 +63,7 @@ type procedure SetFromPixbuf(Pixbuf: TGDKPixbuf); function GetPixbuf: PGdkPixbuf; procedure CopyFromPixbuf(Pixbuf: TGDKPixbuf); - procedure SetFromStock(Stock_ID: string; IconSize: TGTKIconSize); + procedure SetFromIconName(IconName: string; IconSize: TGTKIconSize); end; (********************************************************************************************************************************) @@ -84,15 +81,9 @@ begin FPixbuf := nil; end; -constructor TGDKPixbuf.CreateNew(AOwner: TComponent; const Width, Height, BPP: integer; const HasAlpha: boolean); -begin - inherited Create(AOwner); - FPixbuf := gdk_pixbuf_new(GDK_COLORSPACE_RGB, HasAlpha, BPP, Width, Height); -end; - destructor TGDKPixbuf.Destroy; begin - if FPixbuf <> nil then gdk_pixbuf_unref(FPixbuf); + if FPixbuf <> nil then g_object_unref(FPixbuf); inherited Destroy; end; @@ -121,23 +112,29 @@ begin if P <> nil then FPixbuf := P; end; -function TGDKPixbuf.LoadFromXPM(const Data: PPChar): boolean; +function TGDKPixbuf.LoadFromResource(ResourcePath: string): boolean; var P: Pointer; + Error: PGError; begin - P := gdk_pixbuf_new_from_xpm_data(Data); + Error := nil; + P := gdk_pixbuf_new_from_resource(PChar(ResourcePath), @Error); Result := P <> nil; + if Error <> nil then begin + WriteLn('TGDKPixbuf.LoadFromResource error: ', Error^.message); + g_error_free(Error); + end; if P <> nil then FPixbuf := P; end; -function TGDKPixbuf.LoadFromInline(Data: Pointer): boolean; +function TGDKPixbuf.LoadFromIconTheme(IconName: string; IconSize: Integer): boolean; var P: Pointer; Error: PGError; begin Error := nil; - P := gdk_pixbuf_new_from_inline(-1, Pguint8(Data)^, True, @Error); + P := gtk_icon_theme_load_icon(gtk_icon_theme_get_default(), PChar(IconName), IconSize, [], @Error); Result := P <> nil; if Error <> nil then begin - WriteLn('TGDKPixbuf.LoadFromInline error: ', Error^.message); + WriteLn('TGDKPixbuf.LoadFromIconTheme error: ', Error^.message); g_error_free(Error); end; if P <> nil then FPixbuf := P; @@ -163,12 +160,6 @@ begin gdk_pixbuf_copy_area(Source.FPixbuf, SourceX, SourceY, SourceWidth, SourceHeight, FPixbuf, DestX, DestY); end; -procedure TGDKPixbuf.SetFromStock(Stock_ID: string; IconSize: TGTKIconSize); -begin - FPixbuf := gtk_widget_render_icon(gtk_label_new(nil), PChar(Stock_ID), Ord(IconSize), nil); -end; - - (********************************************************************************************************************************) (********************************************************************************************************************************) constructor TGTKImage.Create(AOwner: TComponent); @@ -203,9 +194,9 @@ begin gtk_image_set_from_pixbuf(PGtkImage(FWidget), Pixbuf.Copy); end; -procedure TGTKImage.SetFromStock(Stock_ID: string; IconSize: TGTKIconSize); +procedure TGTKImage.SetFromIconName(IconName: string; IconSize: TGTKIconSize); begin - gtk_image_set_from_stock(PGtkImage(FWidget), PChar(Stock_ID), Ord(IconSize)); + gtk_image_set_from_icon_name(PGtkImage(FWidget), PChar(IconName), lazgtk3.TGtkIconSize(IconSize)); end; (********************************************************************************************************************************) |
