Changeset 56

Show
Ignore:
Timestamp:
02/09/09 21:04:56 (3 years ago)
Author:
mirko
Message:

Work in progress on future 0.1.0 branch.

Location:
branches/clutter-experiments
Files:
1 added
3 modified

Legend:

Unmodified
Added
Removed
  • branches/clutter-experiments/Makefile

    r52 r56  
    1010all: pdfcube 
    1111 
    12 main.o: main.cc page.hh document.hh 
     12main.o: main.cc page.hh document.hh pdfcube.hh 
    1313 
    1414pdfcube: main.o 
  • branches/clutter-experiments/main.cc

    r55 r56  
    1515#include "document.hh" 
    1616#include "page.hh" 
     17#include "pdfcube.hh" 
    1718 
    1819using namespace std; 
    1920 
    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_actor_set_size(the_stage_m, 1024, 768); 
    69       clutter_color_parse("Black", &stage_color); 
    70       clutter_stage_set_color(CLUTTER_STAGE(the_stage_m), &stage_color); 
    71       return true; 
    72     } 
    73  
    74     /** @brief Loads the PDF document. */ 
    75     bool load() 
    76     { 
    77       // poppler needs an URI (e.g. file:///....) 
    78       g_print(_("Loading %s...\n"), filename_m); 
    79       PopplerDocument* active_document =  
    80         poppler_document_new_from_file(filename_m, NULL, NULL); 
    81       if(active_document == NULL) 
    82         { 
    83           g_print(_("PDF file %s cannot be opened," 
    84                     " check that it exists, permissions" 
    85                     " and that is \nnot encrypted.\n"), filename_m); 
    86           return false; 
    87         } 
    88       g_print(_("Done.\n")); 
    89       if(the_doc_m) delete the_doc_m; 
    90       the_doc_m = new pdfcube::document(active_document); 
    91       return true; 
    92     } 
    93  
    94     /** @brief Main application loop. */ 
    95     void 
    96     main_loop() 
    97     { 
    98       //clutter_stage_hide_cursor (CLUTTER_STAGE (stage)); 
    99       ClutterColor label_color = { 0xff, 0xff, 0xff, 0x99 }; 
    100       progress_label_m =  
    101         clutter_text_new_full("Mono 36", "0%", &label_color); 
    102       guint screen_w, screen_h; 
    103       clutter_actor_get_size(CLUTTER_ACTOR(the_stage_m),  
    104                              &screen_w, &screen_h); 
    105       clutter_actor_set_position(progress_label_m,  
    106                                  screen_w>>1, screen_h>>1); 
    107       clutter_actor_set_anchor_point_from_gravity(progress_label_m,  
    108                                                   CLUTTER_GRAVITY_CENTER); 
    109       clutter_group_add_many(CLUTTER_GROUP(the_stage_m),  
    110                              progress_label_m, NULL); 
    111       clutter_actor_show(the_stage_m); 
    112       g_thread_create(render_thread, this, FALSE, NULL); 
    113        
    114       clutter_threads_enter(); 
    115       clutter_main(); 
    116       clutter_threads_leave(); 
    117     } 
    118  
    119     /** @brief The document. */ 
    120     document* the_doc_m; 
    121      
    122   protected: 
    123     ClutterActor* the_stage_m; 
    124     gchar *filename_m; 
    125     std::string progress_m; 
    126     ClutterActor* progress_label_m; 
    127     ClutterActor* current_page_m; 
    128     ClutterActor* next_page_m; 
    129     int current_page_no_m; 
    130  
    131     static gboolean  
    132     progress_indicator_update(gpointer data) 
    133     { 
    134       app* me = static_cast<app*>(data); 
    135       guint screen_w, screen_h; 
    136       clutter_actor_get_size(CLUTTER_ACTOR(me->the_stage_m),  
    137                              &screen_w, &screen_h); 
    138       clutter_text_set_text(CLUTTER_TEXT(me->progress_label_m),  
    139                             me->progress_m.c_str()); 
    140       clutter_actor_set_anchor_point_from_gravity(me->progress_label_m,  
    141                                                   CLUTTER_GRAVITY_CENTER); 
    142       clutter_actor_set_position(me->progress_label_m,  
    143                                  screen_w>>1, screen_h>>1); 
    144       return FALSE; 
    145     } 
    146  
    147     static gboolean 
    148     progress_indicator_end(gpointer data) 
    149     { 
    150       app* me = static_cast<app*>(data); 
    151       clutter_group_remove(CLUTTER_GROUP(me->the_stage_m),  
    152                                          me->progress_label_m); 
    153       g_object_unref(me->progress_label_m); 
    154  
    155       GError* error = 0; 
    156       GdkPixbuf* buffer = me->the_doc_m->page(0).pixbuf(pdfcube::page::HI_RES); 
    157       me->current_page_m = clutter_texture_new(); 
    158       clutter_texture_set_filter_quality 
    159         (CLUTTER_TEXTURE(me->current_page_m),  
    160          CLUTTER_TEXTURE_QUALITY_HIGH); 
    161       clutter_texture_set_from_rgb_data  
    162         (CLUTTER_TEXTURE(me->current_page_m), 
    163          gdk_pixbuf_get_pixels(buffer), 
    164          gdk_pixbuf_get_has_alpha(buffer), 
    165          gdk_pixbuf_get_width(buffer), 
    166          gdk_pixbuf_get_height(buffer), 
    167          gdk_pixbuf_get_rowstride(buffer), 
    168          4, (ClutterTextureFlags)0, 
    169          &error); 
    170  
    171       guint screen_w, screen_h; 
    172       clutter_actor_get_size(CLUTTER_ACTOR(me->the_stage_m),  
    173                              &screen_w, &screen_h); 
    174        
    175        
    176       // Check if our slot ratio is less or more than owr own 
    177       double aspect = me->the_doc_m->page(0).aspect_ratio(); 
    178        
    179       double w = 0.0, h = 0.0; 
    180       if(screen_h > screen_w/aspect) 
    181         { 
    182           w = screen_w; 
    183           h = w/aspect; 
    184         } 
    185       else  
    186         { 
    187           h = screen_h; 
    188           w = h*aspect; 
    189         } 
    190        
    191       clutter_actor_set_size(me->current_page_m, w, h); 
    192       clutter_group_add_many(CLUTTER_GROUP(me->the_stage_m),  
    193                              me->current_page_m, NULL); 
    194       return FALSE; 
    195     } 
    196  
    197     static gpointer  
    198     render_thread(gpointer data) 
    199     { 
    200       app* me = static_cast<app*>(data); 
    201       std::cerr << me->filename_m << std::endl; 
    202       me->load(); 
    203       // ---------------------------------------------- 
    204       // render low res version of all pages 
    205       // ---------------------------------------------- 
    206       for(int ii(0); ii != me->the_doc_m->n_pages(); ++ii) 
    207         { 
    208           me->the_doc_m->page(ii).render(pdfcube::page::LOW_RES); 
    209           int percent = (100*(ii))/(me->the_doc_m->n_pages()+2); 
    210           std::ostringstream pt; 
    211           pt << percent << "%";  
    212           me->progress_m = pt.str(); 
    213           clutter_threads_add_timeout(0, progress_indicator_update, data); 
    214         } 
    215       me->the_doc_m->page(0).render(pdfcube::page::HI_RES); 
    216       int percent = (100*(me->the_doc_m->n_pages())) / 
    217         (me->the_doc_m->n_pages()+2); 
    218       std::ostringstream pt; 
    219       pt << percent << "%";  
    220       me->progress_m = pt.str(); 
    221       clutter_threads_add_timeout(0, progress_indicator_update, data); 
    222        
    223       me->the_doc_m->page(1).render(pdfcube::page::HI_RES); 
    224       me->progress_m = "100%"; 
    225       clutter_threads_add_timeout(0, progress_indicator_update, data); 
    226       clutter_threads_add_timeout(250, progress_indicator_end, data); 
    227       return 0; 
    228     } 
    229  
    230   }; 
    231 } 
    23221 
    23322void usage() 
     
    27867} 
    27968 
    280 #if 0 
    28169/** 
    28270 * The index class will contain methods to show all the pages in an 
     
    29280  // 3. animate to the single page choosen (clicked or previous on esc) 
    29381  // 
    294 } 
     82}; 
     83 
    29584/** 
    29685 * @brief Abstract animator class. 
     
    30594class animator 
    30695{ 
     96public: 
    30797  virtual ~animator() {} 
    30898 
    309   void 
     99  virtual void 
    310100  setup() = 0; 
    311101   
    312   void 
     102  virtual void 
    313103  render(int frame) = 0; 
    314104   
    315   void 
     105  virtual void 
    316106  tear_down() = 0; 
    317107}; 
     
    319109class replace_animator : public animator 
    320110{ 
    321   replace_animator(pdfcube::document& doc, int page_no); 
    322   // ... 
    323 } 
     111public: 
     112  replace_animator(pdfcube::document& doc, int page_no) {}; 
     113  void 
     114  setup() {} 
     115  void 
     116  render(int frame) {} 
     117  void 
     118  tear_down() {} 
     119}; 
     120 
    324121 
    325122class cube_animator : public animator 
    326123{ 
    327   cube_animator(pdfcube::document& doc, int page_no); 
    328   // ... 
    329 } 
     124public: 
     125  cube_animator(pdfcube::document& doc, int page_no) {}; 
     126  void 
     127  setup() {} 
     128  void 
     129  render(int frame) {} 
     130  void 
     131  tear_down() {} 
     132}; 
     133 
    330134 
    331135/** 
     
    344148      case POPPLER_PAGE_TRANSITION_BOX: 
    345149        return new cube_animator(doc, page_no); 
     150      default: 
     151        return new replace_animator(doc, page_no); 
    346152      } 
    347153    return NULL; 
    348154  } 
    349 } 
    350 #endif 
     155}; 
    351156 
    352157// a main to quick-test some clutter api 
  • branches/clutter-experiments/page.hh

    r55 r56  
    185185      return NULL; 
    186186    } 
    187      
     187 
     188    PopplerPageTransitionType transition_type() 
     189    { 
     190      PopplerPageTransition* ppt = poppler_page_get_transition(poppler_page_m); 
     191      if(ppt) return ppt->type; 
     192      else return POPPLER_PAGE_TRANSITION_REPLACE; 
     193    } 
     194 
    188195  protected: 
    189196