renamed SyncEditData to SyncDocument, since that's essentially what it is ;)
This commit is contained in:
parent
26209abb1c
commit
74eee30216
@ -226,6 +226,10 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\syncdocument.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath="..\sync\track.h"
|
||||
>
|
||||
</File>
|
||||
|
||||
@ -9,10 +9,10 @@
|
||||
#include <stack>
|
||||
#include <list>
|
||||
|
||||
class SyncEditData : public sync::Data
|
||||
class SyncDocument : public sync::Data
|
||||
{
|
||||
public:
|
||||
SyncEditData() : sync::Data(), clientPaused(true) {}
|
||||
SyncDocument() : sync::Data(), clientPaused(true) {}
|
||||
|
||||
void sendSetKeyCommand(int track, int row, const sync::Track::KeyFrame &key)
|
||||
{
|
||||
@ -41,8 +41,6 @@ public:
|
||||
void sendSetRowCommand(int row)
|
||||
{
|
||||
if (INVALID_SOCKET == clientSocket) return;
|
||||
printf("sending row pos\n");
|
||||
|
||||
unsigned char cmd = SET_ROW;
|
||||
send(clientSocket, (char*)&cmd, 1, 0);
|
||||
send(clientSocket, (char*)&row, sizeof(int), 0);
|
||||
@ -67,8 +65,8 @@ public:
|
||||
{
|
||||
public:
|
||||
virtual ~Command() {}
|
||||
virtual void exec(SyncEditData *data) = 0;
|
||||
virtual void undo(SyncEditData *data) = 0;
|
||||
virtual void exec(SyncDocument *data) = 0;
|
||||
virtual void undo(SyncDocument *data) = 0;
|
||||
};
|
||||
|
||||
class InsertCommand : public Command
|
||||
@ -77,7 +75,7 @@ public:
|
||||
InsertCommand(int track, int row, const sync::Track::KeyFrame &key) : track(track), row(row), key(key) {}
|
||||
~InsertCommand() {}
|
||||
|
||||
virtual void exec(SyncEditData *data)
|
||||
virtual void exec(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
assert(!t.isKeyFrame(row));
|
||||
@ -86,7 +84,7 @@ public:
|
||||
data->sendSetKeyCommand(track, row, key); // update clients
|
||||
}
|
||||
|
||||
virtual void undo(SyncEditData *data)
|
||||
virtual void undo(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
assert(t.isKeyFrame(row));
|
||||
@ -106,7 +104,7 @@ public:
|
||||
DeleteCommand(int track, int row) : track(track), row(row) {}
|
||||
~DeleteCommand() {}
|
||||
|
||||
virtual void exec(SyncEditData *data)
|
||||
virtual void exec(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
assert(t.isKeyFrame(row));
|
||||
@ -116,7 +114,7 @@ public:
|
||||
data->sendDeleteKeyCommand(track, row); // update clients
|
||||
}
|
||||
|
||||
virtual void undo(SyncEditData *data)
|
||||
virtual void undo(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
assert(!t.isKeyFrame(row));
|
||||
@ -137,7 +135,7 @@ public:
|
||||
EditCommand(int track, int row, const sync::Track::KeyFrame &key) : track(track), row(row), key(key) {}
|
||||
~EditCommand() {}
|
||||
|
||||
virtual void exec(SyncEditData *data)
|
||||
virtual void exec(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
|
||||
@ -151,7 +149,7 @@ public:
|
||||
data->sendSetKeyCommand(track, row, key); // update clients
|
||||
}
|
||||
|
||||
virtual void undo(SyncEditData *data)
|
||||
virtual void undo(SyncDocument *data)
|
||||
{
|
||||
sync::Track &t = data->getTrack(this->track);
|
||||
|
||||
@ -186,13 +184,13 @@ public:
|
||||
|
||||
size_t getSize() const { return commands.size(); }
|
||||
|
||||
virtual void exec(SyncEditData *data)
|
||||
virtual void exec(SyncDocument *data)
|
||||
{
|
||||
std::list<Command*>::iterator it;
|
||||
for (it = commands.begin(); it != commands.end(); ++it) (*it)->exec(data);
|
||||
}
|
||||
|
||||
virtual void undo(SyncEditData *data)
|
||||
virtual void undo(SyncDocument *data)
|
||||
{
|
||||
std::list<Command*>::iterator it;
|
||||
for (it = commands.begin(); it != commands.end(); ++it) (*it)->undo(data);
|
||||
@ -246,17 +244,17 @@ public:
|
||||
Command *getSetKeyFrameCommand(int track, int row, const sync::Track::KeyFrame &key)
|
||||
{
|
||||
sync::Track &t = getTrack(track);
|
||||
SyncEditData::Command *cmd;
|
||||
SyncDocument::Command *cmd;
|
||||
if (t.isKeyFrame(row)) cmd = new EditCommand(track, row, key);
|
||||
else cmd = new InsertCommand(track, row, key);
|
||||
return cmd;
|
||||
}
|
||||
|
||||
SOCKET clientSocket;
|
||||
// private:
|
||||
std::map<size_t, size_t> clientRemap;
|
||||
bool clientPaused;
|
||||
|
||||
private:
|
||||
std::stack<Command*> undoStack;
|
||||
std::stack<Command*> redoStack;
|
||||
};
|
||||
@ -234,6 +234,19 @@ static ATOM registerMainWindowClass(HINSTANCE hInstance)
|
||||
return RegisterClassEx(&wc);
|
||||
}
|
||||
|
||||
SyncDocument loadDocument()
|
||||
{
|
||||
SyncDocument document;
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
std::string trackName = "balle";
|
||||
|
||||
// find track
|
||||
const sync::Track &track = document.getTrack(trackName);
|
||||
}
|
||||
return document;
|
||||
}
|
||||
|
||||
int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
#ifdef _DEBUG
|
||||
@ -281,7 +294,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
} */
|
||||
#endif
|
||||
|
||||
SyncEditData syncData;
|
||||
SyncDocument syncData;
|
||||
syncData.clientSocket = INVALID_SOCKET;
|
||||
|
||||
ATOM mainClass = registerMainWindowClass(hInstance);
|
||||
@ -293,7 +306,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
}
|
||||
|
||||
trackView = new TrackView();
|
||||
trackView->setSyncData(&syncData);
|
||||
trackView->setDocument(&syncData);
|
||||
|
||||
HWND hwnd = CreateWindowEx(
|
||||
0,
|
||||
@ -377,7 +390,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
{
|
||||
size_t clientIndex = 0;
|
||||
int ret = recv(clientSocket, (char*)&clientIndex, sizeof(int), 0);
|
||||
printf("client index: %d\n", clientIndex);
|
||||
|
||||
// get len
|
||||
int str_len = 0;
|
||||
@ -393,7 +405,6 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
|
||||
// find track
|
||||
size_t serverIndex = syncData.getTrackIndex(trackName.c_str());
|
||||
printf("name: \"%s\"\n", trackName.c_str());
|
||||
|
||||
// setup remap
|
||||
syncData.clientRemap[serverIndex] = clientIndex;
|
||||
|
||||
@ -110,15 +110,15 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
||||
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
||||
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
||||
|
||||
sync::Data *syncData = getSyncData();
|
||||
if (NULL == syncData) return;
|
||||
SyncDocument *document = getDocument();
|
||||
if (NULL == document) return;
|
||||
|
||||
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||
|
||||
sync::Data::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
||||
sync::Data::TrackContainer::iterator trackIter = document->tracks.begin();
|
||||
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
||||
{
|
||||
assert(trackIter != syncData->tracks.end());
|
||||
assert(trackIter != document->tracks.end());
|
||||
if (track < firstTrack) continue;
|
||||
|
||||
RECT topMargin;
|
||||
@ -141,7 +141,7 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
||||
|
||||
const std::basic_string<TCHAR> &trackName = trackIter->first;
|
||||
|
||||
if (this->syncData->clientRemap.count(track) == 0) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
|
||||
if (this->document->clientRemap.count(track) == 0) SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT));
|
||||
else SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||
TextOut(hdc,
|
||||
fillRect.left, 0,
|
||||
@ -210,20 +210,17 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
||||
|
||||
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||
|
||||
sync::Data *syncData = getSyncData();
|
||||
if (NULL == syncData) return;
|
||||
|
||||
int selectLeft = min(selectStartTrack, selectStopTrack);
|
||||
int selectRight = max(selectStartTrack, selectStopTrack);
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
|
||||
sync::Data::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
||||
sync::Data::TrackContainer::iterator trackIter = document->tracks.begin();
|
||||
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
||||
{
|
||||
assert(trackIter != syncData->tracks.end());
|
||||
assert(trackIter != document->tracks.end());
|
||||
size_t trackIndex = trackIter->second;
|
||||
const sync::Track &t = *syncData->actualTracks[trackIndex];
|
||||
const sync::Track &t = *document->actualTracks[trackIndex];
|
||||
|
||||
if (track < firstTrack) continue;
|
||||
for (int row = firstRow; row <= lastRow; ++row)
|
||||
@ -377,7 +374,7 @@ void TrackView::editCopy()
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
int localTrack = track - selectLeft;
|
||||
const sync::Track &t = syncData->getTrack(track);
|
||||
const sync::Track &t = document->getTrack(track);
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
int localRow = row - selectTop;
|
||||
@ -448,17 +445,17 @@ void TrackView::editPaste()
|
||||
{
|
||||
char *src = clipbuf + 2 * sizeof(int) + sizeof(size_t);
|
||||
|
||||
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
|
||||
SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
|
||||
for (int i = 0; i < buffer_size; ++i)
|
||||
{
|
||||
struct CopyEntry ce;
|
||||
memcpy(&ce, src, sizeof(CopyEntry));
|
||||
|
||||
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack + ce.track, editRow + ce.row, ce.keyFrame);
|
||||
SyncDocument::Command *cmd = document->getSetKeyFrameCommand(editTrack + ce.track, editRow + ce.row, ce.keyFrame);
|
||||
multiCmd->addCommand(cmd);
|
||||
src += sizeof(CopyEntry);
|
||||
}
|
||||
syncData->exec(multiCmd);
|
||||
document->exec(multiCmd);
|
||||
}
|
||||
|
||||
GlobalUnlock(hmem);
|
||||
@ -548,9 +545,9 @@ void TrackView::setEditRow(int newEditRow)
|
||||
selectStartRow = selectStopRow = editRow;
|
||||
selectStartTrack = selectStopTrack = editTrack;
|
||||
}
|
||||
if (getSyncData()->clientPaused)
|
||||
if (document->clientPaused)
|
||||
{
|
||||
getSyncData()->sendSetRowCommand(editRow);
|
||||
document->sendSetRowCommand(editRow);
|
||||
}
|
||||
}
|
||||
|
||||
@ -683,16 +680,16 @@ LRESULT TrackView::onHScroll(UINT sbCode, int /*newPos*/)
|
||||
|
||||
void TrackView::editEnterValue()
|
||||
{
|
||||
if (int(editString.size()) > 0 && editTrack < int(syncData->getTrackCount()))
|
||||
if (int(editString.size()) > 0 && editTrack < int(document->getTrackCount()))
|
||||
{
|
||||
sync::Track &t = syncData->getTrack(editTrack);
|
||||
sync::Track &t = document->getTrack(editTrack);
|
||||
|
||||
sync::Track::KeyFrame newKey;
|
||||
if (t.isKeyFrame(editRow)) newKey = *t.getKeyFrame(editRow); // copy old key
|
||||
newKey.value = float(_tstof(editString.c_str())); // modify value
|
||||
|
||||
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack, editRow, newKey);
|
||||
syncData->exec(cmd);
|
||||
SyncDocument::Command *cmd = document->getSetKeyFrameCommand(editTrack, editRow, newKey);
|
||||
document->exec(cmd);
|
||||
|
||||
editString.clear();
|
||||
// invalidatePos(editTrack, editRow);
|
||||
@ -703,9 +700,9 @@ void TrackView::editEnterValue()
|
||||
|
||||
void TrackView::editToggleInterpolationType()
|
||||
{
|
||||
if (editTrack < int(syncData->getTrackCount()))
|
||||
if (editTrack < int(document->getTrackCount()))
|
||||
{
|
||||
sync::Track &t = syncData->getTrack(editTrack);
|
||||
sync::Track &t = document->getTrack(editTrack);
|
||||
|
||||
// find key to modify
|
||||
sync::Track::KeyFrameContainer::const_iterator upper = t.keyFrames.upper_bound(editRow);
|
||||
@ -731,8 +728,8 @@ void TrackView::editToggleInterpolationType()
|
||||
(int(newKey.interpolationType) + 1) % sync::Track::KeyFrame::IT_COUNT
|
||||
);
|
||||
|
||||
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack, int(lower->first), newKey);
|
||||
syncData->exec(cmd);
|
||||
SyncDocument::Command *cmd = document->getSetKeyFrameCommand(editTrack, int(lower->first), newKey);
|
||||
document->exec(cmd);
|
||||
|
||||
invalidateRange(editTrack, editTrack, int(lower->first), int(upper->first));
|
||||
}
|
||||
@ -746,21 +743,21 @@ void TrackView::editDelete()
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
|
||||
if (selectRight >= int(syncData->getTrackCount()))
|
||||
if (selectRight >= int(document->getTrackCount()))
|
||||
{
|
||||
MessageBeep(0);
|
||||
return;
|
||||
}
|
||||
|
||||
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
|
||||
SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
sync::Track &t = syncData->getTrack(track);
|
||||
sync::Track &t = document->getTrack(track);
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
if (t.isKeyFrame(row))
|
||||
{
|
||||
SyncEditData::Command *cmd = new SyncEditData::DeleteCommand(track, row);
|
||||
SyncDocument::Command *cmd = new SyncDocument::DeleteCommand(track, row);
|
||||
multiCmd->addCommand(cmd);
|
||||
}
|
||||
}
|
||||
@ -773,7 +770,7 @@ void TrackView::editDelete()
|
||||
}
|
||||
else
|
||||
{
|
||||
syncData->exec(multiCmd);
|
||||
document->exec(multiCmd);
|
||||
InvalidateRect(getWin(), NULL, FALSE);
|
||||
// invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
|
||||
}
|
||||
@ -786,10 +783,10 @@ void TrackView::editBiasValue(float amount)
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
|
||||
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
|
||||
SyncDocument::MultiCommand *multiCmd = new SyncDocument::MultiCommand();
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
sync::Track &t = syncData->getTrack(track);
|
||||
sync::Track &t = document->getTrack(track);
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
if (t.isKeyFrame(row))
|
||||
@ -798,7 +795,7 @@ void TrackView::editBiasValue(float amount)
|
||||
newKey.value += amount; // modify value
|
||||
|
||||
// add sub-command
|
||||
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(track, row, newKey);
|
||||
SyncDocument::Command *cmd = document->getSetKeyFrameCommand(track, row, newKey);
|
||||
multiCmd->addCommand(cmd);
|
||||
}
|
||||
}
|
||||
@ -811,14 +808,14 @@ void TrackView::editBiasValue(float amount)
|
||||
}
|
||||
else
|
||||
{
|
||||
syncData->exec(multiCmd);
|
||||
document->exec(multiCmd);
|
||||
invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
|
||||
}
|
||||
}
|
||||
|
||||
LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
|
||||
{
|
||||
if (editString.empty() && getSyncData()->clientPaused)
|
||||
if (editString.empty() && document->clientPaused)
|
||||
{
|
||||
switch (keyCode)
|
||||
{
|
||||
@ -898,7 +895,7 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
|
||||
invalidatePos(editTrack, editRow);
|
||||
MessageBeep(0);
|
||||
}
|
||||
getSyncData()->sendPauseCommand( !getSyncData()->clientPaused );
|
||||
document->sendPauseCommand( !document->clientPaused );
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
@ -932,7 +929,7 @@ LRESULT TrackView::onChar(UINT keyCode, UINT flags)
|
||||
case '7':
|
||||
case '8':
|
||||
case '9':
|
||||
if (editTrack < int(syncData->getTrackCount()))
|
||||
if (editTrack < int(document->getTrackCount()))
|
||||
{
|
||||
editString.push_back(char(keyCode));
|
||||
invalidatePos(editTrack, editRow);
|
||||
@ -945,7 +942,7 @@ LRESULT TrackView::onChar(UINT keyCode, UINT flags)
|
||||
break;
|
||||
|
||||
case 's':
|
||||
syncData->sendSaveCommand();
|
||||
document->sendSaveCommand();
|
||||
break;
|
||||
}
|
||||
return FALSE;
|
||||
@ -995,13 +992,13 @@ LRESULT TrackView::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
break;
|
||||
|
||||
case WM_UNDO:
|
||||
if (!syncData->undo()) MessageBeep(0);
|
||||
if (!document->undo()) MessageBeep(0);
|
||||
// unfortunately, we don't know how much to invalidate... so we'll just invalidate it all.
|
||||
InvalidateRect(hwnd, NULL, FALSE);
|
||||
break;
|
||||
|
||||
case WM_REDO:
|
||||
if (!syncData->redo()) MessageBeep(0);
|
||||
if (!document->redo()) MessageBeep(0);
|
||||
// unfortunately, we don't know how much to invalidate... so we'll just invalidate it all.
|
||||
InvalidateRect(hwnd, NULL, FALSE);
|
||||
break;
|
||||
|
||||
@ -4,7 +4,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "synceditdata.h"
|
||||
#include "syncdocument.h"
|
||||
|
||||
#include <list>
|
||||
#include <string>
|
||||
@ -22,8 +22,8 @@ public:
|
||||
HWND create(HINSTANCE hInstance, HWND hwndParent);
|
||||
HWND getWin(){ return hwnd; }
|
||||
|
||||
void setSyncData(SyncEditData *syncData) { this->syncData = syncData; }
|
||||
SyncEditData *getSyncData() { return syncData; }
|
||||
void setDocument(SyncDocument *document) { this->document = document; }
|
||||
SyncDocument *getDocument() { return document; }
|
||||
|
||||
void setRows(int rows);
|
||||
int getRows() const { return rows; }
|
||||
@ -115,7 +115,7 @@ private:
|
||||
|
||||
int getTrackCount()
|
||||
{
|
||||
sync::Data *syncData = getSyncData();
|
||||
sync::Data *syncData = getDocument();
|
||||
if (NULL == syncData) return 0;
|
||||
return int(syncData->getTrackCount());
|
||||
};
|
||||
@ -136,7 +136,7 @@ private:
|
||||
int windowWidth, windowHeight;
|
||||
int windowRows, windowTracks;
|
||||
|
||||
SyncEditData *syncData;
|
||||
SyncDocument *document;
|
||||
|
||||
std::basic_string<TCHAR> editString;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user