Advertisement
palmerstone

DirectX 12 Shader Prism Effect (beta)

Nov 24th, 2011
1,454
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <time.h>
  2. #include <cairo.h>
  3. #include <stdio.h>
  4. #include <stdlib.h>
  5. #include <windows.h>
  6. #include <gtk/gtk.h>
  7. #include <gdk/gdk.h>
  8. #include <gdk/gdkkeysyms.h>
  9. #include <gdk-pixbuf/gdk-pixbuf.h>
  10.  
  11. int global;
  12. char str[500], str2[500], str3[500], str4[500], str5[500], str6[500], slide[500];
  13. char image_list[5000][100];
  14. GtkContainer *box;
  15. GtkWindow *window;
  16. GtkWidget *vbox;
  17. GtkWidget *menubar, *filemenu, *help, *helpmenu;
  18. GtkWidget *file, *quit, *open, *save, *properties, *about, *slideshow, *shownext, *showprevious;
  19. GtkWidget *img, *img2;
  20. GtkWidget *dialog;
  21. GtkRequisition *allocator;
  22.  
  23. void wait(double seconds);
  24. void create_menu();
  25. void show_about();
  26. void open_file();
  27. void show_properties();
  28. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data);
  29. void start_slide();
  30. void get_list(char filename[500]);
  31. void store_list();
  32. void show_next();
  33. void show_previous();
  34.  
  35. void wait(double seconds)
  36. {
  37.     clock_t lol;
  38.     lol = clock() + (seconds * CLOCKS_PER_SEC);
  39.     while(clock() < lol) {}
  40. }
  41.  
  42. void create_menu()
  43. {
  44.     vbox = gtk_vbox_new(FALSE, 0);
  45.     box = gtk_vbox_new(FALSE, 0);
  46.     gtk_box_pack_start(GTK_BOX(box), vbox, TRUE, TRUE, 0);
  47.     menubar = gtk_menu_bar_new();
  48.     filemenu = gtk_menu_new();
  49.  
  50.     file = gtk_menu_item_new_with_label("File");
  51.     quit = gtk_menu_item_new_with_label("Quit                             Ctrl + Q");
  52.     open = gtk_menu_item_new_with_label("Open                           Ctrl + O");
  53.     save = gtk_menu_item_new_with_label("Save");
  54.     slideshow = gtk_menu_item_new_with_label("Start Slide");
  55.     showprevious = gtk_menu_item_new_with_label("Show Previous");
  56.     shownext = gtk_menu_item_new_with_label("Show Next");
  57.     properties = gtk_menu_item_new_with_label("Properties                   Ctrl + P");
  58.  
  59.     gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
  60.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), open);
  61.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), save);
  62.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), slideshow);
  63.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), showprevious);
  64.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), shownext);
  65.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), properties);
  66.     gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
  67.     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);
  68.  
  69.     helpmenu = gtk_menu_new();
  70.     about = gtk_menu_item_new_with_label("About");
  71.     help = gtk_menu_item_new_with_label("Help");
  72.     gtk_menu_item_set_submenu(GTK_MENU_ITEM(help), helpmenu);
  73.     gtk_menu_shell_append(GTK_MENU_SHELL(helpmenu), about);
  74.     gtk_menu_shell_append(GTK_MENU_SHELL(menubar), help);
  75.     gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
  76. }
  77.  
  78. void show_about()
  79. {
  80.     GtkWidget *dialog;
  81.     const char *author[] = {"None yet\n(However, Special thanks to Mehedi Hasan and\nShadman Shadab :-) )",NULL};
  82.     dialog = gtk_about_dialog_new();
  83.     gtk_about_dialog_set_program_name (GTK_ABOUT_DIALOG(dialog),"You just clicked about!");
  84.     gtk_about_dialog_set_authors (GTK_ABOUT_DIALOG(dialog),author);
  85.     gtk_about_dialog_set_comments (GTK_ABOUT_DIALOG(dialog),"Good job and go to hell!!");
  86.     gtk_window_set_position(GTK_WINDOW(dialog),GTK_WIN_POS_CENTER);
  87.     gtk_dialog_run(GTK_DIALOG(dialog));
  88. }
  89.  
  90. void open_file()
  91. {
  92.     dialog = gtk_file_chooser_dialog_new ("Open File",window,GTK_FILE_CHOOSER_ACTION_OPEN,GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,NULL);
  93.     if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
  94.     {
  95.         char *filename;
  96.         filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
  97.         strcpy(slide, filename);
  98.         get_list(filename);
  99.         store_list();
  100.         system(str2);
  101.         gtk_container_remove(GTK_CONTAINER(box), img);
  102.         img = gtk_image_new_from_file(filename);
  103.         gtk_widget_show(img);
  104.         gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  105.         g_free (filename);
  106.     }
  107.     gtk_widget_destroy (dialog);
  108. }
  109.  
  110. void show_properties()
  111. {
  112.  
  113. }
  114.  
  115. static int keyboard_keys(GtkWidget *futile, GdkEventKey *lol, gpointer user_data)
  116. {
  117.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_q || lol->keyval == GDK_KEY_Q))
  118.         exit (0x0);
  119.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_O || lol->keyval == GDK_KEY_o))
  120.         open_file();
  121.     if (lol->state == GDK_CONTROL_MASK && (lol->keyval == GDK_KEY_P || lol->keyval == GDK_KEY_p))
  122.         show_properties();
  123.     if (lol->keyval == GDK_KEY_Right)
  124.         show_next();
  125.     if (lol->keyval == GDK_KEY_Left)
  126.         show_previous();
  127.     return TRUE;
  128. }
  129.  
  130.  
  131. void start_slide()
  132. {
  133.  
  134. }
  135.  
  136. void get_list(char filename[500])
  137. {
  138.     puts(filename);
  139.     int k = 0, j, l = 0, x;
  140.     int len = strlen(filename);
  141.     for (j = len - 1; filename[j] != '\\'; j--) x = 1;
  142.     str[0] = 0;
  143.     strcat(str, "cd /d ");
  144.     for (k = 0; k < j; k++) str4[l++] = filename[k];
  145.     str4[l] = 0;
  146.     str3[0] = filename[0], str3[1] = filename[1], str3[2] = 0;
  147.     system(str3);
  148.     strcat(str, str4);
  149.     strcpy(str2, str);
  150.     strcat(str, " && dir /b >> dir_listing.txt");
  151.     strcat(str2, " && del dir_listing.txt");
  152.     system(str);
  153.     strcat(str4, "\\dir_listing.txt");
  154. }
  155.  
  156. void store_list()
  157. {
  158.     FILE *input;
  159.     input = fopen(str4, "r");
  160.     for (global = 0; ;global++)
  161.     {
  162.         if (fscanf(input, "%[^\n]", image_list[global]) == EOF) break;
  163.         fgetc(input);
  164.     }
  165.     fclose(input);
  166. }
  167.  
  168. void show_next()
  169. {
  170.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  171.     for (; ;)
  172.     {
  173.         for (i = 0; i < global; i++)
  174.         {
  175.             strcpy(str3, image_list[i]);
  176.             l = 0, len = strlen(slide);
  177.             str5[0] = 0;
  178.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  179.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  180.             str5[l] = 0, k = 0;
  181.             strcat(str5, str3), len = strlen(str3);
  182.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  183.             str6[k] = 0;
  184.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  185.             {
  186.                 if (flag2 == 1)
  187.                 {
  188.                     gtk_container_remove(GTK_CONTAINER(box), img);
  189.                     img = gtk_image_new_from_file(str5);
  190.                     gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  191.                     gtk_widget_show(img);
  192.                     strcpy(slide, str5);
  193.                     flag3 = 1;
  194.                     break;
  195.  
  196.                 }
  197.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  198.             }
  199.         }
  200.         if (flag3 == 1) break;
  201.     }
  202. }
  203.  
  204. void show_previous()
  205. {
  206.     int i, j, k, l = 0, len, flag2 = 0, flag3 = 0;
  207.     for (; ;)
  208.     {
  209.         for (i = global - 1; i >= 0; i--)
  210.         {
  211.             strcpy(str3, image_list[i]);
  212.             l = 0, len = strlen(slide);
  213.             str5[0] = 0;
  214.             for (j = len - 1; slide[j] != '\\'; j--) k = 1;
  215.             for (k = 0; k <= j; k++) str5[l++] = slide[k];
  216.             str5[l] = 0, k = 0;
  217.             strcat(str5, str3), len = strlen(str3);
  218.             for (l = len - 4; l < len; l++) str6[k++] = str3[l];
  219.             str6[k] = 0;
  220.             if (strcmp(str6, ".png") == 0 || strcmp(str6, ".jpg") == 0 || strcmp(str6, ".bmp") == 0)
  221.             {
  222.                 if (flag2 == 1)
  223.                 {
  224.                     gtk_container_remove(GTK_CONTAINER(box), img);
  225.                     img = gtk_image_new_from_file(str5);
  226.                     gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  227.                     gtk_widget_show(img);
  228.                     strcpy(slide, str5);
  229.                     flag3 = 1;
  230.                     break;
  231.  
  232.                 }
  233.                 if (strcmp(str5, slide) == 0) flag2 = 1;
  234.             }
  235.         }
  236.         if (flag3 == 1) break;
  237.     }
  238. }
  239.  
  240. int main(int argc, char *argv[])
  241. {
  242.     GdkScreen *screen;
  243.     gtk_init(&argc, &argv);
  244.     window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  245.     //gtk_window_set_policy(GTK_WINDOW(window), TRUE, TRUE, FALSE);
  246.     gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
  247.     gtk_window_set_default_size(GTK_WINDOW(window), 800, 500);
  248.     gtk_window_set_title(GTK_WINDOW(window), "Fireflight Image Viewer 1.052");
  249.  
  250.     create_menu();
  251.     char picturename[] = "C:\\Users\\Public\\Pictures\\Sample Pictures\\Penguins.jpg";
  252.     img = gtk_image_new_from_file(picturename);
  253.     strcpy(slide, picturename);
  254.     gtk_box_pack_start(GTK_BOX(box), img, TRUE, TRUE, 0);
  255.     gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(box));
  256.     get_list(picturename);
  257.     store_list();
  258.     system(str2);
  259.  
  260.     g_signal_connect(G_OBJECT(window), "delete-event",G_CALLBACK(gtk_main_quit), NULL);
  261.     g_signal_connect(G_OBJECT(open), "activate", G_CALLBACK(open_file), NULL);
  262.     g_signal_connect(G_OBJECT(properties), "activate", G_CALLBACK(show_properties), NULL);
  263.     g_signal_connect(G_OBJECT(about), "activate", G_CALLBACK(show_about), NULL);
  264.     g_signal_connect(G_OBJECT(quit), "activate",G_CALLBACK(gtk_main_quit), NULL);
  265.     g_signal_connect(G_OBJECT(slideshow), "activate",G_CALLBACK(start_slide), NULL);
  266.     g_signal_connect(G_OBJECT(shownext), "activate",G_CALLBACK(show_next), NULL);
  267.     g_signal_connect(G_OBJECT(showprevious), "activate",G_CALLBACK(show_previous), NULL);
  268.     g_signal_connect(G_OBJECT(window), "key_press_event", G_CALLBACK(keyboard_keys), (gpointer)window);
  269.     gtk_widget_show_all(GTK_WIDGET(window));
  270.     gtk_main();
  271.  
  272.     return 0x0;
  273. }
  274.  
  275.  
Advertisement
RAW Paste Data Copied
Advertisement