yay, proper scrolling! \o/
This commit is contained in:
parent
18bb1b5566
commit
13628d094d
171
trackview.cpp
171
trackview.cpp
@ -15,16 +15,18 @@ static const int tracks = 16;
|
|||||||
|
|
||||||
int TrackView::getScreenY(int line)
|
int TrackView::getScreenY(int line)
|
||||||
{
|
{
|
||||||
return topMarginHeight + (line - scrollPosY) * fontHeight;
|
return topMarginHeight + (line * fontHeight) - scrollPosY;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void TrackView::onCreate(HWND hwnd)
|
void TrackView::onCreate(HWND hwnd)
|
||||||
{
|
{
|
||||||
scrollPosX = 0;
|
scrollPosX = 0;
|
||||||
scrollPosY = 0;
|
scrollPosY = 0;
|
||||||
windowWidth = -1;
|
windowWidth = -1;
|
||||||
windowHeight = -1;
|
windowHeight = -1;
|
||||||
|
|
||||||
|
editLine = 0;
|
||||||
|
|
||||||
setupScrollBars(hwnd);
|
setupScrollBars(hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -55,25 +57,29 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
{
|
{
|
||||||
TCHAR temp[256];
|
TCHAR temp[256];
|
||||||
|
|
||||||
int firstLine = scrollPosY + max((rcTracks.top - topMarginHeight) / fontHeight, 0);
|
int firstLine = 0; // scrollPosY + max((rcTracks.top - topMarginHeight) / fontHeight, 0);
|
||||||
int lastLine = scrollPosY + min(((rcTracks.bottom - topMarginHeight) + (fontHeight - 1)) / fontHeight, lines - 1);
|
int lastLine = lines; // scrollPosY + min(((rcTracks.bottom - topMarginHeight) + (fontHeight - 1)) / fontHeight, lines - 1);
|
||||||
|
|
||||||
int editLine = firstLine + (lastLine - firstLine) / 2;
|
// int editLine = firstLine + (lastLine - firstLine) / 2;
|
||||||
HBRUSH editBrush = CreateSolidBrush(RGB(255, 255, 0));
|
HBRUSH editBrush = CreateSolidBrush(RGB(255, 255, 0));
|
||||||
|
// HBRUSH editBrush = CreateSolidBrush(RGB(255, 255, 0));
|
||||||
|
|
||||||
lastLine = min(lastLine, lines);
|
lastLine = min(lastLine, lines) - 1;
|
||||||
|
/*
|
||||||
RECT topLeftCorner;
|
RECT topLeftCorner;
|
||||||
topLeftCorner.top = 0;
|
topLeftCorner.top = 0;
|
||||||
topLeftCorner.bottom = topMarginHeight;
|
topLeftCorner.bottom = topMarginHeight;
|
||||||
topLeftCorner.left = 0;
|
topLeftCorner.left = 0;
|
||||||
topLeftCorner.right = leftMarginWidth;
|
topLeftCorner.right = leftMarginWidth;
|
||||||
FillRect(hdc, &topLeftCorner, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
RECT fillRect = topLeftCorner;
|
||||||
|
DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_BOTTOM);
|
||||||
|
FillRect(hdc, &fillRect, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
||||||
ExcludeClipRect(hdc, topLeftCorner.left, topLeftCorner.top, topLeftCorner.right, topLeftCorner.bottom);
|
ExcludeClipRect(hdc, topLeftCorner.left, topLeftCorner.top, topLeftCorner.right, topLeftCorner.bottom);
|
||||||
|
*/
|
||||||
SetBkMode(hdc, TRANSPARENT);
|
SetBkMode(hdc, TRANSPARENT);
|
||||||
|
// SetBkMode(hdc, OPAQUE);
|
||||||
|
|
||||||
for (int line = firstLine; line < lastLine; ++line)
|
for (int line = firstLine; line <= lastLine; ++line)
|
||||||
{
|
{
|
||||||
RECT leftMargin;
|
RECT leftMargin;
|
||||||
leftMargin.left = 0;
|
leftMargin.left = 0;
|
||||||
@ -81,9 +87,8 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
leftMargin.top = getScreenY(line);
|
leftMargin.top = getScreenY(line);
|
||||||
leftMargin.bottom = leftMargin.top + fontHeight;
|
leftMargin.bottom = leftMargin.top + fontHeight;
|
||||||
|
|
||||||
// if (y == editLine) FillRect(hdc, &leftMargin, editBrush);
|
if (line == editLine) FillRect(hdc, &leftMargin, editBrush);
|
||||||
// else
|
else FillRect(hdc, &leftMargin, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
||||||
FillRect(hdc, &leftMargin, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
|
||||||
|
|
||||||
DrawEdge(hdc, &leftMargin, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_RIGHT | BF_BOTTOM | BF_TOP);
|
DrawEdge(hdc, &leftMargin, BDR_RAISEDINNER | BDR_RAISEDOUTER, BF_RIGHT | BF_BOTTOM | BF_TOP);
|
||||||
// Rectangle( hdc, leftMargin.left, leftMargin.top, leftMargin.right, leftMargin.bottom + 1);
|
// Rectangle( hdc, leftMargin.left, leftMargin.top, leftMargin.right, leftMargin.bottom + 1);
|
||||||
@ -129,7 +134,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
ExcludeClipRect(hdc, topMargin.left, topMargin.top, topMargin.right, topMargin.bottom);
|
ExcludeClipRect(hdc, topMargin.left, topMargin.top, topMargin.right, topMargin.bottom);
|
||||||
|
|
||||||
// SetBkColor(hdc, RGB(255, 0, 0));
|
// SetBkColor(hdc, RGB(255, 0, 0));
|
||||||
for (int line = firstLine; line < lastLine; ++line)
|
for (int line = firstLine; line <= lastLine; ++line)
|
||||||
{
|
{
|
||||||
RECT patternDataRect;
|
RECT patternDataRect;
|
||||||
patternDataRect.left = trackLeft;
|
patternDataRect.left = trackLeft;
|
||||||
@ -137,10 +142,13 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
patternDataRect.top = getScreenY(line);
|
patternDataRect.top = getScreenY(line);
|
||||||
patternDataRect.bottom = patternDataRect.top + fontHeight;
|
patternDataRect.bottom = patternDataRect.top + fontHeight;
|
||||||
|
|
||||||
if (line % 8 == 0) FillRect( hdc, &patternDataRect, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
HBRUSH bgBrush = (HBRUSH)GetStockObject(WHITE_BRUSH);
|
||||||
else FillRect( hdc, &patternDataRect, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
if (line % 8 == 0) bgBrush = (HBRUSH)GetStockObject(LTGRAY_BRUSH);
|
||||||
|
if (line == editLine) bgBrush = editBrush;
|
||||||
|
|
||||||
// if (y % 8 == 0) DrawEdge(hdc, &patternDataRect, BDR_RAISEDINNER | BDR_SUNKENOUTER, BF_TOP | BF_BOTTOM | BF_FLAT);
|
RECT fillRect = patternDataRect;
|
||||||
|
if (line == editLine && x == 1) DrawEdge(hdc, &fillRect, BDR_RAISEDINNER | BDR_SUNKENOUTER, BF_ADJUST | BF_TOP | BF_BOTTOM | BF_LEFT | BF_RIGHT);
|
||||||
|
FillRect( hdc, &fillRect, bgBrush);
|
||||||
|
|
||||||
bool key = (line % 8 == 0);
|
bool key = (line % 8 == 0);
|
||||||
float val = (float(line) / 16);
|
float val = (float(line) / 16);
|
||||||
@ -153,7 +161,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
temp, int(_tcslen(temp))
|
temp, int(_tcslen(temp))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
RECT bottomMargin;
|
RECT bottomMargin;
|
||||||
bottomMargin.top = getScreenY(lines);
|
bottomMargin.top = getScreenY(lines);
|
||||||
bottomMargin.bottom = rcTracks.bottom;
|
bottomMargin.bottom = rcTracks.bottom;
|
||||||
@ -161,7 +169,7 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
bottomMargin.right = trackLeft + trackWidth;
|
bottomMargin.right = trackLeft + trackWidth;
|
||||||
DrawEdge(hdc, &bottomMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_TOP);
|
DrawEdge(hdc, &bottomMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_TOP);
|
||||||
FillRect(hdc, &bottomMargin, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
FillRect(hdc, &bottomMargin, (HBRUSH)GetStockObject(WHITE_BRUSH));
|
||||||
|
*/
|
||||||
trackLeft += trackWidth;
|
trackLeft += trackWidth;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -174,23 +182,28 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
|
|||||||
DrawEdge(hdc, &topMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_LEFT);
|
DrawEdge(hdc, &topMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_LEFT);
|
||||||
FillRect(hdc, &topMargin, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
FillRect(hdc, &topMargin, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
||||||
|
|
||||||
/* pad left margin to the left edge */
|
|
||||||
RECT leftMargin;
|
|
||||||
leftMargin.top = getScreenY(lines);
|
|
||||||
leftMargin.bottom = rcTracks.bottom;
|
|
||||||
leftMargin.left = 0;
|
|
||||||
leftMargin.right = leftMarginWidth;
|
|
||||||
DrawEdge(hdc, &leftMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_RIGHT);
|
|
||||||
FillRect(hdc, &leftMargin, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
|
||||||
|
|
||||||
/* right margin */
|
/* right margin */
|
||||||
RECT rightMargin;
|
RECT rightMargin;
|
||||||
rightMargin.top = topMarginHeight;
|
rightMargin.top = getScreenY(0);
|
||||||
rightMargin.bottom = rcTracks.bottom;
|
rightMargin.bottom = getScreenY(lines);
|
||||||
rightMargin.left = trackLeft;
|
rightMargin.left = trackLeft;
|
||||||
rightMargin.right = rcTracks.right;
|
rightMargin.right = rcTracks.right;
|
||||||
DrawEdge(hdc, &rightMargin, BDR_SUNKENINNER | BDR_RAISEDOUTER, BF_ADJUST | BF_LEFT);
|
FillRect( hdc, &rightMargin, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
||||||
FillRect( hdc, &rightMargin, (HBRUSH)GetStockObject(LTGRAY_BRUSH));
|
|
||||||
|
RECT bottomPadding;
|
||||||
|
bottomPadding.top = getScreenY(lines);
|
||||||
|
bottomPadding.bottom = rcTracks.bottom;
|
||||||
|
bottomPadding.left = rcTracks.left;
|
||||||
|
bottomPadding.right = rcTracks.right;
|
||||||
|
FillRect(hdc, &bottomPadding, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
||||||
|
|
||||||
|
RECT topPadding;
|
||||||
|
topPadding.top = rcTracks.top;
|
||||||
|
topPadding.bottom = getScreenY(0);
|
||||||
|
topPadding.left = rcTracks.left;
|
||||||
|
topPadding.right = rcTracks.right;
|
||||||
|
FillRect(hdc, &topPadding, (HBRUSH)GetStockObject(GRAY_BRUSH));
|
||||||
|
|
||||||
|
|
||||||
DeleteObject(editBrush);
|
DeleteObject(editBrush);
|
||||||
}
|
}
|
||||||
@ -199,40 +212,22 @@ void TrackView::setupScrollBars(HWND hwnd)
|
|||||||
{
|
{
|
||||||
SCROLLINFO si = { sizeof(si) };
|
SCROLLINFO si = { sizeof(si) };
|
||||||
si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
|
si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
|
||||||
si.nPos = scrollPosY;
|
si.nPos = editLine;
|
||||||
si.nPage = windowLines;
|
si.nPage = windowLines;
|
||||||
si.nMin = 0;
|
si.nMin = 0;
|
||||||
si.nMax = lines - 1;
|
si.nMax = lines - 1 + windowLines - 1;
|
||||||
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
SetScrollInfo(hwnd, SB_VERT, &si, TRUE);
|
||||||
|
|
||||||
si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
|
si.fMask = SIF_POS | SIF_PAGE | SIF_RANGE | SIF_DISABLENOSCROLL;
|
||||||
si.nPos = scrollPosX;
|
si.nPos = scrollPosX;
|
||||||
si.nPage = windowWidth;
|
si.nPage = windowWidth / 2;
|
||||||
si.nMin = 0;
|
si.nMin = 0;
|
||||||
si.nMax = windowWidth * 2; // 0x80;
|
si.nMax = windowWidth * 2; // 0x80;
|
||||||
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
|
SetScrollInfo(hwnd, SB_HORZ, &si, TRUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
void TrackView::setScrollPos(HWND hwnd, int newScrollPosX, int newScrollPosY)
|
void TrackView::scrollWindow(HWND hwnd, int scrollX, int scrollY)
|
||||||
{
|
{
|
||||||
const int oldScrollPosX = scrollPosX;
|
|
||||||
const int oldScrollPosY = scrollPosY;
|
|
||||||
|
|
||||||
// update scrollPos
|
|
||||||
scrollPosX = newScrollPosX;
|
|
||||||
scrollPosY = newScrollPosY;
|
|
||||||
|
|
||||||
// clamp scrollPos
|
|
||||||
scrollPosX = max(scrollPosX, 0);
|
|
||||||
scrollPosY = max(scrollPosY, 0);
|
|
||||||
|
|
||||||
scrollPosY = min(scrollPosY, (lines) - windowLines);
|
|
||||||
|
|
||||||
if (oldScrollPosX != scrollPosX || oldScrollPosY != scrollPosY)
|
|
||||||
{
|
|
||||||
int scrollX = oldScrollPosX - scrollPosX;
|
|
||||||
int scrollY = (oldScrollPosY - scrollPosY) * fontHeight;
|
|
||||||
|
|
||||||
RECT clip;
|
RECT clip;
|
||||||
GetClientRect(hwnd, &clip);
|
GetClientRect(hwnd, &clip);
|
||||||
|
|
||||||
@ -249,10 +244,55 @@ void TrackView::setScrollPos(HWND hwnd, int newScrollPosX, int newScrollPosY)
|
|||||||
NULL,
|
NULL,
|
||||||
SW_INVALIDATE
|
SW_INVALIDATE
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
void TrackView::setScrollPos(HWND hwnd, int newScrollPosX, int newScrollPosY)
|
||||||
|
{
|
||||||
|
// clamp newscrollPosX
|
||||||
|
newScrollPosX = max(scrollPosX, 0);
|
||||||
|
|
||||||
|
if (newScrollPosX != scrollPosX || newScrollPosY != scrollPosY)
|
||||||
|
{
|
||||||
|
int scrollX = scrollPosX - newScrollPosX;
|
||||||
|
int scrollY = scrollPosY - newScrollPosY;
|
||||||
|
|
||||||
|
// update scrollPos
|
||||||
|
scrollPosX = newScrollPosX;
|
||||||
|
scrollPosY = newScrollPosY;
|
||||||
|
|
||||||
|
scrollWindow(hwnd, scrollX, scrollY);
|
||||||
setupScrollBars(hwnd);
|
setupScrollBars(hwnd);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TrackView::setEditLine(HWND hwnd, int newEditLine)
|
||||||
|
{
|
||||||
|
int oldEditLine = editLine;
|
||||||
|
editLine = newEditLine;
|
||||||
|
|
||||||
|
// clamp to document
|
||||||
|
editLine = max(editLine, 0);
|
||||||
|
editLine = min(editLine, lines - 1);
|
||||||
|
|
||||||
|
RECT clientRect;
|
||||||
|
GetClientRect(hwnd, &clientRect);
|
||||||
|
|
||||||
|
RECT lineRect;
|
||||||
|
lineRect.left = clientRect.left;
|
||||||
|
lineRect.right = clientRect.right;
|
||||||
|
|
||||||
|
lineRect.top = getScreenY(oldEditLine);
|
||||||
|
lineRect.bottom = lineRect.top + fontHeight;
|
||||||
|
InvalidateRect(hwnd, &lineRect, TRUE);
|
||||||
|
|
||||||
|
lineRect.top = getScreenY(editLine);
|
||||||
|
lineRect.bottom = lineRect.top + fontHeight;
|
||||||
|
InvalidateRect(hwnd, &lineRect, TRUE);
|
||||||
|
|
||||||
|
setScrollPos(hwnd, scrollPosX, ((editLine + 1) * fontHeight) - (windowHeight / 2));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
static int getScrollPos(HWND hwnd, int bar)
|
static int getScrollPos(HWND hwnd, int bar)
|
||||||
{
|
{
|
||||||
SCROLLINFO si = { sizeof(si), SIF_TRACKPOS };
|
SCROLLINFO si = { sizeof(si), SIF_TRACKPOS };
|
||||||
@ -265,28 +305,28 @@ void TrackView::onVScroll(HWND hwnd, UINT sbCode, int newPos)
|
|||||||
switch (sbCode)
|
switch (sbCode)
|
||||||
{
|
{
|
||||||
case SB_TOP:
|
case SB_TOP:
|
||||||
setScrollPos(hwnd, scrollPosX, 0);
|
setEditLine(hwnd, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_LINEUP:
|
case SB_LINEUP:
|
||||||
setScrollPos(hwnd, scrollPosX, scrollPosY - 1);
|
setEditLine(hwnd, editLine - 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_LINEDOWN:
|
case SB_LINEDOWN:
|
||||||
setScrollPos(hwnd, scrollPosX, scrollPosY + 1);
|
setEditLine(hwnd, editLine + 1);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_PAGEUP:
|
case SB_PAGEUP:
|
||||||
setScrollPos(hwnd, scrollPosX, scrollPosY - windowLines);
|
setEditLine(hwnd, editLine - windowLines / 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_PAGEDOWN:
|
case SB_PAGEDOWN:
|
||||||
setScrollPos(hwnd, scrollPosX, scrollPosY + windowLines);
|
setEditLine(hwnd, editLine + windowLines / 2);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case SB_THUMBPOSITION:
|
case SB_THUMBPOSITION:
|
||||||
case SB_THUMBTRACK:
|
case SB_THUMBTRACK:
|
||||||
setScrollPos(hwnd, scrollPosX, getScrollPos(hwnd, SB_VERT));
|
setEditLine(hwnd, getScrollPos(hwnd, SB_VERT));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -327,11 +367,11 @@ void TrackView::onKeyDown(HWND hwnd, UINT keyCode, UINT flags)
|
|||||||
{
|
{
|
||||||
switch (keyCode)
|
switch (keyCode)
|
||||||
{
|
{
|
||||||
case VK_UP: setScrollPos(hwnd, scrollPosX, scrollPosY - 1); break;
|
case VK_UP: setEditLine(hwnd, editLine - 1); break;
|
||||||
case VK_DOWN: setScrollPos(hwnd, scrollPosX, scrollPosY + 1); break;
|
case VK_DOWN: setEditLine(hwnd, editLine + 1); break;
|
||||||
|
|
||||||
case VK_PRIOR: setScrollPos(hwnd, scrollPosX, scrollPosY - windowLines); break;
|
case VK_PRIOR: setEditLine(hwnd, editLine - windowLines / 2); break;
|
||||||
case VK_NEXT: setScrollPos(hwnd, scrollPosX, scrollPosY + windowLines); break;
|
case VK_NEXT: setEditLine(hwnd, editLine + windowLines / 2); break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -344,7 +384,8 @@ void TrackView::onSize(HWND hwnd, int width, int height)
|
|||||||
windowHeight = height;
|
windowHeight = height;
|
||||||
|
|
||||||
windowLines = (height - topMarginHeight) / fontHeight;
|
windowLines = (height - topMarginHeight) / fontHeight;
|
||||||
// windowLines = min((height - topMarginHeight) / fontHeight, lines);
|
|
||||||
|
setEditLine(hwnd, editLine);
|
||||||
setupScrollBars(hwnd);
|
setupScrollBars(hwnd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -18,9 +18,12 @@ public:
|
|||||||
|
|
||||||
void setupScrollBars(HWND hwnd);
|
void setupScrollBars(HWND hwnd);
|
||||||
void setScrollPos(HWND hwnd, int newScrollPosX, int newScrollPosY);
|
void setScrollPos(HWND hwnd, int newScrollPosX, int newScrollPosY);
|
||||||
|
void setEditLine(HWND hwnd, int newEditLine);
|
||||||
|
void scrollWindow(HWND hwnd, int newScrollPosX, int newScrollPosY);
|
||||||
|
|
||||||
int getScreenY(int line);
|
int getScreenY(int line);
|
||||||
|
|
||||||
|
int editLine;
|
||||||
int scrollPosX, scrollPosY;
|
int scrollPosX, scrollPosY;
|
||||||
int windowWidth, windowHeight;
|
int windowWidth, windowHeight;
|
||||||
int windowLines;
|
int windowLines;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user