~s-cecilio/lomse/master

« back to all changes in this revision

Viewing changes to src/graphic_model/lomse_box_score_page.cpp

  • Committer: cecilios
  • Date: 2010-11-14 17:47:31 UTC
  • Revision ID: git-v1:1fa3764c8c4d338b95b1a537b1e78271170c0025
latest new code. demo_1 tested on linux and win32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
//--------------------------------------------------------------------------------------
 
2
//  This file is part of the Lomse library.
 
3
//  Copyright (c) 2010 Lomse project
 
4
//
 
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.
 
8
//
 
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.
 
12
//
 
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/>.
 
15
//  
 
16
//  For any comment, suggestion or feature request, please contact the manager of
 
17
//  the project at cecilios@users.sourceforge.net
 
18
//
 
19
//-------------------------------------------------------------------------------------
 
20
 
 
21
#include "lomse_gm_basic.h"
 
22
 
 
23
#include "lomse_internal_model.h"
 
24
#include "lomse_box_system.h"
 
25
 
 
26
//#include <sstream>
 
27
//
 
28
//using namespace std;
 
29
 
 
30
namespace lomse
 
31
{
 
32
 
 
33
 
 
34
//#include "BoxScore.h"
 
35
//#include "BoxPage.h"
 
36
//#include "GmoBoxSlice.h"
 
37
//#include "GmoBoxSystem.h"
 
38
//#include "Handlers.h"
 
39
//
 
40
//
 
41
////access to colors
 
42
//#include "../globals/Colors.h"
 
43
//extern lmColors* g_pColors;
 
44
//
 
45
////-----------------------------------------------------------------------------------------
 
46
//// lmLayer: helper class. A collection of lmShapes
 
47
////-----------------------------------------------------------------------------------------
 
48
//
 
49
////to assign ID to user layers
 
50
//static long m_nLayerCounter = lm_eLayerUser;
 
51
//
 
52
//class lmLayer
 
53
//{
 
54
//public:
 
55
//    lmLayer(long nLayerID) : m_nLayerID(nLayerID) {}
 
56
//    ~lmLayer() {}
 
57
//
 
58
//    void InsertShapeInLayer(lmShape* pShape);
 
59
//    void RenderLayer(lmPaper* pPaper);
 
60
//    lmGMObject* FindShapeAtPos(lmUPoint& uPoint, bool fSelectable);
 
61
//
 
62
//    long                    m_nLayerID;
 
63
//    std::list<lmShape*>           m_Shapes;           //contained shapes, ordered by creation order
 
64
//
 
65
//
 
66
//};
 
67
//
 
68
//void lmLayer::InsertShapeInLayer(lmShape* pShape)
 
69
//{
 
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).
 
76
//    
 
77
//    //wxLogMessage(_T("[lmLayer::InsertShapeInLayer] Shape %d inserted in layer %d"),
 
78
//    //    pShape->GetID(), m_nLayerID);
 
79
//
 
80
//    if (m_Shapes.empty())
 
81
//    {
 
82
//        //this is going to be the first element.
 
83
//        m_Shapes.push_back(pShape);
 
84
//        return;
 
85
//    }
 
86
//
 
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)
 
90
//    {
 
91
//        if ((*itCur)->GetOrder() < pShape->GetOrder())
 
92
//            break;      //insertion point found
 
93
//    }
 
94
//    
 
95
//    //position found: insert before itCur
 
96
//    if (itCur != m_Shapes.end())
 
97
//        m_Shapes.insert(itCur, pShape);
 
98
//    else
 
99
//        m_Shapes.push_back(pShape);
 
100
//        
 
101
//    return;
 
102
//}
 
103
//
 
104
//void lmLayer::RenderLayer(lmPaper* pPaper)
 
105
//{
 
106
//    std::list<lmShape*>::iterator it;
 
107
//    for (it = m_Shapes.begin(); it != m_Shapes.end(); ++it)
 
108
//    {
 
109
//        (*it)->Render(pPaper);
 
110
//    }
 
111
//}
 
112
//
 
113
//lmGMObject* lmLayer::FindShapeAtPos(lmUPoint& uPoint, bool fSelectable)
 
114
//{
 
115
//    std::list<lmShape*>::reverse_iterator it;
 
116
//    for (it = m_Shapes.rbegin(); it != m_Shapes.rend(); ++it)
 
117
//    {
 
118
//        bool fFound = (*it)->HitTest(uPoint);
 
119
//        if ( (fSelectable && (*it)->IsSelectable() && fFound) ||
 
120
//            (!fSelectable && fFound) )
 
121
//            return *it;
 
122
//    }
 
123
//    return (lmGMObject*)NULL;
 
124
//}
 
125
//
 
126
//
 
127
//
 
128
//
 
129
 
 
130
 
 
131
//-------------------------------------------------------------------------------------
 
132
// GmoBoxScorePage implementation
 
133
//-------------------------------------------------------------------------------------
 
134
 
 
135
GmoBoxScorePage::GmoBoxScorePage(GmoStubScore* pStub, GmoObj* owner) 
 
136
    : GmoBox(owner, GmoObj::k_box_score_page)
 
137
//    , m_nNumPage(nNumPage)
 
138
    , m_pStubScore(pStub)
 
139
    , m_nFirstSystem(-1)
 
140
    , m_nLastSystem(-1)
 
141
//    , m_pRenderWindow(NULL)
 
142
{
 
143
//    CreateLayers();     //create standard layers
 
144
//
 
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();
 
153
//      
 
154
//    m_pMarginShapes[0] =
 
155
//        new lmShapeMargin(pScore, this, lmMARGIN_TOP, m_nNumPage, lmHORIZONTAL, 
 
156
//                          uyTopMargin, uPageWidth);
 
157
//
 
158
//    m_pMarginShapes[1] =
 
159
//        new lmShapeMargin(pScore, this, lmMARGIN_BOTTOM, m_nNumPage, lmHORIZONTAL,
 
160
//                          uyBottomMargin, uPageWidth);
 
161
//
 
162
//    m_pMarginShapes[2] =
 
163
//        new lmShapeMargin(pScore, this, lmMARGIN_LEFT, m_nNumPage, lmVERTICAL,
 
164
//                          uxLeftMargin, uPageHeight);
 
165
//
 
166
//    m_pMarginShapes[3] =
 
167
//        new lmShapeMargin(pScore, this, lmMARGIN_RIGHT, m_nNumPage, lmVERTICAL,
 
168
//                          uxRightMargin, uPageHeight);
 
169
    m_pStubScore->add_page(this);
 
170
}
 
171
 
 
172
GmoBoxScorePage::~GmoBoxScorePage()
 
173
{
 
174
//    m_GMObjsWithHandlers.clear();
 
175
//
 
176
//    //delete handlers
 
177
//    for (int i=0; i<4; i++)
 
178
//        delete m_pMarginShapes[i];
 
179
//
 
180
//    //delete layers
 
181
//    std::list<lmLayer*>::iterator itL;
 
182
//    for (itL = m_Layers.begin(); itL != m_Layers.end(); ++itL)
 
183
//        delete *itL;
 
184
}
 
185
 
 
186
//void GmoBoxScorePage::CreateLayers()
 
187
//{
 
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) );
 
195
//}
 
196
//
 
197
//void GmoBoxScorePage::AddShapeToLayer(lmShape* pShape, long nLayerID)
 
198
//{
 
199
//    wxASSERT(nLayerID >= lm_eLayerBackground && nLayerID < m_nLayerCounter);
 
200
//
 
201
//    //find requested layer
 
202
//    std::list<lmLayer*>::iterator it;
 
203
//    for (it = m_Layers.begin(); it != m_Layers.end(); ++it)
 
204
//    {
 
205
//        if ((*it)->m_nLayerID == nLayerID)
 
206
//            break;  //found
 
207
//    }
 
208
//    wxASSERT(it != m_Layers.end());
 
209
//
 
210
//    //add shape to layer
 
211
//    (*it)->InsertShapeInLayer(pShape);
 
212
//}
 
213
//
 
214
//void GmoBoxScorePage::PopulateLayers()
 
215
//{
 
216
//    //reorganize shapes into layers
 
217
//
 
218
//      AddShapesToLayers(this);
 
219
//}
 
220
 
 
221
GmoBoxSystem* GmoBoxScorePage::add_system(int iSystem)  //, LUnits uxPos, LUnits uyPos)
 
222
{
 
223
    //Update references
 
224
    if (m_nFirstSystem == -1)
 
225
        m_nFirstSystem = iSystem;
 
226
    m_nLastSystem = iSystem;
 
227
 
 
228
    //create the system
 
229
    GmoBoxSystem* pSystem = 
 
230
        new GmoBoxSystem(this);  //TODO, m_nNumPage, iSystem, uxPos, uyPos, fFirstOfPage);
 
231
    add_child_box(pSystem);
 
232
 
 
233
    return pSystem;
 
234
}
 
235
 
 
236
GmoBoxSystem* GmoBoxScorePage::get_system(int iSystem)
 
237
{
 
238
        //returns pointer to GmoBoxSystem for system nSystem (0..n-1)
 
239
 
 
240
        int i = iSystem - m_nFirstSystem;
 
241
        if (i < 0)
 
242
                return (GmoBoxSystem*)NULL;             //the system is not in this page
 
243
        else
 
244
                return (GmoBoxSystem*)m_childBoxes[i];
 
245
}
 
246
 
 
247
//lmGMObject* GmoBoxScorePage::FindShapeAtPos(lmUPoint& uPoint, bool fSelectable)
 
248
//{
 
249
//    //look up in active handlers
 
250
//      std::list<lmHandler*>::reverse_iterator it;
 
251
//      for (it = m_ActiveHandlers.rbegin(); it != m_ActiveHandlers.rend(); ++it)
 
252
//    {
 
253
//              if ((*it)->BoundsContainsPoint(uPoint))
 
254
//            return *it;
 
255
//    }
 
256
//
 
257
//    //find in layers
 
258
//    std::list<lmLayer*>::reverse_iterator itL;
 
259
//    for (itL = m_Layers.rbegin(); itL != m_Layers.rend(); ++itL)
 
260
//    {
 
261
//        lmGMObject* pGMO = (*itL)->FindShapeAtPos(uPoint, fSelectable);
 
262
//        if (pGMO)
 
263
//                      return pGMO;    //found
 
264
//    }
 
265
//    return (lmGMObject*)NULL;
 
266
//}
 
267
 
 
268
//void GmoBoxScorePage::on_draw(Drawer* pDrawer, RenderOptions& opt, UPoint& origin)
 
269
//{
 
270
//    //clear lists with renderization information
 
271
//    m_ActiveHandlers.clear();
 
272
//    m_GMObjsWithHandlers.clear();
 
273
//
 
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);
 
278
//
 
279
//    //if debug render box bounds
 
280
//    if (g_fDrawBounds)
 
281
//        lmBox::Render(pPaper, lmUPoint(0,0));
 
282
//
 
283
//    //if requested, book to render page margins
 
284
//    if (g_fShowMargins)
 
285
//        this->OnNeedToDrawHandlers(this);
 
286
//}
 
287
 
 
288
//void GmoBoxScorePage::RenderWithHandlers(lmPaper* pPaper)
 
289
//{
 
290
//    //render page with margins
 
291
//
 
292
//    wxColour color = *wxGREEN;      //TODO User options
 
293
//    for (int i=0; i < 4; i++)
 
294
//    {
 
295
//        m_pMarginShapes[i]->Render(pPaper, color);
 
296
//        AddActiveHandler( m_pMarginShapes[i] );
 
297
//    }
 
298
//}
 
299
//
 
300
//void GmoBoxScorePage::DrawAllHandlers(lmPaper* pPaper)
 
301
//{
 
302
//    //Inform all GMObjects that booked to draw handlers (during renderization) to do
 
303
//    //it now
 
304
//
 
305
//      std::vector<lmGMObject*>::iterator it;
 
306
//      for (it = m_GMObjsWithHandlers.begin(); it != m_GMObjsWithHandlers.end(); ++it)
 
307
//        (*it)->RenderWithHandlers(pPaper);
 
308
//}
 
309
//
 
310
//void GmoBoxScorePage::AddActiveHandler(lmHandler* pHandler)
 
311
//{
 
312
//    m_ActiveHandlers.push_back(pHandler);
 
313
//}
 
314
//
 
315
//void GmoBoxScorePage::OnNeedToDrawHandlers(lmGMObject* pGMO)
 
316
//{
 
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.
 
324
//
 
325
//    m_GMObjsWithHandlers.push_back(pGMO);
 
326
//}
 
327
//
 
328
//wxString GmoBoxScorePage::Dump(int nIndent)
 
329
//{
 
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);
 
334
//
 
335
//    sDump += lmBox::Dump(nIndent);
 
336
//      return sDump;
 
337
//}
 
338
//
 
339
//int GmoBoxScorePage::GetSystemNumber(GmoBoxSystem* pSystem)
 
340
//{
 
341
//      //returns the number of the system (1..n) received as parameter
 
342
//      //precondition: the system must be in this page
 
343
//
 
344
//    //loop to look up in the systems collection
 
345
//      for(int i=0; i < (int)m_childBoxes.size(); i++)
 
346
//    {
 
347
//        if (((GmoBoxSystem*)m_childBoxes[i]) == pSystem)
 
348
//                      return i + m_nFirstSystem;              //system found
 
349
//    }
 
350
//      wxASSERT(false);        //system not in this page
 
351
//      return 0;                       //keep compiler happy
 
352
//}
 
353
 
 
354
 
 
355
 
 
356
}  //namespace lomse
 
357
 
 
358