Commit 9fb081a7 authored by Manish Singh's avatar Manish Singh
Browse files

add gimpmath.h

* libgimp/Makefile.am: add gimpmath.h

* app/gtkwrapbox.[ch]
* app/gtkhwrapbox.[ch]: wrapbox widget from gle

* app/Makefile.am: added those files

* app/interface.c: use an hwrapbox for the toolbar. Still not perfect
yet, working on it.

* app/gimpdrawable.c
* app/about_dialog.c
* app/airbrush.c
* app/blend.c: some minor code cleanup

-Yosh
parent e5411a8e
Wed Sep 1 14:50:29 PDT 1999 Manish Singh <yosh@gimp.org>
* libgimp/Makefile.am: add gimpmath.h
* app/gtkwrapbox.[ch]
* app/gtkhwrapbox.[ch]: wrapbox widget from gle
* app/Makefile.am: added those files
* app/interface.c: use an hwrapbox for the toolbar
* app/gimpdrawable.c
* app/about_dialog.c
* app/airbrush.c
* app/blend.c: some minor code cleanup
1999-09-02 Tor Lillqvist <tml@iki.fi>
* app/paintbrush.c (paintbrush_non_gui_default,
......@@ -44,6 +60,7 @@ Wed Sep 1 23:18:21 BST 1999 Andy Thomas <alt@gimp.org>
the area shown is smaller than the overall image size. Thanks to tml
for the idea.
>>>>>>> 1.1481
Wed Sep 1 22:28:09 BST 1999 Adam D. Moss <adam@gimp.org>
* app/gradient.c
......
......@@ -227,6 +227,10 @@ gimp_SOURCES = \
gradient_select_cmds.c \
gradient.h \
gradient_cmds.c \
gtkwrapbox.c \
gtkwrapbox.h \
gtkhwrapbox.c \
gtkhwrapbox.h \
guides_cmds.c \
gximage.c \
gximage.h \
......
......@@ -368,14 +368,14 @@ about_dialog_load_logo (GtkWidget *window)
}
static void
about_dialog_destroy ()
about_dialog_destroy (void)
{
about_dialog = NULL;
about_dialog_unmap ();
}
static void
about_dialog_unmap ()
about_dialog_unmap (void)
{
if (timer)
{
......
......@@ -167,7 +167,7 @@ airbrush_options_new (void)
}
Tool *
tools_new_airbrush ()
tools_new_airbrush (void)
{
Tool * tool;
PaintCore * private;
......
......@@ -17,6 +17,8 @@
*/
#include "config.h"
#include <stdlib.h>
#include "appenv.h"
#include "asupsample.h"
#include "blend.h"
......
......@@ -17,6 +17,8 @@
*/
#include "config.h"
#include <stdlib.h>
#include "appenv.h"
#include "asupsample.h"
#include "blend.h"
......
......@@ -44,7 +44,7 @@ static GimpDrawableClass *parent_class = NULL;
GtkType
gimp_drawable_get_type ()
gimp_drawable_get_type (void)
{
static GtkType type;
GIMP_TYPE_INIT(type,
......
......@@ -368,14 +368,14 @@ about_dialog_load_logo (GtkWidget *window)
}
static void
about_dialog_destroy ()
about_dialog_destroy (void)
{
about_dialog = NULL;
about_dialog_unmap ();
}
static void
about_dialog_unmap ()
about_dialog_unmap (void)
{
if (timer)
{
......
......@@ -35,6 +35,7 @@
#include "gimage.h"
#include "gimpdnd.h"
#include "gimprc.h"
#include "gtkhwrapbox.h"
#include "indicator_area.h"
#include "interface.h"
#include "menus.h"
......@@ -340,7 +341,7 @@ create_tool_pixmap (GtkWidget *parent,
static void
create_tools (GtkWidget *parent)
{
GtkWidget *table;
GtkWidget *wbox;
GtkWidget *button;
GtkWidget *alignment;
GtkWidget *pixmap;
......@@ -348,9 +349,11 @@ create_tools (GtkWidget *parent)
gint i, j;
/*create_logo (parent);*/
table = gtk_table_new (ROWS, COLUMNS, TRUE);
gtk_box_pack_start (GTK_BOX (parent), table, TRUE, TRUE, 0);
gtk_widget_realize (table);
wbox = GTK_WIDGET (gtk_type_new (gtk_hwrap_box_get_type ()));
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), .36);
gtk_box_pack_start (GTK_BOX (parent), wbox, TRUE, TRUE, 0);
gtk_widget_realize (gtk_widget_get_toplevel (wbox));
group = NULL;
......@@ -365,18 +368,14 @@ create_tools (GtkWidget *parent)
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
gtk_table_attach (GTK_TABLE (table), button,
(i % 3), (i % 3) + 1,
(i / 3), (i / 3) + 1,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
0, 0);
gtk_wrap_box_pack (GTK_WRAP_BOX (wbox), button,
FALSE, TRUE, FALSE, TRUE);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 0);
gtk_container_add (GTK_CONTAINER (button), alignment);
pixmap = create_pixmap_widget (table->window, tool_info[j].icon_data, 22, 22);
pixmap = create_pixmap_widget (wbox->window, tool_info[j].icon_data, 22, 22);
gtk_container_add (GTK_CONTAINER (alignment), pixmap);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
......@@ -406,7 +405,7 @@ create_tools (GtkWidget *parent)
(gpointer) tool_info[j].tool_id);
}
}
gtk_widget_show (table);
gtk_widget_show (wbox);
}
static GdkPixmap *
......
......@@ -35,6 +35,7 @@
#include "gimage.h"
#include "gimpdnd.h"
#include "gimprc.h"
#include "gtkhwrapbox.h"
#include "indicator_area.h"
#include "interface.h"
#include "menus.h"
......@@ -340,7 +341,7 @@ create_tool_pixmap (GtkWidget *parent,
static void
create_tools (GtkWidget *parent)
{
GtkWidget *table;
GtkWidget *wbox;
GtkWidget *button;
GtkWidget *alignment;
GtkWidget *pixmap;
......@@ -348,9 +349,11 @@ create_tools (GtkWidget *parent)
gint i, j;
/*create_logo (parent);*/
table = gtk_table_new (ROWS, COLUMNS, TRUE);
gtk_box_pack_start (GTK_BOX (parent), table, TRUE, TRUE, 0);
gtk_widget_realize (table);
wbox = GTK_WIDGET (gtk_type_new (gtk_hwrap_box_get_type ()));
gtk_wrap_box_set_aspect_ratio (GTK_WRAP_BOX (wbox), .36);
gtk_box_pack_start (GTK_BOX (parent), wbox, TRUE, TRUE, 0);
gtk_widget_realize (gtk_widget_get_toplevel (wbox));
group = NULL;
......@@ -365,18 +368,14 @@ create_tools (GtkWidget *parent)
gtk_toggle_button_set_mode (GTK_TOGGLE_BUTTON (button), FALSE);
gtk_table_attach (GTK_TABLE (table), button,
(i % 3), (i % 3) + 1,
(i / 3), (i / 3) + 1,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
GTK_EXPAND | GTK_SHRINK | GTK_FILL,
0, 0);
gtk_wrap_box_pack (GTK_WRAP_BOX (wbox), button,
FALSE, TRUE, FALSE, TRUE);
alignment = gtk_alignment_new (0.5, 0.5, 0.0, 0.0);
gtk_container_set_border_width (GTK_CONTAINER (alignment), 0);
gtk_container_add (GTK_CONTAINER (button), alignment);
pixmap = create_pixmap_widget (table->window, tool_info[j].icon_data, 22, 22);
pixmap = create_pixmap_widget (wbox->window, tool_info[j].icon_data, 22, 22);
gtk_container_add (GTK_CONTAINER (alignment), pixmap);
gtk_signal_connect (GTK_OBJECT (button), "toggled",
......@@ -406,7 +405,7 @@ create_tools (GtkWidget *parent)
(gpointer) tool_info[j].tool_id);
}
}
gtk_widget_show (table);
gtk_widget_show (wbox);
}
static GdkPixmap *
......
......@@ -44,7 +44,7 @@ static GimpDrawableClass *parent_class = NULL;
GtkType
gimp_drawable_get_type ()
gimp_drawable_get_type (void)
{
static GtkType type;
GIMP_TYPE_INIT(type,
......
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* GtkHWrapBox: Horizontal wrapping box widget
* Copyright (C) 1999 Tim Janik
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library 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
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
* Boston, MA 02111-1307, USA.
*/
#include "gtkhwrapbox.h"
#include <math.h>
/* --- prototypes --- */
static void gtk_hwrap_box_class_init (GtkHWrapBoxClass *klass);
static void gtk_hwrap_box_init (GtkHWrapBox *hwbox);
static void gtk_hwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition);
static void gtk_hwrap_box_size_allocate (GtkWidget *widget,
GtkAllocation *allocation);
/* --- variables --- */
static gpointer parent_class = NULL;
/* --- functions --- */
GtkType
gtk_hwrap_box_get_type (void)
{
static GtkType hwrap_box_type = 0;
if (!hwrap_box_type)
{
static const GtkTypeInfo hwrap_box_info =
{
"GtkHWrapBox",
sizeof (GtkHWrapBox),
sizeof (GtkHWrapBoxClass),
(GtkClassInitFunc) gtk_hwrap_box_class_init,
(GtkObjectInitFunc) gtk_hwrap_box_init,
/* reserved_1 */ NULL,
/* reserved_2 */ NULL,
(GtkClassInitFunc) NULL,
};
hwrap_box_type = gtk_type_unique (GTK_TYPE_WRAP_BOX, &hwrap_box_info);
}
return hwrap_box_type;
}
static void
gtk_hwrap_box_class_init (GtkHWrapBoxClass *class)
{
GtkObjectClass *object_class;
GtkWidgetClass *widget_class;
GtkContainerClass *container_class;
GtkWrapBoxClass *wrap_box_class;
object_class = GTK_OBJECT_CLASS (class);
widget_class = GTK_WIDGET_CLASS (class);
container_class = GTK_CONTAINER_CLASS (class);
wrap_box_class = GTK_WRAP_BOX_CLASS (class);
parent_class = gtk_type_class (GTK_TYPE_WRAP_BOX);
widget_class->size_request = gtk_hwrap_box_size_request;
widget_class->size_allocate = gtk_hwrap_box_size_allocate;
}
static void
gtk_hwrap_box_init (GtkHWrapBox *hwbox)
{
hwbox->max_child_width = 0;
hwbox->max_child_height = 0;
}
static inline void
get_child_requisition (GtkWrapBox *wbox,
GtkWidget *child,
GtkRequisition *child_requisition)
{
if (wbox->homogeneous)
{
GtkHWrapBox *hwbox = GTK_HWRAP_BOX (wbox);
child_requisition->width = hwbox->max_child_width;
child_requisition->height = hwbox->max_child_height;
}
else
gtk_widget_get_child_requisition (child, child_requisition);
}
static void
_gtk_hwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkHWrapBox *this = GTK_HWRAP_BOX (widget);
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkWrapBoxChild *child;
guint area = 0;
g_return_if_fail (requisition != NULL);
/*<h2v-off>*/
requisition->width = 0;
requisition->height = 0;
this->max_child_width = 0;
this->max_child_height = 0;
for (child = wbox->children; child; child = child->next)
if (GTK_WIDGET_VISIBLE (child->widget))
{
GtkRequisition child_requisition;
gtk_widget_size_request (child->widget, &child_requisition);
area += child_requisition.width * child_requisition.height;
this->max_child_width = MAX (this->max_child_width, child_requisition.width);
this->max_child_height = MAX (this->max_child_height, child_requisition.height);
}
if (wbox->homogeneous)
area = this->max_child_width * this->max_child_height * wbox->n_children;
if (area)
{
requisition->width = sqrt (area * wbox->aspect_ratio);
requisition->height = area / requisition->width;
}
else
{
requisition->width = 0;
requisition->height = 0;
}
requisition->width += GTK_CONTAINER (wbox)->border_width * 2;
requisition->height += GTK_CONTAINER (wbox)->border_width * 2;
/*<h2v-on>*/
}
static gfloat
get_layout_size (GtkHWrapBox *this,
guint max_width,
guint *width_inc)
{
GtkWrapBox *wbox = GTK_WRAP_BOX (this);
GtkWrapBoxChild *child;
guint n_rows, left_over = 0, total_height = 0;
gboolean last_row_filled = TRUE;
*width_inc = this->max_child_width + 1;
n_rows = 0;
for (child = wbox->children; child; child = child->next)
{
GtkWrapBoxChild *row_child;
GtkRequisition child_requisition;
guint row_width, row_height, n = 1;
if (!GTK_WIDGET_VISIBLE (child->widget))
continue;
get_child_requisition (wbox, child->widget, &child_requisition);
if (!last_row_filled)
*width_inc = MIN (*width_inc, child_requisition.width - left_over);
row_width = child_requisition.width;
row_height = child_requisition.height;
for (row_child = child->next; row_child && n < wbox->child_limit; row_child = row_child->next)
{
if (GTK_WIDGET_VISIBLE (row_child->widget))
{
get_child_requisition (wbox, row_child->widget, &child_requisition);
if (row_width + wbox->hspacing + child_requisition.width > max_width)
break;
row_width += wbox->hspacing + child_requisition.width;
row_height = MAX (row_height, child_requisition.height);
n++;
}
child = row_child;
}
last_row_filled = n >= wbox->child_limit;
left_over = last_row_filled ? 0 : max_width - (row_width + wbox->hspacing);
total_height += (n_rows ? wbox->vspacing : 0) + row_height;
n_rows++;
}
if (*width_inc > this->max_child_width)
*width_inc = 0;
return MAX (total_height, 1);
}
static void
gtk_hwrap_box_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkHWrapBox *this = GTK_HWRAP_BOX (widget);
GtkWrapBox *wbox = GTK_WRAP_BOX (widget);
GtkWrapBoxChild *child;
gfloat ratio_dist, layout_width = 0;
guint row_inc = 0;
g_return_if_fail (requisition != NULL);
requisition->width = 0;
requisition->height = 0;
this->max_child_width = 0;
this->max_child_height = 0;
/* size_request all children */
for (child = wbox->children; child; child = child->next)
if (GTK_WIDGET_VISIBLE (child->widget))
{
GtkRequisition child_requisition;
gtk_widget_size_request (child->widget, &child_requisition);
this->max_child_width = MAX (this->max_child_width, child_requisition.width);
this->max_child_height = MAX (this->max_child_height, child_requisition.height);
}
/* figure all possible layouts */
ratio_dist = 32768;
layout_width = this->max_child_width;
do
{
gfloat layout_height;
gfloat ratio, dist;
layout_width += row_inc;
layout_height = get_layout_size (this, layout_width, &row_inc);
ratio = layout_width / layout_height; /*<h2v-skip>*/
dist = MAX (ratio, wbox->aspect_ratio) - MIN (ratio, wbox->aspect_ratio);
if (dist < ratio_dist)
{
ratio_dist = dist;
requisition->width = layout_width;
requisition->height = layout_height;
}
/*<h2v-off>*/
g_print ("ratio for width %d height %d = %f\n",
(gint) layout_width,
(gint) layout_height,
ratio);
/*<h2v-on>*/
}
while (row_inc);
/*<h2v-off>*/
requisition->width += GTK_CONTAINER (wbox)->border_width * 2;
requisition->height += GTK_CONTAINER (wbox)->border_width * 2;
g_print ("choosen: width %d, height %d\n",
requisition->width,
requisition->height);
/*<h2v-on>*/
}
static GSList*
list_row_children (GtkWrapBox *wbox,
GtkWrapBoxChild **child_p,
guint row_width,
guint *max_height,
gboolean *can_vexpand)
{
GSList *slist = NULL;
guint width = 0;
GtkWrapBoxChild *child = *child_p;
*max_height = 0;
*can_vexpand = FALSE;
while (child && !GTK_WIDGET_VISIBLE (child->widget))
{
*child_p = child->next;
child = *child_p;
}
if (child)
{
GtkRequisition child_requisition;
guint n = 1;
get_child_requisition (wbox, child->widget, &child_requisition);
width += child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height);
*can_vexpand |= child->vexpand;
slist = g_slist_prepend (slist, child);
*child_p = child->next;
child = *child_p;
while (child && n < wbox->child_limit)
{
if (GTK_WIDGET_VISIBLE (child->widget))
{
get_child_requisition (wbox, child->widget, &child_requisition);
if (width + wbox->hspacing + child_requisition.width > row_width)
break;
width += wbox->hspacing + child_requisition.width;
*max_height = MAX (*max_height, child_requisition.height);
*can_vexpand |= child->vexpand;
slist = g_slist_prepend (slist, child);
n++;
}
*child_p = child->next;
child = *child_p;
}
}
return g_slist_reverse (slist);
}
static void
layout_row (GtkWrapBox *wbox,
GtkAllocation *area,
GSList *children,
guint children_per_line,
gboolean vexpand)
{
GSList *slist;
guint n_children = 0, n_expand_children = 0, have_expand_children = 0, total_width = 0;
gfloat x, width, extra;
GtkAllocation child_allocation;
for (slist = children; slist; slist = slist->next)
{
GtkWrapBoxChild *child = slist->data;
GtkRequisition child_requisition;
n_children++;
if (child->hexpand)
n_expand_children++;
get_child_requisition (wbox, child->widget, &child_requisition);
total_width += child_requisition.width;
}
width = MAX (1, area->width - (n_children - 1) * wbox->hspacing);
if (width > total_width)
extra = width - total_width;
else
extra = 0;
have_expand_children = n_expand_children && extra;
x = area->x;
if (wbox->homogeneous)
{
width = MAX (1, area->width - (children_per_line - 1) * wbox->hspacing);
width /= ((gdouble) children_per_line);
extra = 0;
}
else if (have_expand_children)
{