copypasta!

This commit is contained in:
Erik Faye-Lund 2008-02-11 17:53:12 +00:00
parent 946f151bfc
commit 3a5a1a6c5a
4 changed files with 165 additions and 66 deletions

View File

@ -118,6 +118,8 @@ public:
commands.push_back(cmd); commands.push_back(cmd);
} }
size_t getSize() const { return commands.size(); }
virtual void exec(SyncEditData *data) virtual void exec(SyncEditData *data)
{ {
std::list<Command*>::iterator it; std::list<Command*>::iterator it;
@ -175,18 +177,18 @@ public:
} }
} }
void setKeyFrame(int track, int row, const SyncTrack::KeyFrame &key) Command *getSetKeyFrameCommand(int track, int row, const SyncTrack::KeyFrame &key)
{ {
SyncTrack &t = getTrack(track); SyncTrack &t = getTrack(track);
SyncEditData::Command *cmd; SyncEditData::Command *cmd;
if (t.isKeyFrame(row)) if (t.isKeyFrame(row)) cmd = new EditCommand(track, row, key);
{ else cmd = new InsertCommand(track, row, key);
cmd = new EditCommand(track, row, key); return cmd;
} }
else
void setKeyFrame(int track, int row, const SyncTrack::KeyFrame &key)
{ {
cmd = new InsertCommand(track, row, key); SyncEditData::Command *cmd = getSetKeyFrameCommand(track, row, key);
}
exec(cmd); exec(cmd);
} }

View File

@ -221,7 +221,7 @@ int _tmain(int argc, _TCHAR* argv[])
SyncTrack &camYTrack = syncData.getTrack(_T("cam.y")); SyncTrack &camYTrack = syncData.getTrack(_T("cam.y"));
SyncTrack &camZTrack = syncData.getTrack(_T("cam.z")); SyncTrack &camZTrack = syncData.getTrack(_T("cam.z"));
for (int i = 0; i < 2; ++i) for (int i = 0; i < 16; ++i)
{ {
TCHAR temp[256]; TCHAR temp[256];
_sntprintf_s(temp, 256, _T("gen %02d"), i); _sntprintf_s(temp, 256, _T("gen %02d"), i);

View File

@ -1,6 +1,7 @@
#include "stdafx.h" #include "stdafx.h"
#include "trackview.h" #include "trackview.h"
#include <vector>
static const TCHAR *trackViewWindowClassName = _T("TrackView"); static const TCHAR *trackViewWindowClassName = _T("TrackView");
@ -310,7 +311,14 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
} }
} }
void TrackView::copy() struct CopyEntry
{
int track, row;
SyncTrack::KeyFrame keyFrame;
};
void TrackView::editCopy()
{ {
int selectLeft = min(selectStartTrack, selectStopTrack); int selectLeft = min(selectStartTrack, selectStopTrack);
int selectRight = max(selectStartTrack, selectStopTrack); int selectRight = max(selectStartTrack, selectStopTrack);
@ -340,68 +348,131 @@ void TrackView::copy()
size_t cells = columns * rows; size_t cells = columns * rows;
std::string copyString; std::string copyString;
std::vector<struct CopyEntry> copyEntries;
for (int row = selectTop; row <= selectBottom; ++row) for (int row = selectTop; row <= selectBottom; ++row)
{ {
int localRow = row - selectTop;
for (int track = selectLeft; track <= selectRight; ++track) for (int track = selectLeft; track <= selectRight; ++track)
{ {
int localTrack = track - selectLeft;
const SyncTrack &t = syncData->getTrack(track); const SyncTrack &t = syncData->getTrack(track);
char temp[128]; char temp[128];
if (t.isKeyFrame(row)) sprintf(temp, "%.2f\t", t.getKeyFrame(row)->value); if (t.isKeyFrame(row))
{
const SyncTrack::KeyFrame *keyFrame = t.getKeyFrame(row);
assert(NULL != keyFrame);
CopyEntry ce;
ce.track = localTrack;
ce.row = localRow;
ce.keyFrame = *keyFrame;
copyEntries.push_back(ce);
sprintf(temp, "%.2f\t", keyFrame->value);
}
else sprintf(temp, "--- \t"); else sprintf(temp, "--- \t");
copyString += temp; copyString += temp;
printf("(%d %d) = %s", track - selectLeft, row - selectTop, temp); printf("(%d %d) = %s", localTrack, localRow, temp);
} }
puts(""); puts("");
copyString += "\n"; copyString += "\n";
} }
HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, sizeof(float) * cells); int buffer_width = selectRight - selectLeft + 1;
int buffer_height = selectBottom - selectTop + 1;
size_t buffer_size = copyEntries.size();
HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, sizeof(int) * 3 + sizeof(CopyEntry) * copyEntries.size());
char *clipbuf = (char *)GlobalLock(hmem);
printf("%d %d, size: %d\n", buffer_width, buffer_height, buffer_size);
// copy data
memcpy(clipbuf + 0, &buffer_width, sizeof(int));
memcpy(clipbuf + sizeof(int), &buffer_height, sizeof(int));
memcpy(clipbuf + 2 * sizeof(int), &buffer_size, sizeof(size_t));
if (copyEntries.size() > 0 ) memcpy(clipbuf + 2 * sizeof(int) + sizeof(size_t), &copyEntries[0], sizeof(CopyEntry) * copyEntries.size());
GlobalUnlock(hmem);
clipbuf = NULL;
HGLOBAL hmem_text = GlobalAlloc(GMEM_MOVEABLE, strlen(copyString.c_str()) + 1); HGLOBAL hmem_text = GlobalAlloc(GMEM_MOVEABLE, strlen(copyString.c_str()) + 1);
char *clipbuf = (char *)GlobalLock(hmem_text); clipbuf = (char *)GlobalLock(hmem_text);
memcpy(clipbuf, copyString.c_str(), strlen(copyString.c_str()) + 1); memcpy(clipbuf, copyString.c_str(), strlen(copyString.c_str()) + 1);
GlobalUnlock(hmem_text); GlobalUnlock(hmem_text);
clipbuf = NULL;
// update clipboard // update clipboard
EmptyClipboard(); EmptyClipboard();
SetClipboardData(clipboardFormat, hmem); SetClipboardData(clipboardFormat, hmem);
SetClipboardData(CF_TEXT, hmem_text); /* SetClipboardData(CF_TEXT, hmem_text); */
CloseClipboard(); CloseClipboard();
// should this memory be free'd or not? freeing seems to cause some hick-ups some times...
// GlobalFree(hmem);
// GlobalFree(hmem_text);
} }
void TrackView::cut() void TrackView::editCut()
{ {
/* int selectLeft = min(selectStartTrack, selectStopTrack); editCopy();
int selectRight = max(selectStartTrack, selectStopTrack); editDelete();
int selectTop = min(selectStartRow, selectStopRow); }
int selectBottom = max(selectStartRow, selectStopRow); */
copy(); void TrackView::editPaste()
#if 0
for (int track = selectLeft; track <= selectRight; ++track)
{ {
SyncTrack &t = syncDataEdit.getSyncData()->getTrack(track); #if 1
for (int row = selectTop; row <= selectBottom; ++row) if (FAILED(OpenClipboard(getWin())))
{ {
if (t.isKeyFrame(row)) t.deleteKeyFrame(row); MessageBox(NULL, _T("Failed to open clipboard"), NULL, MB_OK);
return;
} }
if (IsClipboardFormatAvailable(clipboardFormat))
{
HGLOBAL hmem = GetClipboardData(clipboardFormat);
char *clipbuf = (char *)GlobalLock(hmem);
// copy data
int buffer_width, buffer_height, buffer_size;
memcpy(&buffer_width, clipbuf + 0, sizeof(int));
memcpy(&buffer_height, clipbuf + sizeof(int), sizeof(int));
memcpy(&buffer_size, clipbuf + 2 * sizeof(int), sizeof(size_t));
if (buffer_size > 0)
{
printf("%d %d, size: %d\n", buffer_width, buffer_height, buffer_size);
char *src = clipbuf + 2 * sizeof(int) + sizeof(size_t);
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
for (int i = 0; i < buffer_size; ++i)
{
struct CopyEntry ce;
memcpy(&ce, src, sizeof(CopyEntry));
printf("%d,%d = %f\n", ce.track, ce.row, ce.keyFrame.value);
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack + ce.track, editRow + ce.row, ce.keyFrame);
multiCmd->addCommand(cmd);
src += sizeof(CopyEntry);
} }
invalidateRange(selectLeft, selectRight, selectTop, selectBottom); syncData->exec(multiCmd);
}
GlobalUnlock(hmem);
clipbuf = NULL;
}
else if (!IsClipboardFormatAvailable(clipboardFormat))
{
HGLOBAL hmem = GetClipboardData(clipboardFormat);
char *clipbuf = (char *)GlobalLock(hmem);
/* DO STUFFZ! */
GlobalUnlock(hmem);
clipbuf = NULL;
}
else MessageBeep(0);
CloseClipboard();
#endif #endif
} }
void TrackView::paste()
{
/* int selectLeft = min(selectStartTrack, selectStopTrack);
int selectRight = max(selectStartTrack, selectStopTrack);
int selectTop = min(selectStartRow, selectStopRow);
int selectBottom = max(selectStartRow, selectStopRow); */
}
void TrackView::setupScrollBars() void TrackView::setupScrollBars()
{ {
SCROLLINFO si = { sizeof(si) }; SCROLLINFO si = { sizeof(si) };
@ -609,7 +680,7 @@ LRESULT TrackView::onHScroll(UINT sbCode, int /*newPos*/)
return FALSE; return FALSE;
} }
void TrackView::onReturn() void TrackView::editSetValue()
{ {
if (editString.size() > 0) if (editString.size() > 0)
{ {
@ -621,15 +692,38 @@ void TrackView::onReturn()
else MessageBeep(0); else MessageBeep(0);
} }
void TrackView::onDelete() void TrackView::editDelete()
{ {
SyncTrack &track = syncData->getTrack(editTrack); int selectLeft = min(selectStartTrack, selectStopTrack);
if (track.isKeyFrame(editRow)) int selectRight = max(selectStartTrack, selectStopTrack);
int selectTop = min(selectStartRow, selectStopRow);
int selectBottom = max(selectStartRow, selectStopRow);
printf("deleting\n");
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
for (int track = selectLeft; track <= selectRight; ++track)
{ {
syncData->deleteKeyFrame(editTrack, editRow); SyncTrack &t = syncData->getTrack(track);
invalidatePos(editTrack, editRow); for (int row = selectTop; row <= selectBottom; ++row)
{
if (t.isKeyFrame(row))
{
SyncEditData::Command *cmd = new SyncEditData::DeleteCommand(track, row);
multiCmd->addCommand(cmd);
}
}
}
if (0 == multiCmd->getSize())
{
MessageBeep(0);
delete multiCmd;
}
else
{
syncData->exec(multiCmd);
invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
} }
else MessageBeep(0);
} }
void TrackView::bias(float amount) void TrackView::bias(float amount)
@ -681,8 +775,8 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
switch (keyCode) switch (keyCode)
{ {
case VK_RETURN: onReturn(); break; case VK_RETURN: editSetValue(); break;
case VK_DELETE: onDelete(); break; case VK_DELETE: editDelete(); break;
case VK_BACK: case VK_BACK:
if (!editString.empty()) if (!editString.empty())
@ -774,20 +868,23 @@ LRESULT TrackView::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_KEYDOWN: return onKeyDown((UINT)wParam, (UINT)lParam); case WM_KEYDOWN: return onKeyDown((UINT)wParam, (UINT)lParam);
case WM_CHAR: return onChar((UINT)wParam, (UINT)lParam); case WM_CHAR: return onChar((UINT)wParam, (UINT)lParam);
case WM_COPY: copy(); break; case WM_COPY: editCopy(); break;
case WM_CUT: cut(); break; case WM_CUT: editCut(); break;
case WM_PASTE: paste(); break; case WM_PASTE:
editPaste();
InvalidateRect(hwnd, NULL, FALSE);
break;
case WM_UNDO: case WM_UNDO:
if (!syncData->undo()) MessageBeep(0); if (!syncData->undo()) MessageBeep(0);
// unfortunately, we don't know how much to invalidate... so we'll just invalidate it all. // unfortunately, we don't know how much to invalidate... so we'll just invalidate it all.
InvalidateRect(hwnd, NULL, TRUE); InvalidateRect(hwnd, NULL, FALSE);
break; break;
case WM_REDO: case WM_REDO:
if (!syncData->redo()) MessageBeep(0); if (!syncData->redo()) MessageBeep(0);
// unfortunately, we don't know how much to invalidate... so we'll just invalidate it all. // unfortunately, we don't know how much to invalidate... so we'll just invalidate it all.
InvalidateRect(hwnd, NULL, TRUE); InvalidateRect(hwnd, NULL, FALSE);
break; break;
default: default:

View File

@ -38,13 +38,13 @@ 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 editSetValue();
void onDelete();
void bias(float amount); void bias(float amount);
void copy(); void editDelete();
void cut(); void editCopy();
void paste(); void editCut();
void editPaste();
// the window procedure // the window procedure
@ -62,7 +62,7 @@ private:
rect.right = getScreenX(max(startTrack, stopTrack) + 1); rect.right = getScreenX(max(startTrack, stopTrack) + 1);
rect.top = getScreenY(min(startRow, stopRow)); rect.top = getScreenY(min(startRow, stopRow));
rect.bottom = getScreenY(max(startRow, stopRow) + 1); rect.bottom = getScreenY(max(startRow, stopRow) + 1);
InvalidateRect(hwnd, &rect, TRUE); InvalidateRect(hwnd, &rect, FALSE);
} }
void invalidatePos(int track, int row) void invalidatePos(int track, int row)
@ -72,7 +72,7 @@ private:
rect.right = getScreenX(track + 1); rect.right = getScreenX(track + 1);
rect.top = getScreenY(row); rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1); rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, TRUE); InvalidateRect(hwnd, &rect, FALSE);
} }
void invalidateRow(int row) void invalidateRow(int row)
@ -86,7 +86,7 @@ private:
rect.top = getScreenY(row); rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1); rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, TRUE); InvalidateRect(hwnd, &rect, FALSE);
} }
void invalidateTrack(int track) void invalidateTrack(int track)
@ -100,7 +100,7 @@ private:
rect.top = clientRect.top; rect.top = clientRect.top;
rect.bottom = clientRect.bottom; rect.bottom = clientRect.bottom;
InvalidateRect(hwnd, &rect, TRUE); InvalidateRect(hwnd, &rect, FALSE);
} }
void setEditRow(int newEditRow); void setEditRow(int newEditRow);