More than one frame can be created and uploaded.
This commit is contained in:
parent
bedbd1e4e6
commit
ba74ba55f4
7 changed files with 110 additions and 12 deletions
|
@ -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;
|
||||
|
|
|
@ -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<animationLength ? delay : skip), i);
|
||||
}
|
||||
lc_setMode(MODE_ANIMATION_LOOP);
|
||||
}
|
||||
|
||||
|
|
|
@ -11,6 +11,7 @@ void setScene();
|
|||
|
||||
// Hardware Cube
|
||||
void displayCurrentFrame();
|
||||
void uploadAnimation();
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ void on_change_led() {
|
|||
unsigned long frame = 0;
|
||||
gint i = 0;
|
||||
for (i=0; i<27; ++i) {
|
||||
frame |= (currentFrame[i] << i);
|
||||
frame |= (animation[currentFrame][i] << i);
|
||||
}
|
||||
|
||||
// Send it to the cube
|
||||
|
@ -40,7 +40,34 @@ void on_change_mode(int newMode) {
|
|||
lc_setMode(newMode);
|
||||
}
|
||||
|
||||
gchar* on_frame_control_format_value(GtkScale *scale, gdouble value) {
|
||||
return g_strdup_printf("%d/%d", (int)value, animationLength);
|
||||
}
|
||||
|
||||
void on_frame_control_value_changed(GtkRange *frameControl) {
|
||||
currentFrame = (int)(gtk_range_get_value(frameControl)-1);
|
||||
g_print("frame: %d\n", currentFrame);
|
||||
gtk_widget_queue_draw_area(drawingArea, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
|
||||
displayCurrentFrame();
|
||||
}
|
||||
|
||||
void on_button_add_clicked(GtkButton *button) {
|
||||
if (animationLength >= 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();
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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()) {
|
||||
|
|
|
@ -4,12 +4,14 @@
|
|||
<!-- interface-naming-policy project-wide -->
|
||||
<widget class="GtkWindow" id="main_window">
|
||||
<property name="extension_events">cursor</property>
|
||||
<property name="title" translatable="yes">LED Cube Editor v.4</property>
|
||||
<property name="resizable">False</property>
|
||||
<property name="window_position">center-always</property>
|
||||
<signal name="delete_event" handler="on_main_window_delete_event"/>
|
||||
<child>
|
||||
<widget class="GtkVBox" id="outher_frame">
|
||||
<property name="visible">True</property>
|
||||
<property name="spacing">4</property>
|
||||
<child>
|
||||
<widget class="GtkHandleBox" id="handle">
|
||||
<property name="visible">True</property>
|
||||
|
@ -23,6 +25,7 @@
|
|||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-open</property>
|
||||
<signal name="clicked" handler="on_button_load_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -35,6 +38,7 @@
|
|||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-save</property>
|
||||
<signal name="clicked" handler="on_button_save_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -56,6 +60,7 @@
|
|||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-add</property>
|
||||
<signal name="clicked" handler="on_button_add_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -68,6 +73,7 @@
|
|||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-delete</property>
|
||||
<signal name="clicked" handler="on_button_remove_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -89,6 +95,7 @@
|
|||
<property name="label" translatable="yes">toolbutton3</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-execute</property>
|
||||
<signal name="clicked" handler="on_button_upload_clicked"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -120,12 +127,40 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHScale" id="frame_control">
|
||||
<widget class="GtkHBox" id="hbox2">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="spacing">3</property>
|
||||
<child>
|
||||
<widget class="GtkComboBox" id="dropdown_delay">
|
||||
<property name="visible">True</property>
|
||||
<property name="active">0</property>
|
||||
<property name="items" translatable="yes">Short
|
||||
Normal
|
||||
Long</property>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">0</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<widget class="GtkHScale" id="frame_control">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="adjustment">1 1 1 1 1 1</property>
|
||||
<property name="digits">0</property>
|
||||
<property name="value_pos">right</property>
|
||||
<signal name="value_changed" handler="on_frame_control_value_changed"/>
|
||||
<signal name="format_value" handler="on_frame_control_format_value"/>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="padding">5</property>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
</widget>
|
||||
<packing>
|
||||
<property name="position">1</property>
|
||||
</packing>
|
||||
</child>
|
||||
|
|
Loading…
Reference in a new issue