more key-adjust modifiers! and negative values!

This commit is contained in:
Erik Faye-Lund 2008-02-11 21:59:34 +00:00
parent 3a5a1a6c5a
commit 8566ec1002
6 changed files with 188 additions and 51 deletions

View File

@ -5,20 +5,23 @@
#define IDR_ACCELERATOR 101
#define IDR_MENU 102
#define IDD_SETROWS 103
#define IDD_BIASSELECTION 104
#define IDC_EDIT 1002
#define IDC_SETROWS_EDIT 1002
#define IDC_BIASSELECTION_EDIT 1003
#define ID_FILE 40001
#define ID_FILE_EXIT 40002
#define ID_EDIT 40003
#define ID_EDIT_SETROWS 40007
#define ID_EDIT_BIAS 40008
// Next default values for new objects
//
#ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 104
#define _APS_NEXT_COMMAND_VALUE 40008
#define _APS_NEXT_CONTROL_VALUE 1003
#define _APS_NEXT_COMMAND_VALUE 40011
#define _APS_NEXT_CONTROL_VALUE 1004
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -186,18 +186,6 @@ public:
return cmd;
}
void setKeyFrame(int track, int row, const SyncTrack::KeyFrame &key)
{
SyncEditData::Command *cmd = getSetKeyFrameCommand(track, row, key);
exec(cmd);
}
void deleteKeyFrame(int track, int row)
{
assert(getTrack(track).isKeyFrame(row));
Command *cmd = new DeleteCommand(track, row);
exec(cmd);
}
private:

View File

@ -14,6 +14,7 @@ HWND trackViewWin;
HWND statusBarWin;
#define WM_SETROWS (WM_USER+1)
#define WM_BIASSELECTION (WM_USER+2)
#include "network.h"
@ -21,6 +22,10 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
{
switch (message)
{
/* case WM_CHAR:
printf("char: %d %d\n", wParam, lParam);
break; */
case WM_INITDIALOG:
{
int *rows = (int*)lParam;
@ -31,7 +36,8 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
_sntprintf_s(temp, 256, _T("%d"), *rows);
/* set initial row count */
SetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp);
SetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp);
return TRUE;
}
break;
@ -40,7 +46,7 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
{
/* get value */
TCHAR temp[256];
GetWindowText(GetDlgItem(hDlg, IDC_SETROWS_EDIT), temp, 256);
GetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp, 256);
int result = _tstoi(temp);
/* update editor */
@ -53,6 +59,54 @@ static LRESULT CALLBACK setRowsDialogProc(HWND hDlg, UINT message, WPARAM wParam
else if(LOWORD(wParam)== IDCANCEL)
{
EndDialog( hDlg, LOWORD(wParam));
return TRUE;
}
break;
case WM_CLOSE:
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
return FALSE;
}
static LRESULT CALLBACK biasSelectionDialogProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
{
switch (message)
{
case WM_INITDIALOG:
{
int *intialBias = (int*)lParam;
assert(NULL != intialBias);
/* create bias-string */
TCHAR temp[256];
_sntprintf_s(temp, 256, _T("%d"), *intialBias);
/* set initial bias */
SetDlgItemText(hDlg, IDC_SETROWS_EDIT, temp);
}
break;
case WM_COMMAND:
if (LOWORD(wParam) == IDOK)
{
/* get value */
TCHAR temp[256];
GetDlgItemText(hDlg, IDC_BIASSELECTION_EDIT, temp, 256);
int bias = _tstoi(temp);
/* update editor */
SendMessage(GetParent(hDlg), WM_BIASSELECTION, 0, LPARAM(bias));
/* end dialog */
EndDialog(hDlg, LOWORD(wParam));
return TRUE;
}
else if(LOWORD(wParam)== IDCANCEL)
{
EndDialog( hDlg, LOWORD(wParam));
}
break;
@ -113,12 +167,21 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
case WM_SETROWS:
printf("rows: %d\n", int(lParam));
trackView->setRows(int(lParam));
break;
break;
case WM_BIASSELECTION:
trackView->editBiasValue(float(lParam));
break;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case ID_FILE_SAVE: /* meh.*/ break;
case ID_FILE_SAVE:
case ID_FILE_SAVE_AS:
case ID_FILE_OPEN:
MessageBox(trackViewWin, "Not implemented", NULL, MB_OK | MB_ICONERROR);
break;
case ID_FILE_EXIT: PostQuitMessage(0); break;
case ID_EDIT_UNDO: SendMessage(trackViewWin, WM_UNDO, 0, 0); break;
case ID_EDIT_REDO: SendMessage(trackViewWin, WM_REDO, 0, 0); break;
@ -132,15 +195,17 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
int rows = trackView->getRows();
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_SETROWS), hwnd, (DLGPROC)setRowsDialogProc, (LPARAM)&rows);
if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK);
if (IDOK == result)
{
printf("result: %d\n", result);
}
}
break;
default:
printf("cmd %d %d\n", wParam, lParam);
case ID_EDIT_BIAS:
{
HINSTANCE hInstance = GetModuleHandle(NULL);
int initialBias = 0;
INT_PTR result = DialogBoxParam(hInstance, MAKEINTRESOURCE(IDD_BIASSELECTION), hwnd, (DLGPROC)biasSelectionDialogProc, (LPARAM)&initialBias);
if (FAILED(result)) MessageBox(NULL, _T("unable to create dialog box"), NULL, MB_OK);
}
break;
}
break;

View File

@ -57,8 +57,9 @@ BEGIN
"C", ID_EDIT_COPY, VIRTKEY, CONTROL, NOINVERT
"X", ID_EDIT_CUT, VIRTKEY, CONTROL, NOINVERT
"V", ID_EDIT_PASTE, VIRTKEY, CONTROL, NOINVERT
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
"Z", ID_EDIT_REDO, VIRTKEY, SHIFT, CONTROL, NOINVERT
"Z", ID_EDIT_UNDO, VIRTKEY, CONTROL, NOINVERT
"B", ID_EDIT_BIAS, VIRTKEY, CONTROL, NOINVERT
END
@ -86,6 +87,8 @@ BEGIN
MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
MENUITEM SEPARATOR
MENUITEM "&Bias Selection\tCtrl+B", ID_EDIT_BIAS
MENUITEM SEPARATOR
MENUITEM "Set Rows", ID_EDIT_SETROWS
END
END
@ -105,6 +108,15 @@ BEGIN
DEFPUSHBUTTON "OK",IDOK,72,6,50,14
END
IDD_BIASSELECTION DIALOGEX 0, 0, 129, 27
STYLE DS_SETFONT | DS_FIXEDSYS | DS_CENTER | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Bias Selection"
FONT 8, "MS Shell Dlg", 400, 0, 0x1
BEGIN
EDITTEXT IDC_BIASSELECTION_EDIT,7,6,59,12,ES_AUTOHSCROLL | ES_NUMBER
DEFPUSHBUTTON "OK",IDOK,72,6,50,14
END
/////////////////////////////////////////////////////////////////////////////
//
@ -121,6 +133,14 @@ BEGIN
TOPMARGIN, 7
BOTTOMMARGIN, 20
END
IDD_BIASSELECTION, DIALOG
BEGIN
LEFTMARGIN, 7
RIGHTMARGIN, 122
TOPMARGIN, 7
BOTTOMMARGIN, 20
END
END
#endif // APSTUDIO_INVOKED

View File

@ -265,11 +265,11 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
/* format the text */
if (drawEditString) _sntprintf_s(temp, 256, editString.c_str());
else if (!key) _sntprintf_s(temp, 256, _T("---"));
else if (!key) _sntprintf_s(temp, 256, _T(" ---"));
else
{
float val = track.getKeyFrame(row)->value;
_sntprintf_s(temp, 256, _T("%.2f"), val);
_sntprintf_s(temp, 256, _T("% .2f"), val);
}
COLORREF oldCol;
@ -324,7 +324,6 @@ void TrackView::editCopy()
int selectRight = max(selectStartTrack, selectStopTrack);
int selectTop = min(selectStartRow, selectStopRow);
int selectBottom = max(selectStartRow, selectStopRow);
printf("copying:\n");
#if 0
struct CopyEntry
@ -367,15 +366,13 @@ void TrackView::editCopy()
ce.track = localTrack;
ce.row = localRow;
ce.keyFrame = *keyFrame;
copyEntries.push_back(ce);
sprintf(temp, "%.2f\t", keyFrame->value);
}
else sprintf(temp, "--- \t");
copyString += temp;
printf("(%d %d) = %s", localTrack, localRow, temp);
}
puts("");
copyString += "\n";
}
@ -386,7 +383,6 @@ void TrackView::editCopy()
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));
@ -437,7 +433,6 @@ void TrackView::editPaste()
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();
@ -445,7 +440,6 @@ void TrackView::editPaste()
{
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);
@ -680,11 +674,18 @@ LRESULT TrackView::onHScroll(UINT sbCode, int /*newPos*/)
return FALSE;
}
void TrackView::editSetValue()
void TrackView::editEnterValue()
{
if (editString.size() > 0)
{
syncData->setKeyFrame(editTrack, editRow, float(_tstof(editString.c_str())));
SyncTrack &t = syncData->getTrack(editTrack);
SyncTrack::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);
editString.clear();
invalidatePos(editTrack, editRow);
@ -698,7 +699,6 @@ void TrackView::editDelete()
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)
@ -726,17 +726,54 @@ void TrackView::editDelete()
}
}
void TrackView::bias(float amount)
void TrackView::editBiasValue(float amount)
{
SyncTrack &track = syncData->getTrack(editTrack);
int selectLeft = min(selectStartTrack, selectStopTrack);
int selectRight = max(selectStartTrack, selectStopTrack);
int selectTop = min(selectStartRow, selectStopRow);
int selectBottom = max(selectStartRow, selectStopRow);
SyncEditData::MultiCommand *multiCmd = new SyncEditData::MultiCommand();
for (int track = selectLeft; track <= selectRight; ++track)
{
SyncTrack &t = syncData->getTrack(track);
for (int row = selectTop; row <= selectBottom; ++row)
{
if (t.isKeyFrame(row))
{
SyncTrack::KeyFrame newKey = *t.getKeyFrame(row); // copy old key
newKey.value += amount; // modify value
// add sub-command
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(track, row, newKey);
multiCmd->addCommand(cmd);
}
}
}
if (0 == multiCmd->getSize())
{
MessageBeep(0);
delete multiCmd;
}
else
{
syncData->exec(multiCmd);
invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
}
/* SyncTrack &track = syncData->getTrack(editTrack);
if (track.isKeyFrame(editRow))
{
SyncTrack::KeyFrame newKey = *track.getKeyFrame(editRow);
newKey.value += amount;
syncData->setKeyFrame(editTrack, editRow, newKey);
SyncEditData::Command *cmd = syncData->getSetKeyFrameCommand(editTrack, editRow, newKey);
syncData->exec(cmd);
invalidatePos(editTrack, editRow);
}
else MessageBeep(0);
else MessageBeep(0); */
}
LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
@ -746,12 +783,22 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
switch (keyCode)
{
case VK_UP:
if (GetKeyState(VK_CONTROL) < 0) bias(1);
if (GetKeyState(VK_CONTROL) < 0)
{
float bias = 1.0f;
if (GetKeyState(VK_SHIFT) < 0) bias = 0.1f;
editBiasValue(bias);
}
else setEditRow(editRow - 1);
break;
case VK_DOWN:
if (GetKeyState(VK_CONTROL) < 0) bias(-1);
if (GetKeyState(VK_CONTROL) < 0)
{
float bias = 1.0f;
if (GetKeyState(VK_SHIFT) < 0) bias = 0.1f;
editBiasValue(-bias);
}
else setEditRow(editRow + 1);
break;
@ -759,12 +806,22 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
case VK_RIGHT: setEditTrack(editTrack + 1); break;
case VK_PRIOR:
if (GetKeyState(VK_CONTROL) < 0) bias(10);
if (GetKeyState(VK_CONTROL) < 0)
{
float bias = 10.0f;
if (GetKeyState(VK_SHIFT) < 0) bias = 100.0f;
editBiasValue(bias);
}
else setEditRow(editRow - windowRows / 2);
break;
case VK_NEXT:
if (GetKeyState(VK_CONTROL) < 0) bias(-10);
if (GetKeyState(VK_CONTROL) < 0)
{
float bias = 10.0f;
if (GetKeyState(VK_SHIFT) < 0) bias = 100.0f;
editBiasValue(-bias);
}
else setEditRow(editRow + windowRows / 2);
break;
@ -775,7 +832,7 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
switch (keyCode)
{
case VK_RETURN: editSetValue(); break;
case VK_RETURN: editEnterValue(); break;
case VK_DELETE: editDelete(); break;
case VK_BACK:
@ -803,7 +860,6 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT /*flags*/)
LRESULT TrackView::onChar(UINT keyCode, UINT flags)
{
printf("char: \"%c\" (%d) - flags: %x\n", char(keyCode), keyCode, flags);
switch (char(keyCode))
{
case '.':
@ -813,6 +869,13 @@ LRESULT TrackView::onChar(UINT keyCode, UINT flags)
MessageBeep(0);
break;
}
case '-':
if (editString.empty())
{
editString.push_back(char(keyCode));
invalidatePos(editTrack, editRow);
}
break;
case '0':
case '1':
@ -825,7 +888,6 @@ LRESULT TrackView::onChar(UINT keyCode, UINT flags)
case '8':
case '9':
editString.push_back(char(keyCode));
printf("accepted: %c - %s\n", char(keyCode), editString.c_str());
invalidatePos(editTrack, editRow);
break;
}

View File

@ -23,6 +23,7 @@ public:
void setRows(int rows);
int getRows() const { return rows; }
void editBiasValue(float amount);
private:
// some nasty hackery to forward the window messages
@ -38,9 +39,7 @@ private:
LRESULT onKeyDown(UINT keyCode, UINT flags);
LRESULT onChar(UINT keyCode, UINT flags);
void editSetValue();
void bias(float amount);
void editEnterValue();
void editDelete();
void editCopy();
void editCut();