Changeset 52 for branches

Show
Ignore:
Timestamp:
02/01/09 22:06:39 (3 years ago)
Author:
mirko
Message:

Added a check target in the makefile to allow emacs flymake-mode.

Started the app class. It now loads the pdf and renders all pages in
low resolution while displaying a progress indicator.

There is little more to do to reach an usable stage. The bigger step
is to link the app class to the animator interface (and to implement
a couple of animators).

The pdfcube::page class now simply renders pages to GdkPixbuf?
removing the dependency from Clutter in the page class.

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` 
     1CXXFLAGS=-O3 -g -Wall -Weffc++ 
     2LIBS=`pkg-config --libs clutter-0.9 poppler-glib` 
     3INCS=`pkg-config --cflags clutter-0.9 poppler-glib` 
    34 
    45.c.o: 
    5         $(CC) -g -Wall $(CFLAGS) $(INCS) -c $*.c 
     6        $(CC) $(CFLAGS) $(INCS) -c $*.c 
    67.cc.o: 
    7         $(CXX) -g -Wall -Weffc++ $(CXXFLAGS) $(INCS) -c $*.cc 
     8        $(CXX) $(CXXFLAGS) $(INCS) -c $*.cc 
    89 
    910all: pdfcube 
     
    1213 
    1314pdfcube: main.o 
    14         $(CXX) -g -Wall $(CXXFLAGS) -o $@ main.o $(LIBS) 
     15        $(CXX) $(CXXFLAGS) -o $@ main.o $(LIBS) 
    1516 
    1617clean: 
    1718        rm -fr *.o pdfcube 
     19 
     20.PHONY: check-syntax 
     21check-syntax: 
     22        $(CXX) -Wall -Wextra -Weffc++ -pedantic -fsyntax-only $(INCS) $(CHK_SOURCES) 
  • branches/clutter-experiments/main.cc

    r51 r52  
    33// C++ interface (or binding) for Poppler and Clutter or to code the 
    44// whole thing in C using GObjects. 
     5#include <iostream> 
     6#include <sstream> 
    57#include <cmath> 
    6 #include <iostream> 
    78#include <cstdlib> 
     9#include <cstring> 
    810#include <clutter/clutter.h> 
    911#include <poppler.h> 
     
    1618using namespace std; 
    1719 
     20namespace 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 
    18208void usage() 
    19209{ 
    20   cerr << "pdfcube filename.pdf" << endl; 
     210  cerr << _("pdfcube filename.pdf") << endl; 
    21211  exit(1); 
    22212} 
    23213 
    24214 
     215/* 
    25216static gboolean 
    26217on_page_enter(ClutterActor* actor, ClutterEvent *event, gpointer data) 
    27218{ 
     219  double sx, sy; 
     220  clutter_actor_get_scale(actor, &sx, &sy); 
     221  if(sx > 1.0 || sy > 1.0) return FALSE; 
    28222  // Code snippet for a static member of the index class, 
    29223  // data should point to the index instance, so one can  
     
    35229  ClutterEffectTemplate *effect_template =  
    36230    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); 
    40232  clutter_effect_scale(effect_template, actor, 1.12, 1.12, NULL, NULL); 
    41233  g_object_unref(effect_template); 
     
    49241  return TRUE; 
    50242} 
    51  
     243*/ 
    52244static gboolean 
    53245on_stage_button_press (ClutterStage *stage, ClutterEvent *event, gpointer data) 
     
    91283 
    92284  void 
    93   prepare() = 0; 
     285  setup() = 0; 
    94286   
    95287  void 
    96288  render(int frame) = 0; 
    97  
     289   
    98290  void 
    99   unprepare() = 0; 
     291  tear_down() = 0; 
    100292}; 
    101293 
     
    108300class cube_animator : public animator 
    109301{ 
    110   replace_animator(pdfcube::document& doc, int page_no); 
     302  cube_animator(pdfcube::document& doc, int page_no); 
    111303  // ... 
    112304} 
     
    140332  // -------------- 
    141333 
    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  /* 
    183341  // ---------------------------------------------- 
    184342  // render low res version of all pages 
     
    253411  // ------------------------- 
    254412 
    255   /* Connect a signal handler to handle mouse clicks and key presses 
    256      on the stage: */ 
     413  // Connect a signal handler to handle mouse clicks and key presses 
     414  //   on the stage:  
    257415  g_signal_connect (stage, "button-press-event", 
    258416                    G_CALLBACK (on_stage_button_press), NULL); 
     
    262420  clutter_actor_show (stage); 
    263421  clutter_main (); 
    264    
     422*/   
    265423  return 0; 
    266424} 
  • branches/clutter-experiments/page.hh

    r50 r52  
    77#include <glib.h> 
    88#include <poppler.h> 
    9 #include <clutter/clutter.h> 
     9//#include <clutter/clutter.h> 
    1010#include <gdk-pixbuf/gdk-pixbuf.h> 
    1111 
     
    9191              } 
    9292 
    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); 
    9596            poppler_page_render_to_pixbuf(poppler_page_m,  
    9697                                          0, 
     
    100101                                          ((double)h)/size().second,  
    101102                                          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); 
    115104            break; 
    116105          } 
     
    133122                w = h*aspect; 
    134123              } 
    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); 
    137126            poppler_page_render_to_pixbuf(poppler_page_m,  
    138127                                          0, 
     
    142131                                          ((double)h)/size().second,  
    143132                                          0,  
    144                                           buffer); 
    145             GError* error; 
     133                                          hi_res_m); 
     134            GError* error = 0; 
     135             
     136            /* 
    146137            if(!hi_res_m) hi_res_m = clutter_texture_new(); 
    147138            clutter_texture_set_from_rgb_data  
     
    155146                &error); 
    156147            g_object_unref(buffer); 
     148            */ 
    157149            break; 
    158150          } 
     
    198190     * @brief Returns the desired actor (on NULL if not present). 
    199191     */ 
    200     ClutterActor*  
    201     actor(rendering_mode mode) 
     192    GdkPixbuf*  
     193    pixbuf(rendering_mode mode) 
    202194    { 
    203195      switch(mode) 
     
    210202      return NULL; 
    211203    } 
    212  
     204     
    213205  protected: 
    214206 
     
    227219 
    228220    PopplerPage* poppler_page_m; 
    229     ClutterActor* low_res_m; 
    230     ClutterActor* hi_res_m; 
     221    GdkPixbuf* low_res_m; 
     222    GdkPixbuf* hi_res_m; 
    231223  }; 
    232224