Re: [gtk-list] Should there be a gtk "canvas" widget?
- From: Rob Browning <rlb cs utexas edu>
- To: gtk-list redhat com
- Subject: Re: [gtk-list] Should there be a gtk "canvas" widget?
- Date: 15 Feb 1998 16:30:19 -0600
Jon Trowbridge <trow@emccta.com> writes:
> For convenience and perhaps just to shave a tiny bit off of the gtk
> learning curve, maybe there should be a "canvas widget" (to borrow a
> name from Tk) that derive from a drawing area and add the tricky
> bits that are frustrating to newbies, namely:
I have been working off and on on a gtksketchpad widget (a lightweight
canvas) which does essentially what you mention. I have slacked off
though because I wasn't sure anyone would be interested, and my
immediate need has lessened. In addition, I wasn't sure enough about
how the interface should look and what the behavior should be to keep
on working.
What I have so far does handle resizes, etc, and supports a pretty
fast "set background image" function which takes GdkImages as input.
We use it here for live video.
The other feature that I added is the ability to dump the window
contents to a postscript GString which is currently supported for all
the low-level object primitives, but not for the background image.
> plot.set_foreground("red");
> plot.draw_line(10,10,plot.width()-10,10);
That's nice, and I don't handle colors as strings, but I did go a
little further and have the add_XXX function return a pointer that
you can use to later move the object around, etc.
> This is makes it easy for a novice (like me) to actually write a program
> that does something non-trivial.
Right.
> Now I'd be more than happy to clean up this (very simple) code and
> contribute it to gtk--, but it does raise a philosophical question:
> should their be widgets/functionality in gtk-- that doesn't exist in
> gtk+? Or would it be more proper to add define the canvas object in
> gtk+ and then just make a C++ wrapper for it? I would think that the
> latter option made more sense --- but that is sufficiently beyond the
> scope of my current understanding gtk+ that I couldn't be much help in
> such an endeavor...
I really think you're right that the widget should be provided at the
gtk level and then wrappered for C++.
I'm not sure I have time right now, but I would imagine that it might
make sense to think about merging what you have and what I have. I
suspect that if you looked at the existing C code, you wouldn't have
much trouble comprehending or working on it...
Here's my current gtksketchpad.h header for anyone who's interested in
the interface. I'm not convinced it shouldn't be changed. Also, I
didn't know what the overhead for GtkObjects is, but they might be
worth considering for the annotations in place of the linked list of
structs I use now...
/* GTK - The GIMP Toolkit
* Copyright (C) 1995-1997 Peter Mattis, Spencer Kimball and Josh MacDonald
*
* 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., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef __GTK_SKETCHPAD_H__
#define __GTK_SKETCHPAD_H__
#include <gdk/gdk.h>
#include <gtk/gtkmisc.h>
#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */
#define GTK_SKETCHPAD(obj) \
GTK_CHECK_CAST (obj, gtk_sketchpad_get_type (), GtkSketchpad)
#define GTK_SKETCHPAD_CLASS(klass) \
GTK_CHECK_CLASS_CAST (klass, gtk_sketchpad_get_type (), GtkSketchpadClass)
#define GTK_IS_SKETCHPAD(obj) \
GTK_CHECK_TYPE (obj, gtk_sketchpad_get_type ())
typedef struct _GtkSketchpad GtkSketchpad;
typedef struct _GtkSketchpadClass GtkSketchpadClass;
struct _GtkSketchpad
{
GtkMisc misc;
/* user specified size (not including xpad/ypad) */
gint width;
gint height;
GdkImage *image;
GdkBitmap *mask;
GSList *annotations;
};
struct _GtkSketchpadClass
{
GtkMiscClass parent_class;
};
guint gtk_sketchpad_get_type (void);
GtkWidget* gtk_sketchpad_new(const gint width, const gint height);
void gtk_sketchpad_set_size(GtkSketchpad *sketchpad,
const gint width, const gint height);
void gtk_sketchpad_bg_set(GtkSketchpad *sketchpad,
GdkImage *val,
GdkBitmap *mask);
void gtk_sketchpad_bg_get(GtkSketchpad *sketchpad,
GdkImage **val,
GdkBitmap **mask);
gpointer gtk_sketchpad_add_arc(GtkSketchpad *sketchpad,
GdkGC *gc,
const gint filled,
const gint x,
const gint y,
const gint width,
const gint height,
const gint start_angle,
const gint sweep_angle);
gpointer gtk_sketchpad_add_line(GtkSketchpad *sketchpad,
GdkGC *gc,
const gint x1,
const gint y1,
const gint x2,
const gint y2);
gpointer gtk_sketchpad_add_segments(GtkSketchpad *sketchpad,
GdkGC *gc,
const GdkSegment *segments,
const gint num_segments);
gpointer gtk_sketchpad_add_rectangle(GtkSketchpad *sketchpad,
GdkGC *gc,
const gboolean filled,
const gint x, const gint y,
const gint width, const gint height);
gpointer gtk_sketchpad_add_points(GtkSketchpad *sketchpad,
GdkGC *gc,
const GdkPoint *points,
const gint num_points);
GString* gtk_sketchpad_render_ps (GtkSketchpad *widget);
void gtk_sketchpad_sketch_move (GtkSketchpad *sketchpad,
gpointer sketch,
const gint dx,
const gint dy);
#ifdef __cplusplus
}
#endif /* __cplusplus */
#endif /* __GTK_SKETCHPAD_H__ */
#if 0
/* Huh? */
XDrawImageString
XDrawImageString16
/* Not in gdk */
XDrawArcs
XDrawLines
XDrawPoint
XDrawRectangles
/* done */
void gdk_draw_arc
void gdk_draw_segments
void gdk_draw_line
void gdk_draw_points
void gdk_draw_rectangle
/* To be done */
void gdk_draw_string
void gdk_draw_text
/* Not in X? */
void gdk_draw_polygon
void gdk_draw_pixmap
void gdk_draw_bitmap
void gdk_draw_image
#endif
--
Rob Browning <rlb@cs.utexas.edu>
PGP fingerprint = E8 0E 0D 04 F5 21 A0 94 53 2B 97 F5 D6 4E 39 30
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]