From 84361f7a9e03f76e7ea90f48239825dc5bca07e9 Mon Sep 17 00:00:00 2001 From: neoraider Date: Thu, 21 Jun 2007 19:52:03 +0000 Subject: zoomedit: Added level editor zoomedit. --- window.c | 119 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 window.c (limited to 'window.c') diff --git a/window.c b/window.c new file mode 100644 index 0000000..5dcbf20 --- /dev/null +++ b/window.c @@ -0,0 +1,119 @@ +#include "window.h" +#include "ui.h" +#include "draw.h" +#include + + +static GtkWidget *drawingArea = NULL; +static GtkAdjustment *hAdjustment = NULL, *vAdjustment = NULL; + + +static gboolean delete_event(GtkWidget *widget, GdkEvent *event, gpointer data) { + return FALSE; +} + +static void destroy(GtkWidget *widget, gpointer data) { + gtk_main_quit(); +} + +static void refreshScrolling() { + if(getImageWidth() < drawingArea->allocation.width) + setXTranslate((getImageWidth()-drawingArea->allocation.width)/2); + else + setXTranslate(gtk_adjustment_get_value(hAdjustment)); + + if(getImageHeight() < drawingArea->allocation.height) + setYTranslate((getImageHeight()-drawingArea->allocation.height)/2); + else + setYTranslate(gtk_adjustment_get_value(vAdjustment)); + + gdk_window_invalidate_rect(drawingArea->window, NULL, FALSE); +} + +static void updateScrollbars() { + const gdouble imageWidth = getImageWidth(), imageHeight = getImageHeight(); + const gdouble width = drawingArea->allocation.width, height = drawingArea->allocation.height; + gdouble upper, pageSize, value; + + g_object_get(G_OBJECT(hAdjustment), "upper", &upper, "page_size", &pageSize, NULL); + g_object_set(G_OBJECT(hAdjustment), "upper", imageWidth, "page_size", width, NULL); + gtk_adjustment_changed(hAdjustment); + + if(pageSize > upper && width < imageWidth) + value = (imageWidth-width)/2; + else + value = MAX(MIN(gtk_adjustment_get_value(hAdjustment) - (width-pageSize)/2 + (imageWidth-upper)/2, imageWidth-width), 0); + gtk_adjustment_set_value(hAdjustment, value); + + g_object_get(G_OBJECT(vAdjustment), "upper", &upper, "page_size", &pageSize, NULL); + g_object_set(G_OBJECT(vAdjustment), "upper", imageHeight, "page_size", height, NULL); + + if(pageSize > upper && height < imageHeight) + value = (imageHeight-height)/2; + else + value = MAX(MIN(gtk_adjustment_get_value(vAdjustment) - (height-pageSize)/2 + (imageHeight-upper)/2, imageHeight-height), 0); + gtk_adjustment_set_value(vAdjustment, value); + + refreshScrolling(); +} + +GtkWidget* createMainWindow() { + GtkWidget *window, *vbox, *menubar, *toolbar, *table, *vScroll, *hScroll; + GdkColor color = {0, 0, 0, 0}; + + + window = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_default_size(GTK_WINDOW(window), 640, 480); + g_signal_connect(G_OBJECT(window), "delete_event", G_CALLBACK(delete_event), NULL); + g_signal_connect(G_OBJECT(window), "destroy", G_CALLBACK(destroy), NULL); + + vbox = gtk_vbox_new(FALSE, 0); + gtk_container_add(GTK_CONTAINER(window), vbox); + + menubar = getMenu(); + gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); + gtk_widget_show(menubar); + + toolbar = getToolbar(); + gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); + gtk_widget_show(toolbar); + + gtk_window_add_accel_group(GTK_WINDOW(window), getAccels()); + + table = gtk_table_new(2, 2, FALSE); + gtk_box_pack_end(GTK_BOX(vbox), table, TRUE, TRUE, 0); + + drawingArea = gtk_drawing_area_new(); + gtk_widget_modify_bg(drawingArea, GTK_WIDGET_STATE(drawingArea), &color); + g_signal_connect(G_OBJECT(drawingArea), "configure-event", G_CALLBACK(updateScrollbars), NULL); + g_signal_connect(G_OBJECT(drawingArea), "expose-event", G_CALLBACK(drawTopView), NULL); + gtk_table_attach(GTK_TABLE(table), drawingArea, 0, 1, 0, 1, GTK_FILL|GTK_EXPAND|GTK_SHRINK, GTK_FILL|GTK_EXPAND|GTK_SHRINK, 0, 0); + gtk_widget_show(drawingArea); + + hAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100)); + hScroll = gtk_hscrollbar_new(hAdjustment); + g_signal_connect(G_OBJECT(hScroll), "value-changed", G_CALLBACK(refreshScrolling), NULL); + gtk_table_attach(GTK_TABLE(table), hScroll, 0, 1, 1, 2, GTK_FILL|GTK_EXPAND|GTK_SHRINK, 0, 0, 0); + gtk_widget_show(hScroll); + + vAdjustment = GTK_ADJUSTMENT(gtk_adjustment_new(0, 0, 0, 10, 100, 100)); + vScroll = gtk_vscrollbar_new(vAdjustment); + g_signal_connect(G_OBJECT(vScroll), "value-changed", G_CALLBACK(refreshScrolling), NULL); + gtk_table_attach(GTK_TABLE(table), vScroll, 1, 2, 0, 1, 0, GTK_FILL|GTK_EXPAND|GTK_SHRINK, 0, 0); + gtk_widget_show(vScroll); + + gtk_widget_show(table); + gtk_widget_show(vbox); + + return window; +} + +void zoomIn() { + setScale(getScale()*1.5); + updateScrollbars(); +} + +void zoomOut() { + setScale(getScale()/1.5); + updateScrollbars(); +} -- cgit v1.2.3