Toc Gallery Index Tree Gtk.Color_Selection

Screenshot

No screeshot

Hierarchy

Description

A Gtk_Color_Selection widget is a complex dialog that allows the user to select a color based either on its (Red, Green, Blue) or its (Hue, Saturation, Value). An additional field is provided to select the opacity of the color (this is usually called the alpha channel).

See Gtk.Color_Selection_Dialog for a version of this widget that comes with its own dialog.

See Gtk.Extra.Color_Combo for a different way to select colors.

Types

  • type Color_Array is array (Color_Index) of Gdouble;
    Array that indicates the currently selected color. All the values are between 0.0 and 1.0 (a percentage value). They should be converted to absolute values before using them to create a new color, with the following piece of code: Absolute := To_Absolute (Color_Array (Index))
  • type Color_Index is (Red, Green, Blue, Opacity);
    Used as an index to the table used to set and get the currently selected color.
  • type Gtk_Color_Selection is access all Gtk_Color_Selection_Record'Class;
  • type Gtk_Color_Selection_Change_Palette_With_Screen_Func is access procedure (Screen : Gdk.Gdk_Screen; Colors : Gdk.Color.Gdk_Color_Array);
    This function should save the new palette contents, and update the Gtk_Settings property "gtk-color-palette" so all Gtk_Color_Selection widgets will be modified, including the current one. For instance, you would do: Set_String_Property (Get_Default, Gtk_Color_Palette, Palette_To_String (Colors), "Foo");
  • type Gtk_Color_Selection_Record is new Gtk.Box.Gtk_Box_Record with private;

Subprograms

  • procedure Gtk_New (Widget : out Gtk_Color_Selection);
    procedure Initialize (Widget : access Gtk_Color_Selection_Record'Class);
    Creates or initiailizes a new color selection widget.
  • function Get_Type return Glib.GType;
    Return the internal value associated with a Gtk_Color_Selection.
  • procedure Set_Current_Color (Colorsel : access Gtk_Color_Selection_Record; Color : Gdk.Color.Gdk_Color);
    procedure Get_Current_Color (Colorsel : access Gtk_Color_Selection_Record; Color : out Gdk.Color.Gdk_Color);
    Set the current color of the Colorsel. When called for the first time, the original color will the set to Color as well.
  • procedure Set_Previous_Color (Colorsel : access Gtk_Color_Selection_Record; Color : Gdk.Color.Gdk_Color);
    procedure Get_Previous_Color (Colorsel : access Gtk_Color_Selection_Record; Color : out Gdk.Color.Gdk_Color);
    Set the previous color. This procedure should not be called without analysis, as it might seem confusing to see that color change. Calling Set_Current_Color for the first time will also set this color.
  • function Is_Adjusting (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
    Get the current state of the Colorsel. Return TRue if the user is currently dragging a color around, False if the selection has stopped.
  • function To_Absolute (Color : Gdouble) return Gushort;
    Convert from a percentage value as returned by Get_Color to an absolute value as can be used with Gdk_Color.
  • function To_Percent (Color : Gushort) return Gdouble;
    Convert from an absolute value as used in Gdk_Color to a percentage value as used in Set_Color.
  • Opacity

    The color selection widget allows you optionally to select the opacity of the color
  • procedure Set_Has_Opacity_Control (Colorsel : access Gtk_Color_Selection_Record; Has_Opacity : Boolean);
    function Get_Has_Opacity_Control (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
    Set the Colorsel to use or not use opacity. An additional field is displayed to select the opacity if needed.
  • procedure Set_Previous_Alpha (Colorsel : access Gtk_Color_Selection_Record; Alpha : Guint16);
    function Get_Previous_Alpha (Colorsel : access Gtk_Color_Selection_Record) return Guint16;
    Set the previous opacity to Alpha. This procedure should not be called without analysis, as it might seem confusing to see that value change.
  • procedure Set_Current_Alpha (Colorsel : access Gtk_Color_Selection_Record; Alpha : Guint16);
    function Get_Current_Alpha (Colorsel : access Gtk_Color_Selection_Record) return Guint16;
    Set the current opacity to be Alpha. When called for the first time, the original opacity will be set too.
  • Palette

    The color selection widget can optionally display a palette, which the user can change dynamically. This palette helps selecting colors for the user, who can chose faster among a limited set of colors.
  • procedure Set_Has_Palette (Colorsel : access Gtk_Color_Selection_Record; Has_Palette : Boolean);
    function Get_Has_Palette (Colorsel : access Gtk_Color_Selection_Record) return Boolean;
    If Has_Palette is True, then set the Colorsel to show the palette. Hide the palette otherwise.
  • function Palette_From_String (Str : String) return Gdk.Color.Gdk_Color_Array;
    Parses a color palette string; this string is a colon-separated list of color names readable by Gdk.Color.Parse. An empty array is returned if Str couldn't be parsed
  • function Palette_To_String (Colors : Gdk.Color.Gdk_Color_Array) return String;
    Encodes a palette as a string, useful for persistent storage.
  • function Set_Change_Palette_With_Screen_Hook (Func : Gtk_Color_Selection_Change_Palette_With_Screen_Func) return Gtk_Color_Selection_Change_Palette_With_Screen_Func;
    Installs a global function to be called whenever the user tries to modify the palette in a color selection. Return value: the previous change palette hook (that was replaced).

Signals

  • color_changed
    procedure Handler (Selection : access Gtk_Color_Selection_Record'Class);
    Called every time a new color is selected in the dialog

Properties

  • Current_Alpha_Property
    Uint
    The current opacity value (0 fully transparent, 65535 fully
  • Current_Color_Property
    Boxed
    The current color
  • Has_Opacity_Control_Property
    Boolean
    Whether the color selector should allow setting opacity
  • Has_Palette_Property
    Boolean
    Whether a palette should be used

Testgtk source code

This code is part of testgtk, a demo application packaged with GtkAda. Testgtk demonstrates the various widgets of GtkAda
----------------------------------------------------------------------- -- GtkAda - Ada95 binding for the Gimp Toolkit -- -- -- -- Copyright (C) 1998-1999 -- -- Emmanuel Briot, Joel Brobecker and Arnaud Charlet -- -- Copyright (C) 2000-2006 AdaCore -- -- -- -- This library is free software; you can redistribute it and/or -- -- modify it under the terms of the GNU General Public -- -- License as published by the Free Software Foundation; either -- -- version 2 of the License, or (at your option) any later version. -- -- -- -- This library is distributed in the hope that it will be useful, -- -- but WITHOUT ANY WARRANTY; without even the implied warranty of -- -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -- -- General Public License for more details. -- -- -- -- You should have received a copy of the GNU General Public -- -- License along with this library; if not, write to the -- -- Free Software Foundation, Inc., 59 Temple Place - Suite 330, -- -- Boston, MA 02111-1307, USA. -- -- -- -- -- -- -- -- -- -- ----------------------------------------------------------------------- with Gdk; use Gdk; with Gdk.Color; use Gdk.Color; with Gtk; use Gtk; with Glib; use Glib; with Gtk.Color_Selection; use Gtk.Color_Selection; with Gtk.Color_Selection_Dialog; use Gtk.Color_Selection_Dialog; with Gtk.Enums; with Gtk.Handlers; with Gtk.Settings; use Gtk.Settings; with Common; use Common; with Ada.Text_IO; use Ada.Text_IO; with Gtk.Widget; use Gtk.Widget; package body Create_Color_Selection is type Gtk_Color_Dialog_Access is access all Gtk_Color_Selection_Dialog; package Destroy_Dialog_Cb is new Handlers.User_Callback (Gtk_Color_Selection_Dialog_Record, Gtk_Color_Dialog_Access); Dialog : aliased Gtk_Color_Selection_Dialog; package Color_Sel_Cb is new Handlers.Callback (Gtk_Color_Selection_Dialog_Record); procedure Destroy_Dialog (Win : access Gtk_Color_Selection_Dialog_Record'Class; Ptr : Gtk_Color_Dialog_Access); -- Called when the dialog is destroyed procedure On_Palette_Changed (Screen : Gdk.Gdk_Screen; Colors : Gdk.Color.Gdk_Color_Array); -- Called when the palette is changed ---------- -- Help -- ---------- function Help return String is begin return "This widget provides an easy way to select new colors." & " This is a very specific widget, and most applications won't" & " need it. There are two versions, one with a dialog, and one" & " without."; end Help; -------------------- -- Destroy_Dialog -- -------------------- procedure Destroy_Dialog (Win : access Gtk_Color_Selection_Dialog_Record'Class; Ptr : in Gtk_Color_Dialog_Access) is pragma Warnings (Off, Win); begin Ptr.all := null; end Destroy_Dialog; ------------------ -- Close_Window -- ------------------ procedure Close_Window (Win : access Gtk.Widget.Gtk_Widget_Record'Class) is begin Destroy (Win); end Close_Window; ------------------------ -- On_Palette_Changed -- ------------------------ procedure On_Palette_Changed (Screen : Gdk.Gdk_Screen; Colors : Gdk.Color.Gdk_Color_Array) is pragma Unreferenced (Screen); Str : constant String := Palette_To_String (Colors); begin Put_Line ("Palette has changed: "); Put_Line ("Palette=" & Str); Set_String_Property (Get_Default, Gtk_Color_Palette, Palette_To_String (Colors), "On_Palette_Changed"); end On_Palette_Changed; -------------- -- Color_Ok -- -------------- procedure Color_Ok (Dialog : access Gtk_Color_Selection_Dialog_Record'Class) is Color : Gdk_Color; begin Get_Current_Color (Get_Colorsel (Dialog), Color); Put_Line ("Selected color is: "); Put ("Red=" & Guint16'Image (Red (Color))); Put (" Green=" & Guint16'Image (Green (Color))); Put (" Blue=" & Guint16'Image (Blue (Color))); Put (" Alpha=" & Guint16'Image (Get_Current_Alpha (Get_Colorsel (Dialog)))); end Color_Ok; --------- -- Run -- --------- procedure Run (Frame : access Gtk_Frame_Record'Class) is pragma Warnings (Off, Frame); Old : Gtk_Color_Selection_Change_Palette_With_Screen_Func; begin if Dialog = null then Gtk_New (Dialog, Title => "Color Selection Dialog"); Set_Position (Dialog, Enums.Win_Pos_Mouse); Set_Has_Palette (Get_Colorsel (Dialog), True); Set_Has_Opacity_Control (Get_Colorsel (Dialog), True); Old := Set_Change_Palette_With_Screen_Hook (On_Palette_Changed'Access); Destroy_Dialog_Cb.Connect (Dialog, "destroy", Destroy_Dialog_Cb.To_Marshaller (Destroy_Dialog'Access), Dialog'Access); Color_Sel_Cb.Object_Connect (Get_OK_Button (Dialog), "clicked", Color_Sel_Cb.To_Marshaller (Color_Ok'Access), Slot_Object => Dialog); Widget_Handler.Object_Connect (Get_Cancel_Button (Dialog), "clicked", Widget_Handler.To_Marshaller (Close_Window'Access), Slot_Object => Dialog); Show (Dialog); else Destroy (Dialog); end if; end Run; end Create_Color_Selection;

Alphabetical Index