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