refactoring
This commit is contained in:
parent
9bf44409f9
commit
ac84834e1b
@ -42,12 +42,16 @@ int main(int argc, char *argv[])
|
||||
if (0 == ret) done = true;
|
||||
else
|
||||
{
|
||||
printf("cmd: %02x\n", cmd);
|
||||
if (cmd == 1)
|
||||
switch (cmd)
|
||||
{
|
||||
case 1:
|
||||
printf("yes, master!\n");
|
||||
unsigned char cmd = 0x1;
|
||||
send(serverSocket, (char*)&cmd, 1, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
printf("unknown cmd: %02x\n", cmd);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
20
resource.h
Normal file
20
resource.h
Normal file
@ -0,0 +1,20 @@
|
||||
//{{NO_DEPENDENCIES}}
|
||||
// Microsoft Visual C++ generated include file.
|
||||
// Used by synctracker2.rc
|
||||
//
|
||||
#define IDR_ACCELERATOR 101
|
||||
#define IDR_MENU 102
|
||||
#define ID_FILE 40001
|
||||
#define ID_FILE_EXIT 40002
|
||||
#define ID_EDIT 40003
|
||||
|
||||
// Next default values for new objects
|
||||
//
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
#ifndef APSTUDIO_READONLY_SYMBOLS
|
||||
#define _APS_NEXT_RESOURCE_VALUE 103
|
||||
#define _APS_NEXT_COMMAND_VALUE 40004
|
||||
#define _APS_NEXT_CONTROL_VALUE 1001
|
||||
#define _APS_NEXT_SYMED_VALUE 101
|
||||
#endif
|
||||
#endif
|
||||
4
stdafx.h
4
stdafx.h
@ -5,10 +5,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
#define WIN32_LEAN_AND_MEAN // Exclude rarely-used stuff from Windows headers
|
||||
#include <windows.h>
|
||||
|
||||
#include "afxres.h"
|
||||
#include "resource.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <tchar.h>
|
||||
#include <assert.h>
|
||||
|
||||
@ -19,44 +19,25 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
|
||||
{
|
||||
case WM_CREATE:
|
||||
{
|
||||
trackViewWin = trackView->create(GetModuleHandle(NULL), hwnd);
|
||||
|
||||
HINSTANCE hInstance = GetModuleHandle(NULL);
|
||||
trackViewWin = trackView->create(hInstance, hwnd);
|
||||
InitCommonControls();
|
||||
statusBarWin = CreateWindowEx(
|
||||
0, // no extended styles
|
||||
STATUSCLASSNAME, // status bar
|
||||
(LPCTSTR)"mordi", // no text
|
||||
(LPCTSTR)NULL, // no text
|
||||
SBARS_SIZEGRIP | WS_VISIBLE | WS_CHILD, // styles
|
||||
0, 0, 0, 0, // x, y, cx, cy
|
||||
hwnd, // parent window
|
||||
(HMENU)100, // window ID
|
||||
GetModuleHandle(NULL), // instance
|
||||
NULL, // menu
|
||||
hInstance, // instance
|
||||
NULL // window data
|
||||
);
|
||||
|
||||
int statwidths[] = {100, -1};
|
||||
SendMessage(statusBarWin, SB_SETPARTS, sizeof(statwidths)/sizeof(int), (LPARAM)statwidths);
|
||||
int statwidths[] = { 100, -1 };
|
||||
SendMessage(statusBarWin, SB_SETPARTS, sizeof(statwidths) / sizeof(int), (LPARAM)statwidths);
|
||||
SendMessage(statusBarWin, SB_SETTEXT, 0, (LPARAM)"Hi there :)");
|
||||
|
||||
HMENU fileMenu = CreatePopupMenu();
|
||||
AppendMenu(fileMenu, MF_STRING, 0, _T("&Open\tCtrl+O"));
|
||||
AppendMenu(fileMenu, MF_STRING, 2, _T("&Save\tCtrl+S"));
|
||||
AppendMenu(fileMenu, MF_STRING, 3, _T("Save &As"));
|
||||
AppendMenu(fileMenu, MF_SEPARATOR, 0, NULL);
|
||||
AppendMenu(fileMenu, MF_STRING, 3, _T("&Exit"));
|
||||
|
||||
HMENU editMenu = CreatePopupMenu();
|
||||
AppendMenu(editMenu, MF_STRING, WM_UNDO, _T("&Undo\tCtrl+Z"));
|
||||
AppendMenu(editMenu, MF_STRING, WM_REDO, _T("&Redo\tShift+Ctrl+Z"));
|
||||
AppendMenu(editMenu, MF_SEPARATOR, 0, NULL);
|
||||
AppendMenu(editMenu, MF_STRING, WM_CUT, _T("Cu&t\tCtrl+X"));
|
||||
AppendMenu(editMenu, MF_STRING, WM_COPY, _T("&Copy\tCtrl+C"));
|
||||
AppendMenu(editMenu, MF_STRING, WM_PASTE, _T("&Paste\tCtrl+V"));
|
||||
|
||||
HMENU rootMenu = CreateMenu();
|
||||
AppendMenu(rootMenu, MF_STRING | MF_POPUP, (UINT_PTR)fileMenu, _T("&File"));
|
||||
AppendMenu(rootMenu, MF_STRING | MF_POPUP, (UINT_PTR)editMenu, _T("&Edit"));
|
||||
SetMenu(hwnd, rootMenu);
|
||||
SendMessage(statusBarWin, SB_SETTEXT, 1, (LPARAM)"Hi there :)");
|
||||
}
|
||||
break;
|
||||
|
||||
@ -81,15 +62,12 @@ static LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARA
|
||||
case WM_COMMAND:
|
||||
switch (LOWORD(wParam))
|
||||
{
|
||||
// simply forward these
|
||||
case WM_UNDO:
|
||||
case WM_REDO:
|
||||
case WM_COPY:
|
||||
case WM_PASTE:
|
||||
case WM_CUT:
|
||||
SendMessage(trackViewWin, LOWORD(wParam), 0, 0);
|
||||
break;
|
||||
|
||||
case ID_FILE_SAVE: /* meh.*/ break;
|
||||
case ID_EDIT_UNDO: SendMessage(trackViewWin, WM_UNDO, 0, 0); break;
|
||||
case ID_EDIT_REDO: SendMessage(trackViewWin, WM_REDO, 0, 0); break;
|
||||
case ID_EDIT_COPY: SendMessage(trackViewWin, WM_COPY, 0, 0); break;
|
||||
case ID_EDIT_CUT: SendMessage(trackViewWin, WM_CUT, 0, 0); break;
|
||||
case ID_EDIT_PASTE: SendMessage(trackViewWin, WM_PASTE, 0, 0); break;
|
||||
default:
|
||||
printf("cmd %d %d\n", wParam, lParam);
|
||||
}
|
||||
@ -114,7 +92,7 @@ static ATOM registerMainWindowClass(HINSTANCE hInstance)
|
||||
wc.hIcon = LoadIcon(NULL, IDI_APPLICATION);
|
||||
wc.hCursor = LoadCursor(NULL, IDC_ARROW);
|
||||
wc.hbrBackground = (HBRUSH)0;
|
||||
wc.lpszMenuName = NULL;
|
||||
wc.lpszMenuName = (LPCSTR)IDR_MENU;
|
||||
wc.lpszClassName = mainWindowClassName;
|
||||
wc.hIconSm = LoadIcon(NULL, IDI_APPLICATION);
|
||||
|
||||
@ -215,6 +193,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
return 0;
|
||||
}
|
||||
|
||||
HACCEL accel = LoadAccelerators(hInstance, (LPCSTR)IDR_ACCELERATOR);
|
||||
printf("accel: %p\n", accel);
|
||||
|
||||
ShowWindow(hwnd, TRUE);
|
||||
UpdateWindow(hwnd);
|
||||
|
||||
@ -278,11 +259,14 @@ int _tmain(int argc, _TCHAR* argv[])
|
||||
|
||||
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
||||
{
|
||||
if (!TranslateAccelerator(hwnd, accel, &msg))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
if (WM_QUIT == msg.message) done = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
closesocket(serverSocket);
|
||||
closeNetwork();
|
||||
|
||||
105
synctracker2.rc
Normal file
105
synctracker2.rc
Normal file
@ -0,0 +1,105 @@
|
||||
// Microsoft Visual C++ generated resource script.
|
||||
//
|
||||
#include "resource.h"
|
||||
|
||||
#define APSTUDIO_READONLY_SYMBOLS
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 2 resource.
|
||||
//
|
||||
#include "afxres.h"
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#undef APSTUDIO_READONLY_SYMBOLS
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
// Norwegian (Bokmal) resources
|
||||
|
||||
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_NOR)
|
||||
#ifdef _WIN32
|
||||
LANGUAGE LANG_NORWEGIAN, SUBLANG_NORWEGIAN_BOKMAL
|
||||
#pragma code_page(1252)
|
||||
#endif //_WIN32
|
||||
|
||||
#ifdef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// TEXTINCLUDE
|
||||
//
|
||||
|
||||
1 TEXTINCLUDE
|
||||
BEGIN
|
||||
"resource.h\0"
|
||||
END
|
||||
|
||||
2 TEXTINCLUDE
|
||||
BEGIN
|
||||
"#include ""afxres.h""\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
3 TEXTINCLUDE
|
||||
BEGIN
|
||||
"\r\n"
|
||||
"\0"
|
||||
END
|
||||
|
||||
#endif // APSTUDIO_INVOKED
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Accelerator
|
||||
//
|
||||
|
||||
IDR_ACCELERATOR ACCELERATORS
|
||||
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
|
||||
END
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Menu
|
||||
//
|
||||
|
||||
IDR_MENU MENU
|
||||
BEGIN
|
||||
POPUP "&File"
|
||||
BEGIN
|
||||
MENUITEM "&Open\tCtrl+O", ID_FILE_OPEN
|
||||
MENUITEM "&Save\tCtrl+S", ID_FILE_SAVE
|
||||
MENUITEM "Save &As", ID_FILE_SAVE_AS
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "E&xit", ID_FILE_EXIT
|
||||
END
|
||||
POPUP "&Edit"
|
||||
BEGIN
|
||||
MENUITEM "Undo\tCtrl+Z", ID_EDIT_UNDO
|
||||
MENUITEM "Redo\tCtrl+Shift+Z", ID_EDIT_REDO
|
||||
MENUITEM SEPARATOR
|
||||
MENUITEM "&Copy\tCtrl+C", ID_EDIT_COPY
|
||||
MENUITEM "Cu&t\tCtrl+X", ID_EDIT_CUT
|
||||
MENUITEM "&Paste\tCtrl+V", ID_EDIT_PASTE
|
||||
END
|
||||
END
|
||||
|
||||
#endif // Norwegian (Bokmal) resources
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#ifndef APSTUDIO_INVOKED
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
//
|
||||
// Generated from the TEXTINCLUDE 3 resource.
|
||||
//
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////////////////////////
|
||||
#endif // not APSTUDIO_INVOKED
|
||||
|
||||
@ -206,6 +206,10 @@
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\resource.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\stdafx.h"
|
||||
>
|
||||
</File>
|
||||
@ -223,6 +227,10 @@
|
||||
Filter="rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav"
|
||||
UniqueIdentifier="{67DA6AB6-F800-4c08-8B7A-83BB121AAD01}"
|
||||
>
|
||||
<File
|
||||
RelativePath=".\synctracker2.rc"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
||||
142
trackview.cpp
142
trackview.cpp
@ -42,6 +42,9 @@ TrackView::TrackView()
|
||||
selectDarkBrush = CreateSolidBrush(darken(GetSysColor(COLOR_HIGHLIGHT), 0.9f));
|
||||
|
||||
editBrush = CreateSolidBrush(RGB(255, 255, 0));
|
||||
|
||||
clipboardFormat = RegisterClipboardFormat("syncdata");
|
||||
if (0 == clipboardFormat) printf("geh");
|
||||
}
|
||||
|
||||
TrackView::~TrackView()
|
||||
@ -306,6 +309,99 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
||||
}
|
||||
}
|
||||
|
||||
void TrackView::copy()
|
||||
{
|
||||
if (!selectActive) return;
|
||||
|
||||
int selectLeft = min(selectStartTrack, selectStopTrack);
|
||||
int selectRight = max(selectStartTrack, selectStopTrack);
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
printf("copying:\n");
|
||||
|
||||
#if 0
|
||||
struct CopyEntry
|
||||
{
|
||||
int track, row;
|
||||
float val;
|
||||
bool valExisting;
|
||||
};
|
||||
std::vector<CopyEntry> copyBuffer;
|
||||
#endif
|
||||
|
||||
if (FAILED(OpenClipboard(getWin())))
|
||||
{
|
||||
MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
|
||||
return;
|
||||
}
|
||||
|
||||
// gather data
|
||||
int rows = selectBottom - selectTop + 1;
|
||||
int columns = selectRight - selectLeft + 1;
|
||||
size_t cells = columns * rows;
|
||||
HGLOBAL hmem = GlobalAlloc(GMEM_MOVEABLE, sizeof(float) * cells);
|
||||
|
||||
std::string copyString;
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
const SyncTrack &t = syncDataEdit.getSyncData()->getTrack(track);
|
||||
char temp[128];
|
||||
if (t.isKeyFrame(row)) sprintf(temp, "%.2f\t", t.getKeyFrame(row)->value);
|
||||
else sprintf(temp, "--- \t");
|
||||
copyString += temp;
|
||||
printf("(%d %d) = %s", track, row, temp);
|
||||
}
|
||||
puts("");
|
||||
copyString += "\n";
|
||||
}
|
||||
|
||||
HGLOBAL hmem_text = GlobalAlloc(GMEM_MOVEABLE, strlen(copyString.c_str()) + 1);
|
||||
char *clipbuf = (char *)GlobalLock(hmem_text);
|
||||
memcpy(clipbuf, copyString.c_str(), strlen(copyString.c_str()) + 1);
|
||||
GlobalUnlock(hmem_text);
|
||||
|
||||
// update clipboard
|
||||
EmptyClipboard();
|
||||
SetClipboardData(clipboardFormat, hmem);
|
||||
SetClipboardData(CF_TEXT, hmem_text);
|
||||
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()
|
||||
{
|
||||
int selectLeft = min(selectStartTrack, selectStopTrack);
|
||||
int selectRight = max(selectStartTrack, selectStopTrack);
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
|
||||
copy();
|
||||
#if 0
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
SyncTrack &t = syncDataEdit.getSyncData()->getTrack(track);
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
if (t.isKeyFrame(row)) t.deleteKeyFrame(row);
|
||||
}
|
||||
}
|
||||
invalidateRange(selectLeft, selectRight, selectTop, selectBottom);
|
||||
#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()
|
||||
{
|
||||
SCROLLINFO si = { sizeof(si) };
|
||||
@ -518,10 +614,13 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT flags)
|
||||
case VK_NEXT: setEditRow(editRow + windowRows / 2); break;
|
||||
|
||||
case VK_SHIFT:
|
||||
if (selectActive) invalidateRange(selectStartTrack, selectStopTrack, selectStartRow, selectStopRow);
|
||||
// if (selectActive) invalidateRange(selectStartTrack, selectStopTrack, selectStartRow, selectStopRow);
|
||||
if (!selectActive)
|
||||
{
|
||||
selectStartTrack = selectStopTrack = editTrack;
|
||||
selectStartRow = selectStopRow = editRow;
|
||||
selectActive = true;
|
||||
}
|
||||
break;
|
||||
|
||||
// simulate keyboard accelerators
|
||||
@ -529,10 +628,10 @@ LRESULT TrackView::onKeyDown(UINT keyCode, UINT flags)
|
||||
if (ctrlDown) SendMessage(GetParent(this->getWin()), WM_COMMAND, MAKEWPARAM(shiftDown ? WM_REDO : WM_UNDO, 1), 0);
|
||||
break;
|
||||
case 'C':
|
||||
if (ctrlDown && !altDown && !shiftDown)
|
||||
/* if (ctrlDown && !altDown && !shiftDown)
|
||||
{
|
||||
SendMessage(GetParent(this->getWin()), WM_COMMAND, MAKEWPARAM(WM_COPY, 1), 0);
|
||||
}
|
||||
} */
|
||||
// printf("hit '%c', flags: %X\n", keyCode, flags);
|
||||
// if (ctrlDown) SendMessage(GetParent(this->getWin()), WM_COMMAND, MAKEWPARAM(shiftDown ? WM_REDO : WM_UNDO, 1), 0);
|
||||
break;
|
||||
@ -668,40 +767,9 @@ LRESULT TrackView::windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||
case WM_KEYDOWN: return onKeyDown((UINT)wParam, (UINT)lParam);
|
||||
case WM_CHAR: return onChar((UINT)wParam, (UINT)lParam);
|
||||
|
||||
case WM_COPY:
|
||||
{
|
||||
int selectLeft = min(selectStartTrack, selectStopTrack);
|
||||
int selectRight = max(selectStartTrack, selectStopTrack);
|
||||
int selectTop = min(selectStartRow, selectStopRow);
|
||||
int selectBottom = max(selectStartRow, selectStopRow);
|
||||
printf("copying:\n");
|
||||
|
||||
struct CopyEntry
|
||||
{
|
||||
int track, row;
|
||||
float val;
|
||||
bool valExisting;
|
||||
};
|
||||
|
||||
// std::vector<CopyEntry> copyBuffer;
|
||||
if (FAILED(OpenClipboard(getWin())))
|
||||
{
|
||||
MessageBox(NULL, "Failed to open clipboard", NULL, MB_OK);
|
||||
}
|
||||
else
|
||||
{
|
||||
EmptyClipboard();
|
||||
for (int track = selectLeft; track <= selectRight; ++track)
|
||||
{
|
||||
for (int row = selectTop; row <= selectBottom; ++row)
|
||||
{
|
||||
printf("(%d %d) = ", track, row);
|
||||
}
|
||||
}
|
||||
CloseClipboard();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case WM_COPY: copy(); break;
|
||||
case WM_CUT: cut(); break;
|
||||
case WM_PASTE: paste(); break;
|
||||
|
||||
case WM_UNDO:
|
||||
if (!syncDataEdit.undo()) MessageBeep(0);
|
||||
|
||||
@ -137,6 +137,10 @@ private:
|
||||
LRESULT onKeyDown(UINT keyCode, UINT flags);
|
||||
LRESULT onChar(UINT keyCode, UINT flags);
|
||||
|
||||
void copy();
|
||||
void cut();
|
||||
void paste();
|
||||
|
||||
// the window procedure
|
||||
|
||||
void paintTracks(HDC hdc, RECT rcTracks);
|
||||
@ -228,6 +232,8 @@ private:
|
||||
|
||||
HWND hwnd;
|
||||
HBRUSH editBrush;
|
||||
|
||||
UINT clipboardFormat;
|
||||
};
|
||||
|
||||
ATOM registerTrackViewWindowClass(HINSTANCE hInstance);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user