Commit 2c1e3f2f authored by Sven Neumann's avatar Sven Neumann
Browse files

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


--Sven
parent 522f4b34
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
......
......@@ -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 \
......
/* 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;
}
/* 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__ */
/* 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;
}
/* 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__ */
......@@ -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);
}
}
......
......@@ -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;