Encapsulating...

This commit is contained in:
Erik Faye-Lund 2009-01-17 12:20:18 +00:00
parent cabec12793
commit 557473f5a3
4 changed files with 39 additions and 33 deletions

View File

@ -103,7 +103,7 @@ bool SyncDocument::save(const std::string &fileName)
rootNode->appendChild(trackElem); rootNode->appendChild(trackElem);
sync::Track::KeyFrameContainer::const_iterator it; sync::Track::KeyFrameContainer::const_iterator it;
for (it = track.keyFrames.begin(); it != track.keyFrames.end(); ++it) for (it = track.keyFramesBegin(); it != track.keyFramesEnd(); ++it)
{ {
size_t row = it->first; size_t row = it->first;
float value = it->second.value; float value = it->second.value;
@ -123,7 +123,7 @@ bool SyncDocument::save(const std::string &fileName)
trackElem->appendChild(doc->createTextNode(_T("\n\t\t"))); trackElem->appendChild(doc->createTextNode(_T("\n\t\t")));
trackElem->appendChild(keyElem); trackElem->appendChild(keyElem);
} }
if (0 != track.keyFrames.size()) trackElem->appendChild(doc->createTextNode(_T("\n\t"))); if (0 != track.getKeyFrameCount()) trackElem->appendChild(doc->createTextNode(_T("\n\t")));
} }
if (0 != getTrackCount()) rootNode->appendChild(doc->createTextNode(_T("\n"))); if (0 != getTrackCount()) rootNode->appendChild(doc->createTextNode(_T("\n")));

View File

@ -631,7 +631,7 @@ int _tmain(int argc, _TCHAR* argv[])
const sync::Track &track = document.getTrack(serverIndex); const sync::Track &track = document.getTrack(serverIndex);
sync::Track::KeyFrameContainer::const_iterator it; sync::Track::KeyFrameContainer::const_iterator it;
for (it = track.keyFrames.begin(); it != track.keyFrames.end(); ++it) for (it = track.keyFramesBegin(); it != track.keyFramesEnd(); ++it)
{ {
int row = int(it->first); int row = int(it->first);
const sync::Track::KeyFrame &key = it->second; const sync::Track::KeyFrame &key = it->second;

View File

@ -266,15 +266,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
if (!RectVisible(hdc, &patternDataRect)) continue; if (!RectVisible(hdc, &patternDataRect)) continue;
sync::Track::KeyFrame::InterpolationType interpolationType = sync::Track::KeyFrame::IT_STEP; sync::Track::KeyFrame::InterpolationType interpolationType = t.getInterpolationType(row);
sync::Track::KeyFrameContainer::const_iterator upper = t.keyFrames.upper_bound(row);
sync::Track::KeyFrameContainer::const_iterator lower = upper;
if (lower != t.keyFrames.end())
{
lower--;
if (lower != t.keyFrames.end()) interpolationType = lower->second.interpolationType;
}
bool selected = (track >= selectLeft && track <= selectRight) && (row >= selectTop && row <= selectBottom); bool selected = (track >= selectLeft && track <= selectRight) && (row >= selectTop && row <= selectBottom);
HBRUSH baseBrush = bgBaseBrush; HBRUSH baseBrush = bgBaseBrush;
@ -803,33 +795,32 @@ void TrackView::editToggleInterpolationType()
size_t trackIndex = doc->getTrackIndexFromPos(editTrack); size_t trackIndex = doc->getTrackIndexFromPos(editTrack);
sync::Track &t = doc->getTrack(trackIndex); sync::Track &t = doc->getTrack(trackIndex);
// find key to modify // search backwards from editRow for the keyframe to modify
sync::Track::KeyFrameContainer::const_iterator upper = t.keyFrames.upper_bound(editRow); int row = editRow;
// bounds check for (; row >= 0; --row) if (t.isKeyFrame(row)) break;
if (upper == t.keyFrames.end())
// a negative row means no key was found
if (row < 0)
{ {
MessageBeep(-1); MessageBeep(-1);
return; return;
} }
sync::Track::KeyFrameContainer::const_iterator lower = upper; // copy old key to new key
lower--; const sync::Track::KeyFrame *oldKey = t.getKeyFrame(row);
// bounds check again assert(NULL != oldKey);
if (lower == t.keyFrames.end()) sync::Track::KeyFrame newKey(*oldKey);
{
MessageBeep(-1);
return;
}
sync::Track::KeyFrame newKey = lower->second;
// modify interpolation type // modify interpolation type
newKey.interpolationType = sync::Track::KeyFrame::InterpolationType( newKey.interpolationType = sync::Track::KeyFrame::InterpolationType(
(int(newKey.interpolationType) + 1) % sync::Track::KeyFrame::IT_COUNT (int(newKey.interpolationType) + 1) % sync::Track::KeyFrame::IT_COUNT
); );
SyncDocument::Command *cmd = doc->getSetKeyFrameCommand(int(trackIndex), int(lower->first), newKey); // apply change to data-set
SyncDocument::Command *cmd = doc->getSetKeyFrameCommand(int(trackIndex), row, newKey);
doc->exec(cmd); doc->exec(cmd);
// update user interface
SendMessage(GetParent(getWin()), WM_CURRVALDIRTY, 0, 0); SendMessage(GetParent(getWin()), WM_CURRVALDIRTY, 0, 0);
InvalidateRect(getWin(), NULL, FALSE); InvalidateRect(getWin(), NULL, FALSE);
} }

View File

@ -12,10 +12,7 @@ namespace sync
class Track class Track
{ {
public: public:
explicit Track(const std::string &name) : name(name) explicit Track(const std::string &name) : name(name) { }
{
}
struct KeyFrame struct KeyFrame
{ {
@ -27,9 +24,9 @@ namespace sync
IT_RAMP, IT_RAMP,
IT_COUNT // max value IT_COUNT // max value
}; };
KeyFrame() : value(0.0f), interpolationType(IT_STEP) {} KeyFrame() : value(0.0f), interpolationType(IT_STEP) {}
explicit KeyFrame(float value, InterpolationType interpolationType) : KeyFrame(float value, InterpolationType interpolationType) :
value(value), value(value),
interpolationType(interpolationType) interpolationType(interpolationType)
{ {
@ -52,8 +49,26 @@ namespace sync
const std::string &getName() const { return name; } const std::string &getName() const { return name; }
typedef std::map<size_t, struct KeyFrame> KeyFrameContainer; typedef std::map<size_t, struct KeyFrame> KeyFrameContainer;
KeyFrameContainer keyFrames; KeyFrameContainer::const_iterator keyFramesBegin() const { return keyFrames.begin(); }
KeyFrameContainer::const_iterator keyFramesEnd() const { return keyFrames.end(); }
size_t getKeyFrameCount() const { return keyFrames.size(); }
KeyFrame::InterpolationType getInterpolationType(int row) const
{
KeyFrame::InterpolationType interpolationType = KeyFrame::IT_STEP;
{
KeyFrameContainer::const_iterator upper = keyFrames.upper_bound(row);
KeyFrameContainer::const_iterator lower = upper;
if (lower != keyFrames.end())
{
lower--;
if (lower != keyFrames.end()) interpolationType = lower->second.interpolationType;
}
}
return interpolationType;
}
private: private:
KeyFrameContainer keyFrames;
std::string name; std::string name;
}; };
} }