You are not logged in.

#1 2012-12-20 13:41:57

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Gpick colour picker alternative

Hello,

There is gpick [1] colour picker but it has lua as a dependency which makes the whole package not quite lightweight.

Does anyone know a small alternative?

Regards

Robert

[1] http://code.google.com/p/gpick/

Offline

#2 2012-12-20 14:10:55

bjornoslav
Member
Registered: 2011-11-01
Posts: 137

Re: Gpick colour picker alternative

gcolor2?

PS: agave, too smile

Last edited by bjornoslav (2012-12-20 14:12:12)


asus ux303la, core i5@1.6ghz, 8 gb ram, 500gb hdd, hd4400 gpu, crux x64 with openbox

Offline

#3 2012-12-20 14:20:26

Gusar
Member
Registered: 2009-08-25
Posts: 3,408

Re: Gpick colour picker alternative

Run gtk-demo, double-click on "Color Selector"

Online

#4 2012-12-20 16:04:47

WonderWoofy
Member
From: Los Gatos, CA
Registered: 2012-05-19
Posts: 8,412

Re: Gpick colour picker alternative

Hey thats neato!!!  Thanks Gusar, I never knew that was on my machine.

Offline

#5 2012-12-20 20:54:12

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gpick colour picker alternative

Gusar wrote:

Run gtk-demo, double-click on "Color Selector"

This is very nice. Can the color selector be called directly?

Regards

Offline

#6 2012-12-31 17:38:16

orschiro
Member
Registered: 2009-06-04
Posts: 2,136
Website

Re: Gpick colour picker alternative

The following is the code for the color selector:

#include <gtk/gtk.h>

static GtkWidget *window = NULL;
static GtkWidget *da;
static GdkColor color;
static GtkWidget *frame;

/* Expose callback for the drawing area
 */
static gboolean
expose_event_callback (GtkWidget      *widget, 
                       GdkEventExpose *event, 
                       gpointer        data)
{
  GdkWindow *window = gtk_widget_get_window (widget);

  if (window)
    {
      GtkStyle *style;
      cairo_t *cr;

      style = gtk_widget_get_style (widget);

      cr = gdk_cairo_create (window);

      gdk_cairo_set_source_color (cr, &style->bg[GTK_STATE_NORMAL]);
      gdk_cairo_rectangle (cr, &event->area);
      cairo_fill (cr);

      cairo_destroy (cr);
    }

  return TRUE;
}

static void
change_color_callback (GtkWidget *button,
               gpointer   data)
{
  GtkWidget *dialog;
  GtkColorSelection *colorsel;
  gint response;

  dialog = gtk_color_selection_dialog_new ("Changing color");

  gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (window));

  colorsel = 
    GTK_COLOR_SELECTION (gtk_color_selection_dialog_get_color_selection (GTK_COLOR_SELECTION_DIALOG (dialog)));

  gtk_color_selection_set_previous_color (colorsel, &color);
  gtk_color_selection_set_current_color (colorsel, &color);
  gtk_color_selection_set_has_palette (colorsel, TRUE);

  response = gtk_dialog_run (GTK_DIALOG (dialog));

  if (response == GTK_RESPONSE_OK)
    {
      gtk_color_selection_get_current_color (colorsel,
                         &color);

      gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);
    }

  gtk_widget_destroy (dialog);
}

GtkWidget *
do_colorsel (GtkWidget *do_widget)
{
  GtkWidget *vbox;
  GtkWidget *button;
  GtkWidget *alignment;

  if (!window)
    {
      color.red = 0;
      color.blue = 65535;
      color.green = 0;

      window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
      gtk_window_set_screen (GTK_WINDOW (window),
                 gtk_widget_get_screen (do_widget));
      gtk_window_set_title (GTK_WINDOW (window), "Color Selection");

      g_signal_connect (window, "destroy",
            G_CALLBACK (gtk_widget_destroyed), &window);

      gtk_container_set_border_width (GTK_CONTAINER (window), 8);

      vbox = gtk_vbox_new (FALSE, 8);
      gtk_container_set_border_width (GTK_CONTAINER (vbox), 8);
      gtk_container_add (GTK_CONTAINER (window), vbox);

      /*
       * Create the color swatch area
       */


      frame = gtk_frame_new (NULL);
      gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_IN);
      gtk_box_pack_start (GTK_BOX (vbox), frame, TRUE, TRUE, 0);

      da = gtk_drawing_area_new ();

      g_signal_connect (da, "expose_event",
            G_CALLBACK (expose_event_callback), NULL);

      /* set a minimum size */
      gtk_widget_set_size_request (da, 200, 200);
      /* set the color */
      gtk_widget_modify_bg (da, GTK_STATE_NORMAL, &color);

      gtk_container_add (GTK_CONTAINER (frame), da);

      alignment = gtk_alignment_new (1.0, 0.5, 0.0, 0.0);

      button = gtk_button_new_with_mnemonic ("_Change the above color");
      gtk_container_add (GTK_CONTAINER (alignment), button);

      gtk_box_pack_start (GTK_BOX (vbox), alignment, FALSE, FALSE, 0);

      g_signal_connect (button, "clicked",
            G_CALLBACK (change_color_callback), NULL);
    }

  if (!gtk_widget_get_visible (window))
    {
      gtk_widget_show_all (window);
    }
  else
    {
      gtk_widget_destroy (window);
      window = NULL;
    }

  return window;
}

So it should be possible to include that code into main.c, correct?

Offline

Board footer

Powered by FluxBB