First set of camp-merges. Adds brush-scaling for the brush previews.

--Sven
This commit is contained in:
Sven Neumann 1999-08-12 17:53:51 +00:00
parent 522f4b345a
commit 2c1e3f2f7d
16 changed files with 1182 additions and 382 deletions

View File

@ -1,3 +1,13 @@
Thu Aug 12 19:53:19 MEST 1999 Sven Neumann <sven@gimp.org>
* app/Makefile.am
* app/brush_scale.[ch]: new files that add brush-scaling
* app/brush_select.c
* app/devices.c
* app/indicator_area.c: Scale brushes in the preview so they fit
into the preview area. We will use this code for pressure-sensitive
brush-scaling too, but I have to create a GUI for that first.
Thu Aug 12 18:54:38 MEST 1999 Sven Neumann <sven@gimp.org>
* tools/pdbgen/pdb/gimprc.pdb: made the monitor resolution

View File

@ -56,6 +56,8 @@ gimp_SOURCES = \
brush_edit.c \
brush_edit.h \
brush_header.h \
brush_scale.c \
brush_scale.h \
brush_select.c \
brush_select.h \
brush_select_cmds.c \

166
app/base/brush-scale.c Normal file
View File

@ -0,0 +1,166 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <glib.h>
#include "brush_scale.h"
MaskBuf *
brush_scale_mask (MaskBuf *brush_mask,
int dest_width,
int dest_height)
{
MaskBuf *scale_brush;
int src_width;
int src_height;
int value;
int area;
int i, j;
int x, x0, y, y0;
int dx, dx0, dy, dy0;
int fx, fx0, fy, fy0;
unsigned char *src, *dest;
g_return_val_if_fail (brush_mask != NULL &&
dest_width != 0 && dest_height != 0, NULL);
src_width = brush_mask->width;
src_height = brush_mask->height;
scale_brush = mask_buf_new (dest_width, dest_height);
g_return_val_if_fail (scale_brush != NULL, NULL);
/* get the data */
dest = mask_buf_data (scale_brush);
src = mask_buf_data (brush_mask);
fx = fx0 = (256.0 * src_width) / dest_width;
fy = fy0 = (256.0 * src_height) / dest_height;
area = fx0 * fy0;
x = x0 = 0;
y = y0 = 0;
dx = dx0 = 0;
dy = dy0 = 0;
for (i=0; i<dest_height; i++)
{
for (j=0; j<dest_width; j++)
{
value = 0;
fy = fy0;
y = y0;
dy = dy0;
if (dy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * dy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * dy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * dy * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= dy;
dy = 0;
}
while (fy >= 256)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * 256 * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * 256 * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * 256 * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= 256;
}
if (fy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * fy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * fy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * fy * src[x + src_width * y];
dx = 256 - fx;
}
dy = 256 - fy;
}
*dest++ = MIN ((value / area), 255);
x0 = x;
dx0 = dx;
}
x0 = 0;
dx0 = 0;
y0 = y;
dy0 = dy;
}
return scale_brush;
}

49
app/base/brush-scale.h Normal file
View File

@ -0,0 +1,49 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __BRUSH_SCALE_H__
#define __BRUSH_SCALE_H__
#include "temp_buf.h"
/* the pixmap for the brush_scale_indicator */
#define brush_scale_indicator_width 7
#define brush_scale_indicator_height 7
static unsigned char brush_scale_indicator_bits[7][7] =
{
{ 255, 255, 255, 255, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 0, 0, 0, 0, 0, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 255, 255, 255, 255 }
};
/* functions */
MaskBuf * brush_scale_mask (MaskBuf *, int, int);
#endif /* __BRUSH_SCALE_H__ */

166
app/brush_scale.c Normal file
View File

@ -0,0 +1,166 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <glib.h>
#include "brush_scale.h"
MaskBuf *
brush_scale_mask (MaskBuf *brush_mask,
int dest_width,
int dest_height)
{
MaskBuf *scale_brush;
int src_width;
int src_height;
int value;
int area;
int i, j;
int x, x0, y, y0;
int dx, dx0, dy, dy0;
int fx, fx0, fy, fy0;
unsigned char *src, *dest;
g_return_val_if_fail (brush_mask != NULL &&
dest_width != 0 && dest_height != 0, NULL);
src_width = brush_mask->width;
src_height = brush_mask->height;
scale_brush = mask_buf_new (dest_width, dest_height);
g_return_val_if_fail (scale_brush != NULL, NULL);
/* get the data */
dest = mask_buf_data (scale_brush);
src = mask_buf_data (brush_mask);
fx = fx0 = (256.0 * src_width) / dest_width;
fy = fy0 = (256.0 * src_height) / dest_height;
area = fx0 * fy0;
x = x0 = 0;
y = y0 = 0;
dx = dx0 = 0;
dy = dy0 = 0;
for (i=0; i<dest_height; i++)
{
for (j=0; j<dest_width; j++)
{
value = 0;
fy = fy0;
y = y0;
dy = dy0;
if (dy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * dy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * dy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * dy * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= dy;
dy = 0;
}
while (fy >= 256)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * 256 * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * 256 * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * 256 * src[x + src_width * y];
dx = 256 - fx;
}
y++;
fy -= 256;
}
if (fy)
{
fx = fx0;
x = x0;
dx = dx0;
if (dx)
{
value += dx * fy * src[x + src_width * y];
x++;
fx -= dx;
dx = 0;
}
while (fx >= 256)
{
value += 256 * fy * src[x + src_width * y];
x++;
fx -= 256;
}
if (fx)
{
value += fx * fy * src[x + src_width * y];
dx = 256 - fx;
}
dy = 256 - fy;
}
*dest++ = MIN ((value / area), 255);
x0 = x;
dx0 = dx;
}
x0 = 0;
dx0 = 0;
y0 = y;
dy0 = dy;
}
return scale_brush;
}

49
app/brush_scale.h Normal file
View File

@ -0,0 +1,49 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#ifndef __BRUSH_SCALE_H__
#define __BRUSH_SCALE_H__
#include "temp_buf.h"
/* the pixmap for the brush_scale_indicator */
#define brush_scale_indicator_width 7
#define brush_scale_indicator_height 7
static unsigned char brush_scale_indicator_bits[7][7] =
{
{ 255, 255, 255, 255, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 0, 0, 0, 0, 0, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 0, 255, 255, 255 },
{ 255, 255, 255, 255, 255, 255, 255 }
};
/* functions */
MaskBuf * brush_scale_mask (MaskBuf *, int, int);
#endif /* __BRUSH_SCALE_H__ */

View File

@ -15,9 +15,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "gimpcontext.h"
#include "gimplist.h"
@ -54,37 +56,37 @@
GDK_ENTER_NOTIFY_MASK
/* local function prototypes */
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP);
static void display_brush (BrushSelectP, GimpBrushP, int, int);
static void display_brushes (BrushSelectP);
static void display_setup (BrushSelectP);
static void preview_calc_scrollbar (BrushSelectP);
static void brush_select_show_selected (BrushSelectP, int, int);
static void update_active_brush_field (BrushSelectP);
static void edit_active_brush ();
static gint edit_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint new_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint brush_select_brush_dirty_callback(GimpBrushP brush,
BrushSelectP bsp);
static void connect_signals_to_brush (GimpBrushP brush,
BrushSelectP bsp);
static void disconnect_signals_from_brush(GimpBrushP brush,
BrushSelectP bsp);
static void brush_added_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_removed_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP);
static void display_brush (BrushSelectP, GimpBrushP, int, int);
static void display_brushes (BrushSelectP);
static void display_setup (BrushSelectP);
static void preview_calc_scrollbar (BrushSelectP);
static void brush_select_show_selected (BrushSelectP, int, int);
static void update_active_brush_field (BrushSelectP);
static void edit_active_brush ();
static gint edit_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint new_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint brush_select_brush_dirty_callback (GimpBrushP brush,
BrushSelectP bsp);
static void connect_signals_to_brush (GimpBrushP brush,
BrushSelectP bsp);
static void disconnect_signals_from_brush (GimpBrushP brush,
BrushSelectP bsp);
static void brush_added_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_removed_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
/* static void brush_select_map_callback (GtkWidget *, BrushSelectP); */
static void brush_select_close_callback (GtkWidget *, gpointer);
static void brush_select_refresh_callback(GtkWidget *, gpointer);
static void paint_mode_menu_callback (GtkWidget *, gpointer);
static gint brush_select_events (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_resize (GtkWidget *, GdkEvent *, BrushSelectP);
static void brush_select_close_callback (GtkWidget *, gpointer);
static void brush_select_refresh_callback (GtkWidget *, gpointer);
static void paint_mode_menu_callback (GtkWidget *, gpointer);
static gint brush_select_events (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_resize (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void preview_scroll_update (GtkAdjustment *, gpointer);
@ -790,9 +792,10 @@ display_brush (BrushSelectP bsp,
int col,
int row)
{
TempBuf * brush_buf;
MaskBuf * brush_buf;
unsigned char * src, *s;
unsigned char * buf, *b;
gboolean scale = FALSE;
int width, height;
int offset_x, offset_y;
int yend;
@ -803,6 +806,23 @@ display_brush (BrushSelectP bsp,
brush_buf = brush->mask;
if (brush_buf->width > bsp->cell_width ||
brush_buf->height > bsp->cell_height)
{
double ratio_x = (double)brush_buf->width / bsp->cell_width;
double ratio_y = (double)brush_buf->height / bsp->cell_height;
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;
}
/* calculate the offset into the image */
width = (brush_buf->width > bsp->cell_width) ? bsp->cell_width :
brush_buf->width;
@ -835,8 +855,25 @@ display_brush (BrushSelectP bsp,
src += brush_buf->width;
}
g_free (buf);
if (scale)
{
offset_x = (col + 1) * bsp->cell_width -
brush_scale_indicator_width;
offset_y = (row + 1) * bsp->cell_height -
brush_scale_indicator_height - bsp->scroll_offset;;
for (i = 0; i < brush_scale_indicator_height; i++, offset_y++)
{
if (offset_y > 0 && offset_y < bsp->preview->allocation.height)
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview),
brush_scale_indicator_bits[i],
offset_x, offset_y,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}

View File

@ -23,6 +23,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "devices.h"
#include "interface.h"
@ -39,11 +40,11 @@
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_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
@ -87,7 +88,6 @@ struct _DeviceInfoDialog {
GtkWidget **brushes;
GtkWidget **patterns;
GtkWidget **eventboxes;
};
/* Local Data */
@ -182,14 +182,16 @@ create_input_dialog (void)
}
void
input_dialog_able_callback (GtkWidget *w, guint32 deviceid, gpointer data)
input_dialog_able_callback (GtkWidget *w,
guint32 deviceid,
gpointer data)
{
device_status_update (deviceid);
}
static void
input_dialog_destroy_callback (GtkWidget *w,
gpointer call_data)
gpointer call_data)
{
*((GtkWidget **)call_data) = NULL;
}
@ -232,7 +234,7 @@ devices_init (void)
}
void
devices_restore()
devices_restore (void)
{
char *filename;
GList *tmp_list;
@ -281,7 +283,7 @@ 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)
guchar foreground[], gchar *pattern_name)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -386,12 +388,12 @@ devices_rc_update (gchar *name, DeviceValues values,
if (values & DEVICE_BRUSH)
{
device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
}
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)
@ -512,7 +514,8 @@ devices_save_current_info (void)
}
static void
devices_write_rc_device (DeviceInfo *device_info, FILE *fp)
devices_write_rc_device (DeviceInfo *device_info,
FILE *fp)
{
GdkDeviceInfo *gdk_info;
GList *tmp_list;
@ -822,7 +825,7 @@ device_status_destroy_callback (void)
static void
devices_close_callback (GtkWidget *w,
gpointer data)
gpointer data)
{
gtk_widget_hide (GTK_WIDGET(data));
}
@ -928,10 +931,10 @@ brush_popup_open (int preview_id,
}
static void
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -1016,10 +1019,10 @@ device_popup_close (int type)
}
static gint
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -1061,7 +1064,7 @@ device_preview_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
if(type == BRUSH_PREVIEW)
if (type == BRUSH_PREVIEW)
{
brush = device_info->brush;
@ -1070,7 +1073,7 @@ device_preview_events (GtkWidget *widget,
brush->mask->height > CELL_SIZE)
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
}
else if(type == PATTERN_PREVIEW)
else if (type == PATTERN_PREVIEW)
{
pattern = device_info->pattern;
@ -1105,39 +1108,58 @@ device_preview_events (GtkWidget *widget,
}
static gint
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
}
static gint
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
}
static void
device_update_brush(GimpBrushP brush,int preview_id)
device_update_brush (GimpBrushP brush,
int preview_id)
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
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);
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);
@ -1148,7 +1170,8 @@ device_update_brush(GimpBrushP brush,int preview_id)
/* 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);
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);
@ -1168,16 +1191,31 @@ device_update_brush(GimpBrushP brush,int preview_id)
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]),
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],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}
static void
device_update_pattern(GPatternP pattern,int preview_id)
device_update_pattern (GPatternP pattern,
int preview_id)
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -1361,8 +1399,10 @@ device_status_update (guint32 deviceid)
}
}
if (show_indicators) {
brush_area_update();
pattern_area_update();
}
if (show_indicators)
{
brush_area_update();
pattern_area_update();
}
}

View File

@ -15,9 +15,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
#include <string.h>
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "gimpcontext.h"
#include "gimplist.h"
@ -54,37 +56,37 @@
GDK_ENTER_NOTIFY_MASK
/* local function prototypes */
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP);
static void display_brush (BrushSelectP, GimpBrushP, int, int);
static void display_brushes (BrushSelectP);
static void display_setup (BrushSelectP);
static void preview_calc_scrollbar (BrushSelectP);
static void brush_select_show_selected (BrushSelectP, int, int);
static void update_active_brush_field (BrushSelectP);
static void edit_active_brush ();
static gint edit_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint new_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint brush_select_brush_dirty_callback(GimpBrushP brush,
BrushSelectP bsp);
static void connect_signals_to_brush (GimpBrushP brush,
BrushSelectP bsp);
static void disconnect_signals_from_brush(GimpBrushP brush,
BrushSelectP bsp);
static void brush_added_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_removed_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_popup_open (BrushSelectP, int, int, GimpBrushP);
static void brush_popup_close (BrushSelectP);
static void display_brush (BrushSelectP, GimpBrushP, int, int);
static void display_brushes (BrushSelectP);
static void display_setup (BrushSelectP);
static void preview_calc_scrollbar (BrushSelectP);
static void brush_select_show_selected (BrushSelectP, int, int);
static void update_active_brush_field (BrushSelectP);
static void edit_active_brush ();
static gint edit_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint new_brush_callback (GtkWidget *w, GdkEvent *e,
gpointer data);
static gint brush_select_brush_dirty_callback (GimpBrushP brush,
BrushSelectP bsp);
static void connect_signals_to_brush (GimpBrushP brush,
BrushSelectP bsp);
static void disconnect_signals_from_brush (GimpBrushP brush,
BrushSelectP bsp);
static void brush_added_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
static void brush_removed_callback (GimpBrushList *list,
GimpBrushP brush,
BrushSelectP bsp);
/* static void brush_select_map_callback (GtkWidget *, BrushSelectP); */
static void brush_select_close_callback (GtkWidget *, gpointer);
static void brush_select_refresh_callback(GtkWidget *, gpointer);
static void paint_mode_menu_callback (GtkWidget *, gpointer);
static gint brush_select_events (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_resize (GtkWidget *, GdkEvent *, BrushSelectP);
static void brush_select_close_callback (GtkWidget *, gpointer);
static void brush_select_refresh_callback (GtkWidget *, gpointer);
static void paint_mode_menu_callback (GtkWidget *, gpointer);
static gint brush_select_events (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_resize (GtkWidget *, GdkEvent *, BrushSelectP);
static gint brush_select_delete_callback (GtkWidget *, GdkEvent *, gpointer);
static void preview_scroll_update (GtkAdjustment *, gpointer);
@ -790,9 +792,10 @@ display_brush (BrushSelectP bsp,
int col,
int row)
{
TempBuf * brush_buf;
MaskBuf * brush_buf;
unsigned char * src, *s;
unsigned char * buf, *b;
gboolean scale = FALSE;
int width, height;
int offset_x, offset_y;
int yend;
@ -803,6 +806,23 @@ display_brush (BrushSelectP bsp,
brush_buf = brush->mask;
if (brush_buf->width > bsp->cell_width ||
brush_buf->height > bsp->cell_height)
{
double ratio_x = (double)brush_buf->width / bsp->cell_width;
double ratio_y = (double)brush_buf->height / bsp->cell_height;
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;
}
/* calculate the offset into the image */
width = (brush_buf->width > bsp->cell_width) ? bsp->cell_width :
brush_buf->width;
@ -835,8 +855,25 @@ display_brush (BrushSelectP bsp,
src += brush_buf->width;
}
g_free (buf);
if (scale)
{
offset_x = (col + 1) * bsp->cell_width -
brush_scale_indicator_width;
offset_y = (row + 1) * bsp->cell_height -
brush_scale_indicator_height - bsp->scroll_offset;;
for (i = 0; i < brush_scale_indicator_height; i++, offset_y++)
{
if (offset_y > 0 && offset_y < bsp->preview->allocation.height)
gtk_preview_draw_row (GTK_PREVIEW (bsp->preview),
brush_scale_indicator_bits[i],
offset_x, offset_y,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}

View File

@ -23,6 +23,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "devices.h"
#include "interface.h"
@ -39,11 +40,11 @@
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_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
@ -87,7 +88,6 @@ struct _DeviceInfoDialog {
GtkWidget **brushes;
GtkWidget **patterns;
GtkWidget **eventboxes;
};
/* Local Data */
@ -182,14 +182,16 @@ create_input_dialog (void)
}
void
input_dialog_able_callback (GtkWidget *w, guint32 deviceid, gpointer data)
input_dialog_able_callback (GtkWidget *w,
guint32 deviceid,
gpointer data)
{
device_status_update (deviceid);
}
static void
input_dialog_destroy_callback (GtkWidget *w,
gpointer call_data)
gpointer call_data)
{
*((GtkWidget **)call_data) = NULL;
}
@ -232,7 +234,7 @@ devices_init (void)
}
void
devices_restore()
devices_restore (void)
{
char *filename;
GList *tmp_list;
@ -281,7 +283,7 @@ 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)
guchar foreground[], gchar *pattern_name)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -386,12 +388,12 @@ devices_rc_update (gchar *name, DeviceValues values,
if (values & DEVICE_BRUSH)
{
device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
}
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)
@ -512,7 +514,8 @@ devices_save_current_info (void)
}
static void
devices_write_rc_device (DeviceInfo *device_info, FILE *fp)
devices_write_rc_device (DeviceInfo *device_info,
FILE *fp)
{
GdkDeviceInfo *gdk_info;
GList *tmp_list;
@ -822,7 +825,7 @@ device_status_destroy_callback (void)
static void
devices_close_callback (GtkWidget *w,
gpointer data)
gpointer data)
{
gtk_widget_hide (GTK_WIDGET(data));
}
@ -928,10 +931,10 @@ brush_popup_open (int preview_id,
}
static void
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -1016,10 +1019,10 @@ device_popup_close (int type)
}
static gint
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -1061,7 +1064,7 @@ device_preview_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
if(type == BRUSH_PREVIEW)
if (type == BRUSH_PREVIEW)
{
brush = device_info->brush;
@ -1070,7 +1073,7 @@ device_preview_events (GtkWidget *widget,
brush->mask->height > CELL_SIZE)
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
}
else if(type == PATTERN_PREVIEW)
else if (type == PATTERN_PREVIEW)
{
pattern = device_info->pattern;
@ -1105,39 +1108,58 @@ device_preview_events (GtkWidget *widget,
}
static gint
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
}
static gint
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
}
static void
device_update_brush(GimpBrushP brush,int preview_id)
device_update_brush (GimpBrushP brush,
int preview_id)
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
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);
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);
@ -1148,7 +1170,8 @@ device_update_brush(GimpBrushP brush,int preview_id)
/* 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);
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);
@ -1168,16 +1191,31 @@ device_update_brush(GimpBrushP brush,int preview_id)
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]),
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],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}
static void
device_update_pattern(GPatternP pattern,int preview_id)
device_update_pattern (GPatternP pattern,
int preview_id)
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -1361,8 +1399,10 @@ device_status_update (guint32 deviceid)
}
}
if (show_indicators) {
brush_area_update();
pattern_area_update();
}
if (show_indicators)
{
brush_area_update();
pattern_area_update();
}
}

View File

@ -19,27 +19,28 @@
#include <stdlib.h>
#include <string.h>
#include "appenv.h"
#include "brush_scale.h"
#include "indicator_area.h"
#include "gimpbrushlist.h"
#define CELL_SIZE 23 /* The size of the previews */
#define CELL_PADDING 2 /* How much between brush and pattern cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
/* Global variables */
static void
brush_popup_open (GimpBrushP brush, int x, int y);
/* Prototypes */
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
/* Static variables */
static GtkWidget *indicator_table;
@ -52,8 +53,8 @@ static GtkWidget *device_patpreview = NULL;
static void
brush_popup_open (GimpBrushP brush,
int x,
int y)
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -111,10 +112,11 @@ void
brush_area_update ()
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
MaskBuf *brush_buf;
GimpBrushP brush;
unsigned char * src, *s = NULL;
unsigned char *b;
gboolean scale = FALSE;
int width,height;
int offset_x, offset_y;
int yend;
@ -126,12 +128,28 @@ brush_area_update ()
brush = get_active_brush();
if (!brush)
{
g_warning("No gimp brush found\n");
return;
g_warning("No gimp brush found\n");
return;
}
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);
@ -140,9 +158,9 @@ brush_area_update ()
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
memset (buffer, 255, sizeof (buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(brush_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -161,13 +179,27 @@ brush_area_update ()
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(brush_preview),
buffer,
offset_x, i, width);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview),
buffer, offset_x, i, width);
src += brush_buf->width;
}
gtk_widget_draw(brush_preview, NULL);
gtk_widget_show(brush_preview);
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 (brush_preview),
brush_scale_indicator_bits[i],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
gtk_widget_draw (brush_preview, NULL);
gtk_widget_show (brush_preview);
}
static gint
@ -207,7 +239,7 @@ brush_area_events (GtkWidget *widget,
(GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
NULL, NULL, bevent->time);
/* Show the brush popup window if the brush is too large */
if (brush->mask->width > CELL_SIZE ||
@ -226,10 +258,8 @@ brush_area_events (GtkWidget *widget,
return FALSE;
}
void
pattern_area_update()
pattern_area_update ()
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -257,7 +287,7 @@ pattern_area_update()
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(pattern_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -300,9 +330,9 @@ pattern_area_update()
}
static void
pattern_popup_open ( GPatternP pattern,
int x,
int y )
pattern_popup_open (GPatternP pattern,
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -372,8 +402,8 @@ pattern_popup_open ( GPatternP pattern,
}
static gint
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
{
GdkEventButton *bevent;
GPatternP pattern;
@ -425,11 +455,9 @@ pattern_area_events (GtkWidget *widget,
return FALSE;
}
GtkWidget *
indicator_area_create (int width,
int height)
indicator_area_create (int width,
int height)
{
/* Put the brush in the table */
indicator_table = gtk_table_new (1,3, FALSE);
@ -451,7 +479,7 @@ indicator_area_create (int width,
NULL);
gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview,
1, 2, 0, 1);
1, 2, 0, 1);
brush_area_update();
pattern_area_update();

View File

@ -23,6 +23,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "devices.h"
#include "interface.h"
@ -39,11 +40,11 @@
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_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
@ -87,7 +88,6 @@ struct _DeviceInfoDialog {
GtkWidget **brushes;
GtkWidget **patterns;
GtkWidget **eventboxes;
};
/* Local Data */
@ -182,14 +182,16 @@ create_input_dialog (void)
}
void
input_dialog_able_callback (GtkWidget *w, guint32 deviceid, gpointer data)
input_dialog_able_callback (GtkWidget *w,
guint32 deviceid,
gpointer data)
{
device_status_update (deviceid);
}
static void
input_dialog_destroy_callback (GtkWidget *w,
gpointer call_data)
gpointer call_data)
{
*((GtkWidget **)call_data) = NULL;
}
@ -232,7 +234,7 @@ devices_init (void)
}
void
devices_restore()
devices_restore (void)
{
char *filename;
GList *tmp_list;
@ -281,7 +283,7 @@ 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)
guchar foreground[], gchar *pattern_name)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -386,12 +388,12 @@ devices_rc_update (gchar *name, DeviceValues values,
if (values & DEVICE_BRUSH)
{
device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
}
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)
@ -512,7 +514,8 @@ devices_save_current_info (void)
}
static void
devices_write_rc_device (DeviceInfo *device_info, FILE *fp)
devices_write_rc_device (DeviceInfo *device_info,
FILE *fp)
{
GdkDeviceInfo *gdk_info;
GList *tmp_list;
@ -822,7 +825,7 @@ device_status_destroy_callback (void)
static void
devices_close_callback (GtkWidget *w,
gpointer data)
gpointer data)
{
gtk_widget_hide (GTK_WIDGET(data));
}
@ -928,10 +931,10 @@ brush_popup_open (int preview_id,
}
static void
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -1016,10 +1019,10 @@ device_popup_close (int type)
}
static gint
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -1061,7 +1064,7 @@ device_preview_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
if(type == BRUSH_PREVIEW)
if (type == BRUSH_PREVIEW)
{
brush = device_info->brush;
@ -1070,7 +1073,7 @@ device_preview_events (GtkWidget *widget,
brush->mask->height > CELL_SIZE)
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
}
else if(type == PATTERN_PREVIEW)
else if (type == PATTERN_PREVIEW)
{
pattern = device_info->pattern;
@ -1105,39 +1108,58 @@ device_preview_events (GtkWidget *widget,
}
static gint
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
}
static gint
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
}
static void
device_update_brush(GimpBrushP brush,int preview_id)
device_update_brush (GimpBrushP brush,
int preview_id)
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
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);
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);
@ -1148,7 +1170,8 @@ device_update_brush(GimpBrushP brush,int preview_id)
/* 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);
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);
@ -1168,16 +1191,31 @@ device_update_brush(GimpBrushP brush,int preview_id)
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]),
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],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}
static void
device_update_pattern(GPatternP pattern,int preview_id)
device_update_pattern (GPatternP pattern,
int preview_id)
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -1361,8 +1399,10 @@ device_status_update (guint32 deviceid)
}
}
if (show_indicators) {
brush_area_update();
pattern_area_update();
}
if (show_indicators)
{
brush_area_update();
pattern_area_update();
}
}

View File

@ -19,27 +19,28 @@
#include <stdlib.h>
#include <string.h>
#include "appenv.h"
#include "brush_scale.h"
#include "indicator_area.h"
#include "gimpbrushlist.h"
#define CELL_SIZE 23 /* The size of the previews */
#define CELL_PADDING 2 /* How much between brush and pattern cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
/* Global variables */
static void
brush_popup_open (GimpBrushP brush, int x, int y);
/* Prototypes */
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
/* Static variables */
static GtkWidget *indicator_table;
@ -52,8 +53,8 @@ static GtkWidget *device_patpreview = NULL;
static void
brush_popup_open (GimpBrushP brush,
int x,
int y)
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -111,10 +112,11 @@ void
brush_area_update ()
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
MaskBuf *brush_buf;
GimpBrushP brush;
unsigned char * src, *s = NULL;
unsigned char *b;
gboolean scale = FALSE;
int width,height;
int offset_x, offset_y;
int yend;
@ -126,12 +128,28 @@ brush_area_update ()
brush = get_active_brush();
if (!brush)
{
g_warning("No gimp brush found\n");
return;
g_warning("No gimp brush found\n");
return;
}
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);
@ -140,9 +158,9 @@ brush_area_update ()
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
memset (buffer, 255, sizeof (buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(brush_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -161,13 +179,27 @@ brush_area_update ()
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(brush_preview),
buffer,
offset_x, i, width);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview),
buffer, offset_x, i, width);
src += brush_buf->width;
}
gtk_widget_draw(brush_preview, NULL);
gtk_widget_show(brush_preview);
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 (brush_preview),
brush_scale_indicator_bits[i],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
gtk_widget_draw (brush_preview, NULL);
gtk_widget_show (brush_preview);
}
static gint
@ -207,7 +239,7 @@ brush_area_events (GtkWidget *widget,
(GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
NULL, NULL, bevent->time);
/* Show the brush popup window if the brush is too large */
if (brush->mask->width > CELL_SIZE ||
@ -226,10 +258,8 @@ brush_area_events (GtkWidget *widget,
return FALSE;
}
void
pattern_area_update()
pattern_area_update ()
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -257,7 +287,7 @@ pattern_area_update()
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(pattern_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -300,9 +330,9 @@ pattern_area_update()
}
static void
pattern_popup_open ( GPatternP pattern,
int x,
int y )
pattern_popup_open (GPatternP pattern,
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -372,8 +402,8 @@ pattern_popup_open ( GPatternP pattern,
}
static gint
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
{
GdkEventButton *bevent;
GPatternP pattern;
@ -425,11 +455,9 @@ pattern_area_events (GtkWidget *widget,
return FALSE;
}
GtkWidget *
indicator_area_create (int width,
int height)
indicator_area_create (int width,
int height)
{
/* Put the brush in the table */
indicator_table = gtk_table_new (1,3, FALSE);
@ -451,7 +479,7 @@ indicator_area_create (int width,
NULL);
gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview,
1, 2, 0, 1);
1, 2, 0, 1);
brush_area_update();
pattern_area_update();

View File

@ -23,6 +23,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "devices.h"
#include "interface.h"
@ -39,11 +40,11 @@
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_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
@ -87,7 +88,6 @@ struct _DeviceInfoDialog {
GtkWidget **brushes;
GtkWidget **patterns;
GtkWidget **eventboxes;
};
/* Local Data */
@ -182,14 +182,16 @@ create_input_dialog (void)
}
void
input_dialog_able_callback (GtkWidget *w, guint32 deviceid, gpointer data)
input_dialog_able_callback (GtkWidget *w,
guint32 deviceid,
gpointer data)
{
device_status_update (deviceid);
}
static void
input_dialog_destroy_callback (GtkWidget *w,
gpointer call_data)
gpointer call_data)
{
*((GtkWidget **)call_data) = NULL;
}
@ -232,7 +234,7 @@ devices_init (void)
}
void
devices_restore()
devices_restore (void)
{
char *filename;
GList *tmp_list;
@ -281,7 +283,7 @@ 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)
guchar foreground[], gchar *pattern_name)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -386,12 +388,12 @@ devices_rc_update (gchar *name, DeviceValues values,
if (values & DEVICE_BRUSH)
{
device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
}
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)
@ -512,7 +514,8 @@ devices_save_current_info (void)
}
static void
devices_write_rc_device (DeviceInfo *device_info, FILE *fp)
devices_write_rc_device (DeviceInfo *device_info,
FILE *fp)
{
GdkDeviceInfo *gdk_info;
GList *tmp_list;
@ -822,7 +825,7 @@ device_status_destroy_callback (void)
static void
devices_close_callback (GtkWidget *w,
gpointer data)
gpointer data)
{
gtk_widget_hide (GTK_WIDGET(data));
}
@ -928,10 +931,10 @@ brush_popup_open (int preview_id,
}
static void
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -1016,10 +1019,10 @@ device_popup_close (int type)
}
static gint
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -1061,7 +1064,7 @@ device_preview_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
if(type == BRUSH_PREVIEW)
if (type == BRUSH_PREVIEW)
{
brush = device_info->brush;
@ -1070,7 +1073,7 @@ device_preview_events (GtkWidget *widget,
brush->mask->height > CELL_SIZE)
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
}
else if(type == PATTERN_PREVIEW)
else if (type == PATTERN_PREVIEW)
{
pattern = device_info->pattern;
@ -1105,39 +1108,58 @@ device_preview_events (GtkWidget *widget,
}
static gint
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
}
static gint
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
}
static void
device_update_brush(GimpBrushP brush,int preview_id)
device_update_brush (GimpBrushP brush,
int preview_id)
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
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);
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);
@ -1148,7 +1170,8 @@ device_update_brush(GimpBrushP brush,int preview_id)
/* 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);
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);
@ -1168,16 +1191,31 @@ device_update_brush(GimpBrushP brush,int preview_id)
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]),
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],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}
static void
device_update_pattern(GPatternP pattern,int preview_id)
device_update_pattern (GPatternP pattern,
int preview_id)
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -1361,8 +1399,10 @@ device_status_update (guint32 deviceid)
}
}
if (show_indicators) {
brush_area_update();
pattern_area_update();
}
if (show_indicators)
{
brush_area_update();
pattern_area_update();
}
}

View File

@ -23,6 +23,7 @@
#include "appenv.h"
#include "actionarea.h"
#include "brush_scale.h"
#include "gimpbrushlist.h"
#include "devices.h"
#include "interface.h"
@ -39,11 +40,11 @@
#define CELL_SIZE 20 /* The size of the preview cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_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
@ -87,7 +88,6 @@ struct _DeviceInfoDialog {
GtkWidget **brushes;
GtkWidget **patterns;
GtkWidget **eventboxes;
};
/* Local Data */
@ -182,14 +182,16 @@ create_input_dialog (void)
}
void
input_dialog_able_callback (GtkWidget *w, guint32 deviceid, gpointer data)
input_dialog_able_callback (GtkWidget *w,
guint32 deviceid,
gpointer data)
{
device_status_update (deviceid);
}
static void
input_dialog_destroy_callback (GtkWidget *w,
gpointer call_data)
gpointer call_data)
{
*((GtkWidget **)call_data) = NULL;
}
@ -232,7 +234,7 @@ devices_init (void)
}
void
devices_restore()
devices_restore (void)
{
char *filename;
GList *tmp_list;
@ -281,7 +283,7 @@ 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)
guchar foreground[], gchar *pattern_name)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -386,12 +388,12 @@ devices_rc_update (gchar *name, DeviceValues values,
if (values & DEVICE_BRUSH)
{
device_info->brush = gimp_brush_list_get_brush(brush_list, brush_name);
device_info->brush = gimp_brush_list_get_brush (brush_list, brush_name);
}
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)
@ -512,7 +514,8 @@ devices_save_current_info (void)
}
static void
devices_write_rc_device (DeviceInfo *device_info, FILE *fp)
devices_write_rc_device (DeviceInfo *device_info,
FILE *fp)
{
GdkDeviceInfo *gdk_info;
GList *tmp_list;
@ -822,7 +825,7 @@ device_status_destroy_callback (void)
static void
devices_close_callback (GtkWidget *w,
gpointer data)
gpointer data)
{
gtk_widget_hide (GTK_WIDGET(data));
}
@ -928,10 +931,10 @@ brush_popup_open (int preview_id,
}
static void
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
pattern_popup_open (int preview_id,
int x,
int y,
GPatternP pattern)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -1016,10 +1019,10 @@ device_popup_close (int type)
}
static gint
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
device_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid,
int type)
{
GList *tmp_list;
DeviceInfo *device_info;
@ -1061,7 +1064,7 @@ device_preview_events (GtkWidget *widget,
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
if(type == BRUSH_PREVIEW)
if (type == BRUSH_PREVIEW)
{
brush = device_info->brush;
@ -1070,7 +1073,7 @@ device_preview_events (GtkWidget *widget,
brush->mask->height > CELL_SIZE)
brush_popup_open (deviceid, bevent->x, bevent->y, brush);
}
else if(type == PATTERN_PREVIEW)
else if (type == PATTERN_PREVIEW)
{
pattern = device_info->pattern;
@ -1105,39 +1108,58 @@ device_preview_events (GtkWidget *widget,
}
static gint
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
brush_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,BRUSH_PREVIEW));
return (device_preview_events (widget, event, deviceid, BRUSH_PREVIEW));
}
static gint
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
pattern_preview_events (GtkWidget *widget,
GdkEvent *event,
int deviceid)
{
return(device_preview_events(widget,event,deviceid,PATTERN_PREVIEW));
return (device_preview_events (widget, event, deviceid, PATTERN_PREVIEW));
}
static void
device_update_brush(GimpBrushP brush,int preview_id)
device_update_brush (GimpBrushP brush,
int preview_id)
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
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);
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);
@ -1148,7 +1170,8 @@ device_update_brush(GimpBrushP brush,int preview_id)
/* 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);
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);
@ -1168,16 +1191,31 @@ device_update_brush(GimpBrushP brush,int preview_id)
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(deviceD->brushes[preview_id]),
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],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
}
static void
device_update_pattern(GPatternP pattern,int preview_id)
device_update_pattern (GPatternP pattern,
int preview_id)
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -1361,8 +1399,10 @@ device_status_update (guint32 deviceid)
}
}
if (show_indicators) {
brush_area_update();
pattern_area_update();
}
if (show_indicators)
{
brush_area_update();
pattern_area_update();
}
}

View File

@ -19,27 +19,28 @@
#include <stdlib.h>
#include <string.h>
#include "appenv.h"
#include "brush_scale.h"
#include "indicator_area.h"
#include "gimpbrushlist.h"
#define CELL_SIZE 23 /* The size of the previews */
#define CELL_PADDING 2 /* How much between brush and pattern cells */
#define PREVIEW_EVENT_MASK GDK_EXPOSURE_MASK | \
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
GDK_BUTTON_PRESS_MASK | \
GDK_BUTTON_RELEASE_MASK | \
GDK_BUTTON1_MOTION_MASK | \
GDK_ENTER_NOTIFY_MASK | \
GDK_LEAVE_NOTIFY_MASK
/* Global variables */
static void
brush_popup_open (GimpBrushP brush, int x, int y);
/* Prototypes */
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
static void brush_popup_open (GimpBrushP brush, int x, int y);
static gint brush_area_events (GtkWidget *widget, GdkEvent *event);
static void pattern_popup_open (GPatternP brush, int x, int y);
static gint pattern_area_events (GtkWidget *widget, GdkEvent *event);
/* Static variables */
static GtkWidget *indicator_table;
@ -52,8 +53,8 @@ static GtkWidget *device_patpreview = NULL;
static void
brush_popup_open (GimpBrushP brush,
int x,
int y)
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -111,10 +112,11 @@ void
brush_area_update ()
{
guchar buffer[CELL_SIZE];
TempBuf * brush_buf;
MaskBuf *brush_buf;
GimpBrushP brush;
unsigned char * src, *s = NULL;
unsigned char *b;
gboolean scale = FALSE;
int width,height;
int offset_x, offset_y;
int yend;
@ -126,12 +128,28 @@ brush_area_update ()
brush = get_active_brush();
if (!brush)
{
g_warning("No gimp brush found\n");
return;
g_warning("No gimp brush found\n");
return;
}
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);
@ -140,9 +158,9 @@ brush_area_update ()
height = (brush_buf->height > CELL_SIZE) ? CELL_SIZE: brush_buf->height;
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
memset (buffer, 255, sizeof (buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(brush_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -161,13 +179,27 @@ brush_area_update ()
for (j = 0; j < width ; j++)
*b++ = 255 - *s++;
gtk_preview_draw_row (GTK_PREVIEW(brush_preview),
buffer,
offset_x, i, width);
gtk_preview_draw_row (GTK_PREVIEW (brush_preview),
buffer, offset_x, i, width);
src += brush_buf->width;
}
gtk_widget_draw(brush_preview, NULL);
gtk_widget_show(brush_preview);
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 (brush_preview),
brush_scale_indicator_bits[i],
offset_x, offset_y + i,
brush_scale_indicator_width);
}
mask_buf_free (brush_buf);
}
gtk_widget_draw (brush_preview, NULL);
gtk_widget_show (brush_preview);
}
static gint
@ -207,7 +239,7 @@ brush_area_events (GtkWidget *widget,
(GDK_POINTER_MOTION_HINT_MASK |
GDK_BUTTON1_MOTION_MASK |
GDK_BUTTON_RELEASE_MASK),
NULL, NULL, bevent->time);
NULL, NULL, bevent->time);
/* Show the brush popup window if the brush is too large */
if (brush->mask->width > CELL_SIZE ||
@ -226,10 +258,8 @@ brush_area_events (GtkWidget *widget,
return FALSE;
}
void
pattern_area_update()
pattern_area_update ()
{
guchar *buffer = NULL;
TempBuf * pattern_buf;
@ -257,7 +287,7 @@ pattern_area_update()
/* Set buffer to white */
memset(buffer, 255, sizeof(buffer));
for (i = 0; i < CELL_SIZE; i++)
gtk_preview_draw_row (GTK_PREVIEW(pattern_preview), buffer, 0, i, CELL_SIZE);
gtk_preview_draw_row (GTK_PREVIEW (pattern_preview), buffer, 0, i, CELL_SIZE);
offset_x = ((CELL_SIZE - width) >> 1);
offset_y = ((CELL_SIZE - height) >> 1);
@ -300,9 +330,9 @@ pattern_area_update()
}
static void
pattern_popup_open ( GPatternP pattern,
int x,
int y )
pattern_popup_open (GPatternP pattern,
int x,
int y)
{
gint x_org, y_org;
gint scr_w, scr_h;
@ -372,8 +402,8 @@ pattern_popup_open ( GPatternP pattern,
}
static gint
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
pattern_area_events (GtkWidget *widget,
GdkEvent *event)
{
GdkEventButton *bevent;
GPatternP pattern;
@ -425,11 +455,9 @@ pattern_area_events (GtkWidget *widget,
return FALSE;
}
GtkWidget *
indicator_area_create (int width,
int height)
indicator_area_create (int width,
int height)
{
/* Put the brush in the table */
indicator_table = gtk_table_new (1,3, FALSE);
@ -451,7 +479,7 @@ indicator_area_create (int width,
NULL);
gtk_table_attach_defaults (GTK_TABLE(indicator_table), pattern_preview,
1, 2, 0, 1);
1, 2, 0, 1);
brush_area_update();
pattern_area_update();