refactoring
This commit is contained in:
parent
fbf9212544
commit
c14fa89e2f
@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
const TCHAR *mainWindowClassName = _T("MainWindow");
|
const TCHAR *mainWindowClassName = _T("MainWindow");
|
||||||
|
|
||||||
TrackView trackView;
|
TrackView *trackView;
|
||||||
HWND trackViewWin;
|
HWND trackViewWin;
|
||||||
|
|
||||||
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
|
||||||
@ -16,7 +16,7 @@ LRESULT CALLBACK mainWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lPara
|
|||||||
switch(msg)
|
switch(msg)
|
||||||
{
|
{
|
||||||
case WM_CREATE:
|
case WM_CREATE:
|
||||||
trackViewWin = trackView.create(GetModuleHandle(NULL), hwnd);
|
trackViewWin = trackView->create(GetModuleHandle(NULL), hwnd);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case WM_SIZE:
|
case WM_SIZE:
|
||||||
@ -65,6 +65,7 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
|
|
||||||
SyncData syncData;
|
SyncData syncData;
|
||||||
SyncTrack &testTrack = syncData.getTrack("test");
|
SyncTrack &testTrack = syncData.getTrack("test");
|
||||||
|
SyncTrack &test2Track = syncData.getTrack("test2");
|
||||||
|
|
||||||
// testTrack.setKeyFrame(0, SyncTrack::KeyFrame(1.0f));
|
// testTrack.setKeyFrame(0, SyncTrack::KeyFrame(1.0f));
|
||||||
testTrack.setKeyFrame(1, SyncTrack::KeyFrame(2.0f));
|
testTrack.setKeyFrame(1, SyncTrack::KeyFrame(2.0f));
|
||||||
@ -84,6 +85,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trackView = new TrackView();
|
||||||
|
trackView->setSyncData(&syncData);
|
||||||
|
|
||||||
// Step 2: Creating the Window
|
// Step 2: Creating the Window
|
||||||
hwnd = CreateWindowEx(
|
hwnd = CreateWindowEx(
|
||||||
0,
|
0,
|
||||||
@ -111,6 +115,9 @@ int _tmain(int argc, _TCHAR* argv[])
|
|||||||
DispatchMessage(&Msg);
|
DispatchMessage(&Msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
delete trackView;
|
||||||
|
trackView = NULL;
|
||||||
|
|
||||||
UnregisterClass(mainWindowClassName, hInstance);
|
UnregisterClass(mainWindowClassName, hInstance);
|
||||||
return int(Msg.wParam);
|
return int(Msg.wParam);
|
||||||
}
|
}
|
||||||
@ -13,9 +13,8 @@ static const int fontWidth = 6;
|
|||||||
static const int trackWidth = fontWidth * 16;
|
static const int trackWidth = fontWidth * 16;
|
||||||
|
|
||||||
static const int lines = 0x80;
|
static const int lines = 0x80;
|
||||||
static const int tracks = 32;
|
|
||||||
|
|
||||||
TrackView::TrackView()
|
TrackView::TrackView() : syncData(NULL)
|
||||||
{
|
{
|
||||||
scrollPosX = 0;
|
scrollPosX = 0;
|
||||||
scrollPosY = 0;
|
scrollPosY = 0;
|
||||||
@ -75,12 +74,11 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
FillRect(hdc, &fillRect, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
FillRect(hdc, &fillRect, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
||||||
ExcludeClipRect(hdc, topLeftMargin.left, topLeftMargin.top, topLeftMargin.right, topLeftMargin.bottom);
|
ExcludeClipRect(hdc, topLeftMargin.left, topLeftMargin.top, topLeftMargin.right, topLeftMargin.bottom);
|
||||||
|
|
||||||
int firstTrack = min(max(scrollPosX / trackWidth, 0), tracks - 1);
|
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
||||||
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), tracks - 1);
|
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
||||||
|
|
||||||
for (int track = firstTrack; track <= lastTrack; ++track)
|
for (int track = firstTrack; track <= lastTrack; ++track)
|
||||||
{
|
{
|
||||||
char temp[256];
|
|
||||||
RECT topMargin;
|
RECT topMargin;
|
||||||
|
|
||||||
topMargin.top = 0;
|
topMargin.top = 0;
|
||||||
@ -100,10 +98,13 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
FillRect(hdc, &fillRect, bgBrush);
|
FillRect(hdc, &fillRect, bgBrush);
|
||||||
|
|
||||||
/* format the text */
|
/* format the text */
|
||||||
|
TCHAR temp[256];
|
||||||
_sntprintf_s(temp, 256, _T("track %d"), track);
|
_sntprintf_s(temp, 256, _T("track %d"), track);
|
||||||
|
|
||||||
|
std::string trackName(temp);
|
||||||
TextOut(hdc,
|
TextOut(hdc,
|
||||||
fillRect.left, 0,
|
fillRect.left, 0,
|
||||||
temp, int(_tcslen(temp))
|
trackName.c_str(), int(trackName.length())
|
||||||
);
|
);
|
||||||
ExcludeClipRect(hdc, topMargin.left, topMargin.top, topMargin.right, topMargin.bottom);
|
ExcludeClipRect(hdc, topMargin.left, topMargin.top, topMargin.right, topMargin.bottom);
|
||||||
}
|
}
|
||||||
@ -111,7 +112,7 @@ void TrackView::paintTopMargin(HDC hdc, RECT rcTracks)
|
|||||||
RECT topRightMargin;
|
RECT topRightMargin;
|
||||||
topRightMargin.top = 0;
|
topRightMargin.top = 0;
|
||||||
topRightMargin.bottom = topMarginHeight;
|
topRightMargin.bottom = topMarginHeight;
|
||||||
topRightMargin.left = getScreenX(tracks);
|
topRightMargin.left = getScreenX(getTrackCount());
|
||||||
topRightMargin.right = rcTracks.right;
|
topRightMargin.right = rcTracks.right;
|
||||||
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);
|
||||||
@ -124,8 +125,8 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
{
|
{
|
||||||
TCHAR temp[256];
|
TCHAR temp[256];
|
||||||
|
|
||||||
int firstTrack = min(max(scrollPosX / trackWidth, 0), tracks - 1);
|
int firstTrack = min(max(scrollPosX / trackWidth, 0), getTrackCount() - 1);
|
||||||
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), tracks - 1);
|
int lastTrack = min(max(firstTrack + windowTracks + 1, 0), getTrackCount() - 1);
|
||||||
|
|
||||||
int firstLine = editLine - windowLines / 2 - 1;
|
int firstLine = editLine - windowLines / 2 - 1;
|
||||||
int lastLine = editLine + windowLines / 2 + 1;
|
int lastLine = editLine + windowLines / 2 + 1;
|
||||||
@ -215,7 +216,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
RECT rightMargin;
|
RECT rightMargin;
|
||||||
rightMargin.top = getScreenY(0);
|
rightMargin.top = getScreenY(0);
|
||||||
rightMargin.bottom = getScreenY(lines);
|
rightMargin.bottom = getScreenY(lines);
|
||||||
rightMargin.left = getScreenX(tracks);
|
rightMargin.left = getScreenX(getTrackCount());
|
||||||
rightMargin.right = rcTracks.right;
|
rightMargin.right = rcTracks.right;
|
||||||
FillRect( hdc, &rightMargin, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
FillRect( hdc, &rightMargin, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
||||||
}
|
}
|
||||||
@ -253,7 +254,7 @@ void TrackView::setupScrollBars()
|
|||||||
si.nPos = editTrack;
|
si.nPos = editTrack;
|
||||||
si.nPage = windowTracks;
|
si.nPage = windowTracks;
|
||||||
si.nMin = 0;
|
si.nMin = 0;
|
||||||
si.nMax = tracks - 1 + windowTracks - 1;
|
si.nMax = getTrackCount() - 1 + windowTracks - 1;
|
||||||
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
|
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -330,7 +331,7 @@ void TrackView::setEditTrack(int newEditTrack)
|
|||||||
|
|
||||||
// clamp to document
|
// clamp to document
|
||||||
editTrack = max(editTrack, 0);
|
editTrack = max(editTrack, 0);
|
||||||
editTrack = min(editTrack, tracks - 1);
|
editTrack = min(editTrack, getTrackCount() - 1);
|
||||||
|
|
||||||
RECT trackRect;
|
RECT trackRect;
|
||||||
|
|
||||||
@ -414,7 +415,7 @@ void TrackView::onHScroll(UINT sbCode, int newPos)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_RIGHT:
|
case SB_RIGHT:
|
||||||
setEditTrack(tracks - 1);
|
setEditTrack(getTrackCount() - 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_LINELEFT:
|
case SB_LINELEFT:
|
||||||
|
|||||||
14
trackview.h
14
trackview.h
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
#include "syncdata.h"
|
#include "syncdata.h"
|
||||||
|
|
||||||
|
class SyncData;
|
||||||
|
|
||||||
class TrackView
|
class TrackView
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -11,6 +13,9 @@ public:
|
|||||||
HWND create(HINSTANCE hInstance, HWND hwndParent);
|
HWND create(HINSTANCE hInstance, HWND hwndParent);
|
||||||
HWND getWin(){ return hwnd; }
|
HWND getWin(){ return hwnd; }
|
||||||
|
|
||||||
|
void setSyncData(SyncData *syncData) { this->syncData = syncData; }
|
||||||
|
SyncData *getSyncData() { return syncData; }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// some nasty hackery to forward the window messages
|
// some nasty hackery to forward the window messages
|
||||||
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
@ -39,6 +44,13 @@ private:
|
|||||||
int getScreenY(int line);
|
int getScreenY(int line);
|
||||||
int getScreenX(int track);
|
int getScreenX(int track);
|
||||||
|
|
||||||
|
int getTrackCount()
|
||||||
|
{
|
||||||
|
SyncData *syncData = getSyncData();
|
||||||
|
if (NULL == syncData) return 0;
|
||||||
|
return int(syncData->getTrackCount());
|
||||||
|
};
|
||||||
|
|
||||||
/* cursor position */
|
/* cursor position */
|
||||||
int editLine, editTrack;
|
int editLine, editTrack;
|
||||||
|
|
||||||
@ -46,6 +58,8 @@ private:
|
|||||||
int windowWidth, windowHeight;
|
int windowWidth, windowHeight;
|
||||||
int windowLines, windowTracks;
|
int windowLines, windowTracks;
|
||||||
|
|
||||||
|
SyncData *syncData;
|
||||||
|
|
||||||
HWND hwnd;
|
HWND hwnd;
|
||||||
HBRUSH editBrush;
|
HBRUSH editBrush;
|
||||||
};
|
};
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user