//--------------------------------------------------------------------------------------- void CaretPositioner::layout_caret(Caret* pCaret, DocCursor* pCursor, GraphicModel* pGModel) { m_pCursor = pCursor; if (m_pCursor->is_inside_terminal_node()) { ImoObj* pTopLevel = m_pCursor->get_parent_object(); GmoBox* pBox = pGModel->get_box_for_imo(pCursor->get_parent_id()); if (!pBox) { LOMSE_LOG_ERROR("No box for cursor pointed object"); } else { pCaret->set_top_level_box( pBox->get_bounds() ); InnerLevelCaretPositioner* p = new_positioner(pTopLevel, pGModel); p->layout_caret(pCaret, m_pCursor); } } else { TopLevelCaretPositioner p(pGModel); p.layout_caret(pCaret, m_pCursor); } }
//--------------------------------------------------------------------------------------- void TopLevelCaretPositioner::layout_caret(Caret* pCaret, DocCursor* pCursor) { m_pCursor = pCursor; m_state = m_pCursor->get_state(); ImoId id = m_state.get_parent_level_id(); GmoBox* pBox = m_pGModel->get_box_for_imo(id); URect pos; if (pBox) pos = pBox->get_bounds(); else { //at end of document pBox = get_box_for_last_element(); if (pBox) { pos.set_top_left( UPoint(pBox->get_left(), pBox->get_bottom()) ); pos.set_height(1000.0f); pos.set_width(1000.0f); } else { //empty document pos = URect(0.0f, 0.0f, 1000.0f, 1000.0f); } } pCaret->set_type(Caret::k_top_level); pCaret->set_top_level_box(pos); pCaret->set_position( pos.get_top_left() ); pCaret->set_size( USize(pos.get_width(), pos.get_height()) ); }
//--------------------------------------------------------------------------------------- void ScoreCaretPositioner::set_caret_y_pos_and_height(URect* pBounds, ImoId id, int iStaff) { URect staffBounds; if (id >= 0) { GmoShape* pShape = get_shape_for_imo(id, iStaff); GmoBox* pBox = pShape->get_owner_box(); while (pBox && !pBox->is_box_system()) pBox = pBox->get_owner_box(); if (!pBox) { LOMSE_LOG_ERROR("[ScoreCaretPositioner::set_caret_y_pos_and_height] Invalid boxes structure"); throw runtime_error("[ScoreCaretPositioner::set_caret_y_pos_and_height] Invalid boxes structure"); } m_pBoxSystem = static_cast<GmoBoxSystem*>(pBox); int staff = m_spState->staff(); int instr = m_spState->instrument(); GmoShapeStaff* pStaff = m_pBoxSystem->get_staff_shape(instr, staff); staffBounds = pStaff->get_bounds(); } else { //score is empty staffBounds = *pBounds; } //set position and size pBounds->y = staffBounds.y - tenths_to_logical(10); pBounds->height = staffBounds.height + tenths_to_logical(20); }
//--------------------------------------------------------------------------------------- void Layouter::layout_item(ImoContentObj* pItem, GmoBox* pParentBox) { LOMSE_LOG_DEBUG(Logger::k_layout, str(boost::format( "Laying out id %d %s") % pItem->get_id() % pItem->get_name() )); m_pCurLayouter = create_layouter(pItem); m_pCurLayouter->prepare_to_start_layout(); while (!m_pCurLayouter->is_item_layouted()) { m_pCurLayouter->create_main_box(pParentBox, m_pageCursor, m_availableWidth, m_availableHeight); m_pCurLayouter->layout_in_box(); m_pCurLayouter->set_box_height(); if (!m_pCurLayouter->is_item_layouted()) { pParentBox = start_new_page(); } } m_pCurLayouter->add_end_margins(); //update cursor and available space GmoBox* pChildBox = m_pCurLayouter->get_item_main_box(); if (pChildBox) //AWARE: NullLayouter does not create a box { m_pageCursor.y = pChildBox->get_bottom(); m_availableHeight -= pChildBox->get_height(); } if (!pItem->is_score()) delete m_pCurLayouter; }
TEST_FIXTURE(InteractorTestFixture, Interactor_SelectObjectAtScreenPoint) { //as coordinates conversion is involved, the View must be rendered MyDoorway platform; LibraryScope libraryScope(cout, &platform); libraryScope.set_default_fonts_path(TESTLIB_FONTS_PATH); SpDocument spDoc( new Document(libraryScope) ); spDoc->from_string("(lenmusdoc (vers 0.0) (content (score (vers 1.6) " "(instrument (musicData (clef G)(key e)(n c4 q)(r q)(barline simple))))))" ); VerticalBookView* pView = Injector::inject_VerticalBookView(libraryScope, spDoc.get()); SpInteractor pIntor(Injector::inject_Interactor(libraryScope, WpDocument(spDoc), pView, NULL)); pView->set_interactor(pIntor.get()); RenderingBuffer rbuf; pView->set_rendering_buffer(&rbuf); pView->redraw_bitmap(); GraphicModel* pModel = pIntor->get_graphic_model(); GmoBoxDocPage* pPage = pModel->get_page(0); //DocPage GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage GmoBox* pBSys = pBSP->get_child_box(0); //System GmoBox* pBSlice = pBSys->get_child_box(0); //Slice GmoBox* pBSliceInstr = pBSlice->get_child_box(0); //SliceInsr GmoShape* pClef = pBSliceInstr->get_shape(0); //Clef LUnits x = (pClef->get_left() + pClef->get_right()) / 2.0f; LUnits y = (pClef->get_top() + pClef->get_bottom()) / 2.0f; double vx = x; double vy = y; pIntor->model_point_to_screen(&vx, &vy, 0); pIntor->task_action_select_object_and_show_contextual_menu(Pixels(vx), Pixels(vy), 0); CHECK( pIntor->is_in_selection(pClef) == true ); }
//--------------------------------------------------------------------------------------- GmoBoxDocPage* GmoObj::get_page_box() { if (is_box_doc_page()) return static_cast<GmoBoxDocPage*>(this); else { GmoBox* pParent = get_owner_box(); return pParent->get_page_box(); } }
//--------------------------------------------------------------------------------------- LUnits TableSectionLayouter::add_row(GmoBox* pParentMainBox) { GmoBox* pRowBox = m_pRowLayouter->get_item_main_box(); pParentMainBox->add_child_box(pRowBox); LUnits height = pRowBox->get_height(); m_pageCursor.y += height; m_availableHeight -= height; delete m_pRowLayouter; m_pRowLayouter = nullptr; return height; }
TEST_FIXTURE(DocLayouterTestFixture, DocLayouter_BoxSystemGetStaffShape) { Document doc(m_libraryScope); doc.from_string("(lenmusdoc (vers 0.0) " "(pageLayout (pageSize 24000 35700)(pageMargins 1000 1500 3000 2500 4000) landscape) " "(content (score (vers 1.6) " "(instrument (musicData (clef G)(key e)(n c4 q)(r q)(barline simple))))))" ); DocLayouter dl( doc.get_im_model(), m_libraryScope); dl.layout_document(); GraphicModel* pGModel = dl.get_graphic_model(); GmoBoxDocPage* pPage = pGModel->get_page(0); GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage GmoBoxSystem* pBSys = dynamic_cast<GmoBoxSystem*>( pBSP->get_child_box(0) ); GmoShape* pShape = pBSys->get_staff_shape(0); CHECK( pShape != NULL ); CHECK( pShape->is_shape_staff() == true ); GmoShapeStaff* pSS = dynamic_cast<GmoShapeStaff*>(pShape); CHECK( pSS->get_num_staff() == 0 ); delete pGModel; }
TEST_FIXTURE(DocLayouterTestFixture, DocLayouter_EmptyScore_TwoInstruments) { Document doc(m_libraryScope); doc.from_string("(lenmusdoc (vers 0.0) (content (score (vers 1.6) " "(instrument (musicData )) (instrument (musicData )) )))" ); DocLayouter dl( doc.get_im_model(), m_libraryScope); dl.layout_document(); GraphicModel* pGModel = dl.get_graphic_model(); CHECK( pGModel->get_num_pages() == 1 ); GmoBoxDocPage* pPage = pGModel->get_page(0); CHECK( pPage->get_num_boxes() == 1 ); GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent CHECK( pBDPC->get_num_boxes() == 1 ); GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage CHECK( pBSP->get_num_boxes() == 1 ); GmoBoxSystem* pBSys = dynamic_cast<GmoBoxSystem*>( pBSP->get_child_box(0) ); CHECK( pBSys->get_num_shapes() == 2 ); GmoShape* pShape = pBSys->get_staff_shape(0); CHECK( pShape != NULL ); CHECK( pShape->is_shape_staff() == true ); GmoShapeStaff* pSS = dynamic_cast<GmoShapeStaff*>(pShape); CHECK( pSS->get_num_staff() == 0 ); pShape = pBSys->get_staff_shape(1); CHECK( pShape != NULL ); CHECK( pShape->is_shape_staff() == true ); pSS = dynamic_cast<GmoShapeStaff*>(pShape); CHECK( pSS->get_num_staff() == 0 ); CHECK( pBSys->get_num_boxes() == 0 ); delete pGModel; }
TEST_FIXTURE(InteractorTestFixture, Interactor_SelectObject) { SpDocument spDoc( new Document(m_libraryScope) ); spDoc->from_string("(lenmusdoc (vers 0.0) (content (score (vers 1.6) " "(instrument (musicData (clef G)(key e)(n c4 q)(r q)(barline simple))))))" ); View* pView = Injector::inject_View(m_libraryScope, ViewFactory::k_view_simple, spDoc.get()); SpInteractor pIntor(Injector::inject_Interactor(m_libraryScope, WpDocument(spDoc), pView, NULL)); pView->set_interactor(pIntor.get()); GraphicModel* pModel = pIntor->get_graphic_model(); GmoBoxDocPage* pPage = pModel->get_page(0); //DocPage GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage GmoBox* pBSys = pBSP->get_child_box(0); //System GmoBox* pBSlice = pBSys->get_child_box(0); //Slice GmoBox* pBSliceInstr = pBSlice->get_child_box(0); //SliceInsr GmoShape* pClef = pBSliceInstr->get_shape(0); //Clef pIntor->select_object(pClef); CHECK( pIntor->is_in_selection(pClef) == true ); }
//--------------------------------------------------------------------------------------- void TableCellSizer::reposition_cells() { //AWARE: row 0 is correctly positioned, so we start moving from row 1. //In horizontal cells are correctly positioned, so shift is only in vertical. int iH = m_iFirstRow * m_numColumns; USize shift(0.0f, 0.0f); for (int iRow=1; iRow < m_numRows; ++iRow) { shift.height += m_heights[iH]; int iCell = (m_iFirstRow + iRow) * m_numColumns; for (int iCol=0; iCol < m_numColumns; ++iCol, ++iCell) { if (m_cellLayouters[iCell] != nullptr) { GmoBox* pCellBox = m_cellLayouters[iCell]->get_item_main_box(); pCellBox->shift_origin(shift); } } iH += m_numColumns; } }
//--------------------------------------------------------------------------------------- void TableCellSizer::assing_height_to_cells() { for (int iRow=0; iRow < m_numRows; ++iRow) { int iCell = (m_iFirstRow + iRow) * m_numColumns; for (int iCol=0; iCol < m_numColumns; ++iCol, ++iCell) { if (m_cellLayouters[iCell] != nullptr) { int iH = iCell; LUnits height = m_heights[iH]; int rowspan = m_cellLayouters[iCell]->get_rowspan(); while (rowspan > 1) { iH += m_numColumns; height += m_heights[iH]; --rowspan; } GmoBox* pCellBox = m_cellLayouters[iCell]->get_item_main_box(); pCellBox->set_height(height); } } } }
TEST_FIXTURE(DocLayouterTestFixture, DocLayouter_BoxSliceHasBoxSliceInstr) { Document doc(m_libraryScope); doc.from_string("(lenmusdoc (vers 0.0) " "(pageLayout (pageSize 24000 35700)(pageMargins 1000 1500 3000 2500 4000) landscape) " "(content (score (vers 1.6) " "(instrument (musicData (clef G)(key e)(n c4 q)(r q)(barline simple))))))" ); DocLayouter dl( doc.get_im_model(), m_libraryScope); dl.layout_document(); GraphicModel* pGModel = dl.get_graphic_model(); GmoBoxDocPage* pPage = pGModel->get_page(0); GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage GmoBox* pBSys = pBSP->get_child_box(0); //System GmoBox* pBSlice = pBSys->get_child_box(0); //Slice GmoBox* pBox = pBSlice->get_child_box(0); //SliceInstr CHECK( pBox != NULL ); CHECK( pBox->is_box_slice_instr() == true ); //CHECK( pBox->get_width() == 16000.0f ); //CHECK( pBox->get_height() == 735.0f ); //CHECK( pBox->get_left() == 1000.0f ); //CHECK( pBox->get_top() == 1500.0f ); delete pGModel; }
TEST_FIXTURE(DocLayouterTestFixture, DocLayouter_BoxesPositionAndMargins) { Document doc(m_libraryScope); doc.from_string("(lenmusdoc (vers 0.0) " "(content (score (vers 1.6) " "(instrument (musicData (clef G) )) )))" ); DocLayouter dl( doc.get_im_model(), m_libraryScope); dl.layout_document(); GraphicModel* pGModel = dl.get_graphic_model(); CHECK( pGModel->get_num_pages() == 1 ); GmoBoxDocPage* pPage = pGModel->get_page(0); CHECK( pPage->get_num_boxes() == 1 ); GmoBox* pBDPC = pPage->get_child_box(0); //DocPageContent CHECK( pBDPC->get_num_boxes() == 1 ); GmoBox* pBSP = pBDPC->get_child_box(0); //ScorePage CHECK( pBSP->get_num_boxes() == 1 ); GmoBoxSystem* pBSys = dynamic_cast<GmoBoxSystem*>( pBSP->get_child_box(0) ); CHECK( pBSys->get_top_margin() == 0.0f ); CHECK( pBSys->get_bottom_margin() == 0.0f ); CHECK( pBSys->get_num_boxes() == 1 ); GmoBox* pBSlice = pBSys->get_child_box(0); //Slice CHECK( pBSlice->get_top_margin() == 0.0f ); CHECK( pBSlice->get_bottom_margin() == 0.0f ); CHECK( pBSlice->get_left_margin() == 0.0f ); CHECK( pBSlice->get_right_margin() == 0.0f ); CHECK( pBSlice->get_top() == pBSys->get_top() ); CHECK( pBSlice->get_num_boxes() == 1 ); GmoBox* pBSliceInstr = pBSlice->get_child_box(0); //SliceInsr CHECK( pBSliceInstr->get_num_boxes() == 0 ); CHECK( pBSliceInstr->get_top_margin() == 0.0f ); CHECK( pBSliceInstr->get_bottom_margin() == 0.0f ); CHECK( pBSliceInstr->get_left_margin() == 0.0f ); CHECK( pBSliceInstr->get_right_margin() == 0.0f ); CHECK( pBSliceInstr->get_top() == pBSlice->get_top() ); delete pGModel; }
//--------------------------------------------------------------------------------------- GraphicModel* GmoBox::get_graphic_model() { GmoBox* pParent = get_parent_box(); return (pParent == NULL ? NULL : pParent->get_graphic_model()); }
//--------------------------------------------------------------------------------------- void GmoBox::add_shapes_to_tables() { GmoBoxDocPage* pPage = get_parent_box_page(); GmoBox* pBox = this; //gcc complains if next method is invoked directly pBox->add_shapes_to_tables_in(pPage); }