mirror of
git://git.geda-project.org/gparts
synced 2025-05-08 23:02:54 +08:00
Make background color operational. Cleanup interfaces.
This commit is contained in:
parent
7b610acf60
commit
5710fd3070
@ -153,6 +153,6 @@ libmisc_la_LIBADD = $(GLIB_LIBS)
|
||||
libscmcfg_la_SOURCES = \
|
||||
scmcfg-config.c \
|
||||
scmcfg-dirs.c
|
||||
libscmcfg_la_CFLAGS = -Wall $(AM_CFLAGS) $(GLIB_CFLAGS) $(GUILE_CFLAGS)
|
||||
libscmcfg_la_LIBADD = $(GLIB_LIBS) $(GUILE_LIBS) libsch.la libschgui.la
|
||||
libscmcfg_la_CFLAGS = -Wall $(AM_CFLAGS) $(GTK_CFLAGS) $(GUILE_CFLAGS)
|
||||
libscmcfg_la_LIBADD = $(GTK_LIBS) $(GUILE_LIBS) libsch.la libschgui.la
|
||||
|
||||
|
@ -126,59 +126,6 @@ static void
|
||||
schgui_cairo_drafter_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_begin_drawing(SchGUICairoDrafter *drafter, GtkWidget *widget)
|
||||
{
|
||||
SchGUICairoDrafterPrivate *privat = SCHGUI_CAIRO_DRAFTER_GET_PRIVATE(drafter);
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
if (privat->cairo != NULL)
|
||||
{
|
||||
cairo_destroy(privat->cairo);
|
||||
privat->cairo = NULL;
|
||||
}
|
||||
|
||||
//privat->cairo = gdk_cairo_create(gtk_widget_get_window(private->widget));
|
||||
privat->cairo = gdk_cairo_create(widget->window);
|
||||
|
||||
#if 0
|
||||
if (privat->cairo != NULL)
|
||||
{
|
||||
if (privat->pango != NULL)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
privat->pango = pango_cairo_create_context(privat->cairo);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (privat->pango != NULL)
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
//cairo_scale(privat->cairo, privat->zoom, -privat->zoom);
|
||||
|
||||
cairo_identity_matrix(privat->cairo);
|
||||
|
||||
//cairo_translate(privat->cairo, 0, 480);
|
||||
cairo_scale(privat->cairo, 1, -1);
|
||||
cairo_translate(privat->cairo, privat->tx, privat->ty);
|
||||
cairo_scale(privat->cairo, privat->zoom, privat->zoom);
|
||||
|
||||
|
||||
|
||||
cairo_set_line_width(privat->cairo, 20);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
schgui_cairo_drafter_class_init(gpointer g_class, gpointer g_class_data)
|
||||
{
|
||||
@ -918,17 +865,33 @@ schgui_cairo_drafter_draw_text(SchGUICairoDrafter *drafter, const struct _SchTex
|
||||
}
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_end_drawing(SchGUICairoDrafter *drafter)
|
||||
schgui_cairo_drafter_draw_to_widget(SchGUICairoDrafter *drafter, GtkWidget *widget)
|
||||
{
|
||||
SchGUICairoDrafterPrivate *privat = SCHGUI_CAIRO_DRAFTER_GET_PRIVATE(drafter);
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
if (privat->cairo != NULL)
|
||||
{
|
||||
cairo_destroy(privat->cairo);
|
||||
privat->cairo = NULL;
|
||||
}
|
||||
//schgui_cairo_drafter_set_zoom(drafter,1 );
|
||||
//schgui_cairo_drafter_set_translate(drafter, 0, 0);
|
||||
|
||||
//schgui_cairo_drafter_set_zoom(drafter, privat->zoom);
|
||||
//schgui_cairo_drafter_set_translate(privat->drafter, privat->tx, privat->ty);
|
||||
|
||||
privat->cairo = gdk_cairo_create(widget->window);
|
||||
// cairo_scale(privat->cairo, privat->zoom, -privat->zoom);
|
||||
cairo_identity_matrix(privat->cairo);
|
||||
//cairo_translate(privat->cairo, 0, 480);
|
||||
cairo_scale(privat->cairo, 1, -1);
|
||||
cairo_translate(privat->cairo, privat->tx, privat->ty);
|
||||
cairo_scale(privat->cairo, privat->zoom, privat->zoom);
|
||||
cairo_set_line_width(privat->cairo, 20);
|
||||
|
||||
// schgui_cairo_drafter_draw_grid(privat->drafter);
|
||||
|
||||
sch_drawing_draw(privat->drawing, SCH_DRAFTER(drafter));
|
||||
|
||||
cairo_destroy(privat->cairo);
|
||||
privat->cairo = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1109,3 +1072,93 @@ schgui_cairo_drafter_set_property(GObject *object, guint property_id, const GVal
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_zoom_extents(SchGUICairoDrafter *drafter, GtkWidget *widget)
|
||||
{
|
||||
SchGUICairoDrafterPrivate *privat = SCHGUI_CAIRO_DRAFTER_GET_PRIVATE(drafter);
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
if (privat->drawing != NULL)
|
||||
{
|
||||
GeomBounds bounds;
|
||||
int w;
|
||||
int h;
|
||||
double zx;
|
||||
double zy;
|
||||
|
||||
// schgui_cairo_drafter_begin_drawing(privat->drafter, widget);
|
||||
|
||||
sch_drawing_bounds(privat->drawing, drafter, &bounds);
|
||||
|
||||
g_debug("Min X = %d", bounds.min_x);
|
||||
g_debug("Min Y = %d", bounds.min_y);
|
||||
g_debug("Max X = %d", bounds.max_x);
|
||||
g_debug("Max Y = %d", bounds.max_y);
|
||||
|
||||
// schgui_cairo_drafter_end_drawing(privat->drafter);
|
||||
|
||||
gdk_drawable_get_size(gtk_widget_get_window(widget), &w, &h);
|
||||
|
||||
zx = 0.9 * (double)w / (bounds.max_x - bounds.min_x);
|
||||
zy = 0.9 * (double)h / (bounds.max_y - bounds.min_y);
|
||||
|
||||
if (zx < zy)
|
||||
{
|
||||
privat->zoom = zx;
|
||||
}
|
||||
else
|
||||
{
|
||||
privat->zoom = zy;
|
||||
}
|
||||
|
||||
{
|
||||
double m;
|
||||
int exp;
|
||||
int numerator;
|
||||
|
||||
m = frexp(10/privat->zoom, &exp);
|
||||
|
||||
// {
|
||||
// m = 0.1;
|
||||
// }
|
||||
// else if (m < 0.5)
|
||||
// {
|
||||
// m = 0.2;
|
||||
// }
|
||||
// else if (m < 1.0)
|
||||
// {
|
||||
// m = 0.5;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m = 1.0;
|
||||
// }
|
||||
|
||||
if (m > 0.5)
|
||||
{
|
||||
m = 1.0;
|
||||
}
|
||||
else if (m > 0.2)
|
||||
{
|
||||
m = 0.5;
|
||||
}
|
||||
else if (m > 0.1)
|
||||
{
|
||||
m = 0.2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = 0.1;
|
||||
}
|
||||
numerator = privat->zoom * ldexp(m, exp);
|
||||
|
||||
privat->zoom = numerator / ldexp(m, exp);
|
||||
}
|
||||
|
||||
privat->tx = (w - privat->zoom * (bounds.max_x)) / 2 - (privat->zoom * bounds.min_x) / 2;
|
||||
privat->ty = - h - ((privat->zoom * (bounds.max_y + bounds.min_y) ) - h ) / 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,6 @@ struct _SchGUICairoDrafterClass
|
||||
GType
|
||||
schgui_cairo_drafter_get_type(void);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_begin_drawing(SchGUICairoDrafter *drafter, GtkWidget *widget);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_end_drawing(SchGUICairoDrafter *drafter);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_set_zoom(SchGUICairoDrafter *drafter, double zoom);
|
||||
|
||||
@ -41,8 +35,18 @@ schgui_cairo_drafter_text_bounds(SchGUICairoDrafter *drafter, SchText *text, Geo
|
||||
void
|
||||
schgui_cairo_drafter_draw_grid(SchGUICairoDrafter *drafter);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_draw_to_cairo(SchGUICairoDrafter *drafter, cairo_t *cairo);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_draw_to_widget(SchGUICairoDrafter *drafter, GtkWidget *widget);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_set_config(SchGUICairoDrafter *drafter, SchGUIDrawingCfg *config);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_set_drawing(SchGUICairoDrafter *drafter, SchDrawing *drawing);
|
||||
|
||||
void
|
||||
schgui_cairo_drafter_zoom_extents(SchGUICairoDrafter *drafter, GtkWidget *widget);
|
||||
|
||||
|
@ -33,9 +33,10 @@
|
||||
|
||||
#define SCHGUI_DRAWING_CFG_GET_PRIVATE(obj) (G_TYPE_INSTANCE_GET_PRIVATE((obj),SCHGUI_TYPE_DRAWING_CFG,SchGUIDrawingCfgPrivate))
|
||||
|
||||
//enum
|
||||
//{
|
||||
//};
|
||||
enum
|
||||
{
|
||||
SCHGUI_DRAWING_CFG_BACKGROUND = 1
|
||||
};
|
||||
|
||||
typedef struct _SchGUIDrawingCfgPrivate SchGUIDrawingCfgPrivate;
|
||||
|
||||
@ -53,6 +54,9 @@ schgui_drawing_cfg_dispose(GObject *object);
|
||||
static void
|
||||
schgui_drawing_cfg_finalize(GObject *object);
|
||||
|
||||
static void
|
||||
schgui_drawing_cfg_get_background(GObject *object, GValue *value);
|
||||
|
||||
static void
|
||||
schgui_drawing_cfg_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec);
|
||||
|
||||
@ -77,6 +81,18 @@ schgui_drawing_cfg_class_init(gpointer g_class, gpointer g_class_data)
|
||||
|
||||
object_class->get_property = schgui_drawing_cfg_get_property;
|
||||
object_class->set_property = schgui_drawing_cfg_set_property;
|
||||
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
SCHGUI_DRAWING_CFG_BACKGROUND,
|
||||
g_param_spec_boxed(
|
||||
"background",
|
||||
"Background",
|
||||
"Background",
|
||||
GDK_TYPE_COLOR,
|
||||
G_PARAM_LAX_VALIDATION | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
@ -101,6 +117,47 @@ schgui_drawing_cfg_finalize(GObject *object)
|
||||
misc_object_chain_finalize(object);
|
||||
}
|
||||
|
||||
static void
|
||||
schgui_drawing_cfg_get_background(GObject *object, GValue *value)
|
||||
{
|
||||
if (value != NULL)
|
||||
{
|
||||
GdkColor color;
|
||||
int enabled = FALSE;
|
||||
|
||||
if (object != NULL)
|
||||
{
|
||||
enabled = schgui_drawing_cfg_get_color_as_gdk_color(object, 0, &color);
|
||||
}
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
color.red = 0;
|
||||
color.green = 0;
|
||||
color.blue = 0;
|
||||
}
|
||||
|
||||
g_value_set_boxed(value, &color);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
schgui_drawing_cfg_get_background_as_gdk_color(GObject *object, GdkColor *color)
|
||||
{
|
||||
int enabled = FALSE;
|
||||
|
||||
if (object != NULL)
|
||||
{
|
||||
enabled = schgui_drawing_cfg_get_color_as_gdk_color(object, 0, color);
|
||||
}
|
||||
|
||||
if (!enabled)
|
||||
{
|
||||
color->red = 0;
|
||||
color->green = 0;
|
||||
color->blue = 0;
|
||||
}
|
||||
}
|
||||
static void
|
||||
schgui_drawing_cfg_get_property(GObject *object, guint property_id, GValue *value, GParamSpec *pspec)
|
||||
{
|
||||
@ -110,6 +167,10 @@ schgui_drawing_cfg_get_property(GObject *object, guint property_id, GValue *valu
|
||||
{
|
||||
switch (property_id)
|
||||
{
|
||||
case SCHGUI_DRAWING_CFG_BACKGROUND:
|
||||
schgui_drawing_cfg_get_background(object, value);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||
}
|
||||
@ -156,6 +217,10 @@ schgui_drawing_cfg_set_property(GObject *object, guint property_id, const GValue
|
||||
{
|
||||
switch (property_id)
|
||||
{
|
||||
case SCHGUI_DRAWING_CFG_BACKGROUND:
|
||||
schgui_drawing_cfg_set_color_by_gdk_color(SCHGUI_DRAWING_CFG(object), 0, g_value_get_boxed(value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||
}
|
||||
@ -211,6 +276,11 @@ schgui_drawing_cfg_disable_color(SchGUIDrawingCfg *config, int index)
|
||||
if ((privat != NULL) && (privat->colors != NULL))
|
||||
{
|
||||
g_hash_table_remove(privat->colors, GINT_TO_POINTER(index));
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
g_object_notify(G_OBJECT(config), "background");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -238,6 +308,36 @@ schgui_drawing_cfg_get_color(SchGUIDrawingCfg *config, int index, SchGUIDrawingC
|
||||
return enabled;
|
||||
}
|
||||
|
||||
int
|
||||
schgui_drawing_cfg_get_color_as_gdk_color(SchGUIDrawingCfg *config, int index, GdkColor *color)
|
||||
{
|
||||
int enabled = FALSE;
|
||||
|
||||
if (index >= 0)
|
||||
{
|
||||
SchGUIDrawingCfgPrivate *privat = SCHGUI_DRAWING_CFG_GET_PRIVATE(config);
|
||||
|
||||
if ((privat != NULL) && (privat->colors != NULL))
|
||||
{
|
||||
SchGUIDrawingCfgColor *value = g_hash_table_lookup(privat->colors, GINT_TO_POINTER(index));
|
||||
|
||||
if (value != NULL)
|
||||
{
|
||||
if (color != NULL)
|
||||
{
|
||||
color->red = (guint16) (65535.0 * value->red);
|
||||
color->green = (guint16) (65535.0 * value->green);
|
||||
color->blue = (guint16) (65535.0 * value->blue);
|
||||
}
|
||||
|
||||
enabled = TRUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return enabled;
|
||||
}
|
||||
|
||||
SchGUIDrawingCfg*
|
||||
schgui_drawing_cfg_get_default_display(void)
|
||||
{
|
||||
@ -281,29 +381,48 @@ schgui_drawing_cfg_init(GTypeInstance *instance, gpointer g_class)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
schgui_drawing_cfg_set_color_by_gdk_color(SchGUIDrawingCfg *config, int index, const GdkColor *color)
|
||||
{
|
||||
if ((index >= 0) && (color != NULL))
|
||||
{
|
||||
SchGUIDrawingCfgPrivate *privat = SCHGUI_DRAWING_CFG_GET_PRIVATE(config);
|
||||
|
||||
if ((privat != NULL) && (privat->colors != NULL))
|
||||
{
|
||||
SchGUIDrawingCfgColor *value = g_new(SchGUIDrawingCfgColor, 1);
|
||||
|
||||
value->red = (double) color->red / 65535.0;
|
||||
value->green = (double) color->green / 65535.0;
|
||||
value->blue = (double) color->blue / 65535.0;
|
||||
|
||||
g_hash_table_replace(privat->colors, GINT_TO_POINTER(index), value);
|
||||
|
||||
if (index == 0)
|
||||
{
|
||||
g_object_notify(G_OBJECT(config), "background");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
schgui_drawing_cfg_set_color_by_name(SchGUIDrawingCfg *config, int index, const char *color)
|
||||
{
|
||||
if (index >= 0)
|
||||
if ((index >= 0) && (color != NULL))
|
||||
{
|
||||
SchGUIDrawingCfgPrivate *privat = SCHGUI_DRAWING_CFG_GET_PRIVATE(config);
|
||||
|
||||
if ((privat != NULL) && (privat->colors != NULL))
|
||||
{
|
||||
int success;
|
||||
GdkColor value1;
|
||||
GdkColor value;
|
||||
|
||||
success = gdk_color_parse(color, &value1);
|
||||
success = gdk_color_parse(color, &value);
|
||||
|
||||
if (success)
|
||||
{
|
||||
SchGUIDrawingCfgColor *value2 = g_new(SchGUIDrawingCfgColor, 1);
|
||||
|
||||
value2->red = (double) value1.red / 65535.0;
|
||||
value2->green = (double) value1.green / 65535.0;
|
||||
value2->blue = (double) value1.blue / 65535.0;
|
||||
|
||||
g_hash_table_replace(privat->colors, GINT_TO_POINTER(index), value2);
|
||||
schgui_drawing_cfg_set_color_by_gdk_color(config, index, &value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -74,7 +74,15 @@ schgui_drawing_cfg_get_output_line_width(SchGUIDrawingCfg *cfg, int shape_width,
|
||||
void
|
||||
schgui_drawing_cfg_disable_color(SchGUIDrawingCfg *config, int index);
|
||||
|
||||
/*! \brief Get the color used for drawing schematic shapes
|
||||
/*! \brief Get the configured background color
|
||||
*
|
||||
* \param [in] object This configuration
|
||||
* \param [out] color The color of the background
|
||||
*/
|
||||
void
|
||||
schgui_drawing_cfg_get_background_as_gdk_color(GObject *object, GdkColor *color);
|
||||
|
||||
/*! \brief Get a color used for drawing schematic shapes
|
||||
*
|
||||
* \param [in] config This configuration
|
||||
* \param [in] index The color index of the shape
|
||||
@ -85,11 +93,22 @@ schgui_drawing_cfg_disable_color(SchGUIDrawingCfg *config, int index);
|
||||
int
|
||||
schgui_drawing_cfg_get_color(SchGUIDrawingCfg *config, int index, SchGUIDrawingCfgColor *color);
|
||||
|
||||
/*! \brief Get a color used for drawing schematic shapes
|
||||
*
|
||||
* \param [in] config This configuration
|
||||
* \param [in] index The color index of the shape
|
||||
* \param [out] color The color of the shape, when the return value is TRUE
|
||||
* \return TRUE Shapes of this color index are enabled
|
||||
* \return FALSE Shapes of this color index are disabled
|
||||
*/
|
||||
int
|
||||
schgui_drawing_cfg_get_color_as_gdk_color(SchGUIDrawingCfg *config, int index, GdkColor *color);
|
||||
|
||||
/*! \brief Get the default configuration for display
|
||||
*
|
||||
* Do not free the returned pointer.
|
||||
*
|
||||
* return The default configuration for on-screen graphics.
|
||||
* \return The default configuration for on-screen graphics.
|
||||
*/
|
||||
SchGUIDrawingCfg*
|
||||
schgui_drawing_cfg_get_default_display(void);
|
||||
@ -98,11 +117,22 @@ schgui_drawing_cfg_get_default_display(void);
|
||||
*
|
||||
* Do not free the returned pointer.
|
||||
*
|
||||
* return The default configuration for printed graphics.
|
||||
* \return The default configuration for printed graphics.
|
||||
*/
|
||||
SchGUIDrawingCfg*
|
||||
schgui_drawing_cfg_get_default_print(void);
|
||||
|
||||
/*! \brief Set a color used for drawing schematic shapes
|
||||
*
|
||||
* The color index must be a positive integer.
|
||||
*
|
||||
* \param [in] config This configuration
|
||||
* \param [in] index The color index of the shape
|
||||
* \param [out] color The color for the shape
|
||||
*/
|
||||
void
|
||||
schgui_drawing_cfg_set_color_by_gdk_color(SchGUIDrawingCfg *config, int index, const GdkColor *color);
|
||||
|
||||
/*! \brief Set a color used for drawing schematic shapes
|
||||
*
|
||||
* The color index must be a positive integer.
|
||||
|
@ -27,6 +27,7 @@
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
#include "sch-color.h"
|
||||
#include "sch-multiline.h"
|
||||
#include "sch-text.h"
|
||||
#include "sch-drafter.h"
|
||||
@ -42,19 +43,18 @@
|
||||
enum
|
||||
{
|
||||
SCHGUI_DRAWING_VIEW_DRAFTER = 1,
|
||||
SCHGUI_DRAWING_VIEW_DRAWING
|
||||
SCHGUI_DRAWING_VIEW_DRAWING,
|
||||
SCHGUI_DRAWING_VIEW_EXTENTS
|
||||
};
|
||||
|
||||
typedef struct _SchGUIDrawingViewPrivate SchGUIDrawingViewPrivate;
|
||||
|
||||
struct _SchGUIDrawingViewPrivate
|
||||
{
|
||||
SchGUIDrawingCfg *config;
|
||||
int extents;
|
||||
SchGUICairoDrafter *drafter;
|
||||
SchDrawing *drawing;
|
||||
|
||||
gdouble zoom;
|
||||
gdouble tx;
|
||||
gdouble ty;
|
||||
};
|
||||
|
||||
static void
|
||||
@ -67,7 +67,7 @@ static void
|
||||
schgui_drawing_view_init(GTypeInstance *instance, gpointer g_class);
|
||||
|
||||
static void
|
||||
schgui_drawing_view_schematic_shape_init(gpointer g_iface, gpointer g_iface_data);
|
||||
schgui_drawing_view_set_config(SchGUIDrawingView *widget, SchGUIDrawingCfg *config);
|
||||
|
||||
static void
|
||||
schgui_drawing_view_set_property(GObject *object, guint property_id, const GValue *value, GParamSpec *pspec);
|
||||
@ -81,8 +81,7 @@ schgui_drawing_view_expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gp
|
||||
static void
|
||||
schgui_drawing_view_realize_cb(GtkWidget *widget, gpointer user_data);
|
||||
|
||||
static void
|
||||
schgui_drawing_view_unrealize_cb(GtkWidget *widget, gpointer user_data);
|
||||
|
||||
|
||||
static void
|
||||
schgui_drawing_view_class_init(gpointer g_class, gpointer g_class_data)
|
||||
@ -117,6 +116,32 @@ schgui_drawing_view_class_init(gpointer g_class, gpointer g_class_data)
|
||||
G_PARAM_LAX_VALIDATION | G_PARAM_READWRITE | G_PARAM_STATIC_STRINGS
|
||||
)
|
||||
);
|
||||
|
||||
g_object_class_install_property(
|
||||
object_class,
|
||||
SCHGUI_DRAWING_VIEW_EXTENTS,
|
||||
g_param_spec_boolean(
|
||||
"extents",
|
||||
"Extents",
|
||||
"Extents",
|
||||
TRUE,
|
||||
G_PARAM_LAX_VALIDATION | G_PARAM_READABLE | G_PARAM_STATIC_STRINGS
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
static void
|
||||
schgui_drawing_view_configure_event_cb(GtkWidget *widget, GdkEventConfigure *event, gpointer user_data)
|
||||
{
|
||||
SchGUIDrawingViewPrivate *privat = SCHGUI_DRAWING_VIEW_GET_PRIVATE(widget);
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
if (privat->extents)
|
||||
{
|
||||
schgui_drawing_view_zoom_extents(SCHGUI_DRAWING_VIEW(widget));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
@ -136,6 +161,9 @@ schgui_drawing_view_get_property(GObject *object, guint property_id, GValue *val
|
||||
g_value_set_object(value, privat->drawing);
|
||||
break;
|
||||
|
||||
case SCHGUI_DRAWING_VIEW_EXTENTS:
|
||||
g_value_set_boolean(value, privat->extents);
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID(object, property_id, pspec);
|
||||
}
|
||||
@ -145,17 +173,20 @@ schgui_drawing_view_get_property(GObject *object, guint property_id, GValue *val
|
||||
static void
|
||||
schgui_drawing_view_realize_cb(GtkWidget *widget, gpointer user_data)
|
||||
{
|
||||
double blue;
|
||||
GdkColor color;
|
||||
double green;
|
||||
double red;
|
||||
SchGUIDrawingViewPrivate *privat = SCHGUI_DRAWING_VIEW_GET_PRIVATE(widget);
|
||||
|
||||
sch_color_get_default(0, &red, &green, &blue);
|
||||
|
||||
color.red = 65535 * red;
|
||||
color.green = 65535 * green;
|
||||
color.blue = 65535 * blue;
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
schgui_drawing_cfg_get_background_as_gdk_color(privat->config, &color);
|
||||
}
|
||||
else
|
||||
{
|
||||
color.red = 0;
|
||||
color.green = 0;
|
||||
color.blue = 0;
|
||||
}
|
||||
|
||||
gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &color);
|
||||
}
|
||||
|
||||
@ -164,30 +195,9 @@ schgui_drawing_view_expose_event_cb(GtkWidget *widget, GdkEventExpose *event, gp
|
||||
{
|
||||
SchGUIDrawingViewPrivate *privat = SCHGUI_DRAWING_VIEW_GET_PRIVATE(widget);
|
||||
|
||||
if (privat != NULL)
|
||||
if ((privat != NULL) && (privat->drafter != NULL))
|
||||
{
|
||||
if (privat->drawing != NULL)
|
||||
{
|
||||
if (privat->drafter != NULL)
|
||||
{
|
||||
|
||||
schgui_cairo_drafter_set_zoom(privat->drafter,1 );
|
||||
schgui_cairo_drafter_set_translate(privat->drafter, 0, 0);
|
||||
schgui_cairo_drafter_begin_drawing(privat->drafter, widget);
|
||||
schgui_drawing_view_zoom_extents(widget);
|
||||
schgui_cairo_drafter_end_drawing(privat->drafter);
|
||||
|
||||
schgui_cairo_drafter_set_zoom(privat->drafter, privat->zoom);
|
||||
schgui_cairo_drafter_set_translate(privat->drafter, privat->tx, privat->ty);
|
||||
schgui_cairo_drafter_begin_drawing(privat->drafter, widget);
|
||||
|
||||
schgui_cairo_drafter_draw_grid(privat->drafter);
|
||||
|
||||
sch_drawing_draw(privat->drawing, SCH_DRAFTER(privat->drafter));
|
||||
|
||||
schgui_cairo_drafter_end_drawing(privat->drafter);
|
||||
}
|
||||
}
|
||||
schgui_cairo_drafter_draw_to_widget(privat->drafter, widget);
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,13 +247,27 @@ schgui_drawing_view_init(GTypeInstance *instance, gpointer g_class)
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
privat->drafter = SCHGUI_CAIRO_DRAFTER(g_object_new(
|
||||
SCHGUI_TYPE_CAIRO_DRAFTER,
|
||||
"config", schgui_drawing_cfg_get_default_display(),
|
||||
NULL
|
||||
));
|
||||
schgui_drawing_view_set_config(
|
||||
instance,
|
||||
schgui_drawing_cfg_get_default_display()
|
||||
);
|
||||
|
||||
privat->drafter = SCHGUI_CAIRO_DRAFTER(
|
||||
g_object_new(
|
||||
SCHGUI_TYPE_CAIRO_DRAFTER,
|
||||
"config", privat->config,
|
||||
NULL
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
g_signal_connect(
|
||||
G_OBJECT(instance),
|
||||
"configure-event",
|
||||
G_CALLBACK(schgui_drawing_view_configure_event_cb),
|
||||
instance
|
||||
);
|
||||
|
||||
g_signal_connect(
|
||||
G_OBJECT(instance),
|
||||
"expose-event",
|
||||
@ -257,9 +281,32 @@ schgui_drawing_view_init(GTypeInstance *instance, gpointer g_class)
|
||||
G_CALLBACK(schgui_drawing_view_realize_cb),
|
||||
instance
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
static void
|
||||
schgui_drawing_view_set_config(SchGUIDrawingView *widget, SchGUIDrawingCfg *config)
|
||||
{
|
||||
SchGUIDrawingViewPrivate *privat = SCHGUI_DRAWING_VIEW_GET_PRIVATE(widget);
|
||||
|
||||
if (privat != NULL)
|
||||
{
|
||||
if (privat->config != NULL)
|
||||
{
|
||||
g_object_unref(privat->config);
|
||||
}
|
||||
|
||||
privat->config = config;
|
||||
|
||||
if (privat->config != NULL)
|
||||
{
|
||||
g_object_ref(privat->config);
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(widget));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
schgui_drawing_view_set_drafter(SchGUIDrawingView *widget, SchGUICairoDrafter *drafter)
|
||||
{
|
||||
@ -307,6 +354,13 @@ schgui_drawing_view_set_drawing(SchGUIDrawingView *widget, SchDrawing *drawing)
|
||||
/* \todo register signals to update */
|
||||
}
|
||||
|
||||
if (privat->drafter != NULL)
|
||||
{
|
||||
schgui_cairo_drafter_set_drawing(privat->drafter, privat->drawing);
|
||||
|
||||
schgui_drawing_view_zoom_extents(widget);
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw(GTK_WIDGET(widget));
|
||||
}
|
||||
}
|
||||
@ -316,7 +370,6 @@ schgui_drawing_view_set_property(GObject *object, guint property_id, const GValu
|
||||
{
|
||||
switch (property_id)
|
||||
{
|
||||
|
||||
case SCHGUI_DRAWING_VIEW_DRAFTER:
|
||||
schgui_drawing_view_set_drafter(SCHGUI_DRAWING_VIEW(object), g_value_get_object(value));
|
||||
break;
|
||||
@ -335,92 +388,14 @@ schgui_drawing_view_zoom_extents(SchGUIDrawingView *widget)
|
||||
{
|
||||
SchGUIDrawingViewPrivate *privat = SCHGUI_DRAWING_VIEW_GET_PRIVATE(widget);
|
||||
|
||||
if (privat != NULL)
|
||||
if ((privat != NULL) && (privat->drafter != NULL))
|
||||
{
|
||||
if (privat->drawing != NULL)
|
||||
{
|
||||
if (privat->drafter != NULL)
|
||||
{
|
||||
GeomBounds bounds;
|
||||
int w;
|
||||
int h;
|
||||
double zx;
|
||||
double zy;
|
||||
schgui_cairo_drafter_zoom_extents(privat->drafter, GTK_WIDGET(widget));
|
||||
|
||||
// schgui_cairo_drafter_begin_drawing(privat->drafter, widget);
|
||||
privat->extents = TRUE;
|
||||
g_object_notify(G_OBJECT(widget), "extents");
|
||||
|
||||
sch_drawing_bounds(privat->drawing, privat->drafter, &bounds);
|
||||
|
||||
g_debug("Min X = %d", bounds.min_x);
|
||||
g_debug("Min Y = %d", bounds.min_y);
|
||||
g_debug("Max X = %d", bounds.max_x);
|
||||
g_debug("Max Y = %d", bounds.max_y);
|
||||
|
||||
// schgui_cairo_drafter_end_drawing(privat->drafter);
|
||||
|
||||
gdk_drawable_get_size(gtk_widget_get_window(widget), &w, &h);
|
||||
|
||||
zx = 0.9 * (double)w / (bounds.max_x - bounds.min_x);
|
||||
zy = 0.9 * (double)h / (bounds.max_y - bounds.min_y);
|
||||
|
||||
if (zx < zy)
|
||||
{
|
||||
privat->zoom = zx;
|
||||
}
|
||||
else
|
||||
{
|
||||
privat->zoom = zy;
|
||||
}
|
||||
|
||||
{
|
||||
double m;
|
||||
int exp;
|
||||
int numerator;
|
||||
|
||||
m = frexp(10/privat->zoom, &exp);
|
||||
|
||||
//if (m < 0.2)
|
||||
// {
|
||||
// m = 0.1;
|
||||
// }
|
||||
// else if (m < 0.5)
|
||||
// {
|
||||
// m = 0.2;
|
||||
// }
|
||||
// else if (m < 1.0)
|
||||
// {
|
||||
// m = 0.5;
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// m = 1.0;
|
||||
// }
|
||||
|
||||
if (m > 0.5)
|
||||
{
|
||||
m = 1.0;
|
||||
}
|
||||
else if (m > 0.2)
|
||||
{
|
||||
m = 0.5;
|
||||
}
|
||||
else if (m > 0.1)
|
||||
{
|
||||
m = 0.2;
|
||||
}
|
||||
else
|
||||
{
|
||||
m = 0.1;
|
||||
}
|
||||
numerator = privat->zoom * ldexp(m, exp);
|
||||
|
||||
privat->zoom = numerator / ldexp(m, exp);
|
||||
}
|
||||
|
||||
privat->tx = (w - privat->zoom * (bounds.max_x)) / 2 - (privat->zoom * bounds.min_x) / 2;
|
||||
privat->ty = - h - ((privat->zoom * (bounds.max_y + bounds.min_y) ) - h ) / 2;
|
||||
}
|
||||
}
|
||||
gtk_widget_queue_draw(GTK_WIDGET(widget));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -44,12 +44,29 @@ struct _SchGUIDrawingViewClass
|
||||
GType
|
||||
schgui_drawing_view_get_type(void);
|
||||
|
||||
/*! \brief Set a new drafter fo this widget
|
||||
*
|
||||
* Drafters know 'how' to draw the contents of the window. Currently, the drafter
|
||||
* cannot be changed.
|
||||
*
|
||||
* \param [in] widget This widget.
|
||||
* \param [in] drafter A new drafter for this widget.
|
||||
*/
|
||||
void
|
||||
schgui_drawing_view_set_drafter(SchGUIDrawingView *widget, SchGUICairoDrafter *drafter);
|
||||
|
||||
/*! \brief Set the contents of the window to a new drawing.
|
||||
*
|
||||
* \param [in] widget This widget.
|
||||
* \param [in] drawing The new drawing to show in the window.
|
||||
*/
|
||||
void
|
||||
schgui_drawing_view_set_drawing(SchGUIDrawingView *widget, SchDrawing *drawing);
|
||||
|
||||
/*! \brief Enlarges the drawing to fit the widget.
|
||||
*
|
||||
* \param [in] widget This widget.
|
||||
*/
|
||||
void
|
||||
schgui_drawing_view_zoom_extents(SchGUIDrawingView *widget);
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include <glib.h>
|
||||
#include <glib-object.h>
|
||||
#include <libguile.h>
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#include "geom.h"
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user