- Timestamp:
- 02/01/09 22:06:39 (3 years ago)
- Location:
- branches/clutter-experiments
- Files:
-
- 3 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/clutter-experiments/Makefile
r48 r52 1 LIBS=`pkg-config --libs clutter-0.8 poppler-glib` 2 INCS=`pkg-config --cflags clutter-0.8 poppler-glib` 1 CXXFLAGS=-O3 -g -Wall -Weffc++ 2 LIBS=`pkg-config --libs clutter-0.9 poppler-glib` 3 INCS=`pkg-config --cflags clutter-0.9 poppler-glib` 3 4 4 5 .c.o: 5 $(CC) -g -Wall$(CFLAGS) $(INCS) -c $*.c6 $(CC) $(CFLAGS) $(INCS) -c $*.c 6 7 .cc.o: 7 $(CXX) -g -Wall -Weffc++$(CXXFLAGS) $(INCS) -c $*.cc8 $(CXX) $(CXXFLAGS) $(INCS) -c $*.cc 8 9 9 10 all: pdfcube … … 12 13 13 14 pdfcube: main.o 14 $(CXX) -g -Wall$(CXXFLAGS) -o $@ main.o $(LIBS)15 $(CXX) $(CXXFLAGS) -o $@ main.o $(LIBS) 15 16 16 17 clean: 17 18 rm -fr *.o pdfcube 19 20 .PHONY: check-syntax 21 check-syntax: 22 $(CXX) -Wall -Wextra -Weffc++ -pedantic -fsyntax-only $(INCS) $(CHK_SOURCES) -
branches/clutter-experiments/main.cc
r51 r52 3 3 // C++ interface (or binding) for Poppler and Clutter or to code the 4 4 // whole thing in C using GObjects. 5 #include <iostream> 6 #include <sstream> 5 7 #include <cmath> 6 #include <iostream>7 8 #include <cstdlib> 9 #include <cstring> 8 10 #include <clutter/clutter.h> 9 11 #include <poppler.h> … … 16 18 using namespace std; 17 19 20 namespace pdfcube { 21 22 class app 23 { 24 public: 25 26 app(const app&); 27 app& operator=(const app&); 28 29 /** @brief */ 30 app() 31 : the_doc_m(), 32 the_stage_m(), 33 filename_m(), 34 progress_m(), 35 progress_label_m(), 36 current_page_m(), 37 next_page_m(), 38 current_page_no_m(0) 39 { } 40 41 bool init(int* argc, char** argv[]) 42 { 43 gchar **file_array; 44 GOptionEntry options[] = { 45 // TODO: add stage color/image and cube top color/image options 46 { G_OPTION_REMAINING, 47 0, 48 0, 49 G_OPTION_ARG_FILENAME_ARRAY, 50 &file_array, 51 "Presentation PDF file to load", 52 "FILE" }, 53 { 0, 0, 0, (GOptionArg)0, 0, 0, 0 } 54 }; 55 g_thread_init(NULL); 56 clutter_threads_init(); 57 clutter_init_with_args (argc, argv, "PDFCube 0.1.0", 58 options, NULL, NULL); 59 60 // FIXME 61 if(file_array[0] == 0 || file_array[1] != 0) 62 return false; 63 filename_m = file_array[0]; 64 g_print(_("File is: %s\n"), filename_m); 65 66 ClutterColor stage_color; 67 the_stage_m = clutter_stage_get_default(); 68 clutter_color_parse("Black", &stage_color); 69 clutter_stage_set_color(CLUTTER_STAGE(the_stage_m), &stage_color); 70 return true; 71 } 72 73 /** @brief Loads the PDF document. */ 74 bool load() 75 { 76 // poppler needs an URI (e.g. file:///....) 77 g_print(_("Loading %s...\n"), filename_m); 78 PopplerDocument* active_document = 79 poppler_document_new_from_file(filename_m, NULL, NULL); 80 if(active_document == NULL) 81 { 82 g_print(_("PDF file %s cannot be opened, check it exists, permissions" 83 " and that is \nnot encrypted.\n"), filename_m); 84 return false; 85 } 86 g_print(_("Done.\n")); 87 if(the_doc_m) delete the_doc_m; 88 the_doc_m = new pdfcube::document(active_document); 89 return true; 90 } 91 92 /** @brief Main application loop. */ 93 void 94 main_loop() 95 { 96 //clutter_stage_hide_cursor (CLUTTER_STAGE (stage)); 97 ClutterColor label_color = { 0xff, 0xff, 0xff, 0x99 }; 98 progress_label_m = 99 clutter_text_new_full("Mono 36", "0%", &label_color); 100 guint screen_w, screen_h; 101 clutter_actor_get_size(CLUTTER_ACTOR(the_stage_m), &screen_w, &screen_h); 102 clutter_actor_set_position(progress_label_m, screen_w>>1, screen_h>>1); 103 clutter_actor_set_anchor_point_from_gravity(progress_label_m, 104 CLUTTER_GRAVITY_CENTER); 105 clutter_group_add_many(CLUTTER_GROUP(the_stage_m), 106 progress_label_m, NULL); 107 clutter_actor_show(the_stage_m); 108 g_thread_create(render_thread, this, FALSE, NULL); 109 110 clutter_threads_enter(); 111 clutter_main(); 112 clutter_threads_leave(); 113 } 114 115 /** @brief The document. */ 116 document* the_doc_m; 117 118 protected: 119 ClutterActor* the_stage_m; 120 gchar *filename_m; 121 std::string progress_m; 122 ClutterActor* progress_label_m; 123 ClutterActor* current_page_m; 124 ClutterActor* next_page_m; 125 int current_page_no_m; 126 127 static gboolean 128 progress_indicator_update(gpointer data) 129 { 130 app* me = static_cast<app*>(data); 131 guint screen_w, screen_h; 132 clutter_actor_get_size(CLUTTER_ACTOR(me->the_stage_m), 133 &screen_w, &screen_h); 134 clutter_text_set_text(CLUTTER_TEXT(me->progress_label_m), 135 me->progress_m.c_str()); 136 clutter_actor_set_anchor_point_from_gravity(me->progress_label_m, 137 CLUTTER_GRAVITY_CENTER); 138 clutter_actor_set_position(me->progress_label_m, 139 screen_w>>1, screen_h>>1); 140 return FALSE; 141 } 142 143 static gboolean 144 progress_indicator_end(gpointer data) 145 { 146 app* me = static_cast<app*>(data); 147 clutter_group_remove(CLUTTER_GROUP(me->the_stage_m), 148 me->progress_label_m); 149 g_object_unref(me->progress_label_m); 150 151 GError* error = 0; 152 GdkPixbuf* buffer = me->the_doc_m->page(0).pixbuf(pdfcube::page::HI_RES); 153 me->current_page_m = clutter_texture_new(); 154 clutter_texture_set_from_rgb_data 155 (CLUTTER_TEXTURE(me->current_page_m), 156 gdk_pixbuf_get_pixels(buffer), 157 gdk_pixbuf_get_has_alpha(buffer), 158 gdk_pixbuf_get_width(buffer), 159 gdk_pixbuf_get_height(buffer), 160 gdk_pixbuf_get_rowstride(buffer), 161 4, (ClutterTextureFlags)0, 162 &error); 163 guint screen_w, screen_h; 164 clutter_actor_get_size(CLUTTER_ACTOR(me->the_stage_m), 165 &screen_w, &screen_h); 166 clutter_actor_set_size(me->current_page_m, screen_w, screen_h); 167 clutter_group_add_many(CLUTTER_GROUP(me->the_stage_m), 168 me->current_page_m, NULL); 169 return FALSE; 170 } 171 172 static gpointer 173 render_thread(gpointer data) 174 { 175 app* me = static_cast<app*>(data); 176 std::cerr << me->filename_m << std::endl; 177 me->load(); 178 // ---------------------------------------------- 179 // render low res version of all pages 180 // ---------------------------------------------- 181 for(int ii(0); ii != me->the_doc_m->n_pages(); ++ii) 182 { 183 me->the_doc_m->page(ii).render(pdfcube::page::LOW_RES); 184 int percent = (100*(ii-1))/(me->the_doc_m->n_pages()); 185 std::ostringstream pt; 186 pt << percent << "%"; 187 me->progress_m = pt.str(); 188 clutter_threads_add_timeout(0, progress_indicator_update, data); 189 } 190 me->the_doc_m->page(0).render(pdfcube::page::HI_RES); 191 int percent = (100*(me->the_doc_m->n_pages()-1)) / 192 (me->the_doc_m->n_pages()); 193 std::ostringstream pt; 194 pt << percent << "%"; 195 me->progress_m = pt.str(); 196 clutter_threads_add_timeout(0, progress_indicator_update, data); 197 198 me->the_doc_m->page(1).render(pdfcube::page::HI_RES); 199 me->progress_m = "100%"; 200 clutter_threads_add_timeout(0, progress_indicator_update, data); 201 clutter_threads_add_timeout(250, progress_indicator_end, data); 202 return 0; 203 } 204 205 }; 206 } 207 18 208 void usage() 19 209 { 20 cerr << "pdfcube filename.pdf"<< endl;210 cerr << _("pdfcube filename.pdf") << endl; 21 211 exit(1); 22 212 } 23 213 24 214 215 /* 25 216 static gboolean 26 217 on_page_enter(ClutterActor* actor, ClutterEvent *event, gpointer data) 27 218 { 219 double sx, sy; 220 clutter_actor_get_scale(actor, &sx, &sy); 221 if(sx > 1.0 || sy > 1.0) return FALSE; 28 222 // Code snippet for a static member of the index class, 29 223 // data should point to the index instance, so one can … … 35 229 ClutterEffectTemplate *effect_template = 36 230 clutter_effect_template_new(timeline, 37 CLUTTER_ALPHA_SINE_HALF); 38 gint x, y; 39 clutter_actor_get_position(actor, &x, &y); 231 clutter_sine_half_func); 40 232 clutter_effect_scale(effect_template, actor, 1.12, 1.12, NULL, NULL); 41 233 g_object_unref(effect_template); … … 49 241 return TRUE; 50 242 } 51 243 */ 52 244 static gboolean 53 245 on_stage_button_press (ClutterStage *stage, ClutterEvent *event, gpointer data) … … 91 283 92 284 void 93 prepare() = 0;285 setup() = 0; 94 286 95 287 void 96 288 render(int frame) = 0; 97 289 98 290 void 99 unprepare() = 0;291 tear_down() = 0; 100 292 }; 101 293 … … 108 300 class cube_animator : public animator 109 301 { 110 replace_animator(pdfcube::document& doc, int page_no);302 cube_animator(pdfcube::document& doc, int page_no); 111 303 // ... 112 304 } … … 140 332 // -------------- 141 333 142 PopplerDocument* pdoc; 143 GError *error = NULL; 144 ClutterActor *stage; 145 gchar **pdfcube_filename = NULL; 146 147 // Clutter options parsing 148 GOptionEntry options[] = { 149 { G_OPTION_REMAINING, 150 0, 151 0, 152 G_OPTION_ARG_FILENAME_ARRAY, 153 &pdfcube_filename, 154 "Presentation PDF file to load", 155 "FILE" }, 156 { NULL } 157 }; 158 159 if (argc == 1) 160 usage(); 161 162 clutter_init_with_args (&argc, &argv, "PDFCube 0.1.0", 163 options, NULL, 164 NULL); 165 166 stage = clutter_stage_get_default(); 167 168 ClutterColor stage_color; 169 // parse from command line (init to black first) 170 clutter_color_parse("DarkRed", &stage_color); 171 clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); 172 173 // poppler needs an URI (e.g. file:///....) 174 pdoc = poppler_document_new_from_file(*pdfcube_filename, NULL, NULL); 175 if(pdoc == NULL) 176 { 177 g_print(_("PDF file %s cannot be opened, check it exists, permissions" 178 " and that is \nnot encrypted.\n"), argv[1]); 179 return -1; 180 } 181 pdfcube::document doc(pdoc); 182 334 pdfcube::app the_app; 335 336 the_app.init(&argc, &argv); 337 338 the_app.main_loop(); 339 340 /* 183 341 // ---------------------------------------------- 184 342 // render low res version of all pages … … 253 411 // ------------------------- 254 412 255 / *Connect a signal handler to handle mouse clicks and key presses256 on the stage: */413 // Connect a signal handler to handle mouse clicks and key presses 414 // on the stage: 257 415 g_signal_connect (stage, "button-press-event", 258 416 G_CALLBACK (on_stage_button_press), NULL); … … 262 420 clutter_actor_show (stage); 263 421 clutter_main (); 264 422 */ 265 423 return 0; 266 424 } -
branches/clutter-experiments/page.hh
r50 r52 7 7 #include <glib.h> 8 8 #include <poppler.h> 9 #include <clutter/clutter.h>9 //#include <clutter/clutter.h> 10 10 #include <gdk-pixbuf/gdk-pixbuf.h> 11 11 … … 91 91 } 92 92 93 GdkPixbuf* buffer = NULL; 94 buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); 93 // GdkPixbuf* low_res_m = NULL; 94 if(!low_res_m) 95 low_res_m = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); 95 96 poppler_page_render_to_pixbuf(poppler_page_m, 96 97 0, … … 100 101 ((double)h)/size().second, 101 102 0, 102 buffer); 103 GError* error; 104 if(!low_res_m) low_res_m = clutter_texture_new(); 105 clutter_texture_set_from_rgb_data 106 (CLUTTER_TEXTURE(low_res_m), 107 gdk_pixbuf_get_pixels(buffer), 108 gdk_pixbuf_get_has_alpha(buffer), 109 gdk_pixbuf_get_width(buffer), 110 gdk_pixbuf_get_height(buffer), 111 gdk_pixbuf_get_rowstride(buffer), 112 4, (ClutterTextureFlags)0, 113 &error); 114 g_object_unref(buffer); 103 low_res_m); 115 104 break; 116 105 } … … 133 122 w = h*aspect; 134 123 } 135 GdkPixbuf* buffer = NULL;136 buffer= gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h);124 if(!hi_res_m) 125 hi_res_m = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); 137 126 poppler_page_render_to_pixbuf(poppler_page_m, 138 127 0, … … 142 131 ((double)h)/size().second, 143 132 0, 144 buffer); 145 GError* error; 133 hi_res_m); 134 GError* error = 0; 135 136 /* 146 137 if(!hi_res_m) hi_res_m = clutter_texture_new(); 147 138 clutter_texture_set_from_rgb_data … … 155 146 &error); 156 147 g_object_unref(buffer); 148 */ 157 149 break; 158 150 } … … 198 190 * @brief Returns the desired actor (on NULL if not present). 199 191 */ 200 ClutterActor*201 actor(rendering_mode mode)192 GdkPixbuf* 193 pixbuf(rendering_mode mode) 202 194 { 203 195 switch(mode) … … 210 202 return NULL; 211 203 } 212 204 213 205 protected: 214 206 … … 227 219 228 220 PopplerPage* poppler_page_m; 229 ClutterActor* low_res_m;230 ClutterActor* hi_res_m;221 GdkPixbuf* low_res_m; 222 GdkPixbuf* hi_res_m; 231 223 }; 232 224

