1
//--------------------------------------------------------------------------------------
2
// This file is part of the Lomse library.
3
// Copyright (c) 2010 Lomse project
5
// Lomse is free software; you can redistribute it and/or modify it under the
6
// terms of the GNU General Public License as published by the Free Software Foundation,
7
// either version 3 of the License, or (at your option) any later version.
9
// Lomse is distributed in the hope that it will be useful, but WITHOUT ANY
10
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11
// PARTICULAR PURPOSE. See the GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License along
14
// with Lomse; if not, see <http://www.gnu.org/licenses/>.
16
// For any comment, suggestion or feature request, please contact the manager of
17
// the project at cecilios@users.sourceforge.net
19
//-------------------------------------------------------------------------------------
21
#include "lomse_gm_basic.h"
23
#include "lomse_internal_model.h"
24
#include "lomse_box_system.h"
28
//using namespace std;
34
//#include "BoxScore.h"
35
//#include "BoxPage.h"
36
//#include "GmoBoxSlice.h"
37
//#include "GmoBoxSystem.h"
38
//#include "Handlers.h"
42
//#include "../globals/Colors.h"
43
//extern lmColors* g_pColors;
45
////-----------------------------------------------------------------------------------------
46
//// lmLayer: helper class. A collection of lmShapes
47
////-----------------------------------------------------------------------------------------
49
////to assign ID to user layers
50
//static long m_nLayerCounter = lm_eLayerUser;
55
// lmLayer(long nLayerID) : m_nLayerID(nLayerID) {}
58
// void InsertShapeInLayer(lmShape* pShape);
59
// void RenderLayer(lmPaper* pPaper);
60
// lmGMObject* FindShapeAtPos(lmUPoint& uPoint, bool fSelectable);
63
// std::list<lmShape*> m_Shapes; //contained shapes, ordered by creation order
68
//void lmLayer::InsertShapeInLayer(lmShape* pShape)
70
// //Algorithm: the sorted list is traversed in order to find the element which is
71
// //greater than or equal to the object to be inserted.
72
// //In the worst case, when the object to be inserted is larger than all of the
73
// //objects already present in the list, the entire list needs to be traversed
74
// //before doing the insertion. Therefore, the total running time for the insert
75
// //operation is O(n).
77
// //wxLogMessage(_T("[lmLayer::InsertShapeInLayer] Shape %d inserted in layer %d"),
78
// // pShape->GetID(), m_nLayerID);
80
// if (m_Shapes.empty())
82
// //this is going to be the first element.
83
// m_Shapes.push_back(pShape);
87
// //there are elements. Find where to insert new item
88
// std::list<lmShape*>::iterator itCur;
89
// for (itCur = m_Shapes.begin(); itCur != m_Shapes.end(); ++itCur)
91
// if ((*itCur)->GetOrder() < pShape->GetOrder())
92
// break; //insertion point found
95
// //position found: insert before itCur
96
// if (itCur != m_Shapes.end())
97
// m_Shapes.insert(itCur, pShape);
99
// m_Shapes.push_back(pShape);
104
//void lmLayer::RenderLayer(lmPaper* pPaper)
106
// std::list<lmShape*>::iterator it;
107
// for (it = m_Shapes.begin(); it != m_Shapes.end(); ++it)
109
// (*it)->Render(pPaper);
113
//lmGMObject* lmLayer::FindShapeAtPos(lmUPoint& uPoint, bool fSelectable)
115
// std::list<lmShape*>::reverse_iterator it;
116
// for (it = m_Shapes.rbegin(); it != m_Shapes.rend(); ++it)
118
// bool fFound = (*it)->HitTest(uPoint);
119
// if ( (fSelectable && (*it)->IsSelectable() && fFound) ||
120
// (!fSelectable && fFound) )
123
// return (lmGMObject*)NULL;
131
//-------------------------------------------------------------------------------------
132
// GmoBoxScorePage implementation
133
//-------------------------------------------------------------------------------------
135
GmoBoxScorePage::GmoBoxScorePage(GmoStubScore* pStub, GmoObj* owner)
136
: GmoBox(owner, GmoObj::k_box_score_page)
137
// , m_nNumPage(nNumPage)
138
, m_pStubScore(pStub)
141
// , m_pRenderWindow(NULL)
143
// CreateLayers(); //create standard layers
145
// //create margin shapes
146
// lmScore* pScore = (lmScore*)m_pOwner;
147
// LUnits uxLeftMargin = pScore->GetLeftMarginXPos();
148
// LUnits uxRightMargin = pScore->GetRightMarginXPos();
149
// LUnits uyTopMargin = pScore->GetPageTopMargin();
150
// LUnits uyBottomMargin = pScore->GetMaximumY();
151
// LUnits uPageWidth = pScore->GetPaperSize().GetWidth();
152
// LUnits uPageHeight = pScore->GetPaperSize().GetHeight();
154
// m_pMarginShapes[0] =
155
// new lmShapeMargin(pScore, this, lmMARGIN_TOP, m_nNumPage, lmHORIZONTAL,
156
// uyTopMargin, uPageWidth);
158
// m_pMarginShapes[1] =
159
// new lmShapeMargin(pScore, this, lmMARGIN_BOTTOM, m_nNumPage, lmHORIZONTAL,
160
// uyBottomMargin, uPageWidth);
162
// m_pMarginShapes[2] =
163
// new lmShapeMargin(pScore, this, lmMARGIN_LEFT, m_nNumPage, lmVERTICAL,
164
// uxLeftMargin, uPageHeight);
166
// m_pMarginShapes[3] =
167
// new lmShapeMargin(pScore, this, lmMARGIN_RIGHT, m_nNumPage, lmVERTICAL,
168
// uxRightMargin, uPageHeight);
169
m_pStubScore->add_page(this);
172
GmoBoxScorePage::~GmoBoxScorePage()
174
// m_GMObjsWithHandlers.clear();
177
// for (int i=0; i<4; i++)
178
// delete m_pMarginShapes[i];
181
// std::list<lmLayer*>::iterator itL;
182
// for (itL = m_Layers.begin(); itL != m_Layers.end(); ++itL)
186
//void GmoBoxScorePage::CreateLayers()
188
// //create standard layers and layer indexes
189
// m_Layers.push_back( new lmLayer(lm_eLayerBackground) );
190
// m_Layers.push_back( new lmLayer(lm_eLayerStaff) );
191
// m_Layers.push_back( new lmLayer(lm_eLayerBarlines) );
192
// m_Layers.push_back( new lmLayer(lm_eLayerNotes) );
193
// m_Layers.push_back( new lmLayer(lm_eLayerAuxObjs) );
194
// m_Layers.push_back( new lmLayer(lm_eLayerTop) );
197
//void GmoBoxScorePage::AddShapeToLayer(lmShape* pShape, long nLayerID)
199
// wxASSERT(nLayerID >= lm_eLayerBackground && nLayerID < m_nLayerCounter);
201
// //find requested layer
202
// std::list<lmLayer*>::iterator it;
203
// for (it = m_Layers.begin(); it != m_Layers.end(); ++it)
205
// if ((*it)->m_nLayerID == nLayerID)
208
// wxASSERT(it != m_Layers.end());
210
// //add shape to layer
211
// (*it)->InsertShapeInLayer(pShape);
214
//void GmoBoxScorePage::PopulateLayers()
216
// //reorganize shapes into layers
218
// AddShapesToLayers(this);
221
GmoBoxSystem* GmoBoxScorePage::add_system(int iSystem) //, LUnits uxPos, LUnits uyPos)
224
if (m_nFirstSystem == -1)
225
m_nFirstSystem = iSystem;
226
m_nLastSystem = iSystem;
229
GmoBoxSystem* pSystem =
230
new GmoBoxSystem(this); //TODO, m_nNumPage, iSystem, uxPos, uyPos, fFirstOfPage);
231
add_child_box(pSystem);
236
GmoBoxSystem* GmoBoxScorePage::get_system(int iSystem)
238
//returns pointer to GmoBoxSystem for system nSystem (0..n-1)
240
int i = iSystem - m_nFirstSystem;
242
return (GmoBoxSystem*)NULL; //the system is not in this page
244
return (GmoBoxSystem*)m_childBoxes[i];
247
//lmGMObject* GmoBoxScorePage::FindShapeAtPos(lmUPoint& uPoint, bool fSelectable)
249
// //look up in active handlers
250
// std::list<lmHandler*>::reverse_iterator it;
251
// for (it = m_ActiveHandlers.rbegin(); it != m_ActiveHandlers.rend(); ++it)
253
// if ((*it)->BoundsContainsPoint(uPoint))
258
// std::list<lmLayer*>::reverse_iterator itL;
259
// for (itL = m_Layers.rbegin(); itL != m_Layers.rend(); ++itL)
261
// lmGMObject* pGMO = (*itL)->FindShapeAtPos(uPoint, fSelectable);
263
// return pGMO; //found
265
// return (lmGMObject*)NULL;
268
//void GmoBoxScorePage::on_draw(Drawer* pDrawer, RenderOptions& opt, UPoint& origin)
270
// //clear lists with renderization information
271
// m_ActiveHandlers.clear();
272
// m_GMObjsWithHandlers.clear();
274
// //render shapes in layers
275
// std::list<lmLayer*>::iterator itL;
276
// for (itL = m_Layers.begin(); itL != m_Layers.end(); ++itL)
277
// (*itL)->RenderLayer(pPaper);
279
// //if debug render box bounds
280
// if (g_fDrawBounds)
281
// lmBox::Render(pPaper, lmUPoint(0,0));
283
// //if requested, book to render page margins
284
// if (g_fShowMargins)
285
// this->OnNeedToDrawHandlers(this);
288
//void GmoBoxScorePage::RenderWithHandlers(lmPaper* pPaper)
290
// //render page with margins
292
// wxColour color = *wxGREEN; //TODO User options
293
// for (int i=0; i < 4; i++)
295
// m_pMarginShapes[i]->Render(pPaper, color);
296
// AddActiveHandler( m_pMarginShapes[i] );
300
//void GmoBoxScorePage::DrawAllHandlers(lmPaper* pPaper)
302
// //Inform all GMObjects that booked to draw handlers (during renderization) to do
305
// std::vector<lmGMObject*>::iterator it;
306
// for (it = m_GMObjsWithHandlers.begin(); it != m_GMObjsWithHandlers.end(); ++it)
307
// (*it)->RenderWithHandlers(pPaper);
310
//void GmoBoxScorePage::AddActiveHandler(lmHandler* pHandler)
312
// m_ActiveHandlers.push_back(pHandler);
315
//void GmoBoxScorePage::OnNeedToDrawHandlers(lmGMObject* pGMO)
317
// //This method is invoked by objects contained in this BoxPage.
318
// //Handlers are not rendered during shapes renderization. Instead, if
319
// //during renderization and object has the need to draw handlers (for instance,
320
// //if the object is selected) if MUST inform its parent BoxPage by invoking this
321
// //method. BoxPage mantains a list of objects having requested to draw handlers
322
// //and, when appropriate, it will invoke method DrawHandlers for those objects,
323
// //so that they can do it.
325
// m_GMObjsWithHandlers.push_back(pGMO);
328
//wxString GmoBoxScorePage::Dump(int nIndent)
330
// wxString sDump = _T("");
331
// sDump.append(nIndent * lmINDENT_STEP, _T(' '));
332
// sDump += wxString::Format(_T("GmoBoxScorePage %d (systems %d to %d), "),
333
// m_nNumPage, m_nFirstSystem, m_nLastSystem);
335
// sDump += lmBox::Dump(nIndent);
339
//int GmoBoxScorePage::GetSystemNumber(GmoBoxSystem* pSystem)
341
// //returns the number of the system (1..n) received as parameter
342
// //precondition: the system must be in this page
344
// //loop to look up in the systems collection
345
// for(int i=0; i < (int)m_childBoxes.size(); i++)
347
// if (((GmoBoxSystem*)m_childBoxes[i]) == pSystem)
348
// return i + m_nFirstSystem; //system found
350
// wxASSERT(false); //system not in this page
351
// return 0; //keep compiler happy