void processNormalKeys(unsigned char key, int x, int y) { if (key == 27) //Escape Character exit(0); if (key == 'c' || key == 'C') //regen colours setColour(); if (key == 'h' || key == 'H') //reset back to original colours resetColour(); glutPostRedisplay(); }
void Tetris::dragDrop(GtkWidget *widget, GdkDragContext *context, gint x, gint y, GtkSelectionData *data, guint info, guint time, Tetris * t) { const char *fileuri; GError *error = NULL; GFile *file; GFile *outfile; GFileInfo *fileinfo; GFileInputStream *istream; GFileOutputStream *outstream; goffset filesize; gssize bytesread, byteswrote; GdkPixbufLoader *loader; GdkPixbuf *pixbuf; guchar *buffer; /* Accept a dropped filename and try and load it as the background image. In the event of any kind of failure we silently ignore it. */ /* FIXME: We don't handle colour gradients (e.g. from the gimp) */ /* FIXME: Dropped URLs from mozilla don't work (see below). */ if (data->length < 0) { gtk_drag_finish (context, FALSE, FALSE, time); return; } gtk_drag_finish (context, TRUE, FALSE, time); if (info == COLOUR) { if (data->length == 8) decodeColour ((guint16 *)data->data, t); return; } if (info == RESET) { resetColour (t); return; } fileuri = decodeDropData ((char *)data->data, info); /* Silently ignore bad data. */ if (fileuri == NULL) goto error_exit; /* Now that we have a URI we load it and test it to see if it is * an image file. */ file = g_file_new_for_uri (fileuri); istream = g_file_read (file, NULL, &error); if (error) goto error_exit; fileinfo = g_file_input_stream_query_info (istream, (char *)G_FILE_ATTRIBUTE_STANDARD_SIZE, NULL, &error); if (error) goto error_exit_handle; filesize = g_file_info_get_size (fileinfo); buffer = (guchar *)g_malloc (filesize); if (buffer == NULL) goto error_exit_handle; bytesread = g_input_stream_read (G_INPUT_STREAM (istream), buffer, filesize, NULL, &error); /* FIXME: We should reread if not enough was read. */ if (error || (bytesread != filesize)) goto error_exit_buffer; loader = gdk_pixbuf_loader_new (); if (!gdk_pixbuf_loader_write (loader, buffer, filesize, NULL)) goto error_exit_loader; gdk_pixbuf_loader_close (loader, NULL); pixbuf = gdk_pixbuf_loader_get_pixbuf (loader); if (pixbuf == NULL) goto error_exit_loader; g_object_ref (pixbuf); /* We now have an image file, in memory, that we know gdk-pixbuf * can handle. Now we save it to disk. This is necessary so that * "slow" URIs (e.g. http) behave well in the long run. */ outfile = g_file_new_for_path (t->bgPixmap); outstream = g_file_replace (outfile, NULL, FALSE, G_FILE_CREATE_PRIVATE, NULL, &error); if (error) goto error_exit_loader; byteswrote = g_output_stream_write (G_OUTPUT_STREAM (outstream), buffer, bytesread, NULL, &error); if (byteswrote != filesize) goto error_exit_saver; t->usebg = TRUE; t->saveBgOptions (); error_exit_saver: g_object_unref(outstream); error_exit_loader: g_object_unref (loader); error_exit_buffer: g_free (buffer); error_exit_handle: g_object_unref(istream); error_exit: if(error) g_error_free(error); return; }