Changeset 50
- Timestamp:
- 01/22/09 22:43:20 (3 years ago)
- Location:
- branches/clutter-experiments
- Files:
-
- 2 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/clutter-experiments/main.cc
r49 r50 29 29 clutter_event_get_coords (event, &x, &y); 30 30 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)); 31 33 return TRUE; /* Stop further handling of this event. */ 32 34 } … … 103 105 int main(int argc, char* argv[]) 104 106 { 107 // -------------- 108 // Initialization 109 // -------------- 110 105 111 PopplerDocument* pdoc; 106 112 GError *error = NULL; … … 133 139 clutter_color_parse("DarkRed", &stage_color); 134 140 clutter_stage_set_color(CLUTTER_STAGE(stage), &stage_color); 135 141 136 142 // poppler needs an URI (e.g. file:///....) 137 143 pdoc = poppler_document_new_from_file(*pdfcube_filename, NULL, NULL); … … 144 150 pdfcube::document doc(pdoc); 145 151 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 // -------------------------- 146 164 guint screen_w = 0; 147 165 guint screen_h = 0; 148 166 clutter_stage_fullscreen (CLUTTER_STAGE (stage)); 149 167 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 154 179 for(int ii(0); ii != doc.n_pages(); ++ii) 155 180 { 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 161 207 ClutterActor* page = 162 208 CLUTTER_ACTOR(doc.page(ii).actor(pdfcube::page::LOW_RES)); 163 clutter_actor_set_x164 (page, (int)((double)row*screen_w)/rows + padding/2);165 c lutter_actor_set_y166 (page, (int)((double)col*screen_h)/rows + padding/2); 167 clutter_actor_set_ size168 (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); 171 217 clutter_group_add_many(CLUTTER_GROUP(stage), page, NULL); 172 218 } 219 220 // ------------------------- 173 221 174 222 /* Connect a signal handler to handle mouse clicks and key presses -
branches/clutter-experiments/page.hh
r48 r50 46 46 { } 47 47 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 48 64 enum rendering_mode { LOW_RES, HI_RES }; 49 65 … … 58 74 case LOW_RES: 59 75 { 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 61 93 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); 65 95 poppler_page_render_to_pixbuf(poppler_page_m, 66 96 0, 67 97 0, 68 320,69 240,70 240.0f/h,98 w, 99 h, 100 ((double)h)/size().second, 71 101 0, 72 102 buffer); … … 87 117 case HI_RES: 88 118 { 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 } 90 135 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); 94 137 poppler_page_render_to_pixbuf(poppler_page_m, 95 138 0, 96 139 0, 97 1600,98 1200,99 1200.0f/h,140 w, 141 h, 142 ((double)h)/size().second, 100 143 0, 101 144 buffer);

