void TabMenuControl::HighlightNextMenuItem() { const unsigned page = GetPageNum(GetTabMenuDisplay()->GetSelectedIndex()); if (page + 1 < GetNumPages()) // don't wrap SetLastContentPage(page + 1); else if (page >= GetNumPages()) // initial state is menu (page == NunPages) SetLastContentPage(0); }
const Document::PageSize PDFDocument::GetPageSize( int page, float zoom, int rotation) { assert((page >= 0) && (page < GetNumPages())); const fz_irect& bbox = GetBoundingBox( GetPage(page), Transform(zoom, rotation)); return PageSize(bbox.x1 - bbox.x0, bbox.y1 - bbox.y0); }
inline bool TabMenuDisplay::HighlightNext() { const unsigned i = cursor + 1; if (i >= GetNumPages()) return false; SetCursor(i); return true; }
int TabMenuDisplay::GetPageNum(MenuTabIndex i) const { assert(i.IsSub()); assert(i.main_index < main_menu_buttons.size()); assert(i.sub_index < GetNumPages()); const MainMenuButton &main_button = GetMainMenuButton(i.main_index); return main_button.first_page_index + i.sub_index; }
int TabMenuControl::GetPageNum(MenuTabIndex i) const { if (!i.IsSub()) return this->GetMenuPage(); assert(i.main_index < main_menu_buttons.size()); assert(i.sub_index < GetNumPages()); const MainMenuButton &main_button = GetMainMenuButton(i.main_index); return main_button.first_page_index + i.sub_index; }
inline bool TabMenuDisplay::HighlightPrevious() { if (cursor == 0) return false; const unsigned i = cursor - 1; assert(i < GetNumPages()); SetCursor(i); return true; }
bool CGUITextBox::GetCondition(int condition, int data) const { switch (condition) { case CONTAINER_HAS_NEXT: return (GetCurrentPage() < GetNumPages()); case CONTAINER_HAS_PREVIOUS: return (GetCurrentPage() > 1); default: return false; } }
TabMenuControl::MenuTabIndex TabMenuControl::FindPage(unsigned page) const { if (page >= GetNumPages()) return MenuTabIndex::None(); const unsigned main_index = pages[page].main_menu_index; const unsigned first_page_index = main_menu_buttons[main_index]->first_page_index; assert(page >= first_page_index); assert(page <= main_menu_buttons[main_index]->last_page_index); const unsigned sub_index = page - first_page_index; return MenuTabIndex(main_index, sub_index); }
std::string CGUITextBox::GetLabel(int info) const { std::string label; switch (info) { case CONTAINER_NUM_PAGES: label = StringUtils::Format("%u", GetNumPages()); break; case CONTAINER_CURRENT_PAGE: label = StringUtils::Format("%u", GetCurrentPage()); break; default: break; } return label; }
void PDFDocument::Render( Document::PixelWriter* pw, int page, float zoom, int rotation) { assert((page >= 0) && (page < GetNumPages())); std::unique_lock<std::mutex> lock(_render_mutex); // 1. Init MuPDF structures. const fz_matrix& m = Transform(zoom, rotation); pdf_page* page_struct = GetPage(page); const fz_irect& bbox = GetBoundingBox(page_struct, m); fz_pixmap* pixmap = fz_new_pixmap_with_bbox( _fz_context, fz_device_rgb(_fz_context), FZ_OBJ(bbox), nullptr, 1); fz_device* dev = fz_new_draw_device(_fz_context, FZ_OBJ(fz_identity), pixmap); // 2. Render page. fz_clear_pixmap_with_value(_fz_context, pixmap, 0xff); pdf_run_page( _fz_context, _pdf_document, page_struct, dev, FZ_OBJ(m), nullptr); // 3. Write pixmap to buffer. The page is vertically divided into n equal // stripes, each copied to pw by one thread. assert(fz_pixmap_components(_fz_context, pixmap) == 4); uint8_t* buffer = reinterpret_cast<uint8_t*>(fz_pixmap_samples(_fz_context, pixmap)); const int num_cols = fz_pixmap_width(_fz_context, pixmap); const int num_rows = fz_pixmap_height(_fz_context, pixmap); ExecuteInParallel([=](int num_threads, int i) { const int num_rows_per_thread = num_rows / num_threads; const int y_begin = i * num_rows_per_thread; const int y_end = (i == num_threads - 1) ? num_rows : (i + 1) * num_rows_per_thread; uint8_t* p = buffer + y_begin * num_cols * 4; for (int y = y_begin; y < y_end; ++y) { for (int x = 0; x < num_cols; ++x) { pw->Write(x, y, p[0], p[1], p[2]); p += 4; } } }); // 4. Clean up. fz_close_device(_fz_context, dev); fz_drop_device(_fz_context, dev); fz_drop_pixmap(_fz_context, pixmap); }
void TabMenuControl::InitMenu(const PageItem pages_in[], unsigned num_pages, const TCHAR *main_menu_captions[], unsigned num_menu_captions) { assert(pages_in); assert(main_menu_captions); pages = pages_in; for (unsigned i = 0; i < num_menu_captions; i++) CreateSubMenu(pages_in, num_pages, main_menu_captions[i], i); pager.AddClient(tab_display); buttons.append(new SubMenuButton(caption)); assert(GetNumPages() == num_pages); }
void TBTabContainer::SetValue(int index) { if (index == m_current_page || !GetNumPages()) return; m_current_page = index; // Update the pages visibility and tabs pressed value. index = 0; TBWidget *page = m_content_root.GetFirstChild(); TBWidget *tab = m_tab_layout.GetFirstChild(); for ( ; page && tab; page = page->GetNext(), tab = tab->GetNext(), index++) { bool active = index == m_current_page; page->SetVisibilility(active ? WIDGET_VISIBILITY_VISIBLE : WIDGET_VISIBILITY_INVISIBLE); tab->SetValue(active ? 1 : 0); } TBWidgetEvent ev(EVENT_TYPE_TAB_CHANGED); InvokeEvent(ev); }
pdf_page* PDFDocument::GetPage(int page) { assert((page >= 0) && (page < GetNumPages())); return _page_cache->Get(page); }
int CGUITextBox::GetCurrentPage() const { if (m_offset + m_itemsPerPage >= GetRows()) // last page return GetNumPages(); return m_offset / m_itemsPerPage + 1; }