From: <wha...@us...> - 2011-07-26 11:36:35
|
Revision: 7546 http://planeshift.svn.sourceforge.net/planeshift/?rev=7546&view=rev Author: whacko88 Date: 2011-07-26 11:36:28 +0000 (Tue, 26 Jul 2011) Log Message: ----------- * fixed a couple of bugs about resizing and the invalid selected SheetLine * completed documentation * fixed drawing ledger lines Modified Paths: -------------- soc/2011/sound/src/client/gui/pawsmusicwindow.cpp soc/2011/sound/src/client/gui/pawsmusicwindow.h soc/2011/sound/src/client/gui/pawssheetline.cpp soc/2011/sound/src/client/gui/pawssheetline.h Modified: soc/2011/sound/src/client/gui/pawsmusicwindow.cpp =================================================================== --- soc/2011/sound/src/client/gui/pawsmusicwindow.cpp 2011-07-25 23:08:33 UTC (rev 7545) +++ soc/2011/sound/src/client/gui/pawsmusicwindow.cpp 2011-07-26 11:36:28 UTC (rev 7546) @@ -423,7 +423,7 @@ // hide edit buttons SetToolbarButtons(); - pawsMusicWindow::UpdateScrollBar(this); + UpdateScrollBar(); return true; } @@ -496,7 +496,7 @@ // updating if(updateScrollBar) { - pawsMusicWindow::UpdateScrollBar(this); + UpdateScrollBar(); } return true; @@ -508,6 +508,19 @@ //------------------// +void pawsMusicWindow::OnSheetLineCallback(void* object, SheetLine* sheetLine) +{ + pawsMusicWindow* musicWindow = (pawsMusicWindow*)object; + + if(sheetLine->Prev() == 0 && sheetLine->Next() == 0 + && sheetLine == musicWindow->selectedSheetLine) + { + musicWindow->selectedSheetLine = 0; + } + + musicWindow->UpdateScrollBar(); +} + void pawsMusicWindow::Unload() { DeleteAll(); @@ -701,9 +714,12 @@ } // checking cache variable - if(selectedSheetLine->Contains(selectedMeasure)) + if(selectedSheetLine != 0) { - return selectedSheetLine; + if(selectedSheetLine->Contains(selectedMeasure)) + { + return selectedSheetLine; + } } // getting selected SheetLine @@ -721,19 +737,16 @@ return sheetLine; } -void pawsMusicWindow::UpdateScrollBar(void* object) +void pawsMusicWindow::UpdateScrollBar() { - pawsMusicWindow* musicWindow = (pawsMusicWindow*)object; - int nCurrentLine; float newTickValue; int nSheetLine = 0; - SheetLine* currentSheetLine = musicWindow->pawsLine1->GetLine(); - pawsScrollBar* scrollBar = musicWindow->scrollBar; + SheetLine* currentSheetLine = pawsLine1->GetLine(); // counting sheet lines - for(SheetLine* l = musicWindow->linesHead; l != 0; l = l->Next()) + for(SheetLine* l = linesHead; l != 0; l = l->Next()) { nSheetLine++; @@ -791,7 +804,7 @@ pawsLine2->SetLine(sheetLine); } - UpdateScrollBar(this); + UpdateScrollBar(); } pawsButton* pawsMusicWindow::GetButton(int buttonID) @@ -940,7 +953,7 @@ if(linesHead == 0) { linesHead = new SheetLine(lastMeasure); - linesHead->SetCallback(this, &UpdateScrollBar); + linesHead->SetCallback(this, &OnSheetLineCallback); measuresHead = lastMeasure; lastLine = linesHead; Modified: soc/2011/sound/src/client/gui/pawsmusicwindow.h =================================================================== --- soc/2011/sound/src/client/gui/pawsmusicwindow.h 2011-07-25 23:08:33 UTC (rev 7545) +++ soc/2011/sound/src/client/gui/pawsmusicwindow.h 2011-07-26 11:36:28 UTC (rev 7546) @@ -198,6 +198,12 @@ pawsScrollBar* scrollBar; /** + * Callback of SheetLine. Update the scroll bar and keep the selected + * SheetLine valid. + */ + static void OnSheetLineCallback(void* object, SheetLine* sheetLine); + + /** * Unloads the previous musical sheet. */ void Unload(); @@ -232,10 +238,9 @@ SheetLine* GetSelectedSheetLine(); /** - * Update the tick value and current position of the scroll bar. It is a - * callback function that is called when the number of lines changes. + * Update the tick value and current position of the scroll bar. */ - static void UpdateScrollBar(void* object); + void UpdateScrollBar(); /** * Resize all the SheetLines from the given one display the selected chord. Modified: soc/2011/sound/src/client/gui/pawssheetline.cpp =================================================================== --- soc/2011/sound/src/client/gui/pawssheetline.cpp 2011-07-25 23:08:33 UTC (rev 7545) +++ soc/2011/sound/src/client/gui/pawssheetline.cpp 2011-07-26 11:36:28 UTC (rev 7546) @@ -427,14 +427,36 @@ } // has this note ledger lines? - bool hasLedgerLine; - if(pawsLine->isDouble) + bool hasLedgerLine; // true if the drawed note is cut by a line + int nLedgerLines = 0; + + hasLedgerLine = (notePos % 2) == 0; + + if(notePos == 0) { - hasLedgerLine = (notePos <= -12 || 12 <= notePos || notePos == 0) && notePos % 2 == 0; + nLedgerLines = 1; } + else if(notePos >= 12) + { + nLedgerLines = (notePos - 12) / 2 + 1; + } else { - hasLedgerLine = (12 <= notePos || notePos <= 0) && notePos % 2 == 0; + + if(pawsLine->isDouble) + { + if(notePos <= -12) + { + nLedgerLines = (-notePos - 12) / 2 + 1; + } + } + else + { + if(notePos <= 0) + { + nLedgerLines = -notePos / 2 + 1; + } + } } // Sonora has some character printed on a lower line than other @@ -528,26 +550,40 @@ } // handling ledger lines - if(hasLedgerLine) + if(nLedgerLines > 0) { - if(lowString[0] == '\0') + wchar_t tempString[2]; + int hPos = horizontalPos - pawsLine->ledgerLineShift; + int yPos = yNoteLow; + + // fixing initial position + if(!hasLedgerLine) { - lowString[0] = LEDGER_LINE_SONORA; - nextHPosLowString -= pawsLine->ledgerLineShift; + if(notePos > 0) + { + yPos += 0.5 * pawsLine->staffRowHeight; + } + else + { + yPos -= 0.5 * pawsLine->staffRowHeight; + } } - else if(lowString[1] == '\0' && !isLowerNote) // there's only an alteration char + + tempString[0] = LEDGER_LINE_SONORA; + tempString[1] = '\0'; + + for(; nLedgerLines > 0; nLedgerLines--) { - lowString[1] = LEDGER_LINE_SONORA; - nextHPosLowString -= pawsLine->ledgerLineShift; - } - else - { - wchar_t tempString[2]; - int hPos = horizontalPos - pawsLine->ledgerLineShift; - tempString[0] = LEDGER_LINE_SONORA; - tempString[1] = '\0'; + pawsLine->graphics2D->Write(pawsLine->GetFont(), hPos, yPos, pawsLine->GetFontColour(), -1, tempString); - pawsLine->graphics2D->Write(pawsLine->GetFont(), hPos, yNoteLow, pawsLine->GetFontColour(), -1, tempString); + if(notePos > 0) + { + yPos += pawsLine->staffRowHeight; + } + else + { + yPos -= pawsLine->staffRowHeight; + } } } @@ -1414,6 +1450,11 @@ next->prev = prev; } + // updating prev and next so that the call back object + // knows if this line is being deleting or creating + prev = 0; + next = 0; + Callback(); } @@ -1735,7 +1776,7 @@ return endChord; } -void SheetLine::SetCallback(void* object, void (*function)(void*)) +void SheetLine::SetCallback(void* object, void (*function)(void*, SheetLine*)) { hasCallback = true; callbackObject = object; @@ -1746,7 +1787,7 @@ { if(hasCallback) { - callbackFunction(callbackObject); + callbackFunction(callbackObject, this); } } @@ -1778,18 +1819,13 @@ // setting size of the line nAlter = (musicWindow->fifths >= 0 ? musicWindow->fifths : -musicWindow->fifths); - newSize = screenFrame.xmax - screenFrame.xmin - 2 * staffMarginLateral - cleffCharLength - nAlter * alterCharLength; + newSize = screenFrame.xmax - screenFrame.xmin - 2 * staffMarginLateral - cleffCharLength - nAlter * alterCharLength - doubleLineWidth;; if(line->HasFirstMeasure()) { newSize -= metricCharLength; } - if(line->HasLastMeasure()) - { - newSize -= doubleLineWidth; - } - if(line->SetSize(newSize, this) && resize) { line->ResizeAll(); Modified: soc/2011/sound/src/client/gui/pawssheetline.h =================================================================== --- soc/2011/sound/src/client/gui/pawssheetline.h 2011-07-25 23:08:33 UTC (rev 7545) +++ soc/2011/sound/src/client/gui/pawssheetline.h 2011-07-26 11:36:28 UTC (rev 7546) @@ -67,6 +67,8 @@ /** * Constructor. + * @param position the note's position. + * @param alter the note's alteration. */ Note(short int position, short int alter); @@ -83,17 +85,18 @@ { public: /** - * Constructor. Default duration is a sixteenth. + * Constructor. Default duration is a quarter. */ Chord(); /** * Copy constructor. It copies notes and duration. + * @param chord the Chord to copy. */ Chord(Chord* chord); /** - * Destructor. + * Destructor. It removes itself from the list. */ ~Chord(); @@ -416,8 +419,8 @@ uint nChords; ///< The number of chords in this measure. uint notesSpace; ///< Space between notes. - Chord* firstChord; - Chord* lastChord; + Chord* firstChord; ///< First chord of the measure. + Chord* lastChord; ///< Last chord of the measure. /** * Inserts a chord after the given one. @@ -456,7 +459,15 @@ class SheetLine { public: + /** + * Constructor. + * @param firstMeasure the first measure of the SheetLine. + */ SheetLine(Measure* firstMeasure); + + /** + * Destructor. It does not delete its measures. + */ ~SheetLine(); /** @@ -595,21 +606,24 @@ * @param object the callback object. * @param function the callback function. */ - void SetCallback(void* object, void (*function)(void*)); + void SetCallback(void* object, void (*function)(void*, SheetLine*)); private: - SheetLine* prev; - SheetLine* next; + SheetLine* prev; ///< The previous SheetLine. + SheetLine* next; ///< The next SheetLine. - uint size; - uint noteLength; - Measure* firstMeasure; - Measure* lastMeasure; + uint size; ///< The size of this SheetLine. + uint noteLength; ///< The width of notes. + Measure* firstMeasure; ///< The first measure of this SheetLine. + Measure* lastMeasure; ///< The last measure of this SheetLine. - bool hasCallback; ///< True if there is a Callback set, false otherwise. - void* callbackObject; ///< Callback object. - void (*callbackFunction)(void*); ///< Callback function. + bool hasCallback; ///< True if there is a Callback set, false otherwise. + void* callbackObject; ///< Callback object. + void (*callbackFunction)(void*, SheetLine*); ///< Callback function. + /** + * Calls the callback function. + */ void Callback(); }; @@ -623,7 +637,14 @@ class pawsSheetLine: public pawsWidget { public: + /** + * Constructor. + */ pawsSheetLine(); + + /** + * Destructor. + */ virtual ~pawsSheetLine(); /** @@ -678,18 +699,18 @@ // positioning parameters int staffMarginUp; ///< Vertical margin before the staff. - int staffMarginLateral; + int staffMarginLateral; ///< Horizontal margin before the staff. - int cleffCharLength; - int alterCharLength; - int metricCharLength; - int noteCharLength; - int doubleLineWidth; - int ledgerLineShift; + int cleffCharLength; ///< Width of the font's cleff char. + int alterCharLength; ///< Width of the font's alteration chars. + int metricCharLength; ///< Width of the font's big number char. + int noteCharLength; ///< Width of the font's note char. + int doubleLineWidth; ///< Width of the final vertical double line. + int ledgerLineShift; ///< Space between the start of the ledger line and the beginning of the note. - int noteCharHeight; - float staffRowHeight; - int centralCPos; ///< The position of the central C with this font + int noteCharHeight; ///< Height of the font's note char. + float staffRowHeight; ///< Height of a staff's row. + int centralCPos; ///< The position of the central C with this font. /** * Decode the char into the symbol format. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |