better centering of the edit-line

This commit is contained in:
Erik Faye-Lund 2007-12-04 08:43:29 +00:00
parent d4a3bf9b85
commit aff6317808
2 changed files with 17 additions and 12 deletions

View File

@ -22,7 +22,15 @@ TrackView::TrackView(HWND hwnd)
windowWidth = -1; windowWidth = -1;
windowHeight = -1; windowHeight = -1;
editLine = 0; editLine = 0;
this->hwnd = hwnd; this->hwnd = hwnd;
editBrush = CreateSolidBrush(RGB(255, 255, 0));
}
TrackView::~TrackView()
{
DeleteObject(editBrush);
} }
int TrackView::getScreenY(int line) int TrackView::getScreenY(int line)
@ -69,9 +77,8 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
firstLine = min(max(firstLine, 0), lines - 1); firstLine = min(max(firstLine, 0), lines - 1);
lastLine = min(max(lastLine, 0), lines - 1); lastLine = min(max(lastLine, 0), lines - 1);
// int editLine = firstLine + (lastLine - firstLine) / 2; // printf("%d %d\n", firstLine, lastLine);
HBRUSH editBrush = CreateSolidBrush(RGB(255, 255, 0)); SetBkMode(hdc, TRANSPARENT);
// HBRUSH editBrush = CreateSolidBrush(RGB(255, 255, 0));
RECT topLeftCorner; RECT topLeftCorner;
topLeftCorner.top = 0; topLeftCorner.top = 0;
@ -83,9 +90,6 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
FillRect(hdc, &fillRect, (HBRUSH)GetStockObject(LTGRAY_BRUSH)); 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, OPAQUE);
for (int line = firstLine; line <= lastLine; ++line) for (int line = firstLine; line <= lastLine; ++line)
{ {
RECT leftMargin; RECT leftMargin;
@ -208,9 +212,6 @@ void TrackView::paintTracks(HDC hdc, RECT rcTracks)
topPadding.left = rcTracks.left; topPadding.left = rcTracks.left;
topPadding.right = rcTracks.right; topPadding.right = rcTracks.right;
FillRect(hdc, &topPadding, (HBRUSH)GetStockObject(GRAY_BRUSH)); FillRect(hdc, &topPadding, (HBRUSH)GetStockObject(GRAY_BRUSH));
DeleteObject(editBrush);
} }
void TrackView::setupScrollBars() void TrackView::setupScrollBars()
@ -294,7 +295,7 @@ void TrackView::setEditLine(int newEditLine)
lineRect.bottom = lineRect.top + fontHeight; lineRect.bottom = lineRect.top + fontHeight;
InvalidateRect(hwnd, &lineRect, TRUE); InvalidateRect(hwnd, &lineRect, TRUE);
setScrollPos(scrollPosX, ((editLine + 1) * fontHeight) - (windowHeight / 2)); setScrollPos(scrollPosX, (editLine * fontHeight) - ((windowHeight - topMarginHeight) / 2) + fontHeight / 2);
} }
static int getScrollPos(HWND hwnd, int bar) static int getScrollPos(HWND hwnd, int bar)

View File

@ -4,6 +4,7 @@ class TrackView
{ {
public: public:
TrackView(HWND hwnd); TrackView(HWND hwnd);
~TrackView();
// events // events
void onCreate(); void onCreate();
@ -31,6 +32,9 @@ public:
int windowLines; int windowLines;
HWND hwnd; HWND hwnd;
HBRUSH editBrush;
}; };
ATOM registerTrackViewWindowClass(HINSTANCE hInstance); ATOM registerTrackViewWindowClass(HINSTANCE hInstance);