Changeset 50 for branches

Show
Ignore:
Timestamp:
01/22/09 22:43:20 (3 years ago)
Author:
mirko
Message:

A decent index page with clutter, experimental branch

Location:
branches/clutter-experiments
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • branches/clutter-experiments/main.cc

    r49 r50  
    2929  clutter_event_get_coords (event, &x, &y); 
    3030  g_print ("Stage clicked at (%d, %d)\n", x, y); 
     31  // clutter cluttered my first draw, so redraw on click to allow testing. 
     32  clutter_actor_queue_redraw(CLUTTER_ACTOR(stage)); 
    3133  return TRUE; /* Stop further handling of this event. */ 
    3234} 
     
    103105int main(int argc, char* argv[]) 
    104106{ 
     107  // -------------- 
     108  // Initialization 
     109  // -------------- 
     110 
    105111  PopplerDocument* pdoc; 
    106112  GError        *error = NULL;  
     
    133139  clutter_color_parse("DarkRed", &stage_color); 
    134140  clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); 
    135  
     141   
    136142  // poppler needs an URI (e.g. file:///....) 
    137143  pdoc = poppler_document_new_from_file(*pdfcube_filename, NULL, NULL); 
     
    144150  pdfcube::document doc(pdoc); 
    145151   
     152  // ---------------------------------------------- 
     153  // render low res version of all pages 
     154  // TODO: show fancy progress bar in the meantime. 
     155  // ---------------------------------------------- 
     156  for(int ii(0); ii != doc.n_pages(); ++ii) 
     157    doc.page(ii).render(pdfcube::page::LOW_RES); 
     158 
     159 
     160  // -------------------------- 
     161  // arrange pages in an index 
     162  // TODO: move in an animation 
     163  // -------------------------- 
    146164  guint screen_w = 0; 
    147165  guint screen_h = 0; 
    148166  clutter_stage_fullscreen (CLUTTER_STAGE (stage)); 
    149167  clutter_actor_get_size(CLUTTER_ACTOR(stage), &screen_w, &screen_h); 
    150   int padding = 6; 
    151  
    152   // render low res version of all pages 
    153   // TODO: show fancy progress bar in the meantime. 
     168 
     169  double frows = ::sqrt(doc.n_pages()); 
     170  double fcols = std::ceil(((double)doc.n_pages())/std::floor(frows)); 
     171 
     172  int cols = std::floor(fcols); 
     173  int rows = frows; 
     174 
     175  double box_w = ((double)screen_w)/cols; 
     176  double box_h = ((double)screen_h)/rows; 
     177  double min_padding = 6; 
     178 
    154179  for(int ii(0); ii != doc.n_pages(); ++ii) 
    155180    { 
    156       int rows = 1+(int)::sqrt(doc.n_pages()); 
    157       int row = ii%rows; 
    158       int col = ii/rows; 
    159       cerr << "row: " << row << " col: " << col << endl; 
    160       doc.page(ii).render(pdfcube::page::LOW_RES); 
     181      int row = ii%cols; 
     182      int col = ii/cols; 
     183      double box_x = ((double)row*screen_w)/cols; 
     184      double box_y = ((double)col*screen_h)/rows; 
     185 
     186      double aspect = doc.page(ii).aspect_ratio(); 
     187       
     188      double w = 0.0, h = 0.0; 
     189       
     190      // Check if our slot ratio is less or more than owr own 
     191      if(box_h > box_w/aspect) 
     192        { 
     193          w = box_w - min_padding*2; 
     194          h = w/aspect; 
     195        } 
     196      else  
     197        { 
     198          h = box_h - min_padding*2; 
     199          w = h*aspect; 
     200        } 
     201       
     202      double padding_x = (box_w - w)/2; 
     203      double padding_y = (box_h - h)/2; 
     204 
     205      cerr << w << ", " << h << ", " << aspect << endl; 
     206 
    161207      ClutterActor* page =  
    162208        CLUTTER_ACTOR(doc.page(ii).actor(pdfcube::page::LOW_RES)); 
    163       clutter_actor_set_x 
    164         (page, (int)((double)row*screen_w)/rows + padding/2); 
    165       clutter_actor_set_y 
    166         (page, (int)((double)col*screen_h)/rows + padding/2); 
    167       clutter_actor_set_size 
    168         (page,  
    169          (int)((double)screen_w)/rows - padding, 
    170          (int)((double)screen_h)/rows - padding) ; 
     209      guint sx, sy; 
     210      clutter_actor_get_size(page, &sx, &sy); 
     211      cerr << sx << ", " << sy << endl; 
     212 
     213      clutter_actor_set_position(page,  
     214                                 (int)(box_x + padding_x), 
     215                                 (int)(box_y + padding_y)); 
     216      clutter_actor_set_size(page, (int)w, (int)h); 
    171217      clutter_group_add_many(CLUTTER_GROUP(stage), page, NULL); 
    172218    } 
     219 
     220  // ------------------------- 
    173221 
    174222  /* Connect a signal handler to handle mouse clicks and key presses 
  • branches/clutter-experiments/page.hh

    r48 r50  
    4646    { } 
    4747     
     48    double 
     49    aspect_ratio() 
     50    { 
     51      double w, h; 
     52      poppler_page_get_size(poppler_page_m, &w, &h); 
     53      return w/h; 
     54    } 
     55 
     56    std::pair<double, double> 
     57    size() 
     58    { 
     59      double w, h; 
     60      poppler_page_get_size(poppler_page_m, &w, &h); 
     61      return std::make_pair(w,h); 
     62    } 
     63     
    4864    enum rendering_mode { LOW_RES, HI_RES }; 
    4965     
     
    5874        case LOW_RES: 
    5975          { 
    60             double w, h; 
     76            int w,h; 
     77            // we assume 4/3 aspect monitor can do better 
     78            double box_w = 320; 
     79            double box_h = 240; 
     80            double aspect = aspect_ratio(); 
     81            // Check if our slot ratio is less or more than owr own 
     82            if(box_h > box_w/aspect) 
     83              { 
     84                w = box_w; 
     85                h = w/aspect; 
     86              } 
     87            else  
     88              { 
     89                h = box_h; 
     90                w = h*aspect; 
     91              } 
     92 
    6193            GdkPixbuf* buffer = NULL; 
    62             poppler_page_get_size(poppler_page_m, &w, &h); 
    63             g_print("Page %f by %f\n", w, h); 
    64             buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 320, 240); 
     94            buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); 
    6595            poppler_page_render_to_pixbuf(poppler_page_m,  
    6696                                          0, 
    6797                                          0,  
    68                                           320,  
    69                                           240,  
    70                                           240.0f/h,  
     98                                          w,  
     99                                          h,  
     100                                          ((double)h)/size().second,  
    71101                                          0,  
    72102                                          buffer); 
     
    87117        case HI_RES: 
    88118          { 
    89             double w, h; 
     119            int w, h; 
     120            // we assume 4/3 aspect monitor can do better 
     121            double box_w = 1600; 
     122            double box_h = 1200; 
     123            double aspect = aspect_ratio(); 
     124            // Check if our slot ratio is less or more than owr own 
     125            if(box_h > box_w/aspect) 
     126              { 
     127                w = box_w; 
     128                h = w/aspect; 
     129              } 
     130            else  
     131              { 
     132                h = box_h; 
     133                w = h*aspect; 
     134              } 
    90135            GdkPixbuf* buffer = NULL; 
    91             poppler_page_get_size(poppler_page_m, &w, &h); 
    92             g_print("Page is %f by %f\n", w, h); 
    93             buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, 1600, 1200); 
     136            buffer = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, w, h); 
    94137            poppler_page_render_to_pixbuf(poppler_page_m,  
    95138                                          0, 
    96139                                          0,  
    97                                           1600,  
    98                                           1200,  
    99                                           1200.0f/h,  
     140                                          w,  
     141                                          h,  
     142                                          ((double)h)/size().second,  
    100143                                          0,  
    101144                                          buffer);