summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSøren Sandmann <sandmann@redhat.com>2008-03-09 12:34:53 -0400
committerSøren Sandmann <sandmann@redhat.com>2008-03-09 12:34:53 -0400
commit4d16fbd0b71834eb0192a0ae396e466e835c7af9 (patch)
treeddf2c40f514d6848774346b37c03e23a1d97ccee
parent1e212475d90102c11d2642b046c63afd1363e797 (diff)
s/app/window/
-rw-r--r--siv.c213
1 files changed, 98 insertions, 115 deletions
diff --git a/siv.c b/siv.c
index f4f6906..7e70601 100644
--- a/siv.c
+++ b/siv.c
@@ -35,13 +35,6 @@
typedef struct Window Window;
struct Window
{
-
-};
-
-typedef struct Application Application;
-
-struct Application
-{
GladeXML * xml;
GdkPixbuf * original;
GdkPixbuf * displayed;
@@ -54,8 +47,8 @@ struct Application
GtkAllocation allocation;
};
-#define GET_WIDGET(app,name) \
- ((void *)glade_xml_get_widget(app->xml, name))
+#define GET_WIDGET(window,name) \
+ ((void *)glade_xml_get_widget(window->xml, name))
static void
sorry (GtkWidget *parent_window,
@@ -83,13 +76,13 @@ sorry (GtkWidget *parent_window,
}
static double
-get_scale (Application *app)
+get_scale (Window *window)
{
- return pow (1.05, app->zoom_level);
+ return pow (1.05, window->zoom_level);
}
static void
-compute_size (Application *app, int *w, int *h)
+compute_size (Window *window, int *w, int *h)
{
int d;
double scale;
@@ -97,14 +90,14 @@ compute_size (Application *app, int *w, int *h)
if (!w) w = &d;
if (!h) h = &d;
- scale = get_scale (app);
+ scale = get_scale (window);
- *w = gdk_pixbuf_get_width (app->original) * scale;
- *h = gdk_pixbuf_get_height (app->original) * scale;
+ *w = gdk_pixbuf_get_width (window->original) * scale;
+ *h = gdk_pixbuf_get_height (window->original) * scale;
}
static gboolean
-on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
+on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Window *window)
{
GdkPixbuf *tmp;
GdkInterpType interp;
@@ -113,16 +106,16 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
GdkRectangle image;
guint32 color1, color2;
- if (!app->original)
+ if (!window->original)
return TRUE;
- if (!GTK_WIDGET_DRAWABLE (GET_WIDGET (app, "drawing_area")))
+ if (!GTK_WIDGET_DRAWABLE (GET_WIDGET (window, "drawing_area")))
return TRUE;
gdk_window_get_size (drawing_area->window, &window_width, &window_height);
image.x = image.y = 0;
- compute_size (app, &image.width, &image.height);
+ compute_size (window, &image.width, &image.height);
if (image.width < window_width)
image.x = (window_width - image.width) / 2;
@@ -135,7 +128,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
tmp = gdk_pixbuf_new (GDK_COLORSPACE_RGB, TRUE, 8, dest.width, dest.height);
- if (gtk_check_menu_item_get_active (GET_WIDGET (app, "menu_no")))
+ if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_no")))
{
GdkColor color = drawing_area->style->bg[GTK_STATE_NORMAL];
@@ -145,7 +138,7 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
color2 = color1;
}
- else if (gtk_check_menu_item_get_active (GET_WIDGET (app, "menu_white")))
+ else if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_white")))
{
color1 = 0x00ffffff;
color2 = 0x00ffffff;
@@ -156,15 +149,15 @@ on_expose (GtkWidget *drawing_area, GdkEventExpose *expose, Application *app)
color2 = 0x00cccccc;
}
- if (gtk_check_menu_item_get_active (GET_WIDGET (app, "menu_smooth_image")))
+ if (gtk_check_menu_item_get_active (GET_WIDGET (window, "menu_smooth_image")))
interp = GDK_INTERP_BILINEAR;
else
interp = GDK_INTERP_NEAREST;
- gdk_pixbuf_composite_color (app->original, tmp,
+ gdk_pixbuf_composite_color (window->original, tmp,
0, 0, dest.width, dest.height,
-(dest.x - image.x), -(dest.y - image.y),
- get_scale (app), get_scale (app),
+ get_scale (window), get_scale (window),
interp, 0xff,
dest.x - image.x, dest.y - image.y,
16, color1, color2);
@@ -192,18 +185,18 @@ adjust_adjustment (GtkAdjustment *adj, int old_size, int new_size)
}
static void
-rebuild (Application *app)
+rebuild (Window *window)
{
gboolean can_zoom_out;
gboolean can_zoom_in;
- if (app->zoom_level < MIN_ZOOM)
- app->zoom_level = MIN_ZOOM;
+ if (window->zoom_level < MIN_ZOOM)
+ window->zoom_level = MIN_ZOOM;
- if (app->zoom_level > MAX_ZOOM)
- app->zoom_level = MAX_ZOOM;
+ if (window->zoom_level > MAX_ZOOM)
+ window->zoom_level = MAX_ZOOM;
- if (!app->original)
+ if (!window->original)
{
can_zoom_out = FALSE;
can_zoom_in = FALSE;
@@ -213,112 +206,112 @@ rebuild (Application *app)
int w, h;
GtkAdjustment *vadj, *hadj;
- compute_size (app, &w, &h);
+ compute_size (window, &w, &h);
- can_zoom_in = app->zoom_level < MAX_ZOOM;
+ can_zoom_in = window->zoom_level < MAX_ZOOM;
- can_zoom_out = app->zoom_level > MIN_ZOOM;
- if (app->zoom_level <= 0 && (w < 32 || h < 32))
+ can_zoom_out = window->zoom_level > MIN_ZOOM;
+ if (window->zoom_level <= 0 && (w < 32 || h < 32))
can_zoom_out = FALSE;
- gtk_widget_hide (GET_WIDGET (app, "scrolled_window"));
+ gtk_widget_hide (GET_WIDGET (window, "scrolled_window"));
- hadj = gtk_scrolled_window_get_hadjustment (GET_WIDGET (app, "scrolled_window"));
- vadj = gtk_scrolled_window_get_vadjustment (GET_WIDGET (app, "scrolled_window"));
+ hadj = gtk_scrolled_window_get_hadjustment (GET_WIDGET (window, "scrolled_window"));
+ vadj = gtk_scrolled_window_get_vadjustment (GET_WIDGET (window, "scrolled_window"));
#if 0
- gtk_viewport_set_hadjustment (GET_WIDGET (app, "viewport1"), NULL);
- gtk_viewport_set_vadjustment (GET_WIDGET (app, "viewport1"), NULL);
+ gtk_viewport_set_hadjustment (GET_WIDGET (window, "viewport1"), NULL);
+ gtk_viewport_set_vadjustment (GET_WIDGET (window, "viewport1"), NULL);
#endif
- if (app->first)
+ if (window->first)
{
gtk_adjustment_set_value (hadj, 0.0);
gtk_adjustment_set_value (vadj, 0.0);
- app->first = FALSE;
+ window->first = FALSE;
}
else
{
if (hadj->page_size < w)
- adjust_adjustment (hadj, app->width, w);
+ adjust_adjustment (hadj, window->width, w);
if (vadj->page_size < h)
- adjust_adjustment (vadj, app->height, h);
+ adjust_adjustment (vadj, window->height, h);
}
- gtk_widget_set_size_request (GET_WIDGET (app, "drawing_area"), w, h);
+ gtk_widget_set_size_request (GET_WIDGET (window, "drawing_area"), w, h);
- gtk_widget_show (GET_WIDGET (app, "scrolled_window"));
+ gtk_widget_show (GET_WIDGET (window, "scrolled_window"));
#if 0
- gtk_viewport_set_hadjustment (GET_WIDGET (app, "viewport1"), hadj);
- gtk_viewport_set_vadjustment (GET_WIDGET (app, "viewport1"), vadj);
+ gtk_viewport_set_hadjustment (GET_WIDGET (window, "viewport1"), hadj);
+ gtk_viewport_set_vadjustment (GET_WIDGET (window, "viewport1"), vadj);
#endif
- app->width = w;
- app->height = h;
+ window->width = w;
+ window->height = h;
}
- gtk_widget_set_sensitive (GET_WIDGET (app, "menu_zoom_out"), can_zoom_out);
- gtk_widget_set_sensitive (GET_WIDGET (app, "zoom_out"), can_zoom_out);
- gtk_widget_set_sensitive (GET_WIDGET (app, "menu_zoom_in"), can_zoom_in);
- gtk_widget_set_sensitive (GET_WIDGET (app, "zoom_in"), can_zoom_in);
+ gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_out"), can_zoom_out);
+ gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_out"), can_zoom_out);
+ gtk_widget_set_sensitive (GET_WIDGET (window, "menu_zoom_in"), can_zoom_in);
+ gtk_widget_set_sensitive (GET_WIDGET (window, "zoom_in"), can_zoom_in);
- gtk_widget_queue_draw (GET_WIDGET (app, "drawing_area"));
+ gtk_widget_queue_draw (GET_WIDGET (window, "drawing_area"));
}
static void
-on_zoom_in (GtkWidget *widget, Application *app)
+on_zoom_in (GtkWidget *widget, Window *window)
{
- app->zoom_level += 5;
- rebuild (app);
+ window->zoom_level += 5;
+ rebuild (window);
};
static void
-on_zoom_out (GtkWidget *widget, Application *app)
+on_zoom_out (GtkWidget *widget, Window *window)
{
- app->zoom_level -= 5;
- rebuild (app);
+ window->zoom_level -= 5;
+ rebuild (window);
};
static void
-on_zoom_normal (GtkWidget *widget, Application *app)
+on_zoom_normal (GtkWidget *widget, Window *window)
{
- app->zoom_level = 0;
- rebuild (app);
+ window->zoom_level = 0;
+ rebuild (window);
};
static void
-on_rotate_left (GtkWidget *widget, Application *app)
+on_rotate_left (GtkWidget *widget, Window *window)
{
g_print ("rotate_left\n");
};
static void
-on_rotate_right (GtkWidget *widget, Application *app)
+on_rotate_right (GtkWidget *widget, Window *window)
{
g_print ("rotate_right\n");
};
static void
-on_various (GtkWidget *widget, Application *app)
+on_various (GtkWidget *widget, Window *window)
{
- rebuild (app);
+ rebuild (window);
}
static gboolean
-on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
+on_scroll (GtkWidget *widget, GdkEventScroll *event, Window *window)
{
if (event->state & GDK_CONTROL_MASK)
{
if (event->direction == GDK_SCROLL_UP)
- app->zoom_level += 1;
+ window->zoom_level += 1;
else if (event->direction == GDK_SCROLL_DOWN)
- app->zoom_level -= 1;
+ window->zoom_level -= 1;
else
return FALSE;
- rebuild (app);
+ rebuild (window);
return TRUE;
}
@@ -328,9 +321,9 @@ on_scroll (GtkWidget *widget, GdkEventScroll *event, Application *app)
static void
on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
- Application *app = data;
+ Window *window = data;
- if (app->allocation.width == 0 || app->allocation.height == 0)
+ if (window->allocation.width == 0 || window->allocation.height == 0)
{
gtk_widget_queue_draw (widget);
}
@@ -341,18 +334,18 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
GdkRegion *region;
int dx, dy;
- if (!app->original)
+ if (!window->original)
return;
- compute_size (app, &old.width, &old.height);
- old.x = (app->allocation.width - old.width) / 2;
- old.y = (app->allocation.height - old.height) / 2;
+ compute_size (window, &old.width, &old.height);
+ old.x = (window->allocation.width - old.width) / 2;
+ old.y = (window->allocation.height - old.height) / 2;
new = old;
new.x = (allocation->width - old.width) / 2;
new.y = (allocation->height - old.height) / 2;
- if (old.width < allocation->width && old.width < app->allocation.width)
+ if (old.width < allocation->width && old.width < window->allocation.width)
{
dx = new.x - old.x;
}
@@ -360,11 +353,11 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
dx = 0;
- if (old.width < allocation->width || old.width < app->allocation.width)
+ if (old.width < allocation->width || old.width < window->allocation.width)
gtk_widget_queue_draw (widget);
}
- if (old.height < allocation->height && old.height < app->allocation.height)
+ if (old.height < allocation->height && old.height < window->allocation.height)
{
dy = new.y - old.y;
}
@@ -372,7 +365,7 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
{
dy = 0;
- if (old.height < allocation->height || old.height < app->allocation.height)
+ if (old.height < allocation->height || old.height < window->allocation.height)
gtk_widget_queue_draw (widget);
}
@@ -384,11 +377,11 @@ on_size_allocate (GtkWidget *widget, GtkAllocation *allocation, gpointer data)
}
- app->allocation = *allocation;
+ window->allocation = *allocation;
}
static void
-connect_signals (Application *app)
+connect_signals (Window *window)
{
int i;
@@ -428,26 +421,19 @@ connect_signals (Application *app)
for (i = 0; i < G_N_ELEMENTS (connections); ++i)
{
const Info *info = &connections[i];
- GtkWidget *widget = glade_xml_get_widget (app->xml, info->widget);
+ GtkWidget *widget = glade_xml_get_widget (window->xml, info->widget);
if (widget)
- g_signal_connect (widget, info->signal, info->callback, app);
+ g_signal_connect (widget, info->signal, info->callback, window);
else
g_error ("Couldn't find widget %s\n", info->widget);
}
}
-static void
-set_icons (Application *app)
+static Window *
+window_new (void)
{
- /* FIXME */
-};
-
-static gboolean
-build_gui (Application *app)
-{
-#if 0
- set_shadows ();
-#endif
+ Window *window = g_new0 (Window, 1);
+
if (!g_file_test (GLADE_FILE, G_FILE_TEST_EXISTS))
{
sorry (NULL,
@@ -458,21 +444,21 @@ build_gui (Application *app)
return FALSE;
}
- app->xml = glade_xml_new (GLADE_FILE, NULL, NULL);
+ window->xml = glade_xml_new (GLADE_FILE, NULL, NULL);
- gtk_widget_add_events (GET_WIDGET (app, "drawing_area"), GDK_SCROLL_MASK);
+ gtk_widget_add_events (GET_WIDGET (window, "drawing_area"), GDK_SCROLL_MASK);
gtk_widget_set_redraw_on_allocate (
- GET_WIDGET (app, "drawing_area"), FALSE);
+ GET_WIDGET (window, "drawing_area"), FALSE);
/* Connect signals */
- connect_signals (app);
+ connect_signals (window);
- app->zoom_level = 0;
- app->first = TRUE;
+ window->zoom_level = 0;
+ window->first = TRUE;
- rebuild (app);
-
- return TRUE;
+ rebuild (window);
+
+ return window;
}
static const char *
@@ -529,7 +515,7 @@ disable_g_slice (void)
typedef struct
{
const char *filename;
- Application *app;
+ Window *window;
} FileOpenData;
static gboolean
@@ -545,11 +531,11 @@ load_file (gpointer data)
sorry (NULL, "Could not open %s: %s\n", open_data->filename, err->message);
else
{
- open_data->app->original = pixbuf;
- rebuild (open_data->app);
+ open_data->window->original = pixbuf;
+ rebuild (open_data->window);
}
- g_print ("orignal: %p\n", open_data->app->original);
+ g_print ("orignal: %p\n", open_data->window->original);
g_free (open_data);
@@ -560,7 +546,7 @@ int
main (int argc,
char **argv)
{
- Application *app;
+ Window *window;
const char *filename;
disable_g_slice();
@@ -569,16 +555,13 @@ main (int argc,
gtk_init (&argc, &argv);
- app = g_new0 (Application, 1);
-
- if (!build_gui (app))
- return -1;
+ window = window_new ();
if (filename)
{
FileOpenData *file_open_data = g_new0 (FileOpenData, 1);
file_open_data->filename = filename;
- file_open_data->app = app;
+ file_open_data->window = window;
/* This has to run at G_PRIORITY_LOW because of bug 350517
*/