rocket/editor/trackview.h
Erik Faye-Lund 31698760f1 const
2010-03-19 17:41:32 +01:00

200 lines
4.7 KiB
C++

/* Copyright (C) 2007-2008 Erik Faye-Lund and Egbert Teeselink
* For conditions of distribution and use, see copyright notice in LICENSE.TXT
*/
#pragma once
#include "syncdocument.h"
#include <string>
// custom messages
#define WM_REDO (WM_USER + 0x40 + 3)
#define WM_ROWCHANGED (WM_USER + 0x40 + 4)
#define WM_TRACKCHANGED (WM_USER + 0x40 + 5)
#define WM_CURRVALDIRTY (WM_USER + 0x40 + 6)
class TrackView
{
public:
TrackView();
~TrackView();
HWND create(HINSTANCE hInstance, HWND hwndParent);
HWND getWin() const { return hwnd; }
void setDocument(SyncDocument *document) { this->document = document; }
const SyncDocument *getDocument() const { return document; }
SyncDocument *getDocument() { return document; }
void setRows(size_t rows);
size_t getRows() const
{
if (NULL == document) return 0;
return document->getRows();
}
void setFont(HFONT font);
void editEnterValue();
void editDelete();
void editCopy();
void editCut();
void editPaste();
void editBiasValue(float amount);
void editToggleInterpolationType();
void setEditRow(int newEditRow);
int getEditRow() const { return editRow; }
void setEditTrack(int newEditTrack);
int getEditTrack() const { return editTrack; }
void selectAll()
{
selectStartTrack = int(this->getTrackCount()) - 1;
selectStopTrack = editTrack = 0;
selectStartRow = int(this->getRows()) - 1;
selectStopRow = editRow = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectTrack(int track)
{
selectStartTrack = selectStopTrack = editTrack = track;
selectStartRow = int(this->getRows()) - 1;
selectStopRow = editRow = 0;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectRow(int row)
{
selectStartTrack = int(this->getTrackCount()) - 1;
selectStopTrack = editTrack = 0;
selectStartRow = selectStopRow = editRow = row;
InvalidateRect(hwnd, NULL, FALSE);
}
void selectNone()
{
selectStartTrack = selectStopTrack = editTrack;
selectStartRow = selectStopRow = editRow;
InvalidateRect(hwnd, NULL, FALSE);
}
private:
// some nasty hackery to forward the window messages
friend static LRESULT CALLBACK trackViewWindowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
LRESULT windowProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam);
// events
LRESULT onCreate();
LRESULT onPaint();
LRESULT onVScroll(UINT sbCode, int newPos);
LRESULT onHScroll(UINT sbCode, int newPos);
LRESULT onSize(int width, int height);
LRESULT onKeyDown(UINT keyCode, UINT flags);
LRESULT onChar(UINT keyCode, UINT flags);
void paintTracks(HDC hdc, RECT rcTracks);
void paintTopMargin(HDC hdc, RECT rcTracks);
void setupScrollBars();
void setScrollPos(int newScrollPosX, int newScrollPosY);
void scrollWindow(int newScrollPosX, int newScrollPosY);
void invalidateRange(int startTrack, int stopTrack, int startRow, int stopRow)
{
RECT rect;
rect.left = getScreenX(min(startTrack, stopTrack));
rect.right = getScreenX(max(startTrack, stopTrack) + 1);
rect.top = getScreenY(min(startRow, stopRow));
rect.bottom = getScreenY(max(startRow, stopRow) + 1);
InvalidateRect(hwnd, &rect, FALSE);
}
void invalidatePos(int track, int row)
{
RECT rect;
rect.left = getScreenX(track);
rect.right = getScreenX(track + 1);
rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, FALSE);
}
void invalidateRow(int row)
{
RECT clientRect;
GetClientRect(hwnd, &clientRect);
RECT rect;
rect.left = clientRect.left;
rect.right = clientRect.right;
rect.top = getScreenY(row);
rect.bottom = getScreenY(row + 1);
InvalidateRect(hwnd, &rect, FALSE);
}
void invalidateTrack(int track)
{
RECT clientRect;
GetClientRect(hwnd, &clientRect);
RECT rect;
rect.left = getScreenX(track);
rect.right = getScreenX(track + 1);
rect.top = clientRect.top;
rect.bottom = clientRect.bottom;
InvalidateRect(hwnd, &rect, FALSE);
}
int getScreenY(int row) const;
int getScreenX(size_t track) const;
size_t getTrackCount() const
{
const SyncDocument *doc = getDocument();
if (NULL == doc) return 0;
return int(doc->getTrackOrderCount());
};
int selectStartTrack, selectStopTrack;
int selectStartRow, selectStopRow;
HFONT font;
int rowHeight;
int fontWidth;
int trackWidth;
int topMarginHeight;
int leftMarginWidth;
HBRUSH bgBaseBrush, bgDarkBrush;
HBRUSH selectBaseBrush, selectDarkBrush;
HPEN rowPen, rowSelectPen;
HBRUSH editBrush;
HPEN lerpPen, cosinePen, rampPen;
/* cursor position */
int editRow, editTrack;
int scrollPosX, scrollPosY;
int windowWidth, windowHeight;
int windowRows, windowTracks;
SyncDocument *document;
std::basic_string<TCHAR> editString;
HWND hwnd;
UINT clipboardFormat;
};
ATOM registerTrackViewWindowClass(HINSTANCE hInstance);