mirror of https://github.com/GNOME/gimp.git
use the new [gimp|pattern]_preview_widgets.
Mon Aug 30 22:15:29 MEST 1999 Sven Neumann <sven@gimp.org> * app/devices.c: use the new [gimp|pattern]_preview_widgets. * plug-ins/xjt/xjt.c: correct a gccism --Sven
This commit is contained in:
parent
859481e573
commit
04cfec7586
|
@ -1,3 +1,9 @@
|
|||
Mon Aug 30 22:15:29 MEST 1999 Sven Neumann <sven@gimp.org>
|
||||
|
||||
* app/devices.c: use the new [gimp|pattern]_preview_widgets.
|
||||
|
||||
* plug-ins/xjt/xjt.c: correct a gccism
|
||||
|
||||
Mon Aug 30 03:37:28 1999 Jay Cox (jaycox@earthlink.net)
|
||||
|
||||
* app/brush_edit.[ch]: Allow the user to change a brush's name.
|
||||
|
|
511
app/devices.c
511
app/devices.c
|
@ -23,12 +23,11 @@
|
|||
|
||||
#include "appenv.h"
|
||||
#include "actionarea.h"
|
||||
#include "brush_scale.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpbrushpreview.h"
|
||||
#include "gimppatternpreview.h"
|
||||
#include "devices.h"
|
||||
#include "interface.h"
|
||||
#include "gimprc.h"
|
||||
#include "patterns.h"
|
||||
#include "palette.h"
|
||||
#include "session.h"
|
||||
#include "tools.h"
|
||||
|
@ -39,16 +38,11 @@
|
|||
#include "libgimp/gimpenv.h"
|
||||
|
||||
#define CELL_SIZE 20 /* The size of the preview cells */
|
||||
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON1_MOTION_MASK | \
|
||||
GDK_ENTER_NOTIFY_MASK | \
|
||||
GDK_LEAVE_NOTIFY_MASK
|
||||
|
||||
#define BRUSH_PREVIEW 1
|
||||
#define PATTERN_PREVIEW 2
|
||||
|
||||
typedef struct _DeviceInfo DeviceInfo;
|
||||
|
||||
struct _DeviceInfo {
|
||||
|
@ -94,10 +88,6 @@ struct _DeviceInfoDialog {
|
|||
|
||||
GList *devices_info = NULL;
|
||||
DeviceInfoDialog *deviceD = NULL;
|
||||
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
|
||||
GtkWidget *device_bpreview = NULL;
|
||||
GtkWidget *device_patpopup = NULL;
|
||||
GtkWidget *device_patpreview = NULL;
|
||||
/* If true, don't update device information dialog */
|
||||
int suppress_update = FALSE;
|
||||
|
||||
|
@ -111,8 +101,6 @@ static void devices_write_rc (void);
|
|||
static void device_status_destroy_callback (void);
|
||||
static void devices_close_callback (GtkWidget *, gpointer);
|
||||
static void device_status_update_current ();
|
||||
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
|
||||
/* Global data */
|
||||
int current_device = GDK_CORE_POINTER;
|
||||
|
@ -263,14 +251,14 @@ devices_restore (void)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
}
|
||||
|
@ -279,11 +267,17 @@ devices_restore (void)
|
|||
}
|
||||
|
||||
void
|
||||
devices_rc_update (gchar *name, DeviceValues values,
|
||||
GdkInputMode mode, gint num_axes,
|
||||
GdkAxisUse *axes, gint num_keys, GdkDeviceKey *keys,
|
||||
gchar *brush_name, ToolType tool,
|
||||
guchar foreground[], gchar *pattern_name)
|
||||
devices_rc_update (gchar *name,
|
||||
DeviceValues values,
|
||||
GdkInputMode mode,
|
||||
gint num_axes,
|
||||
GdkAxisUse *axes,
|
||||
gint num_keys,
|
||||
GdkDeviceKey *keys,
|
||||
gchar *brush_name,
|
||||
ToolType tool,
|
||||
guchar foreground[],
|
||||
gchar *pattern_name)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
|
@ -393,7 +387,7 @@ devices_rc_update (gchar *name, DeviceValues values,
|
|||
|
||||
if (values & DEVICE_PATTERN)
|
||||
{
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list,pattern_name);
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
||||
}
|
||||
|
||||
if (values & DEVICE_TOOL)
|
||||
|
@ -437,14 +431,14 @@ select_device (guint32 new_device)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
select_pattern (device_info->pattern);
|
||||
}
|
||||
|
||||
suppress_update = FALSE;
|
||||
|
@ -755,25 +749,17 @@ create_device_status (void)
|
|||
2, 3, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
|
||||
(GtkSignalFunc) brush_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->brushes[i] = gimp_brush_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_brush_preview_set_tooltips (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
||||
3, 4, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
|
||||
deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
|
||||
(GtkSignalFunc) pattern_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->patterns[i] = gimp_pattern_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_pattern_preview_set_tooltips (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
||||
4, 5, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
@ -864,428 +850,6 @@ device_status_update_current ()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GimpBrushP brush)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_bpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
|
||||
gtk_widget_show (device_bpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (brush->mask->width >> 1);
|
||||
y = y_org + y - (brush->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
|
||||
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);
|
||||
|
||||
gtk_widget_popup (device_bpopup, x, y);
|
||||
|
||||
/* Draw the brush */
|
||||
buf = g_new (gchar, brush->mask->width);
|
||||
src = (gchar *)temp_buf_data (brush->mask);
|
||||
for (y = 0; y < brush->mask->height; y++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
for (x = 0; x < brush->mask->width; x++)
|
||||
buf[x] = 255 - src[x];
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
|
||||
src += brush->mask->width;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_bpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pattern_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GPatternP pattern)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_patpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
|
||||
gtk_widget_show (device_patpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (pattern->mask->width >> 1);
|
||||
y = y_org + y - (pattern->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
|
||||
y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);
|
||||
|
||||
gtk_widget_popup (device_patpopup, x, y);
|
||||
|
||||
/* Draw the pattern */
|
||||
buf = g_new (gchar, pattern->mask->width * 3);
|
||||
src = (gchar *)temp_buf_data (pattern->mask);
|
||||
for (y = 0; y < pattern->mask->height; y++)
|
||||
{
|
||||
if (pattern->mask->bytes == 1)
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x];
|
||||
buf[x*3+1] = src[x];
|
||||
buf[x*3+2] = src[x];
|
||||
}
|
||||
else
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x*3+0];
|
||||
buf[x*3+1] = src[x*3+1];
|
||||
buf[x*3+2] = src[x*3+2];
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
|
||||
src += pattern->mask->width * pattern->mask->bytes;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_patpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
device_popup_close (int type)
|
||||
{
|
||||
if(type == BRUSH_PREVIEW)
|
||||
{
|
||||
if (device_bpopup != NULL)
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
if (device_patpopup != NULL)
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
device_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid,
|
||||
int type)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
GdkEventButton *bevent;
|
||||
GimpBrushP brush;
|
||||
GPatternP pattern;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_EXPOSE:
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
tmp_list = devices_info;
|
||||
while (tmp_list)
|
||||
{
|
||||
device_info = (DeviceInfo *)tmp_list->data;
|
||||
|
||||
if (device_info->device == deviceD->ids[deviceid])
|
||||
break;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if(tmp_list == NULL)
|
||||
{
|
||||
g_message(_("Failed to find device_info\n"));
|
||||
break; /* Error no device info */
|
||||
}
|
||||
|
||||
/* Grab the pointer */
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
(GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK),
|
||||
NULL, NULL, bevent->time);
|
||||
|
||||
if (type == BRUSH_PREVIEW)
|
||||
{
|
||||
brush = device_info->brush;
|
||||
|
||||
/* Show the brush popup window if the brush is too large */
|
||||
if (brush->mask->width > CELL_SIZE ||
|
||||
brush->mask->height > CELL_SIZE)
|
||||
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
pattern = device_info->pattern;
|
||||
|
||||
/* Show the pattern popup window if the pattern is too large */
|
||||
if (pattern->mask->width > CELL_SIZE ||
|
||||
pattern->mask->height > CELL_SIZE)
|
||||
pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
/* Ungrab the pointer */
|
||||
gdk_pointer_ungrab (bevent->time);
|
||||
|
||||
/* Close the device preview popup window */
|
||||
device_popup_close (type);
|
||||
}
|
||||
break;
|
||||
case GDK_DELETE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
brush_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
|
||||
}
|
||||
|
||||
static gint
|
||||
pattern_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_brush (GimpBrushP brush,
|
||||
int preview_id)
|
||||
{
|
||||
guchar buffer[CELL_SIZE];
|
||||
MaskBuf * brush_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
gboolean scale = FALSE;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
|
||||
if (no_data || no_interface) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip (tool_tips, deviceD->brushes[preview_id], brush->name, NULL);
|
||||
|
||||
brush_buf = brush->mask;
|
||||
|
||||
if (brush_buf->width > CELL_SIZE || brush_buf->height > CELL_SIZE)
|
||||
{
|
||||
double ratio_x = (double)brush_buf->width / CELL_SIZE;
|
||||
double ratio_y = (double)brush_buf->height / CELL_SIZE;
|
||||
|
||||
if (ratio_x >= ratio_y)
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_x,
|
||||
(double)(brush_buf->height) / ratio_x);
|
||||
else
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_y,
|
||||
(double)(brush_buf->height) / ratio_y);
|
||||
scale = TRUE;
|
||||
}
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
src = mask_buf_data (brush_buf);
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
|
||||
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
for (j = 0; j < width ; j++)
|
||||
*b++ = 255 - *s++;
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += brush_buf->width;
|
||||
}
|
||||
|
||||
if (scale)
|
||||
{
|
||||
offset_y = CELL_SIZE - brush_scale_indicator_height - 1;
|
||||
for (i = 0; i < brush_scale_indicator_height; i++)
|
||||
{
|
||||
offset_x = CELL_SIZE - brush_scale_indicator_width - 1;
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
brush_scale_indicator_bits[i][0],
|
||||
offset_x, offset_y + i,
|
||||
brush_scale_indicator_width);
|
||||
}
|
||||
mask_buf_free (brush_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_pattern (GPatternP pattern,
|
||||
int preview_id)
|
||||
{
|
||||
guchar *buffer = NULL;
|
||||
TempBuf * pattern_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
int rowstride;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
if (no_interface || no_data) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);
|
||||
|
||||
buffer = g_new (guchar, pattern->mask->width * 3);
|
||||
pattern_buf = pattern->mask;
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
|
||||
height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
rowstride = pattern_buf->width * pattern_buf->bytes;
|
||||
src = mask_buf_data (pattern_buf) + (ystart - offset_y) * rowstride;
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
|
||||
if (pattern_buf->bytes == 1)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s;
|
||||
*b++ = *s;
|
||||
*b++ = *s++;
|
||||
}
|
||||
else
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += rowstride;
|
||||
}
|
||||
g_free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
device_status_update (guint32 deviceid)
|
||||
|
@ -1386,17 +950,20 @@ device_status_update (guint32 deviceid)
|
|||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->colors[i],ttbuf,NULL);
|
||||
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
||||
|
||||
|
||||
device_update_brush(device_info->brush,i);
|
||||
gtk_widget_draw (deviceD->brushes[i],NULL);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
|
||||
device_update_pattern(device_info->pattern,i);
|
||||
gtk_widget_draw (deviceD->patterns[i],NULL);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
|
||||
if (device_info->brush)
|
||||
{
|
||||
gimp_brush_preview_update (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
device_info->brush);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
}
|
||||
if (device_info->pattern)
|
||||
{
|
||||
gimp_pattern_preview_update (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
device_info->pattern);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
#include "appenv.h"
|
||||
#include "actionarea.h"
|
||||
#include "brush_scale.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpbrushpreview.h"
|
||||
#include "gimppatternpreview.h"
|
||||
#include "devices.h"
|
||||
#include "interface.h"
|
||||
#include "gimprc.h"
|
||||
#include "patterns.h"
|
||||
#include "palette.h"
|
||||
#include "session.h"
|
||||
#include "tools.h"
|
||||
|
@ -39,16 +38,11 @@
|
|||
#include "libgimp/gimpenv.h"
|
||||
|
||||
#define CELL_SIZE 20 /* The size of the preview cells */
|
||||
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON1_MOTION_MASK | \
|
||||
GDK_ENTER_NOTIFY_MASK | \
|
||||
GDK_LEAVE_NOTIFY_MASK
|
||||
|
||||
#define BRUSH_PREVIEW 1
|
||||
#define PATTERN_PREVIEW 2
|
||||
|
||||
typedef struct _DeviceInfo DeviceInfo;
|
||||
|
||||
struct _DeviceInfo {
|
||||
|
@ -94,10 +88,6 @@ struct _DeviceInfoDialog {
|
|||
|
||||
GList *devices_info = NULL;
|
||||
DeviceInfoDialog *deviceD = NULL;
|
||||
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
|
||||
GtkWidget *device_bpreview = NULL;
|
||||
GtkWidget *device_patpopup = NULL;
|
||||
GtkWidget *device_patpreview = NULL;
|
||||
/* If true, don't update device information dialog */
|
||||
int suppress_update = FALSE;
|
||||
|
||||
|
@ -111,8 +101,6 @@ static void devices_write_rc (void);
|
|||
static void device_status_destroy_callback (void);
|
||||
static void devices_close_callback (GtkWidget *, gpointer);
|
||||
static void device_status_update_current ();
|
||||
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
|
||||
/* Global data */
|
||||
int current_device = GDK_CORE_POINTER;
|
||||
|
@ -263,14 +251,14 @@ devices_restore (void)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
}
|
||||
|
@ -279,11 +267,17 @@ devices_restore (void)
|
|||
}
|
||||
|
||||
void
|
||||
devices_rc_update (gchar *name, DeviceValues values,
|
||||
GdkInputMode mode, gint num_axes,
|
||||
GdkAxisUse *axes, gint num_keys, GdkDeviceKey *keys,
|
||||
gchar *brush_name, ToolType tool,
|
||||
guchar foreground[], gchar *pattern_name)
|
||||
devices_rc_update (gchar *name,
|
||||
DeviceValues values,
|
||||
GdkInputMode mode,
|
||||
gint num_axes,
|
||||
GdkAxisUse *axes,
|
||||
gint num_keys,
|
||||
GdkDeviceKey *keys,
|
||||
gchar *brush_name,
|
||||
ToolType tool,
|
||||
guchar foreground[],
|
||||
gchar *pattern_name)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
|
@ -393,7 +387,7 @@ devices_rc_update (gchar *name, DeviceValues values,
|
|||
|
||||
if (values & DEVICE_PATTERN)
|
||||
{
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list,pattern_name);
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
||||
}
|
||||
|
||||
if (values & DEVICE_TOOL)
|
||||
|
@ -437,14 +431,14 @@ select_device (guint32 new_device)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
select_pattern (device_info->pattern);
|
||||
}
|
||||
|
||||
suppress_update = FALSE;
|
||||
|
@ -755,25 +749,17 @@ create_device_status (void)
|
|||
2, 3, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
|
||||
(GtkSignalFunc) brush_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->brushes[i] = gimp_brush_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_brush_preview_set_tooltips (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
||||
3, 4, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
|
||||
deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
|
||||
(GtkSignalFunc) pattern_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->patterns[i] = gimp_pattern_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_pattern_preview_set_tooltips (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
||||
4, 5, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
@ -864,428 +850,6 @@ device_status_update_current ()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GimpBrushP brush)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_bpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
|
||||
gtk_widget_show (device_bpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (brush->mask->width >> 1);
|
||||
y = y_org + y - (brush->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
|
||||
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);
|
||||
|
||||
gtk_widget_popup (device_bpopup, x, y);
|
||||
|
||||
/* Draw the brush */
|
||||
buf = g_new (gchar, brush->mask->width);
|
||||
src = (gchar *)temp_buf_data (brush->mask);
|
||||
for (y = 0; y < brush->mask->height; y++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
for (x = 0; x < brush->mask->width; x++)
|
||||
buf[x] = 255 - src[x];
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
|
||||
src += brush->mask->width;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_bpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pattern_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GPatternP pattern)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_patpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
|
||||
gtk_widget_show (device_patpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (pattern->mask->width >> 1);
|
||||
y = y_org + y - (pattern->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
|
||||
y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);
|
||||
|
||||
gtk_widget_popup (device_patpopup, x, y);
|
||||
|
||||
/* Draw the pattern */
|
||||
buf = g_new (gchar, pattern->mask->width * 3);
|
||||
src = (gchar *)temp_buf_data (pattern->mask);
|
||||
for (y = 0; y < pattern->mask->height; y++)
|
||||
{
|
||||
if (pattern->mask->bytes == 1)
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x];
|
||||
buf[x*3+1] = src[x];
|
||||
buf[x*3+2] = src[x];
|
||||
}
|
||||
else
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x*3+0];
|
||||
buf[x*3+1] = src[x*3+1];
|
||||
buf[x*3+2] = src[x*3+2];
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
|
||||
src += pattern->mask->width * pattern->mask->bytes;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_patpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
device_popup_close (int type)
|
||||
{
|
||||
if(type == BRUSH_PREVIEW)
|
||||
{
|
||||
if (device_bpopup != NULL)
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
if (device_patpopup != NULL)
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
device_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid,
|
||||
int type)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
GdkEventButton *bevent;
|
||||
GimpBrushP brush;
|
||||
GPatternP pattern;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_EXPOSE:
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
tmp_list = devices_info;
|
||||
while (tmp_list)
|
||||
{
|
||||
device_info = (DeviceInfo *)tmp_list->data;
|
||||
|
||||
if (device_info->device == deviceD->ids[deviceid])
|
||||
break;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if(tmp_list == NULL)
|
||||
{
|
||||
g_message(_("Failed to find device_info\n"));
|
||||
break; /* Error no device info */
|
||||
}
|
||||
|
||||
/* Grab the pointer */
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
(GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK),
|
||||
NULL, NULL, bevent->time);
|
||||
|
||||
if (type == BRUSH_PREVIEW)
|
||||
{
|
||||
brush = device_info->brush;
|
||||
|
||||
/* Show the brush popup window if the brush is too large */
|
||||
if (brush->mask->width > CELL_SIZE ||
|
||||
brush->mask->height > CELL_SIZE)
|
||||
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
pattern = device_info->pattern;
|
||||
|
||||
/* Show the pattern popup window if the pattern is too large */
|
||||
if (pattern->mask->width > CELL_SIZE ||
|
||||
pattern->mask->height > CELL_SIZE)
|
||||
pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
/* Ungrab the pointer */
|
||||
gdk_pointer_ungrab (bevent->time);
|
||||
|
||||
/* Close the device preview popup window */
|
||||
device_popup_close (type);
|
||||
}
|
||||
break;
|
||||
case GDK_DELETE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
brush_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
|
||||
}
|
||||
|
||||
static gint
|
||||
pattern_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_brush (GimpBrushP brush,
|
||||
int preview_id)
|
||||
{
|
||||
guchar buffer[CELL_SIZE];
|
||||
MaskBuf * brush_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
gboolean scale = FALSE;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
|
||||
if (no_data || no_interface) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip (tool_tips, deviceD->brushes[preview_id], brush->name, NULL);
|
||||
|
||||
brush_buf = brush->mask;
|
||||
|
||||
if (brush_buf->width > CELL_SIZE || brush_buf->height > CELL_SIZE)
|
||||
{
|
||||
double ratio_x = (double)brush_buf->width / CELL_SIZE;
|
||||
double ratio_y = (double)brush_buf->height / CELL_SIZE;
|
||||
|
||||
if (ratio_x >= ratio_y)
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_x,
|
||||
(double)(brush_buf->height) / ratio_x);
|
||||
else
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_y,
|
||||
(double)(brush_buf->height) / ratio_y);
|
||||
scale = TRUE;
|
||||
}
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
src = mask_buf_data (brush_buf);
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
|
||||
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
for (j = 0; j < width ; j++)
|
||||
*b++ = 255 - *s++;
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += brush_buf->width;
|
||||
}
|
||||
|
||||
if (scale)
|
||||
{
|
||||
offset_y = CELL_SIZE - brush_scale_indicator_height - 1;
|
||||
for (i = 0; i < brush_scale_indicator_height; i++)
|
||||
{
|
||||
offset_x = CELL_SIZE - brush_scale_indicator_width - 1;
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
brush_scale_indicator_bits[i][0],
|
||||
offset_x, offset_y + i,
|
||||
brush_scale_indicator_width);
|
||||
}
|
||||
mask_buf_free (brush_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_pattern (GPatternP pattern,
|
||||
int preview_id)
|
||||
{
|
||||
guchar *buffer = NULL;
|
||||
TempBuf * pattern_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
int rowstride;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
if (no_interface || no_data) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);
|
||||
|
||||
buffer = g_new (guchar, pattern->mask->width * 3);
|
||||
pattern_buf = pattern->mask;
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
|
||||
height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
rowstride = pattern_buf->width * pattern_buf->bytes;
|
||||
src = mask_buf_data (pattern_buf) + (ystart - offset_y) * rowstride;
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
|
||||
if (pattern_buf->bytes == 1)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s;
|
||||
*b++ = *s;
|
||||
*b++ = *s++;
|
||||
}
|
||||
else
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += rowstride;
|
||||
}
|
||||
g_free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
device_status_update (guint32 deviceid)
|
||||
|
@ -1386,17 +950,20 @@ device_status_update (guint32 deviceid)
|
|||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->colors[i],ttbuf,NULL);
|
||||
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
||||
|
||||
|
||||
device_update_brush(device_info->brush,i);
|
||||
gtk_widget_draw (deviceD->brushes[i],NULL);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
|
||||
device_update_pattern(device_info->pattern,i);
|
||||
gtk_widget_draw (deviceD->patterns[i],NULL);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
|
||||
if (device_info->brush)
|
||||
{
|
||||
gimp_brush_preview_update (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
device_info->brush);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
}
|
||||
if (device_info->pattern)
|
||||
{
|
||||
gimp_pattern_preview_update (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
device_info->pattern);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
#include "appenv.h"
|
||||
#include "actionarea.h"
|
||||
#include "brush_scale.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpbrushpreview.h"
|
||||
#include "gimppatternpreview.h"
|
||||
#include "devices.h"
|
||||
#include "interface.h"
|
||||
#include "gimprc.h"
|
||||
#include "patterns.h"
|
||||
#include "palette.h"
|
||||
#include "session.h"
|
||||
#include "tools.h"
|
||||
|
@ -39,16 +38,11 @@
|
|||
#include "libgimp/gimpenv.h"
|
||||
|
||||
#define CELL_SIZE 20 /* The size of the preview cells */
|
||||
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON1_MOTION_MASK | \
|
||||
GDK_ENTER_NOTIFY_MASK | \
|
||||
GDK_LEAVE_NOTIFY_MASK
|
||||
|
||||
#define BRUSH_PREVIEW 1
|
||||
#define PATTERN_PREVIEW 2
|
||||
|
||||
typedef struct _DeviceInfo DeviceInfo;
|
||||
|
||||
struct _DeviceInfo {
|
||||
|
@ -94,10 +88,6 @@ struct _DeviceInfoDialog {
|
|||
|
||||
GList *devices_info = NULL;
|
||||
DeviceInfoDialog *deviceD = NULL;
|
||||
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
|
||||
GtkWidget *device_bpreview = NULL;
|
||||
GtkWidget *device_patpopup = NULL;
|
||||
GtkWidget *device_patpreview = NULL;
|
||||
/* If true, don't update device information dialog */
|
||||
int suppress_update = FALSE;
|
||||
|
||||
|
@ -111,8 +101,6 @@ static void devices_write_rc (void);
|
|||
static void device_status_destroy_callback (void);
|
||||
static void devices_close_callback (GtkWidget *, gpointer);
|
||||
static void device_status_update_current ();
|
||||
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
|
||||
/* Global data */
|
||||
int current_device = GDK_CORE_POINTER;
|
||||
|
@ -263,14 +251,14 @@ devices_restore (void)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
}
|
||||
|
@ -279,11 +267,17 @@ devices_restore (void)
|
|||
}
|
||||
|
||||
void
|
||||
devices_rc_update (gchar *name, DeviceValues values,
|
||||
GdkInputMode mode, gint num_axes,
|
||||
GdkAxisUse *axes, gint num_keys, GdkDeviceKey *keys,
|
||||
gchar *brush_name, ToolType tool,
|
||||
guchar foreground[], gchar *pattern_name)
|
||||
devices_rc_update (gchar *name,
|
||||
DeviceValues values,
|
||||
GdkInputMode mode,
|
||||
gint num_axes,
|
||||
GdkAxisUse *axes,
|
||||
gint num_keys,
|
||||
GdkDeviceKey *keys,
|
||||
gchar *brush_name,
|
||||
ToolType tool,
|
||||
guchar foreground[],
|
||||
gchar *pattern_name)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
|
@ -393,7 +387,7 @@ devices_rc_update (gchar *name, DeviceValues values,
|
|||
|
||||
if (values & DEVICE_PATTERN)
|
||||
{
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list,pattern_name);
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
||||
}
|
||||
|
||||
if (values & DEVICE_TOOL)
|
||||
|
@ -437,14 +431,14 @@ select_device (guint32 new_device)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
select_pattern (device_info->pattern);
|
||||
}
|
||||
|
||||
suppress_update = FALSE;
|
||||
|
@ -755,25 +749,17 @@ create_device_status (void)
|
|||
2, 3, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
|
||||
(GtkSignalFunc) brush_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->brushes[i] = gimp_brush_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_brush_preview_set_tooltips (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
||||
3, 4, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
|
||||
deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
|
||||
(GtkSignalFunc) pattern_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->patterns[i] = gimp_pattern_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_pattern_preview_set_tooltips (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
||||
4, 5, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
@ -864,428 +850,6 @@ device_status_update_current ()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GimpBrushP brush)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_bpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
|
||||
gtk_widget_show (device_bpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (brush->mask->width >> 1);
|
||||
y = y_org + y - (brush->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
|
||||
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);
|
||||
|
||||
gtk_widget_popup (device_bpopup, x, y);
|
||||
|
||||
/* Draw the brush */
|
||||
buf = g_new (gchar, brush->mask->width);
|
||||
src = (gchar *)temp_buf_data (brush->mask);
|
||||
for (y = 0; y < brush->mask->height; y++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
for (x = 0; x < brush->mask->width; x++)
|
||||
buf[x] = 255 - src[x];
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
|
||||
src += brush->mask->width;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_bpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pattern_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GPatternP pattern)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_patpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
|
||||
gtk_widget_show (device_patpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (pattern->mask->width >> 1);
|
||||
y = y_org + y - (pattern->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
|
||||
y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);
|
||||
|
||||
gtk_widget_popup (device_patpopup, x, y);
|
||||
|
||||
/* Draw the pattern */
|
||||
buf = g_new (gchar, pattern->mask->width * 3);
|
||||
src = (gchar *)temp_buf_data (pattern->mask);
|
||||
for (y = 0; y < pattern->mask->height; y++)
|
||||
{
|
||||
if (pattern->mask->bytes == 1)
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x];
|
||||
buf[x*3+1] = src[x];
|
||||
buf[x*3+2] = src[x];
|
||||
}
|
||||
else
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x*3+0];
|
||||
buf[x*3+1] = src[x*3+1];
|
||||
buf[x*3+2] = src[x*3+2];
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
|
||||
src += pattern->mask->width * pattern->mask->bytes;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_patpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
device_popup_close (int type)
|
||||
{
|
||||
if(type == BRUSH_PREVIEW)
|
||||
{
|
||||
if (device_bpopup != NULL)
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
if (device_patpopup != NULL)
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
device_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid,
|
||||
int type)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
GdkEventButton *bevent;
|
||||
GimpBrushP brush;
|
||||
GPatternP pattern;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_EXPOSE:
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
tmp_list = devices_info;
|
||||
while (tmp_list)
|
||||
{
|
||||
device_info = (DeviceInfo *)tmp_list->data;
|
||||
|
||||
if (device_info->device == deviceD->ids[deviceid])
|
||||
break;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if(tmp_list == NULL)
|
||||
{
|
||||
g_message(_("Failed to find device_info\n"));
|
||||
break; /* Error no device info */
|
||||
}
|
||||
|
||||
/* Grab the pointer */
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
(GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK),
|
||||
NULL, NULL, bevent->time);
|
||||
|
||||
if (type == BRUSH_PREVIEW)
|
||||
{
|
||||
brush = device_info->brush;
|
||||
|
||||
/* Show the brush popup window if the brush is too large */
|
||||
if (brush->mask->width > CELL_SIZE ||
|
||||
brush->mask->height > CELL_SIZE)
|
||||
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
pattern = device_info->pattern;
|
||||
|
||||
/* Show the pattern popup window if the pattern is too large */
|
||||
if (pattern->mask->width > CELL_SIZE ||
|
||||
pattern->mask->height > CELL_SIZE)
|
||||
pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
/* Ungrab the pointer */
|
||||
gdk_pointer_ungrab (bevent->time);
|
||||
|
||||
/* Close the device preview popup window */
|
||||
device_popup_close (type);
|
||||
}
|
||||
break;
|
||||
case GDK_DELETE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
brush_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
|
||||
}
|
||||
|
||||
static gint
|
||||
pattern_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_brush (GimpBrushP brush,
|
||||
int preview_id)
|
||||
{
|
||||
guchar buffer[CELL_SIZE];
|
||||
MaskBuf * brush_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
gboolean scale = FALSE;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
|
||||
if (no_data || no_interface) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip (tool_tips, deviceD->brushes[preview_id], brush->name, NULL);
|
||||
|
||||
brush_buf = brush->mask;
|
||||
|
||||
if (brush_buf->width > CELL_SIZE || brush_buf->height > CELL_SIZE)
|
||||
{
|
||||
double ratio_x = (double)brush_buf->width / CELL_SIZE;
|
||||
double ratio_y = (double)brush_buf->height / CELL_SIZE;
|
||||
|
||||
if (ratio_x >= ratio_y)
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_x,
|
||||
(double)(brush_buf->height) / ratio_x);
|
||||
else
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_y,
|
||||
(double)(brush_buf->height) / ratio_y);
|
||||
scale = TRUE;
|
||||
}
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
src = mask_buf_data (brush_buf);
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
|
||||
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
for (j = 0; j < width ; j++)
|
||||
*b++ = 255 - *s++;
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += brush_buf->width;
|
||||
}
|
||||
|
||||
if (scale)
|
||||
{
|
||||
offset_y = CELL_SIZE - brush_scale_indicator_height - 1;
|
||||
for (i = 0; i < brush_scale_indicator_height; i++)
|
||||
{
|
||||
offset_x = CELL_SIZE - brush_scale_indicator_width - 1;
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
brush_scale_indicator_bits[i][0],
|
||||
offset_x, offset_y + i,
|
||||
brush_scale_indicator_width);
|
||||
}
|
||||
mask_buf_free (brush_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_pattern (GPatternP pattern,
|
||||
int preview_id)
|
||||
{
|
||||
guchar *buffer = NULL;
|
||||
TempBuf * pattern_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
int rowstride;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
if (no_interface || no_data) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);
|
||||
|
||||
buffer = g_new (guchar, pattern->mask->width * 3);
|
||||
pattern_buf = pattern->mask;
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
|
||||
height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
rowstride = pattern_buf->width * pattern_buf->bytes;
|
||||
src = mask_buf_data (pattern_buf) + (ystart - offset_y) * rowstride;
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
|
||||
if (pattern_buf->bytes == 1)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s;
|
||||
*b++ = *s;
|
||||
*b++ = *s++;
|
||||
}
|
||||
else
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += rowstride;
|
||||
}
|
||||
g_free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
device_status_update (guint32 deviceid)
|
||||
|
@ -1386,17 +950,20 @@ device_status_update (guint32 deviceid)
|
|||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->colors[i],ttbuf,NULL);
|
||||
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
||||
|
||||
|
||||
device_update_brush(device_info->brush,i);
|
||||
gtk_widget_draw (deviceD->brushes[i],NULL);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
|
||||
device_update_pattern(device_info->pattern,i);
|
||||
gtk_widget_draw (deviceD->patterns[i],NULL);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
|
||||
if (device_info->brush)
|
||||
{
|
||||
gimp_brush_preview_update (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
device_info->brush);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
}
|
||||
if (device_info->pattern)
|
||||
{
|
||||
gimp_pattern_preview_update (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
device_info->pattern);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
#include "appenv.h"
|
||||
#include "actionarea.h"
|
||||
#include "brush_scale.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpbrushpreview.h"
|
||||
#include "gimppatternpreview.h"
|
||||
#include "devices.h"
|
||||
#include "interface.h"
|
||||
#include "gimprc.h"
|
||||
#include "patterns.h"
|
||||
#include "palette.h"
|
||||
#include "session.h"
|
||||
#include "tools.h"
|
||||
|
@ -39,16 +38,11 @@
|
|||
#include "libgimp/gimpenv.h"
|
||||
|
||||
#define CELL_SIZE 20 /* The size of the preview cells */
|
||||
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON1_MOTION_MASK | \
|
||||
GDK_ENTER_NOTIFY_MASK | \
|
||||
GDK_LEAVE_NOTIFY_MASK
|
||||
|
||||
#define BRUSH_PREVIEW 1
|
||||
#define PATTERN_PREVIEW 2
|
||||
|
||||
typedef struct _DeviceInfo DeviceInfo;
|
||||
|
||||
struct _DeviceInfo {
|
||||
|
@ -94,10 +88,6 @@ struct _DeviceInfoDialog {
|
|||
|
||||
GList *devices_info = NULL;
|
||||
DeviceInfoDialog *deviceD = NULL;
|
||||
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
|
||||
GtkWidget *device_bpreview = NULL;
|
||||
GtkWidget *device_patpopup = NULL;
|
||||
GtkWidget *device_patpreview = NULL;
|
||||
/* If true, don't update device information dialog */
|
||||
int suppress_update = FALSE;
|
||||
|
||||
|
@ -111,8 +101,6 @@ static void devices_write_rc (void);
|
|||
static void device_status_destroy_callback (void);
|
||||
static void devices_close_callback (GtkWidget *, gpointer);
|
||||
static void device_status_update_current ();
|
||||
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
|
||||
/* Global data */
|
||||
int current_device = GDK_CORE_POINTER;
|
||||
|
@ -263,14 +251,14 @@ devices_restore (void)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
}
|
||||
|
@ -279,11 +267,17 @@ devices_restore (void)
|
|||
}
|
||||
|
||||
void
|
||||
devices_rc_update (gchar *name, DeviceValues values,
|
||||
GdkInputMode mode, gint num_axes,
|
||||
GdkAxisUse *axes, gint num_keys, GdkDeviceKey *keys,
|
||||
gchar *brush_name, ToolType tool,
|
||||
guchar foreground[], gchar *pattern_name)
|
||||
devices_rc_update (gchar *name,
|
||||
DeviceValues values,
|
||||
GdkInputMode mode,
|
||||
gint num_axes,
|
||||
GdkAxisUse *axes,
|
||||
gint num_keys,
|
||||
GdkDeviceKey *keys,
|
||||
gchar *brush_name,
|
||||
ToolType tool,
|
||||
guchar foreground[],
|
||||
gchar *pattern_name)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
|
@ -393,7 +387,7 @@ devices_rc_update (gchar *name, DeviceValues values,
|
|||
|
||||
if (values & DEVICE_PATTERN)
|
||||
{
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list,pattern_name);
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
||||
}
|
||||
|
||||
if (values & DEVICE_TOOL)
|
||||
|
@ -437,14 +431,14 @@ select_device (guint32 new_device)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
select_pattern (device_info->pattern);
|
||||
}
|
||||
|
||||
suppress_update = FALSE;
|
||||
|
@ -755,25 +749,17 @@ create_device_status (void)
|
|||
2, 3, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
|
||||
(GtkSignalFunc) brush_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->brushes[i] = gimp_brush_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_brush_preview_set_tooltips (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
||||
3, 4, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
|
||||
deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
|
||||
(GtkSignalFunc) pattern_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->patterns[i] = gimp_pattern_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_pattern_preview_set_tooltips (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
||||
4, 5, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
@ -864,428 +850,6 @@ device_status_update_current ()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GimpBrushP brush)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_bpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
|
||||
gtk_widget_show (device_bpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (brush->mask->width >> 1);
|
||||
y = y_org + y - (brush->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
|
||||
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);
|
||||
|
||||
gtk_widget_popup (device_bpopup, x, y);
|
||||
|
||||
/* Draw the brush */
|
||||
buf = g_new (gchar, brush->mask->width);
|
||||
src = (gchar *)temp_buf_data (brush->mask);
|
||||
for (y = 0; y < brush->mask->height; y++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
for (x = 0; x < brush->mask->width; x++)
|
||||
buf[x] = 255 - src[x];
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
|
||||
src += brush->mask->width;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_bpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pattern_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GPatternP pattern)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_patpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
|
||||
gtk_widget_show (device_patpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (pattern->mask->width >> 1);
|
||||
y = y_org + y - (pattern->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
|
||||
y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);
|
||||
|
||||
gtk_widget_popup (device_patpopup, x, y);
|
||||
|
||||
/* Draw the pattern */
|
||||
buf = g_new (gchar, pattern->mask->width * 3);
|
||||
src = (gchar *)temp_buf_data (pattern->mask);
|
||||
for (y = 0; y < pattern->mask->height; y++)
|
||||
{
|
||||
if (pattern->mask->bytes == 1)
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x];
|
||||
buf[x*3+1] = src[x];
|
||||
buf[x*3+2] = src[x];
|
||||
}
|
||||
else
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x*3+0];
|
||||
buf[x*3+1] = src[x*3+1];
|
||||
buf[x*3+2] = src[x*3+2];
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
|
||||
src += pattern->mask->width * pattern->mask->bytes;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_patpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
device_popup_close (int type)
|
||||
{
|
||||
if(type == BRUSH_PREVIEW)
|
||||
{
|
||||
if (device_bpopup != NULL)
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
if (device_patpopup != NULL)
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
device_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid,
|
||||
int type)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
GdkEventButton *bevent;
|
||||
GimpBrushP brush;
|
||||
GPatternP pattern;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_EXPOSE:
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
tmp_list = devices_info;
|
||||
while (tmp_list)
|
||||
{
|
||||
device_info = (DeviceInfo *)tmp_list->data;
|
||||
|
||||
if (device_info->device == deviceD->ids[deviceid])
|
||||
break;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if(tmp_list == NULL)
|
||||
{
|
||||
g_message(_("Failed to find device_info\n"));
|
||||
break; /* Error no device info */
|
||||
}
|
||||
|
||||
/* Grab the pointer */
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
(GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK),
|
||||
NULL, NULL, bevent->time);
|
||||
|
||||
if (type == BRUSH_PREVIEW)
|
||||
{
|
||||
brush = device_info->brush;
|
||||
|
||||
/* Show the brush popup window if the brush is too large */
|
||||
if (brush->mask->width > CELL_SIZE ||
|
||||
brush->mask->height > CELL_SIZE)
|
||||
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
pattern = device_info->pattern;
|
||||
|
||||
/* Show the pattern popup window if the pattern is too large */
|
||||
if (pattern->mask->width > CELL_SIZE ||
|
||||
pattern->mask->height > CELL_SIZE)
|
||||
pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
/* Ungrab the pointer */
|
||||
gdk_pointer_ungrab (bevent->time);
|
||||
|
||||
/* Close the device preview popup window */
|
||||
device_popup_close (type);
|
||||
}
|
||||
break;
|
||||
case GDK_DELETE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
brush_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
|
||||
}
|
||||
|
||||
static gint
|
||||
pattern_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_brush (GimpBrushP brush,
|
||||
int preview_id)
|
||||
{
|
||||
guchar buffer[CELL_SIZE];
|
||||
MaskBuf * brush_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
gboolean scale = FALSE;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
|
||||
if (no_data || no_interface) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip (tool_tips, deviceD->brushes[preview_id], brush->name, NULL);
|
||||
|
||||
brush_buf = brush->mask;
|
||||
|
||||
if (brush_buf->width > CELL_SIZE || brush_buf->height > CELL_SIZE)
|
||||
{
|
||||
double ratio_x = (double)brush_buf->width / CELL_SIZE;
|
||||
double ratio_y = (double)brush_buf->height / CELL_SIZE;
|
||||
|
||||
if (ratio_x >= ratio_y)
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_x,
|
||||
(double)(brush_buf->height) / ratio_x);
|
||||
else
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_y,
|
||||
(double)(brush_buf->height) / ratio_y);
|
||||
scale = TRUE;
|
||||
}
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
src = mask_buf_data (brush_buf);
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
|
||||
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
for (j = 0; j < width ; j++)
|
||||
*b++ = 255 - *s++;
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += brush_buf->width;
|
||||
}
|
||||
|
||||
if (scale)
|
||||
{
|
||||
offset_y = CELL_SIZE - brush_scale_indicator_height - 1;
|
||||
for (i = 0; i < brush_scale_indicator_height; i++)
|
||||
{
|
||||
offset_x = CELL_SIZE - brush_scale_indicator_width - 1;
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
brush_scale_indicator_bits[i][0],
|
||||
offset_x, offset_y + i,
|
||||
brush_scale_indicator_width);
|
||||
}
|
||||
mask_buf_free (brush_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_pattern (GPatternP pattern,
|
||||
int preview_id)
|
||||
{
|
||||
guchar *buffer = NULL;
|
||||
TempBuf * pattern_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
int rowstride;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
if (no_interface || no_data) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);
|
||||
|
||||
buffer = g_new (guchar, pattern->mask->width * 3);
|
||||
pattern_buf = pattern->mask;
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
|
||||
height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
rowstride = pattern_buf->width * pattern_buf->bytes;
|
||||
src = mask_buf_data (pattern_buf) + (ystart - offset_y) * rowstride;
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
|
||||
if (pattern_buf->bytes == 1)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s;
|
||||
*b++ = *s;
|
||||
*b++ = *s++;
|
||||
}
|
||||
else
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += rowstride;
|
||||
}
|
||||
g_free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
device_status_update (guint32 deviceid)
|
||||
|
@ -1386,17 +950,20 @@ device_status_update (guint32 deviceid)
|
|||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->colors[i],ttbuf,NULL);
|
||||
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
||||
|
||||
|
||||
device_update_brush(device_info->brush,i);
|
||||
gtk_widget_draw (deviceD->brushes[i],NULL);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
|
||||
device_update_pattern(device_info->pattern,i);
|
||||
gtk_widget_draw (deviceD->patterns[i],NULL);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
|
||||
if (device_info->brush)
|
||||
{
|
||||
gimp_brush_preview_update (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
device_info->brush);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
}
|
||||
if (device_info->pattern)
|
||||
{
|
||||
gimp_pattern_preview_update (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
device_info->pattern);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -23,12 +23,11 @@
|
|||
|
||||
#include "appenv.h"
|
||||
#include "actionarea.h"
|
||||
#include "brush_scale.h"
|
||||
#include "gimpbrushlist.h"
|
||||
#include "gimpbrushpreview.h"
|
||||
#include "gimppatternpreview.h"
|
||||
#include "devices.h"
|
||||
#include "interface.h"
|
||||
#include "gimprc.h"
|
||||
#include "patterns.h"
|
||||
#include "palette.h"
|
||||
#include "session.h"
|
||||
#include "tools.h"
|
||||
|
@ -39,16 +38,11 @@
|
|||
#include "libgimp/gimpenv.h"
|
||||
|
||||
#define CELL_SIZE 20 /* The size of the preview cells */
|
||||
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
|
||||
GDK_BUTTON_PRESS_MASK | \
|
||||
#define PREVIEW_EVENT_MASK GDK_BUTTON_PRESS_MASK | \
|
||||
GDK_BUTTON_RELEASE_MASK | \
|
||||
GDK_BUTTON1_MOTION_MASK | \
|
||||
GDK_ENTER_NOTIFY_MASK | \
|
||||
GDK_LEAVE_NOTIFY_MASK
|
||||
|
||||
#define BRUSH_PREVIEW 1
|
||||
#define PATTERN_PREVIEW 2
|
||||
|
||||
typedef struct _DeviceInfo DeviceInfo;
|
||||
|
||||
struct _DeviceInfo {
|
||||
|
@ -94,10 +88,6 @@ struct _DeviceInfoDialog {
|
|||
|
||||
GList *devices_info = NULL;
|
||||
DeviceInfoDialog *deviceD = NULL;
|
||||
GtkWidget *device_bpopup = NULL; /* Can't share since differnt depths */
|
||||
GtkWidget *device_bpreview = NULL;
|
||||
GtkWidget *device_patpopup = NULL;
|
||||
GtkWidget *device_patpreview = NULL;
|
||||
/* If true, don't update device information dialog */
|
||||
int suppress_update = FALSE;
|
||||
|
||||
|
@ -111,8 +101,6 @@ static void devices_write_rc (void);
|
|||
static void device_status_destroy_callback (void);
|
||||
static void devices_close_callback (GtkWidget *, gpointer);
|
||||
static void device_status_update_current ();
|
||||
static gint brush_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
static gint pattern_preview_events (GtkWidget *, GdkEvent *, int);
|
||||
|
||||
/* Global data */
|
||||
int current_device = GDK_CORE_POINTER;
|
||||
|
@ -263,14 +251,14 @@ devices_restore (void)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
}
|
||||
|
@ -279,11 +267,17 @@ devices_restore (void)
|
|||
}
|
||||
|
||||
void
|
||||
devices_rc_update (gchar *name, DeviceValues values,
|
||||
GdkInputMode mode, gint num_axes,
|
||||
GdkAxisUse *axes, gint num_keys, GdkDeviceKey *keys,
|
||||
gchar *brush_name, ToolType tool,
|
||||
guchar foreground[], gchar *pattern_name)
|
||||
devices_rc_update (gchar *name,
|
||||
DeviceValues values,
|
||||
GdkInputMode mode,
|
||||
gint num_axes,
|
||||
GdkAxisUse *axes,
|
||||
gint num_keys,
|
||||
GdkDeviceKey *keys,
|
||||
gchar *brush_name,
|
||||
ToolType tool,
|
||||
guchar foreground[],
|
||||
gchar *pattern_name)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
|
@ -393,7 +387,7 @@ devices_rc_update (gchar *name, DeviceValues values,
|
|||
|
||||
if (values & DEVICE_PATTERN)
|
||||
{
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list,pattern_name);
|
||||
device_info->pattern = pattern_list_get_pattern (pattern_list, pattern_name);
|
||||
}
|
||||
|
||||
if (values & DEVICE_TOOL)
|
||||
|
@ -437,14 +431,14 @@ select_device (guint32 new_device)
|
|||
|
||||
if (device_info->is_init)
|
||||
{
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
gtk_widget_activate (tool_info[(int) device_info->tool].tool_widget);
|
||||
palette_set_foreground (device_info->foreground[0],
|
||||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
if (device_info->brush)
|
||||
select_brush (device_info->brush);
|
||||
if (device_info->pattern)
|
||||
select_pattern(device_info->pattern);
|
||||
select_pattern (device_info->pattern);
|
||||
}
|
||||
|
||||
suppress_update = FALSE;
|
||||
|
@ -755,25 +749,17 @@ create_device_status (void)
|
|||
2, 3, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
deviceD->brushes[i] = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->brushes[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->brushes[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->brushes[i]), "event",
|
||||
(GtkSignalFunc) brush_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->brushes[i] = gimp_brush_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_brush_preview_set_tooltips (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->brushes[i],
|
||||
3, 4, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
||||
|
||||
deviceD->patterns[i] = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_preview_size (GTK_PREVIEW (deviceD->patterns[i]), CELL_SIZE, CELL_SIZE);
|
||||
gtk_widget_set_events (deviceD->patterns[i], PREVIEW_EVENT_MASK);
|
||||
gtk_signal_connect (GTK_OBJECT (deviceD->patterns[i]), "event",
|
||||
(GtkSignalFunc) pattern_preview_events,
|
||||
(gpointer)i);
|
||||
|
||||
deviceD->patterns[i] = gimp_pattern_preview_new (CELL_SIZE, CELL_SIZE);
|
||||
gimp_pattern_preview_set_tooltips (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
tool_tips);
|
||||
gtk_table_attach (GTK_TABLE(deviceD->table), deviceD->patterns[i],
|
||||
4, 5, i, i+1,
|
||||
0, 0, 2, 2);
|
||||
|
@ -864,428 +850,6 @@ device_status_update_current ()
|
|||
}
|
||||
}
|
||||
|
||||
static void
|
||||
brush_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GimpBrushP brush)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_bpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_bpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_bpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_bpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_bpreview = gtk_preview_new (GTK_PREVIEW_GRAYSCALE);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_bpreview);
|
||||
gtk_widget_show (device_bpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->brushes[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (brush->mask->width >> 1);
|
||||
y = y_org + y - (brush->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + brush->mask->width > scr_w) ? scr_w - brush->mask->width : x;
|
||||
y = (y + brush->mask->height > scr_h) ? scr_h - brush->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_bpreview), brush->mask->width, brush->mask->height);
|
||||
|
||||
gtk_widget_popup (device_bpopup, x, y);
|
||||
|
||||
/* Draw the brush */
|
||||
buf = g_new (gchar, brush->mask->width);
|
||||
src = (gchar *)temp_buf_data (brush->mask);
|
||||
for (y = 0; y < brush->mask->height; y++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
for (x = 0; x < brush->mask->width; x++)
|
||||
buf[x] = 255 - src[x];
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_bpreview), (guchar *)buf, 0, y, brush->mask->width);
|
||||
src += brush->mask->width;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_bpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
pattern_popup_open (int preview_id,
|
||||
int x,
|
||||
int y,
|
||||
GPatternP pattern)
|
||||
{
|
||||
gint x_org, y_org;
|
||||
gint scr_w, scr_h;
|
||||
gchar *src, *buf;
|
||||
|
||||
/* make sure the popup exists and is not visible */
|
||||
if (device_patpopup == NULL)
|
||||
{
|
||||
GtkWidget *frame;
|
||||
|
||||
device_patpopup = gtk_window_new (GTK_WINDOW_POPUP);
|
||||
gtk_window_set_policy (GTK_WINDOW (device_patpopup), FALSE, FALSE, TRUE);
|
||||
|
||||
frame = gtk_frame_new (NULL);
|
||||
gtk_frame_set_shadow_type (GTK_FRAME (frame), GTK_SHADOW_OUT);
|
||||
gtk_container_add (GTK_CONTAINER (device_patpopup), frame);
|
||||
gtk_widget_show (frame);
|
||||
device_patpreview = gtk_preview_new (GTK_PREVIEW_COLOR);
|
||||
gtk_container_add (GTK_CONTAINER (frame), device_patpreview);
|
||||
gtk_widget_show (device_patpreview);
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
|
||||
/* decide where to put the popup */
|
||||
gdk_window_get_origin (deviceD->patterns[preview_id]->window, &x_org, &y_org);
|
||||
scr_w = gdk_screen_width ();
|
||||
scr_h = gdk_screen_height ();
|
||||
x = x_org + x - (pattern->mask->width >> 1);
|
||||
y = y_org + y - (pattern->mask->height >> 1);
|
||||
x = (x < 0) ? 0 : x;
|
||||
y = (y < 0) ? 0 : y;
|
||||
x = (x + pattern->mask->width > scr_w) ? scr_w - pattern->mask->width : x;
|
||||
y = (y + pattern->mask->height > scr_h) ? scr_h - pattern->mask->height : y;
|
||||
gtk_preview_size (GTK_PREVIEW (device_patpreview), pattern->mask->width, pattern->mask->height);
|
||||
|
||||
gtk_widget_popup (device_patpopup, x, y);
|
||||
|
||||
/* Draw the pattern */
|
||||
buf = g_new (gchar, pattern->mask->width * 3);
|
||||
src = (gchar *)temp_buf_data (pattern->mask);
|
||||
for (y = 0; y < pattern->mask->height; y++)
|
||||
{
|
||||
if (pattern->mask->bytes == 1)
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x];
|
||||
buf[x*3+1] = src[x];
|
||||
buf[x*3+2] = src[x];
|
||||
}
|
||||
else
|
||||
for (x = 0; x < pattern->mask->width; x++)
|
||||
{
|
||||
buf[x*3+0] = src[x*3+0];
|
||||
buf[x*3+1] = src[x*3+1];
|
||||
buf[x*3+2] = src[x*3+2];
|
||||
}
|
||||
gtk_preview_draw_row (GTK_PREVIEW (device_patpreview), (guchar *)buf, 0, y, pattern->mask->width);
|
||||
src += pattern->mask->width * pattern->mask->bytes;
|
||||
}
|
||||
g_free(buf);
|
||||
|
||||
/* Draw the brush preview */
|
||||
gtk_widget_draw (device_patpreview, NULL);
|
||||
}
|
||||
|
||||
static void
|
||||
device_popup_close (int type)
|
||||
{
|
||||
if(type == BRUSH_PREVIEW)
|
||||
{
|
||||
if (device_bpopup != NULL)
|
||||
gtk_widget_hide (device_bpopup);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
if (device_patpopup != NULL)
|
||||
gtk_widget_hide (device_patpopup);
|
||||
}
|
||||
}
|
||||
|
||||
static gint
|
||||
device_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid,
|
||||
int type)
|
||||
{
|
||||
GList *tmp_list;
|
||||
DeviceInfo *device_info;
|
||||
GdkEventButton *bevent;
|
||||
GimpBrushP brush;
|
||||
GPatternP pattern;
|
||||
|
||||
switch (event->type)
|
||||
{
|
||||
case GDK_EXPOSE:
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_PRESS:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
tmp_list = devices_info;
|
||||
while (tmp_list)
|
||||
{
|
||||
device_info = (DeviceInfo *)tmp_list->data;
|
||||
|
||||
if (device_info->device == deviceD->ids[deviceid])
|
||||
break;
|
||||
|
||||
tmp_list = tmp_list->next;
|
||||
}
|
||||
|
||||
if(tmp_list == NULL)
|
||||
{
|
||||
g_message(_("Failed to find device_info\n"));
|
||||
break; /* Error no device info */
|
||||
}
|
||||
|
||||
/* Grab the pointer */
|
||||
gdk_pointer_grab (widget->window, FALSE,
|
||||
(GDK_POINTER_MOTION_HINT_MASK |
|
||||
GDK_BUTTON1_MOTION_MASK |
|
||||
GDK_BUTTON_RELEASE_MASK),
|
||||
NULL, NULL, bevent->time);
|
||||
|
||||
if (type == BRUSH_PREVIEW)
|
||||
{
|
||||
brush = device_info->brush;
|
||||
|
||||
/* Show the brush popup window if the brush is too large */
|
||||
if (brush->mask->width > CELL_SIZE ||
|
||||
brush->mask->height > CELL_SIZE)
|
||||
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
|
||||
}
|
||||
else if (type == PATTERN_PREVIEW)
|
||||
{
|
||||
pattern = device_info->pattern;
|
||||
|
||||
/* Show the pattern popup window if the pattern is too large */
|
||||
if (pattern->mask->width > CELL_SIZE ||
|
||||
pattern->mask->height > CELL_SIZE)
|
||||
pattern_popup_open (deviceid, bevent->x, bevent->y, pattern);
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case GDK_BUTTON_RELEASE:
|
||||
bevent = (GdkEventButton *) event;
|
||||
|
||||
if (bevent->button == 1)
|
||||
{
|
||||
/* Ungrab the pointer */
|
||||
gdk_pointer_ungrab (bevent->time);
|
||||
|
||||
/* Close the device preview popup window */
|
||||
device_popup_close (type);
|
||||
}
|
||||
break;
|
||||
case GDK_DELETE:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gint
|
||||
brush_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
|
||||
}
|
||||
|
||||
static gint
|
||||
pattern_preview_events (GtkWidget *widget,
|
||||
GdkEvent *event,
|
||||
int deviceid)
|
||||
{
|
||||
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_brush (GimpBrushP brush,
|
||||
int preview_id)
|
||||
{
|
||||
guchar buffer[CELL_SIZE];
|
||||
MaskBuf * brush_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
gboolean scale = FALSE;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
|
||||
if (no_data || no_interface) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip (tool_tips, deviceD->brushes[preview_id], brush->name, NULL);
|
||||
|
||||
brush_buf = brush->mask;
|
||||
|
||||
if (brush_buf->width > CELL_SIZE || brush_buf->height > CELL_SIZE)
|
||||
{
|
||||
double ratio_x = (double)brush_buf->width / CELL_SIZE;
|
||||
double ratio_y = (double)brush_buf->height / CELL_SIZE;
|
||||
|
||||
if (ratio_x >= ratio_y)
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_x,
|
||||
(double)(brush_buf->height) / ratio_x);
|
||||
else
|
||||
brush_buf = brush_scale_mask (brush_buf,
|
||||
(double)(brush_buf->width) / ratio_y,
|
||||
(double)(brush_buf->height) / ratio_y);
|
||||
scale = TRUE;
|
||||
}
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
src = mask_buf_data (brush_buf);
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (brush_buf->width > CELL_SIZE) ? CELL_SIZE: brush_buf->width;
|
||||
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
for (j = 0; j < width ; j++)
|
||||
*b++ = 255 - *s++;
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += brush_buf->width;
|
||||
}
|
||||
|
||||
if (scale)
|
||||
{
|
||||
offset_y = CELL_SIZE - brush_scale_indicator_height - 1;
|
||||
for (i = 0; i < brush_scale_indicator_height; i++)
|
||||
{
|
||||
offset_x = CELL_SIZE - brush_scale_indicator_width - 1;
|
||||
gtk_preview_draw_row (GTK_PREVIEW (deviceD->brushes[preview_id]),
|
||||
brush_scale_indicator_bits[i][0],
|
||||
offset_x, offset_y + i,
|
||||
brush_scale_indicator_width);
|
||||
}
|
||||
mask_buf_free (brush_buf);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
device_update_pattern (GPatternP pattern,
|
||||
int preview_id)
|
||||
{
|
||||
guchar *buffer = NULL;
|
||||
TempBuf * pattern_buf;
|
||||
unsigned char * src, *s = NULL;
|
||||
unsigned char *b;
|
||||
int rowstride;
|
||||
int width,height;
|
||||
int offset_x, offset_y;
|
||||
int yend;
|
||||
int ystart;
|
||||
int i, j;
|
||||
if (no_interface || no_data) return;
|
||||
/* Set the tip to be the name of the brush */
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->patterns[preview_id],pattern->name,NULL);
|
||||
|
||||
buffer = g_new (guchar, pattern->mask->width * 3);
|
||||
pattern_buf = pattern->mask;
|
||||
|
||||
/* Limit to cell size */
|
||||
width = (pattern_buf->width > CELL_SIZE) ? CELL_SIZE: pattern_buf->width;
|
||||
height = (pattern_buf->height > CELL_SIZE) ? CELL_SIZE: pattern_buf->height;
|
||||
|
||||
/* Set buffer to white */
|
||||
memset(buffer, 255, sizeof(buffer));
|
||||
for (i = 0; i < CELL_SIZE; i++)
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]), buffer, 0, i, CELL_SIZE);
|
||||
|
||||
offset_x = ((CELL_SIZE - width) >> 1);
|
||||
offset_y = ((CELL_SIZE - height) >> 1);
|
||||
|
||||
ystart = BOUNDS (offset_y, 0, CELL_SIZE);
|
||||
yend = BOUNDS (offset_y + height, 0, CELL_SIZE);
|
||||
|
||||
/* Get the pointer into the brush mask data */
|
||||
rowstride = pattern_buf->width * pattern_buf->bytes;
|
||||
src = mask_buf_data (pattern_buf) + (ystart - offset_y) * rowstride;
|
||||
|
||||
for (i = ystart; i < yend; i++)
|
||||
{
|
||||
/* Invert the mask for display. We're doing this because
|
||||
* a value of 255 in the mask means it is full intensity.
|
||||
* However, it makes more sense for full intensity to show
|
||||
* up as black in this brush preview window...
|
||||
*/
|
||||
s = src;
|
||||
b = buffer;
|
||||
|
||||
if (pattern_buf->bytes == 1)
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s;
|
||||
*b++ = *s;
|
||||
*b++ = *s++;
|
||||
}
|
||||
else
|
||||
for (j = 0; j < width; j++)
|
||||
{
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
*b++ = *s++;
|
||||
}
|
||||
|
||||
gtk_preview_draw_row (GTK_PREVIEW(deviceD->patterns[preview_id]),
|
||||
buffer,
|
||||
offset_x, i, width);
|
||||
|
||||
src += rowstride;
|
||||
}
|
||||
g_free(buffer);
|
||||
}
|
||||
|
||||
void
|
||||
device_status_update (guint32 deviceid)
|
||||
|
@ -1386,17 +950,20 @@ device_status_update (guint32 deviceid)
|
|||
device_info->foreground[1],
|
||||
device_info->foreground[2]);
|
||||
|
||||
gtk_tooltips_set_tip(tool_tips,deviceD->colors[i],ttbuf,NULL);
|
||||
gtk_tooltips_set_tip(tool_tips, deviceD->colors[i], ttbuf, NULL);
|
||||
|
||||
|
||||
device_update_brush(device_info->brush,i);
|
||||
gtk_widget_draw (deviceD->brushes[i],NULL);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
|
||||
device_update_pattern(device_info->pattern,i);
|
||||
gtk_widget_draw (deviceD->patterns[i],NULL);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
|
||||
if (device_info->brush)
|
||||
{
|
||||
gimp_brush_preview_update (GIMP_BRUSH_PREVIEW (deviceD->brushes[i]),
|
||||
device_info->brush);
|
||||
gtk_widget_show (deviceD->brushes[i]);
|
||||
}
|
||||
if (device_info->pattern)
|
||||
{
|
||||
gimp_pattern_preview_update (GIMP_PATTERN_PREVIEW (deviceD->patterns[i]),
|
||||
device_info->pattern);
|
||||
gtk_widget_show (deviceD->patterns[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -142,7 +142,7 @@ typedef enum
|
|||
PTYP_2xINT = 5,
|
||||
PTYP_3xINT = 6,
|
||||
PTYP_2xFLT = 7,
|
||||
PTYP_3xFLT = 8,
|
||||
PTYP_3xFLT = 8
|
||||
} t_param_typ;
|
||||
|
||||
typedef struct
|
||||
|
|
Loading…
Reference in New Issue