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);
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;
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(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")));

View File

@ -631,7 +631,7 @@ int _tmain(int argc, _TCHAR* argv[])
const sync::Track &track = document.getTrack(serverIndex);
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);
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;
sync::Track::KeyFrame::InterpolationType interpolationType = sync::Track::KeyFrame::IT_STEP;
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;
}
sync::Track::KeyFrame::InterpolationType interpolationType = t.getInterpolationType(row);
bool selected = (track >= selectLeft && track <= selectRight) && (row >= selectTop && row <= selectBottom);
HBRUSH baseBrush = bgBaseBrush;
@ -803,33 +795,32 @@ void TrackView::editToggleInterpolationType()
size_t trackIndex = doc->getTrackIndexFromPos(editTrack);
sync::Track &t = doc->getTrack(trackIndex);
// find key to modify
sync::Track::KeyFrameContainer::const_iterator upper = t.keyFrames.upper_bound(editRow);
// bounds check
if (upper == t.keyFrames.end())
// search backwards from editRow for the keyframe to modify
int row = editRow;
for (; row >= 0; --row) if (t.isKeyFrame(row)) break;
// a negative row means no key was found
if (row < 0)
{
MessageBeep(-1);
return;
}
sync::Track::KeyFrameContainer::const_iterator lower = upper;
lower--;
// bounds check again
if (lower == t.keyFrames.end())
{
MessageBeep(-1);
return;
}
// copy old key to new key
const sync::Track::KeyFrame *oldKey = t.getKeyFrame(row);
assert(NULL != oldKey);
sync::Track::KeyFrame newKey(*oldKey);
sync::Track::KeyFrame newKey = lower->second;
// modify interpolation type
newKey.interpolationType = sync::Track::KeyFrame::InterpolationType(
(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);
// update user interface
SendMessage(GetParent(getWin()), WM_CURRVALDIRTY, 0, 0);
InvalidateRect(getWin(), NULL, FALSE);
}

View File

@ -12,10 +12,7 @@ namespace sync
class Track
{
public:
explicit Track(const std::string &name) : name(name)
{
}
explicit Track(const std::string &name) : name(name) { }
struct KeyFrame
{
@ -29,7 +26,7 @@ namespace sync
};
KeyFrame() : value(0.0f), interpolationType(IT_STEP) {}
explicit KeyFrame(float value, InterpolationType interpolationType) :
KeyFrame(float value, InterpolationType interpolationType) :
value(value),
interpolationType(interpolationType)
{
@ -52,8 +49,26 @@ namespace sync
const std::string &getName() const { return name; }
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:
KeyFrameContainer keyFrames;
std::string name;
};
}