modules/colorsel_triangle.c Cleanup, indentation madness, first steps
2000-12-28 Simon Budig <simon@gimp.org> * modules/colorsel_triangle.c Cleanup, indentation madness, first steps towards a one-click color-selector.
This commit is contained in:
@ -1,3 +1,9 @@
|
||||
2000-12-28 Simon Budig <simon@gimp.org>
|
||||
|
||||
* modules/colorsel_triangle.c
|
||||
Cleanup, indentation madness, first steps towards a one-click
|
||||
color-selector.
|
||||
|
||||
2000-12-28 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/channel.c
|
||||
|
@ -18,11 +18,9 @@
|
||||
*
|
||||
* Ported to loadable colour selector interface by Austin Donnelly
|
||||
* <austin@gimp.org>
|
||||
*
|
||||
*/
|
||||
#include "config.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gdk/gdk.h>
|
||||
@ -37,18 +35,29 @@
|
||||
|
||||
|
||||
/* prototypes */
|
||||
static GtkWidget * colorsel_triangle_new (int, int, int,
|
||||
GimpColorSelector_Callback, void *,
|
||||
void **);
|
||||
static void colorsel_triangle_free (void *);
|
||||
static void colorsel_triangle_setcolor (void *, int, int, int, int);
|
||||
static GtkWidget * colorsel_triangle_new (gint red,
|
||||
gint green,
|
||||
gint blue,
|
||||
GimpColorSelector_Callback callback,
|
||||
gpointer callback_data,
|
||||
gpointer *selector_data);
|
||||
|
||||
static void colorsel_triangle_free (gpointer selector_data);
|
||||
|
||||
static void colorsel_triangle_setcolor (gpointer selector_data,
|
||||
gint red,
|
||||
gint green,
|
||||
gint blue,
|
||||
gint set_current);
|
||||
|
||||
static void colorsel_triangle_drag_begin (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gpointer data);
|
||||
|
||||
static void colorsel_triangle_drag_end (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gpointer data);
|
||||
|
||||
static void colorsel_triangle_drop_handle (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
gint x,
|
||||
@ -57,6 +66,7 @@ static void colorsel_triangle_drop_handle (GtkWidget *widget,
|
||||
guint info,
|
||||
guint time,
|
||||
gpointer data);
|
||||
|
||||
static void colorsel_triangle_drag_handle (GtkWidget *widget,
|
||||
GdkDragContext *context,
|
||||
GtkSelectionData *selection_data,
|
||||
@ -78,7 +88,7 @@ static GimpModuleInfo info = {
|
||||
NULL,
|
||||
N_("Painter-style color selector as a pluggable color selector"),
|
||||
"Simon Budig <Simon.Budig@unix-ag.org>",
|
||||
"v0.01",
|
||||
"v0.02",
|
||||
"(c) 1999, released under the GPL",
|
||||
"17 Jan 1999"
|
||||
};
|
||||
@ -115,8 +125,6 @@ typedef enum {
|
||||
GREEN_BLUE
|
||||
} ColorSelectFillType;
|
||||
|
||||
typedef struct _ColorSelect _ColorSelect, *ColorSelectP;
|
||||
|
||||
struct _ColorSelect {
|
||||
gint values[6];
|
||||
gfloat oldsat;
|
||||
@ -125,15 +133,22 @@ struct _ColorSelect {
|
||||
GtkWidget *preview;
|
||||
GtkWidget *color_preview;
|
||||
GimpColorSelector_Callback callback;
|
||||
void *data;
|
||||
gpointer data;
|
||||
};
|
||||
|
||||
typedef struct _ColorSelect ColorSelect;
|
||||
|
||||
static GtkWidget * create_preview (ColorSelectP);
|
||||
static GtkWidget * create_color_preview (ColorSelectP);
|
||||
static void color_select_update_rgb_values (ColorSelectP);
|
||||
static void update_previews (ColorSelectP, gint);
|
||||
static void color_select_update_hsv_values (ColorSelectP);
|
||||
|
||||
static GtkWidget * create_preview (ColorSelect *coldata);
|
||||
|
||||
static GtkWidget * create_color_preview (ColorSelect *coldata);
|
||||
|
||||
static void color_select_update_rgb_values (ColorSelect *coldata);
|
||||
|
||||
static void update_previews (ColorSelect *coldata,
|
||||
gboolean hue_changed);
|
||||
|
||||
static void color_select_update_hsv_values (ColorSelect *coldata);
|
||||
|
||||
|
||||
/*************************************************************/
|
||||
@ -163,9 +178,9 @@ module_init (GimpModuleInfo **inforet)
|
||||
|
||||
|
||||
G_MODULE_EXPORT void
|
||||
module_unload (void *shutdown_data,
|
||||
void (*completed_cb)(void *),
|
||||
void *completed_data)
|
||||
module_unload (gpointer shutdown_data,
|
||||
void (*completed_cb) (gpointer),
|
||||
gpointer completed_data)
|
||||
{
|
||||
#ifndef __EMX__
|
||||
gimp_color_selector_unregister (shutdown_data, completed_cb, completed_data);
|
||||
@ -180,23 +195,23 @@ module_unload (void *shutdown_data,
|
||||
/* methods */
|
||||
|
||||
static GtkWidget *
|
||||
colorsel_triangle_new (int r, int g, int b,
|
||||
colorsel_triangle_new (gint red, gint green, gint blue,
|
||||
GimpColorSelector_Callback callback,
|
||||
void *callback_data,
|
||||
gpointer callback_data,
|
||||
/* RETURNS: */
|
||||
void **selector_data)
|
||||
gpointer *selector_data)
|
||||
{
|
||||
ColorSelectP coldata;
|
||||
ColorSelect *coldata;
|
||||
GtkWidget *preview;
|
||||
GtkWidget *color_preview;
|
||||
GtkWidget *frame;
|
||||
GtkWidget *hbox;
|
||||
GtkWidget *vbox;
|
||||
|
||||
coldata = g_malloc (sizeof (_ColorSelect));
|
||||
coldata->values[RED] = r;
|
||||
coldata->values[GREEN] = g;
|
||||
coldata->values[BLUE] = b;
|
||||
coldata = g_malloc (sizeof (ColorSelect));
|
||||
coldata->values[RED] = red;
|
||||
coldata->values[GREEN] = green;
|
||||
coldata->values[BLUE] = blue;
|
||||
color_select_update_hsv_values (coldata);
|
||||
|
||||
coldata->oldsat = 0;
|
||||
@ -207,8 +222,6 @@ colorsel_triangle_new (int r, int g, int b,
|
||||
coldata->callback = callback;
|
||||
coldata->data = callback_data;
|
||||
|
||||
/* gtk_rc_parse ("colorselrc"); */
|
||||
|
||||
preview = create_preview (coldata);
|
||||
coldata->preview = preview;
|
||||
|
||||
@ -237,7 +250,7 @@ colorsel_triangle_new (int r, int g, int b,
|
||||
|
||||
|
||||
static void
|
||||
colorsel_triangle_free (void *selector_data)
|
||||
colorsel_triangle_free (gpointer selector_data)
|
||||
{
|
||||
/* anything else needed to go? */
|
||||
g_free (selector_data);
|
||||
@ -245,17 +258,17 @@ colorsel_triangle_free (void *selector_data)
|
||||
|
||||
|
||||
static void
|
||||
colorsel_triangle_setcolor (void *selector_data,
|
||||
int r, int g, int b,
|
||||
int set_current)
|
||||
colorsel_triangle_setcolor (gpointer selector_data,
|
||||
gint red, gint green, gint blue,
|
||||
gint set_current)
|
||||
{
|
||||
ColorSelectP coldata;
|
||||
ColorSelect *coldata;
|
||||
|
||||
coldata = selector_data;
|
||||
|
||||
coldata->values[RED] = r;
|
||||
coldata->values[GREEN] = g;
|
||||
coldata->values[BLUE] = b;
|
||||
coldata->values[RED] = red;
|
||||
coldata->values[GREEN] = green;
|
||||
coldata->values[BLUE] = blue;
|
||||
color_select_update_hsv_values (coldata);
|
||||
update_previews (coldata, TRUE);
|
||||
}
|
||||
@ -331,7 +344,7 @@ color_hsv_to_rgb (gfloat hue,
|
||||
}
|
||||
|
||||
static void
|
||||
color_select_update_rgb_values (ColorSelectP csp)
|
||||
color_select_update_rgb_values (ColorSelect *csp)
|
||||
{
|
||||
gfloat h, s, v;
|
||||
gfloat f, p, q, t;
|
||||
@ -397,12 +410,12 @@ color_select_update_rgb_values (ColorSelectP csp)
|
||||
}
|
||||
|
||||
static void
|
||||
color_select_update_hsv_values (ColorSelectP csp)
|
||||
color_select_update_hsv_values (ColorSelect *csp)
|
||||
{
|
||||
int r, g, b;
|
||||
float h, s, v;
|
||||
int min, max;
|
||||
int delta;
|
||||
gint r, g, b;
|
||||
gfloat h, s, v;
|
||||
gint min, max;
|
||||
gint delta;
|
||||
|
||||
if (csp)
|
||||
{
|
||||
@ -468,7 +481,7 @@ color_select_update_hsv_values (ColorSelectP csp)
|
||||
|
||||
|
||||
static void
|
||||
update_previews (ColorSelectP coldata,
|
||||
update_previews (ColorSelect *coldata,
|
||||
gint hue_changed)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
@ -494,33 +507,44 @@ update_previews (ColorSelectP coldata,
|
||||
|
||||
if (hue_changed) {
|
||||
for (y = COLORWHEELRADIUS; y > -COLORWHEELRADIUS; y--) {
|
||||
dx = (int) sqrt((float) abs((COLORWHEELRADIUS)*(COLORWHEELRADIUS)-y*y));
|
||||
dx = (int) sqrt ((float) abs ((COLORWHEELRADIUS) * (COLORWHEELRADIUS)
|
||||
- y * y));
|
||||
for (x = -dx, k=0; x <= dx; x++) {
|
||||
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
|
||||
r2 = (x * x) + (y * y);
|
||||
if ( r2 <= COLORWHEELRADIUS * COLORWHEELRADIUS) {
|
||||
if (r2 > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1,
|
||||
&buf[k], &buf[k+1], &buf[k+2]);
|
||||
} else {
|
||||
val = (float) ((x-sx)*(hy-vy)-(y-sy)*(hx-vx)) / (float) ((vx-sx)*(hy-vy)-(vy-sy)*(hx-vx));
|
||||
val = (float) ( (x-sx) * (hy - vy) - (y - sy) * (hx - vx)) /
|
||||
(float) ((vx-sx) * (hy - vy) - (vy - sy) * (hx - vx));
|
||||
|
||||
if (val>0 && val<=1) { /* eigentlich val>=0, aber dann Grafikfehler... */
|
||||
sat = (val==0?0: ((float) (y-sy-val*(vy-sy)) / (val * (float) (hy-vy))));
|
||||
sat = (val == 0 ? 0: ((float) (y - sy - val * (vy - sy)) /
|
||||
(val * (float) (hy - vy))));
|
||||
if (sat >= 0 && sat <= 1)
|
||||
color_hsv_to_rgb (hue, sat, val, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
color_hsv_to_rgb (hue, sat, val,
|
||||
&buf[k], &buf[k+1], &buf[k+2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
k += 3;
|
||||
}
|
||||
/* gtk_preview_draw_row (GTK_PREVIEW (preview), buf, 0, COLORWHEELRADIUS - y - 1, PREVIEWSIZE); */
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS - dx, COLORWHEELRADIUS - y - 1, 2*dx+1);
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS - dx,
|
||||
COLORWHEELRADIUS - y - 1, 2*dx+1);
|
||||
}
|
||||
|
||||
/* Marker im aeusseren Ring */
|
||||
|
||||
x0 = (gint) (sin(hue*G_PI/180) * ((float) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1)/2 + COLORTRIANGLERADIUS) + 0.5);
|
||||
y0 = (gint) (cos(hue*G_PI/180) * ((float) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1)/2 + COLORTRIANGLERADIUS) + 0.5);
|
||||
color_hsv_to_rgb (atan2 (x0,y0) / G_PI * 180, 1, 1, &buf[0], &buf[1], &buf[2]);
|
||||
x0 = (gint) (sin (hue * G_PI/180) *
|
||||
((float) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
|
||||
COLORTRIANGLERADIUS) + 0.5);
|
||||
y0 = (gint) (cos (hue * G_PI/180) *
|
||||
((float) (COLORWHEELRADIUS - COLORTRIANGLERADIUS + 1) / 2 +
|
||||
COLORTRIANGLERADIUS) + 0.5);
|
||||
color_hsv_to_rgb (atan2 (x0, y0) / G_PI * 180, 1, 1,
|
||||
&buf[0], &buf[1], &buf[2]);
|
||||
col = INTENSITY (buf[0], buf[1], buf[2]) > 127 ? 0 : 255 ;
|
||||
|
||||
for (y = y0 - 4 ; y <= y0 + 4 ; y++) {
|
||||
@ -529,10 +553,13 @@ update_previews (ColorSelectP coldata,
|
||||
if (r2 <= 20 && r2 >= 6)
|
||||
buf[k] = buf[k+1] = buf[k+2] = col;
|
||||
else
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1,
|
||||
&buf[k], &buf[k+1], &buf[k+2]);
|
||||
k += 3;
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS + x0-4, COLORWHEELRADIUS - 1 - y, 9);
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
COLORWHEELRADIUS + x0-4,
|
||||
COLORWHEELRADIUS - 1 - y, 9);
|
||||
}
|
||||
|
||||
|
||||
@ -548,18 +575,23 @@ update_previews (ColorSelectP coldata,
|
||||
buf[k] = buf[k+1] = buf[k+2] = BGCOLOR;
|
||||
r2 = (x - x0) * (x - x0) + (y - y0) * (y - y0);
|
||||
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
color_hsv_to_rgb (atan2 (x, y) / G_PI * 180, 1, 1,
|
||||
&buf[k], &buf[k+1], &buf[k+2]);
|
||||
} else {
|
||||
val = (float) ((x-sx)*(hy-vy)-(y-sy)*(hx-vx)) / (float) ((vx-sx)*(hy-vy)-(vy-sy)*(hx-vx));
|
||||
val = (float) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
|
||||
(float) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
|
||||
if (val > 0 && val <= 1) { /* eigentlich val>=0, aber dann Grafikfehler... */
|
||||
sat = (val==0?0: ((float) (y-sy-val*(vy-sy)) / (val * (float) (hy-vy))));
|
||||
sat = (val == 0 ? 0 : ((float) (y - sy - val * (vy - sy)) /
|
||||
(val * (float) (hy - vy))));
|
||||
if (sat >= 0 && sat <= 1)
|
||||
color_hsv_to_rgb (hue, sat, val, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
}
|
||||
}
|
||||
k += 3;
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS + x0-4, COLORWHEELRADIUS - 1 - y, 9);
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
COLORWHEELRADIUS + x0 - 4,
|
||||
COLORWHEELRADIUS - 1 - y, 9);
|
||||
}
|
||||
|
||||
coldata->oldsat = coldata->values[SATURATION] / 100.0;
|
||||
@ -585,11 +617,14 @@ update_previews (ColorSelectP coldata,
|
||||
buf[k] = buf[k+1] = buf[k+2] = col;
|
||||
else {
|
||||
if (x * x + y * y > COLORTRIANGLERADIUS * COLORTRIANGLERADIUS) {
|
||||
color_hsv_to_rgb (atan2 (x,y) / G_PI * 180, 1, 1, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
color_hsv_to_rgb (atan2 (x, y) / G_PI * 180, 1, 1,
|
||||
&buf[k], &buf[k+1], &buf[k+2]);
|
||||
} else {
|
||||
val = (float) ((x-sx)*(hy-vy)-(y-sy)*(hx-vx)) / (float) ((vx-sx)*(hy-vy)-(vy-sy)*(hx-vx));
|
||||
val = (float) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx)) /
|
||||
(float) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
|
||||
if (val > 0 && val <= 1) { /* eigentlich val>=0, aber dann Grafikfehler... */
|
||||
sat = (val==0?0: ((float) (y-sy-val*(vy-sy)) / (val * (float) (hy-vy))));
|
||||
sat = (val == 0 ? 0 : ((float) (y - sy - val * (vy - sy)) /
|
||||
(val * (float) (hy - vy))));
|
||||
if (sat >= 0 && sat <= 1)
|
||||
color_hsv_to_rgb (hue, sat, val, &buf[k], &buf[k+1], &buf[k+2]);
|
||||
}
|
||||
@ -597,7 +632,9 @@ update_previews (ColorSelectP coldata,
|
||||
}
|
||||
k += 3;
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf, COLORWHEELRADIUS + x0-4, COLORWHEELRADIUS - 1 - y, 9);
|
||||
gtk_preview_draw_row (GTK_PREVIEW (preview), buf,
|
||||
COLORWHEELRADIUS + x0 - 4,
|
||||
COLORWHEELRADIUS - 1 - y, 9);
|
||||
}
|
||||
gtk_widget_draw (preview, NULL);
|
||||
|
||||
@ -622,8 +659,8 @@ static gint
|
||||
color_selection_callback (GtkWidget *widget,
|
||||
GdkEvent *event)
|
||||
{
|
||||
ColorSelectP coldata;
|
||||
gint x,y, mousex, mousey;
|
||||
ColorSelect *coldata;
|
||||
gint x,y, angle, mousex, mousey;
|
||||
gfloat r;
|
||||
gfloat hue, sat, val;
|
||||
gint hx,hy, sx,sy, vx,vy;
|
||||
@ -632,9 +669,11 @@ color_selection_callback (GtkWidget *widget,
|
||||
|
||||
switch (event->type) {
|
||||
case GDK_BUTTON_PRESS:
|
||||
gtk_grab_add (widget);
|
||||
x = event->button.x - COLORWHEELRADIUS - 1;
|
||||
y = - event->button.y + COLORWHEELRADIUS + 1;
|
||||
r = sqrt ((float) (x * x + y * y));
|
||||
angle = ((int) (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
|
||||
if ( /* r <= COLORWHEELRADIUS && */ r > COLORTRIANGLERADIUS)
|
||||
coldata->mode = 1; /* Dragging in the Ring */
|
||||
else
|
||||
@ -644,16 +683,21 @@ color_selection_callback (GtkWidget *widget,
|
||||
case GDK_MOTION_NOTIFY:
|
||||
x = event->motion.x - COLORWHEELRADIUS - 1;
|
||||
y = - event->motion.y + COLORWHEELRADIUS + 1;
|
||||
r = sqrt ((float) (x * x + y * y));
|
||||
angle = ((int) (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
coldata->mode = 0;
|
||||
gtk_grab_remove (widget);
|
||||
break;
|
||||
|
||||
default:
|
||||
gtk_widget_get_pointer (widget, &x, &y);
|
||||
x = x - COLORWHEELRADIUS - 1;
|
||||
y = - y + COLORWHEELRADIUS + 1;
|
||||
r = sqrt ((float) (x * x + y * y));
|
||||
angle = ((int) (atan2 (x, y) / G_PI * 180) + 360 ) % 360;
|
||||
break;
|
||||
}
|
||||
|
||||
@ -662,12 +706,14 @@ color_selection_callback (GtkWidget *widget,
|
||||
(mousex != event->motion.x || mousey != event->motion.y)))
|
||||
return FALSE;
|
||||
|
||||
if (coldata->mode == 1) {
|
||||
coldata->values[HUE] = ( (int) (atan2 (x, y) / G_PI * 180) + 360 ) %360;
|
||||
if (coldata->mode == 1 ||
|
||||
(r > COLORWHEELRADIUS &&
|
||||
(abs (angle - coldata->values[HUE]) < 30 ||
|
||||
abs (abs (angle - coldata->values[HUE]) - 360) < 30))) {
|
||||
coldata->values[HUE] = angle;
|
||||
color_select_update_rgb_values (coldata);
|
||||
update_previews (coldata, TRUE);
|
||||
}
|
||||
if (coldata->mode == 2) {
|
||||
} else {
|
||||
hue = (float) coldata->values[HUE] * G_PI / 180;
|
||||
hx = sin (hue) * COLORTRIANGLERADIUS;
|
||||
hy = cos (hue) * COLORTRIANGLERADIUS;
|
||||
@ -678,25 +724,43 @@ color_selection_callback (GtkWidget *widget,
|
||||
hue = (float) coldata->values[HUE];
|
||||
if ((x - sx) * vx + (y - sy) * vy < 0) {
|
||||
sat = 1;
|
||||
val = ((float) ((x-sx)*(hx-sx)+(y-sy)*(hy-sy)))/((hx-sx)*(hx-sx)+(hy-sy)*(hy-sy));
|
||||
if (val<0) val=0; else if (val>1) val=1;
|
||||
} else if ((x-sx)*hx+(y-sy)*hy < 0) {
|
||||
val = ((float) ( (x - sx) * (hx - sx) + (y - sy) * (hy - sy)))
|
||||
/ ((hx - sx) * (hx - sx) + (hy - sy) * (hy - sy));
|
||||
if (val < 0)
|
||||
val = 0;
|
||||
else if (val > 1)
|
||||
val = 1;
|
||||
} else
|
||||
if ((x - sx) * hx + (y - sy) * hy < 0) {
|
||||
sat = 0;
|
||||
val = ((float) ((x-sx)*(vx-sx)+(y-sy)*(vy-sy)))/((vx-sx)*(vx-sx)+(vy-sy)*(vy-sy));
|
||||
if (val<0) val=0; else if (val>1) val=1;
|
||||
val = ((float) ( (x - sx) * (vx - sx) + (y - sy) * (vy - sy)))
|
||||
/ ((vx - sx) * (vx - sx) + (vy - sy) * (vy - sy));
|
||||
if (val < 0)
|
||||
val = 0;
|
||||
else if (val > 1)
|
||||
val = 1;
|
||||
} else if ((x - hx) * sx + (y - hy) * sy < 0) {
|
||||
val = 1;
|
||||
sat = ((float) ((x-vx)*(hx-vx)+(y-vy)*(hy-vy)))/((hx-vx)*(hx-vx)+(hy-vy)*(hy-vy));
|
||||
if (sat<0) sat=0; else if (sat>1) sat=1;
|
||||
sat = ((float) ( (x - vx) * (hx - vx) + (y - vy) * (hy - vy)))
|
||||
/ ((hx - vx) * (hx - vx) + (hy - vy) * (hy - vy));
|
||||
if (sat < 0)
|
||||
sat = 0;
|
||||
else if (sat > 1)
|
||||
sat = 1;
|
||||
} else {
|
||||
val = (float) ((x-sx)*(hy-vy)-(y-sy)*(hx-vx)) / (float) ((vx-sx)*(hy-vy)-(vy-sy)*(hx-vx));
|
||||
val = (float) ( (x - sx) * (hy - vy) - (y - sy) * (hx - vx))
|
||||
/ (float) ((vx - sx) * (hy - vy) - (vy - sy) * (hx - vx));
|
||||
if (val <= 0) {
|
||||
val = 0;
|
||||
sat = 0;
|
||||
} else {
|
||||
if (val>1) val=1;
|
||||
if (val > 1)
|
||||
val = 1;
|
||||
sat = (float) (y - sy - val * (vy - sy)) / (val * (float) (hy - vy));
|
||||
if (sat<0) sat=0; else if (sat>1) sat=1;
|
||||
if (sat < 0)
|
||||
sat = 0;
|
||||
else if (sat > 1)
|
||||
sat = 1;
|
||||
}
|
||||
}
|
||||
|
||||
@ -716,7 +780,7 @@ color_selection_callback (GtkWidget *widget,
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_preview (ColorSelectP coldata)
|
||||
create_preview (ColorSelect *coldata)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
guchar buf[3*PREVIEWSIZE];
|
||||
@ -746,7 +810,7 @@ create_preview (ColorSelectP coldata)
|
||||
}
|
||||
|
||||
static GtkWidget *
|
||||
create_color_preview (ColorSelectP coldata)
|
||||
create_color_preview (ColorSelect *coldata)
|
||||
{
|
||||
GtkWidget *preview;
|
||||
|
||||
@ -791,9 +855,9 @@ colorsel_triangle_drag_begin (GtkWidget *widget,
|
||||
{
|
||||
GtkWidget *window;
|
||||
GdkColor bg;
|
||||
ColorSelectP coldata;
|
||||
ColorSelect *coldata;
|
||||
|
||||
coldata = (ColorSelectP) data;
|
||||
coldata = (ColorSelect *) data;
|
||||
|
||||
window = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_widget_set_app_paintable (GTK_WIDGET (window), TRUE);
|
||||
@ -835,9 +899,9 @@ colorsel_triangle_drop_handle (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
guint16 *vals;
|
||||
ColorSelectP coldata;
|
||||
ColorSelect *coldata;
|
||||
|
||||
coldata = (ColorSelectP) data;
|
||||
coldata = (ColorSelect *) data;
|
||||
|
||||
if (selection_data->length < 0)
|
||||
return;
|
||||
@ -868,9 +932,9 @@ colorsel_triangle_drag_handle (GtkWidget *widget,
|
||||
gpointer data)
|
||||
{
|
||||
guint16 vals[4];
|
||||
ColorSelectP coldata;
|
||||
ColorSelect *coldata;
|
||||
|
||||
coldata = (ColorSelectP) data;
|
||||
coldata = (ColorSelect *) data;
|
||||
|
||||
vals[0] = coldata->values[RED] * 0xff;
|
||||
vals[1] = coldata->values[GREEN] * 0xff;
|
||||
|
Reference in New Issue
Block a user