more. stuff.
This commit is contained in:
parent
2a106f7949
commit
d54d8587c9
@ -17,38 +17,87 @@ public:
|
|||||||
virtual void undo(SyncEditData *data) = 0;
|
virtual void undo(SyncEditData *data) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class InsertCommand : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
InsertCommand(size_t track, size_t row, const SyncTrack::KeyFrame &key) : track(track), row(row), key(key) {}
|
||||||
|
~InsertCommand() {}
|
||||||
|
|
||||||
|
virtual void exec(SyncEditData *data)
|
||||||
|
{
|
||||||
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
assert(!track.isKeyFrame(row));
|
||||||
|
track.setKeyFrame(row, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void undo(SyncEditData *data)
|
||||||
|
{
|
||||||
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
assert(track.isKeyFrame(row));
|
||||||
|
track.deleteKeyFrame(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t track, row;
|
||||||
|
SyncTrack::KeyFrame key;
|
||||||
|
};
|
||||||
|
|
||||||
|
class DeleteCommand : public Command
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
DeleteCommand(size_t track, size_t row) : track(track), row(row) {}
|
||||||
|
~DeleteCommand() {}
|
||||||
|
|
||||||
|
virtual void exec(SyncEditData *data)
|
||||||
|
{
|
||||||
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
assert(track.isKeyFrame(row));
|
||||||
|
oldKey = *track.getKeyFrame(row);
|
||||||
|
track.deleteKeyFrame(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
virtual void undo(SyncEditData *data)
|
||||||
|
{
|
||||||
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
assert(!track.isKeyFrame(row));
|
||||||
|
track.setKeyFrame(row, oldKey);
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
size_t track, row;
|
||||||
|
SyncTrack::KeyFrame oldKey;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
class EditCommand : public Command
|
class EditCommand : public Command
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
EditCommand(size_t track, size_t row, bool existing, float value) : track(track), row(row), newValExisting(existing), newVal(value) {}
|
EditCommand(size_t track, size_t row, const SyncTrack::KeyFrame &key) : track(track), row(row), key(key) {}
|
||||||
~EditCommand() {}
|
~EditCommand() {}
|
||||||
|
|
||||||
virtual void exec(SyncEditData *data)
|
virtual void exec(SyncEditData *data)
|
||||||
{
|
{
|
||||||
SyncTrack &track = data->getTrack(this->track);
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
|
||||||
// store old state
|
// store old key
|
||||||
oldValExisting = track.isKeyFrame(row);
|
assert(track.isKeyFrame(row));
|
||||||
if (oldValExisting) oldVal = track.getKeyFrame(row)->value;
|
oldKey = *track.getKeyFrame(row);
|
||||||
|
|
||||||
// update
|
// update
|
||||||
if (!newValExisting) track.deleteKeyFrame(row);
|
track.setKeyFrame(row, key);
|
||||||
else track.setKeyFrame(row, newVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void undo(SyncEditData *data)
|
virtual void undo(SyncEditData *data)
|
||||||
{
|
{
|
||||||
SyncTrack &track = data->getTrack(this->track);
|
SyncTrack &track = data->getTrack(this->track);
|
||||||
|
|
||||||
// un-update
|
assert(track.isKeyFrame(row));
|
||||||
if (!oldValExisting) track.deleteKeyFrame(row);
|
track.setKeyFrame(row, oldKey);
|
||||||
else track.setKeyFrame(row, oldVal);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
size_t track, row;
|
size_t track, row;
|
||||||
float newVal, oldVal;
|
SyncTrack::KeyFrame oldKey, key;
|
||||||
bool newValExisting, oldValExisting;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MultiCommand : public Command
|
class MultiCommand : public Command
|
||||||
@ -126,6 +175,28 @@ public:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setKey(int track, int row, float val)
|
||||||
|
{
|
||||||
|
SyncTrack &t = getTrack(track);
|
||||||
|
SyncEditData::Command *cmd;
|
||||||
|
if (t.isKeyFrame(row))
|
||||||
|
{
|
||||||
|
cmd = new EditCommand(track, row, val);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
cmd = new InsertCommand(track, row, val);
|
||||||
|
}
|
||||||
|
exec(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
|
void deleteKey(int track, int row)
|
||||||
|
{
|
||||||
|
assert(getTrack(track).isKeyFrame(row));
|
||||||
|
Command *cmd = new DeleteCommand(track, row);
|
||||||
|
exec(cmd);
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
std::stack<Command*> undoStack;
|
std::stack<Command*> undoStack;
|
||||||
|
|||||||
@ -27,8 +27,8 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
|
|||||||
assert(NULL != rows);
|
assert(NULL != rows);
|
||||||
|
|
||||||
/* create row-string */
|
/* create row-string */
|
||||||
char temp[256];
|
TCHAR temp[256];
|
||||||
_snprintf(temp, 256, "%d", *rows);
|
_sntprintf_s(temp, 256, _T("%d"), *rows);
|
||||||
|
|
||||||
/* set initial row count */
|
/* set initial row count */
|
||||||
SetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp);
|
SetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp);
|
||||||
@ -39,9 +39,9 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
|
|||||||
if (LOWORD(wParam) == IDOK)
|
if (LOWORD(wParam) == IDOK)
|
||||||
{
|
{
|
||||||
/* get value */
|
/* get value */
|
||||||
char temp[256];
|
TCHAR temp[256];
|
||||||
GetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp, 256);
|
GetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp, 256);
|
||||||
int result = atoi(temp);
|
int result = _tstoi(temp);
|
||||||
|
|
||||||
/* update editor */
|
/* update editor */
|
||||||
SendMessage(GetParent(hDlg), WM_SETROWS, 0, result);
|
SendMessage(GetParent(hDlg), WM_SETROWS, 0, result);
|
||||||
@ -131,7 +131,7 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
|
|||||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||||
int rows = trackView->getRows();
|
int rows = trackView->getRows();
|
||||||
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
|
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
|
||||||
if (FAILED(result)) MessageBox(NULL, "unable to create dialog box", NULL, MB_OK);
|
if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK);
|
||||||
if (IDOK == result)
|
if (IDOK == result)
|
||||||
{
|
{
|
||||||
printf("result: %d\n", result);
|
printf("result: %d\n", result);
|
||||||
@ -223,8 +223,8 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
|
|
||||||
for (int i = 0; i < 2; ++i)
|
for (int i = 0; i < 2; ++i)
|
||||||
{
|
{
|
||||||
char temp[256];
|
TCHAR temp[256];
|
||||||
_snprintf(temp, 256, "gen %02d", i);
|
_sntprintf_s(temp, 256, _T("gen %02d"), i);
|
||||||
SyncTrack &temp2 = syncData.getTrack(temp);
|
SyncTrack &temp2 = syncData.getTrack(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -38,13 +38,14 @@ TrackView::TrackView()
|
|||||||
|
|
||||||
// selectBaseBrush = CreateSolidBrush(RGB(0xff, 0xdd, 0xff));
|
// selectBaseBrush = CreateSolidBrush(RGB(0xff, 0xdd, 0xff));
|
||||||
// selectDarkBrush = CreateSolidBrush(RGB(0xdd, 0xbb, 0xdd));
|
// selectDarkBrush = CreateSolidBrush(RGB(0xdd, 0xbb, 0xdd));
|
||||||
|
|
||||||
selectBaseBrush = GetSysColorBrush(COLOR_HIGHLIGHT);
|
selectBaseBrush = GetSysColorBrush(COLOR_HIGHLIGHT);
|
||||||
selectDarkBrush = CreateSolidBrush(darken(GetSysColor(COLOR_HIGHLIGHT), 0.9f));
|
selectDarkBrush = CreateSolidBrush(darken(GetSysColor(COLOR_HIGHLIGHT), 0.9f));
|
||||||
|
|
||||||
editBrush = CreateSolidBrush(RGB(255, 255, 0));
|
editBrush = CreateSolidBrush(RGB(255, 255, 0)); // yellow
|
||||||
|
|
||||||
clipboardFormat = RegisterClipboardFormat("syncdata");
|
clipboardFormat = RegisterClipboardFormat(_T("syncdata"));
|
||||||
if (0 == clipboardFormat) printf("geh");
|
assert(0 != clipboardFormat);
|
||||||
}
|
}
|
||||||
|
|
||||||
TrackView::~TrackView()
|
TrackView::~TrackView()
|
||||||
@ -97,13 +98,14 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
fillRect = topLeftMargin;
|
fillRect = topLeftMargin;
|
||||||
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_BOTTOM);
|
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_BOTTOM);
|
||||||
FillRect(hdc, &fillRect, GetSysColorBrush(COLOR_3DFACE));
|
FillRect(hdc, &fillRect, GetSysColorBrush(COLOR_3DFACE));
|
||||||
ExcludeClipRect(hdc, topLeftMargin.left, topLeftMargin.top, topLeftMargin.right, topLeftMargin.bottom);
|
|
||||||
|
|
||||||
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
||||||
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
||||||
|
|
||||||
SyncData *syncData = getSyncData();
|
SyncData *syncData = getSyncData();
|
||||||
if (NULL == syncData) return;
|
if (NULL == syncData) return;
|
||||||
|
|
||||||
|
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||||
|
|
||||||
SyncData::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
SyncData::TrackContainer::iterator trackIter = syncData->tracks.begin();
|
||||||
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
for (int track = 0; track <= lastTrack; ++track, ++trackIter)
|
||||||
@ -134,7 +136,6 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
fillRect.left, 0,
|
fillRect.left, 0,
|
||||||
trackName.data(), int(trackName.length())
|
trackName.data(), int(trackName.length())
|
||||||
);
|
);
|
||||||
ExcludeClipRect(hdc, topMargin.left, topMargin.top, topMargin.right, topMargin.bottom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
RECT topRightMargin;
|
RECT topRightMargin;
|
||||||
@ -145,7 +146,9 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
fillRect = topRightMargin;
|
fillRect = topRightMargin;
|
||||||
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_BOTTOM);
|
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_BOTTOM);
|
||||||
FillRect(hdc, &fillRect, GetSysColorBrush(COLOR_3DFACE));
|
FillRect(hdc, &fillRect, GetSysColorBrush(COLOR_3DFACE));
|
||||||
ExcludeClipRect(hdc, topRightMargin.left, topRightMargin.top, topRightMargin.right, topRightMargin.bottom);
|
|
||||||
|
// make sure that the top margin isn't overdrawn by the track-data
|
||||||
|
ExcludeClipRect(hdc, 0, 0, rcTracks.right, topMarginHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
||||||
@ -162,9 +165,6 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
lastRow = min(max(lastRow, 0), rows - 1);
|
lastRow = min(max(lastRow, 0), rows - 1);
|
||||||
|
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
|
||||||
// SelectObject(hdc, editBrush);
|
|
||||||
|
|
||||||
paintTopMargin(hdc, rcTracks);
|
paintTopMargin(hdc, rcTracks);
|
||||||
|
|
||||||
for (int row = firstRow; row <= lastRow; ++row)
|
for (int row = firstRow; row <= lastRow; ++row)
|
||||||
@ -183,19 +183,18 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
FillRect(hdc, &leftMargin, fillBrush);
|
FillRect(hdc, &leftMargin, fillBrush);
|
||||||
|
|
||||||
DrawEdge(hdc, &leftMargin, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_RIGHT | BF_BOTTOM | BF_TOP);
|
DrawEdge(hdc, &leftMargin, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_RIGHT | BF_BOTTOM | BF_TOP);
|
||||||
// Rectangle( hdc, leftMargin.left, leftMargin.top, leftMargin.right, leftMargin.bottom + 1);
|
if ((row % 8) == 0) SetTextColor(hdc, RGB(0, 0, 0));
|
||||||
if ((row % 16) == 0) SetTextColor(hdc, RGB(0, 0, 0));
|
else if ((row % 4) == 0) SetTextColor(hdc, RGB(64, 64, 64));
|
||||||
else if ((row % 8) == 0) SetTextColor(hdc, RGB(32, 32, 32));
|
else SetTextColor(hdc, RGB(128, 128, 128));
|
||||||
else if ((row % 4) == 0) SetTextColor(hdc, RGB(64, 64, 64));
|
|
||||||
else SetTextColor(hdc, RGB(128, 128, 128));
|
/* if ((row % 4) == 0) SetTextColor(hdc, GetSysColor(COLOR_BTNTEXT));
|
||||||
|
else SetTextColor(hdc, GetSysColor(COLOR_GRAYTEXT)); */
|
||||||
|
|
||||||
_sntprintf_s(temp, 256, _T("%0*Xh"), 5, row);
|
_sntprintf_s(temp, 256, _T("%0*Xh"), 5, row);
|
||||||
TextOut(hdc,
|
TextOut(hdc,
|
||||||
leftMargin.left, leftMargin.top,
|
leftMargin.left, leftMargin.top,
|
||||||
temp, int(_tcslen(temp))
|
temp, int(_tcslen(temp))
|
||||||
);
|
);
|
||||||
|
|
||||||
ExcludeClipRect(hdc, leftMargin.left, leftMargin.top, leftMargin.right, leftMargin.bottom);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
SetTextColor(hdc, GetSysColor(COLOR_WINDOWTEXT));
|
||||||
@ -330,7 +329,7 @@ void TrackView::copy()
|
|||||||
|
|
||||||
if (FAILED(OpenClipboard(getWin())))
|
if (FAILED(OpenClipboard(getWin())))
|
||||||
{
|
{
|
||||||
MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
|
MessageBox(NULL, _T("Failed to open clipboard"), NULL, MB_OK);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -607,6 +606,29 @@ LRESULT TrackView::onHScroll(UINT sbCode, int newPos)
|
|||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackView::onReturn()
|
||||||
|
{
|
||||||
|
if (editString.size() > 0)
|
||||||
|
{
|
||||||
|
syncData->setKey(editTrack, editRow, float(_tstof(editString.c_str())));
|
||||||
|
|
||||||
|
editString.clear();
|
||||||
|
invalidatePos(editTrack, editRow);
|
||||||
|
}
|
||||||
|
else MessageBeep(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackView::onDelete()
|
||||||
|
{
|
||||||
|
SyncTrack &track = syncData->getTrack(editTrack);
|
||||||
|
if (track.isKeyFrame(editRow))
|
||||||
|
{
|
||||||
|
syncData->deleteKey(editTrack, editRow);
|
||||||
|
invalidatePos(editTrack, editRow);
|
||||||
|
}
|
||||||
|
else MessageBeep(0);
|
||||||
|
}
|
||||||
|
|
||||||
LRESULT TrackView::onKeyDown(UINT keyCode, UINT flags)
|
LRESULT TrackView::onKeyDown(UINT keyCode, UINT flags)
|
||||||
{
|
{
|
||||||
bool refreshCaret = false;
|
bool refreshCaret = false;
|
||||||
@ -645,31 +667,8 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT flags)
|
|||||||
|
|
||||||
switch (keyCode)
|
switch (keyCode)
|
||||||
{
|
{
|
||||||
case VK_RETURN:
|
case VK_RETURN: onReturn(); break;
|
||||||
if (editString.size() > 0)
|
case VK_DELETE: onDelete(); break;
|
||||||
{
|
|
||||||
SyncEditData::EditCommand *cmd = new SyncEditData::EditCommand(
|
|
||||||
editTrack, editRow,
|
|
||||||
true, float(_tstof(editString.c_str()))
|
|
||||||
);
|
|
||||||
syncData->exec(cmd);
|
|
||||||
|
|
||||||
editString.clear();
|
|
||||||
invalidatePos(editTrack, editRow);
|
|
||||||
}
|
|
||||||
else MessageBeep(0);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_DELETE:
|
|
||||||
{
|
|
||||||
SyncEditData::EditCommand *cmd = new SyncEditData::EditCommand(
|
|
||||||
editTrack, editRow,
|
|
||||||
false, 0.0f
|
|
||||||
);
|
|
||||||
syncData->exec(cmd);
|
|
||||||
invalidatePos(editTrack, editRow);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case VK_BACK:
|
case VK_BACK:
|
||||||
if (editString.size() > 0)
|
if (editString.size() > 0)
|
||||||
|
|||||||
@ -38,6 +38,9 @@ private:
|
|||||||
LRESULT onKeyDown(UINT keyCode, UINT flags);
|
LRESULT onKeyDown(UINT keyCode, UINT flags);
|
||||||
LRESULT onChar(UINT keyCode, UINT flags);
|
LRESULT onChar(UINT keyCode, UINT flags);
|
||||||
|
|
||||||
|
void onReturn();
|
||||||
|
void onDelete();
|
||||||
|
|
||||||
void copy();
|
void copy();
|
||||||
void cut();
|
void cut();
|
||||||
void paste();
|
void paste();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user