From c0fea9ab74971bfc3febc7c3459525ebd49b2dbb Mon Sep 17 00:00:00 2001 From: btowal2 Date: Sat, 14 Mar 2009 07:48:04 +0000 Subject: [PATCH] possibly last commit git-svn-id: https://subversion.cs.uiuc.edu/svn/bang/eoh2009@181 69d76c3e-0761-0410-948c-9895a8bb34fc --- src/app/server-menu.c | 6 +- src/app/tabs.c | 2 +- src/app/tabs.h | 2 +- src/base/bang-module-api.h | 2 +- src/modules/fractal-module.c | 196 +++++++++++++++++++++++++++++++---- 5 files changed, 183 insertions(+), 25 deletions(-) diff --git a/src/app/server-menu.c b/src/app/server-menu.c index 090b9a0..f5d0a80 100644 --- a/src/app/server-menu.c +++ b/src/app/server-menu.c @@ -47,7 +47,9 @@ static void net_status(int signal, int num_args, void **args) { static void connect_to_peer(GtkDialog *dialog, gint response_id) { if (response_id == 1) { - GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + GtkWidget *content_area = (GtkWidget *)gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + + GList *node = gtk_container_get_children(GTK_CONTAINER(content_area)); GtkWidget *entry = node->data; @@ -61,7 +63,7 @@ static void connect_to_peer(GtkDialog *dialog, gint response_id) { void BMACHINE_connect_peer() { GtkWidget *input_dialog = gtk_dialog_new(); - GtkWidget *content_area = gtk_dialog_get_content_area(GTK_DIALOG(input_dialog)); + GtkWidget *content_area = (GtkWidget *)gtk_dialog_get_content_area(GTK_DIALOG(input_dialog)); GtkWidget *entry = gtk_entry_new_with_max_length(300); GtkWidget *ok = gtk_button_new_from_stock(GTK_STOCK_OK); GtkWidget *cancel = gtk_button_new_from_stock(GTK_STOCK_CANCEL); diff --git a/src/app/tabs.c b/src/app/tabs.c index ae9bc49..9893db9 100644 --- a/src/app/tabs.c +++ b/src/app/tabs.c @@ -88,4 +88,4 @@ static void remove_peer_from_list(int peer_id) { gtk_container_remove(GTK_CONTAINER(peerlist),iter->data); peer_id = peer_id; -} \ No newline at end of file +} diff --git a/src/app/tabs.h b/src/app/tabs.h index 8878283..3392909 100644 --- a/src/app/tabs.h +++ b/src/app/tabs.h @@ -24,4 +24,4 @@ void BMACHINE_open_module_tab(char *filename); */ void update_peer_tree(); -#endif \ No newline at end of file +#endif diff --git a/src/base/bang-module-api.h b/src/base/bang-module-api.h index d7682c2..361a810 100644 --- a/src/base/bang-module-api.h +++ b/src/base/bang-module-api.h @@ -201,7 +201,7 @@ typedef struct { int (*BANG_get_my_id) (BANG_module_info *info); void (*BANG_assert_authority) (BANG_module_info *info, int id); void (*BANG_assert_authority_to_peer) (BANG_module_info *info, int authority, int peer); - void (*BANG_request_job) (BANG_module_info *info, int id); + void (*BANG_request_job) (BANG_module_info *info, int id); void (*BANG_finished_request) (BANG_module_info *info, BANG_job *job); void (*BANG_send_job) (BANG_module_info *info, BANG_job *job); } BANG_api; diff --git a/src/modules/fractal-module.c b/src/modules/fractal-module.c index e72eb50..b6e7ffc 100644 --- a/src/modules/fractal-module.c +++ b/src/modules/fractal-module.c @@ -20,6 +20,14 @@ char BANG_module_name[8] = "fractal"; unsigned char BANG_module_version[] = {0,0,1}; BANG_api *api; +/* Backing pixmap for drawing area */ +static GdkPixmap *pixmap = NULL; +static GtkWidget *window; +static GtkWidget *label; +GtkWidget *drawing_area; +GtkWidget *vbox; +GtkWidget *button; + typedef struct _peerContainer{ int frame; int needsState; @@ -53,6 +61,9 @@ static int jobsLeft = -1; static int peerArrSize = 0; static int *jobArr = NULL; static peerContainer **peerArr = NULL; +int currentFrame = 0; +pixelStruct **frameData; +static int initFlag = 1; /** * Callback for when a finished job is sent to you. @@ -195,7 +206,40 @@ static void peer_removed_callback(BANG_module_info* info, int peer) { } +/* Create a new backing pixmap of the appropriate size */ +static gboolean +configure_event (GtkWidget *widget, GdkEventConfigure *event) +{ + if (pixmap) + g_object_unref (pixmap); + + pixmap = gdk_pixmap_new (widget->window, + widget->allocation.width, + widget->allocation.height, + -1); + gdk_draw_rectangle (pixmap, + widget->style->white_gc, + TRUE, + 0, 0, + widget->allocation.width, + widget->allocation.height); + + return TRUE; +} +/* Redraw the screen from the backing pixmap */ +static gboolean +expose_event (GtkWidget *widget, GdkEventExpose *event) +{ + gdk_draw_drawable (widget->window, + widget->style->fg_gc[GTK_WIDGET_STATE (widget)], + pixmap, + event->area.x, event->area.y, + event->area.x, event->area.y, + event->area.width, event->area.height); + + return FALSE; +} static int mapIterToColor(int iter, int maxIter) { #define COL_MAX 256 @@ -216,27 +260,79 @@ static int mapIterToColor(int iter, int maxIter) { return retCol; } +static void drawPixel(GtkWidget *widget, int x, int y, int color) { + + static int count = 0; + static GdkColormap *colormap = NULL; + if (colormap == NULL) + colormap = gdk_colormap_get_system(); + static GdkGC *gc = NULL; + if (gc == NULL) + gc = gdk_gc_new(pixmap); + + GdkColor pixelColor; + pixelColor.red = (color & 0xFF0000) >> 8; + pixelColor.green = (color & 0xFF00); + pixelColor.blue = (color & 0xFF) << 8; + + gdk_colormap_alloc_color(colormap, &pixelColor, FALSE, TRUE); + + gdk_gc_set_foreground(gc, &pixelColor); + gdk_draw_point(pixmap, gc, x, y); + gtk_widget_queue_draw_area (widget, x, y, 1, 1); + +} + +static gboolean button_press_event (GtkWidget *widget, GdkEventButton *event) { + //If this is the first click, initialize everything + if (initFlag == 1) { + initAuthData(); + initFlag = 0; + } + + changePosState((int)event->x, (int)event->y); + + + //Start displaying the frames + + +} + + static pixelStruct* process_frames(int numFrames, int *frame, int *numPixels) { - pixelStruct *data = calloc((numFrames+1) * winX * winY, sizeof(pixelStruct)); + + pixelStruct *data = calloc((numFrames+1) * fractalStateData.winX * + fractalStateData.winY, sizeof(pixelStruct)); *numPixels = 0; + double dev = 1.3; + double midX = fractalStateData.x; + double midY = fractalStateData.y; + double leftBorder; + double rightBorder; + double bottomBorder; + double topBorder; + double Re_factor; + double Im_factor; + unsigned MaxIterations = 250; + unsigned x; + unsigned y; + unsigned n; + int i; - for (i=0; i < numFrames; ++i) { - double dev = 1.3 / frame[i]; - double leftBorder = fractalStateData.x - dev; - double rightBorder = fractalStateData.x + dev; - double bottomBorder = fractalStateData.y - dev; - double topBorder = fractalStateData.y + dev; - double Re_factor = (rightBorder-leftBorder)/(winX-1); - double Im_factor = (topBorder-bottomBorder)/(winY-1); - unsigned MaxIterations = frame[i]*50 + 100; - unsigned x; - unsigned y; - unsigned n; - - for(y=0; y < winY; ++y) { + for (i=0; i