diff --git a/editor/config.h b/editor/config.h index 614c7bf..2520266 100644 --- a/editor/config.h +++ b/editor/config.h @@ -38,13 +38,16 @@ extern GLUquadricObj *quadric; extern GdkGLConfig *glConfig; extern GdkGLWindow *glWindow; extern GdkGLContext *glContext; +extern GtkWidget *drawingArea; extern GladeXML *xml; // Dimensions, positions extern gfloat light0Pos[]; // LED data -extern gint currentFrame[27]; +extern gint animation[32][28]; +extern gint currentFrame; +extern gint animationLength; // Connection extern gboolean isCubeConnected; diff --git a/editor/display.c b/editor/display.c index 122d017..12cd0e1 100644 --- a/editor/display.c +++ b/editor/display.c @@ -12,10 +12,12 @@ extern void lc_setMode(int); extern void lc_setFrame(unsigned long); +extern int lc_saveFrame(unsigned long frame, int delay, int index); void drawLEDs(gint mode) { gint x, y, z; gint ledIndex = 0; + gint iLED = 0; if (ledOrientation == TOP_ORIENTATION) { glRotatef(90, 2, 0, 0); @@ -28,8 +30,9 @@ void drawLEDs(gint mode) { if (mode == PICKING_MODE) { glColor3ub(0, 0, ledIndex*8); } else { - glMaterialfv(GL_FRONT, GL_AMBIENT, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial)); - glMaterialfv(GL_FRONT, GL_DIFFUSE, (currentFrame[ledIndex-1] == 1 ? ledOnMaterial : ledOffMaterial)); + iLED = animation[currentFrame][ledIndex-1]; + glMaterialfv(GL_FRONT, GL_AMBIENT, (iLED == 1 ? ledOnMaterial : ledOffMaterial)); + glMaterialfv(GL_FRONT, GL_DIFFUSE, (iLED == 1 ? ledOnMaterial : ledOffMaterial)); } glPushMatrix(); @@ -115,9 +118,30 @@ void displayCurrentFrame() { int i; unsigned long frame = 0; for (i=0; i<27; ++i) { - if (currentFrame[i] == 1) frame |= (1 << i); + if (animation[currentFrame][i] == 1) frame |= (1 << i); } lc_setMode(MODE_ANIMATION_STOP); lc_setFrame(frame); } +void uploadAnimation() { + int i, j; + unsigned long frame = 0; + int delay = 0; // TODO: Implement the delay + int skip = 1; // Skip + + // Maximum delay + for (i=0; i<5; ++i) delay |= (1 << i); + + lc_setMode(MODE_ANIMATION_STOP); + for (i=0; i<32; ++i) { + frame = 0; + for (j=0; j<27; ++j) { + if (animation[i][j] == 1) frame |= (1 << j); + } + + lc_saveFrame(frame, (i= 32) return; + + GtkRange *frameControl = GTK_RANGE(glade_xml_get_widget(xml, "frame_control")); + + animationLength++; + currentFrame = animationLength-1; + gtk_range_set_range(frameControl, 1.0, (double)animationLength+1.0); + gtk_range_set_value(frameControl, animationLength); + + gtk_widget_queue_draw_area(drawingArea, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT); + displayCurrentFrame(); +} + +void on_button_upload_clicked(GtkButton *button) { + uploadAnimation(); +} void on_main_window_delete_event(GtkObject *object, gpointer userData) { gtk_main_quit(); diff --git a/editor/input.c b/editor/input.c index a68a851..38f69b8 100644 --- a/editor/input.c +++ b/editor/input.c @@ -33,7 +33,7 @@ void mouse(gint x, gint y) { glReadPixels(x, viewport[3]-y, 1, 1, GL_RGB, GL_UNSIGNED_BYTE, (void*)pixel); position = ((gint)pixel[2]/8)-1; // Selected LED - currentFrame[position] = currentFrame[position] == 0 ? 1 : 0; + animation[currentFrame][position] = animation[currentFrame][position] == 0 ? 1 : 0; displayCurrentFrame(); } diff --git a/editor/main.c b/editor/main.c index d91c9e3..7baa66d 100644 --- a/editor/main.c +++ b/editor/main.c @@ -35,7 +35,9 @@ GtkWidget *window, *drawingArea; GladeXML *xml; // LED data -gint currentFrame[27] = {0}; +gint animation[32][28] = {{0}}; +gint currentFrame = 0; +gint animationLength = 1; // Hardware gboolean isCubeConnected = FALSE; @@ -84,8 +86,6 @@ gint main(gint argc, gchar *argv[]) { glLightfv(GL_LIGHT0, GL_AMBIENT, backgroundColor); glMatrixMode(GL_MODELVIEW); - currentFrame[13] = 1; // Initial sequence - moveCameraPosition(21); // Configure the OpenGL widget glConfig = gdk_gl_config_new_by_mode(GDK_GL_MODE_RGB | GDK_GL_MODE_DEPTH | GDK_GL_MODE_DOUBLE); @@ -105,6 +105,14 @@ gint main(gint argc, gchar *argv[]) { drawingArea = glade_xml_get_widget(xml, "drawing_area"); gtk_widget_set_gl_capability(drawingArea, glConfig, NULL, TRUE, GDK_GL_RGBA_TYPE); + // Configure the first frame + animation[currentFrame][13] = 1; + animation[currentFrame][27] = 1; // delay to "normal" + g_print("frame: %d\n", currentFrame); + gtk_combo_box_set_active(GTK_COMBO_BOX(glade_xml_get_widget(xml, "dropdown_delay")), 1); + moveCameraPosition(21); + + glade_xml_signal_autoconnect(xml); if (g_thread_supported()) { diff --git a/editor/main_gui.glade b/editor/main_gui.glade index 53125a5..83198d0 100644 --- a/editor/main_gui.glade +++ b/editor/main_gui.glade @@ -4,12 +4,14 @@ cursor + LED Cube Editor v.4 False center-always True + 4 True @@ -23,6 +25,7 @@ toolbutton3 True gtk-open + False @@ -35,6 +38,7 @@ toolbutton3 True gtk-save + False @@ -56,6 +60,7 @@ toolbutton3 True gtk-add + False @@ -68,6 +73,7 @@ toolbutton3 True gtk-delete + False @@ -89,6 +95,7 @@ toolbutton3 True gtk-execute + False @@ -120,12 +127,40 @@ - + True - True + 3 + + + True + 0 + Short +Normal +Long + + + False + 5 + 0 + + + + + True + True + 1 1 1 1 1 1 + 0 + right + + + + + 5 + 1 + + - False 1