Qt Tas editor branch view in work.

This commit is contained in:
mjbudd77 2021-11-15 20:38:14 -05:00
parent 27e0f16e08
commit 13f8180c96
4 changed files with 169 additions and 71 deletions

View File

@ -27,5 +27,6 @@
<file>icons/JumpTarget.png</file> <file>icons/JumpTarget.png</file>
<file>icons/Undo.png</file> <file>icons/Undo.png</file>
<file>icons/find.png</file> <file>icons/find.png</file>
<file>icons/cloud.png</file>
</qresource> </qresource>
</RCC> </RCC>

View File

@ -606,6 +606,10 @@ error:
void BOOKMARKS::redrawBookmarksSectionCaption() void BOOKMARKS::redrawBookmarksSectionCaption()
{ {
int prev_edit_mode = editMode; int prev_edit_mode = editMode;
if ( taseditorConfig == NULL )
{
return;
}
if (taseditorConfig->displayBranchesTree) if (taseditorConfig->displayBranchesTree)
{ {
editMode = EDIT_MODE_BRANCHES; editMode = EDIT_MODE_BRANCHES;

View File

@ -23,9 +23,12 @@ Branches - Manager of Branches
#include <math.h> #include <math.h>
#include <zlib.h> #include <zlib.h>
#include <QFontMetrics>
#include "utils/xstring.h" #include "utils/xstring.h"
#include <Qt/TasEditor/taseditor_project.h> #include "Qt/fceuWrapper.h"
#include <Qt/TasEditor/TasEditorWindow.h> #include "Qt/TasEditor/taseditor_project.h"
#include "Qt/TasEditor/TasEditorWindow.h"
//LRESULT APIENTRY BranchesBitmapWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); //LRESULT APIENTRY BranchesBitmapWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
@ -51,17 +54,51 @@ int corners_cursor_shift[BRANCHES_ANIMATION_FRAMES] = {0, 0, 1, 1, 2, 2, 2, 2, 1
BRANCHES::BRANCHES(QWidget *parent) BRANCHES::BRANCHES(QWidget *parent)
: QWidget(parent) : QWidget(parent)
{ {
std::string fontString;
//this->parent = qobject_cast <TasEditorWindow*>( parent ); //this->parent = qobject_cast <TasEditorWindow*>( parent );
this->setFocusPolicy(Qt::StrongFocus); this->setFocusPolicy(Qt::StrongFocus);
this->setMouseTracking(true); this->setMouseTracking(true);
this->setMinimumWidth(BRANCHES_BITMAP_WIDTH); this->setMinimumWidth(BRANCHES_BITMAP_WIDTH);
this->setMinimumHeight(BRANCHES_BITMAP_HEIGHT); this->setMinimumHeight(BRANCHES_BITMAP_HEIGHT);
g_config->getOption("SDL.TasBranchFont", &fontString);
if ( fontString.size() > 0 )
{
font.fromString( QString::fromStdString( fontString ) );
}
else
{
font.setFamily("Courier New");
font.setStyle( QFont::StyleNormal );
font.setStyleHint( QFont::Monospace );
}
calcFontData();
} }
BRANCHES::~BRANCHES(void) BRANCHES::~BRANCHES(void)
{ {
} }
//----------------------------------------------------------------------------
void BRANCHES::calcFontData(void)
{
QWidget::setFont(font);
QFontMetrics metrics(font);
#if QT_VERSION > QT_VERSION_CHECK(5, 11, 0)
pxCharWidth = metrics.horizontalAdvance(QLatin1Char('2'));
#else
pxCharWidth = metrics.width(QLatin1Char('2'));
#endif
pxCharHeight = metrics.capHeight();
pxLineSpacing = metrics.lineSpacing();
pxBoxWidth = pxLineSpacing;
pxBoxHeight = pxLineSpacing;
}
void BRANCHES::init() void BRANCHES::init()
{ {
free(); free();
@ -120,7 +157,7 @@ void BRANCHES::init()
for (int i = TOTAL_BOOKMARKS; i >= 0; i--) for (int i = TOTAL_BOOKMARKS; i >= 0; i--)
{ {
branchX[i] = branchPreviousX[i] = branchCurrentX[i] = EMPTY_BRANCHES_X_BASE; branchX[i] = branchPreviousX[i] = branchCurrentX[i] = EMPTY_BRANCHES_X_BASE;
branchY[i] = branchPreviousY[i] = branchCurrentY[i] = EMPTY_BRANCHES_Y_BASE + EMPTY_BRANCHES_Y_FACTOR * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS); branchY[i] = branchPreviousY[i] = branchCurrentY[i] = EMPTY_BRANCHES_Y_BASE + pxBoxHeight * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS);
} }
reset(); reset();
cornersCursorX = cornersCursorY = 0; cornersCursorX = cornersCursorY = 0;
@ -227,7 +264,7 @@ void BRANCHES::reset()
branchPreviousX[i] = branchCurrentX[i]; branchPreviousX[i] = branchCurrentX[i];
branchPreviousY[i] = branchCurrentY[i]; branchPreviousY[i] = branchCurrentY[i];
branchX[i] = EMPTY_BRANCHES_X_BASE; branchX[i] = EMPTY_BRANCHES_X_BASE;
branchY[i] = EMPTY_BRANCHES_Y_BASE + EMPTY_BRANCHES_Y_FACTOR * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS); branchY[i] = EMPTY_BRANCHES_Y_BASE + pxBoxHeight * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS);
} }
cloudPreviousX = cloudCurrentX; cloudPreviousX = cloudCurrentX;
cloudX = cloudCurrentX = BRANCHES_CLOUD_X; cloudX = cloudCurrentX = BRANCHES_CLOUD_X;
@ -515,6 +552,10 @@ void BRANCHES::redrawBranchesBitmap()
void BRANCHES::paintEvent(QPaintEvent *event) void BRANCHES::paintEvent(QPaintEvent *event)
{ {
int x,y;
char txt[4];
QPixmap cloud(":/icons/cloud.png");
QPainter painter(this); QPainter painter(this);
viewWidth = event->rect().width(); viewWidth = event->rect().width();
@ -623,73 +664,112 @@ void BRANCHES::paintEvent(QPaintEvent *event)
} }
} }
} }
// if (changesSinceCurrentBranch) if (changesSinceCurrentBranch)
// { {
// if (isSafeToShowBranchesData() && bookmarks->itemUnderMouse == ITEM_UNDER_MOUSE_FIREBALL) if (isSafeToShowBranchesData() && bookmarks->itemUnderMouse == ITEM_UNDER_MOUSE_FIREBALL)
// SelectObject(hBitmapDC, selectPen); {
// else //SelectObject(hBitmapDC, selectPen);
// SelectObject(hBitmapDC, timelinePen); }
// if (currentBranch == ITEM_UNDER_MOUSE_CLOUD) else
// { {
// parentX = cloudCurrentX; //SelectObject(hBitmapDC, timelinePen);
// parentY = BRANCHES_CLOUD_Y; }
// } else if (currentBranch == ITEM_UNDER_MOUSE_CLOUD)
// { {
// parentX = branchCurrentX[currentBranch]; parentX = cloudCurrentX;
// parentY = branchCurrentY[currentBranch]; parentY = BRANCHES_CLOUD_Y;
// } }
// MoveToEx(hBitmapDC, parentX, parentY, 0); else
// tempBranchX = branchCurrentX[ITEM_UNDER_MOUSE_FIREBALL]; {
// tempBranchY = branchCurrentY[ITEM_UNDER_MOUSE_FIREBALL]; parentX = branchCurrentX[currentBranch];
// LineTo(hBitmapDC, tempBranchX, tempBranchY); parentY = branchCurrentY[currentBranch];
// } }
//MoveToEx(hBitmapDC, parentX, parentY, 0);
tempBranchX = branchCurrentX[ITEM_UNDER_MOUSE_FIREBALL];
tempBranchY = branchCurrentY[ITEM_UNDER_MOUSE_FIREBALL];
//LineTo(hBitmapDC, tempBranchX, tempBranchY);
painter.drawLine( parentX, parentY, tempBranchX, tempBranchY );
}
// // cloud // // cloud
// TransparentBlt(hBitmapDC, cloudCurrentX - BRANCHES_CLOUD_HALFWIDTH, BRANCHES_CLOUD_Y - BRANCHES_CLOUD_HALFHEIGHT, BRANCHES_CLOUD_WIDTH, BRANCHES_CLOUD_HEIGHT, hSpritesheetDC, BRANCHES_CLOUD_SPRITESHEET_X, BRANCHES_CLOUD_SPRITESHEET_Y, BRANCHES_CLOUD_WIDTH, BRANCHES_CLOUD_HEIGHT, 0x00FF00); // TransparentBlt(hBitmapDC, cloudCurrentX - BRANCHES_CLOUD_HALFWIDTH, BRANCHES_CLOUD_Y - BRANCHES_CLOUD_HALFHEIGHT, BRANCHES_CLOUD_WIDTH, BRANCHES_CLOUD_HEIGHT, hSpritesheetDC, BRANCHES_CLOUD_SPRITESHEET_X, BRANCHES_CLOUD_SPRITESHEET_Y, BRANCHES_CLOUD_WIDTH, BRANCHES_CLOUD_HEIGHT, 0x00FF00);
painter.drawPixmap( cloudCurrentX - BRANCHES_CLOUD_HALFWIDTH, BRANCHES_CLOUD_Y - BRANCHES_CLOUD_HALFHEIGHT, BRANCHES_CLOUD_WIDTH, BRANCHES_CLOUD_HEIGHT, cloud );
// // branches rectangles // // branches rectangles
// for (int i = 0; i < TOTAL_BOOKMARKS; ++i) for (int i = 0; i < TOTAL_BOOKMARKS; ++i)
// { {
// tempRect.left = branchCurrentX[i] - DIGIT_RECT_HALFWIDTH; x = branchCurrentX[i] - pxBoxWidth/2;
// tempRect.top = branchCurrentY[i] - DIGIT_RECT_HALFHEIGHT; y = branchCurrentY[i] - pxBoxHeight/2;
// tempRect.right = tempRect.left + DIGIT_RECT_WIDTH; //tempRect.right = tempRect.left + DIGIT_RECT_WIDTH;
// tempRect.bottom = tempRect.top + DIGIT_RECT_HEIGHT; //tempRect.bottom = tempRect.top + DIGIT_RECT_HEIGHT;
// if (!bookmarks->bookmarksArray[i].notEmpty && bookmarks->bookmarksArray[i].floatingPhase > 0) if (!bookmarks->bookmarksArray[i].notEmpty && bookmarks->bookmarksArray[i].floatingPhase > 0)
// { {
// tempRect.left += bookmarks->bookmarksArray[i].floatingPhase; //tempRect.left += bookmarks->bookmarksArray[i].floatingPhase;
// tempRect.right += bookmarks->bookmarksArray[i].floatingPhase; //tempRect.right += bookmarks->bookmarksArray[i].floatingPhase;
// } }
// if (bookmarks->bookmarksArray[i].flashPhase) if (bookmarks->bookmarksArray[i].flashPhase)
// { {
// // draw colored rect // draw colored rect
// HBRUSH color_brush = CreateSolidBrush(bookmark_flash_colors[bookmarks.bookmarksArray[i].flashType][bookmarks.bookmarksArray[i].flashPhase]); //HBRUSH color_brush = CreateSolidBrush(bookmark_flash_colors[bookmarks.bookmarksArray[i].flashType][bookmarks.bookmarksArray[i].flashPhase]);
// FrameRect(hBitmapDC, &tempRect, color_brush); //FrameRect(hBitmapDC, &tempRect, color_brush);
// DeleteObject(color_brush); //DeleteObject(color_brush);
// } else }
// { else
// // draw black rect {
// FrameRect(hBitmapDC, &tempRect, normalBrush); painter.setPen( QColor( 0x0, 0x0, 0x0 ) );
// } // draw black rect
// } //FrameRect(hBitmapDC, &tempRect, normalBrush);
// // digits }
// for (int i = 0; i < TOTAL_BOOKMARKS; ++i) if (i == bookmarks->itemUnderMouse)
// { {
// tempBranchX = branchCurrentX[i] - DIGIT_BITMAP_HALFWIDTH; painter.fillRect( x, y, pxBoxWidth, pxBoxHeight, QColor(255,235,154) );
// tempBranchY = branchCurrentY[i] - DIGIT_BITMAP_HALFHEIGHT; }
// if (i == currentBranch) else
// { {
// if (i == bookmarks.itemUnderMouse) painter.fillRect( x, y, pxBoxWidth, pxBoxHeight, QColor(255,255,255) );
// BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH + BLUE_DIGITS_SPRITESHEET_DX, MOUSEOVER_DIGITS_SPRITESHEET_DY, SRCCOPY); }
// else painter.drawRect( x, y, pxBoxWidth, pxBoxHeight );
// BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH + BLUE_DIGITS_SPRITESHEET_DX, 0, SRCCOPY); }
// } else // digits
// { for (int i = 0; i < TOTAL_BOOKMARKS; ++i)
// if (!bookmarks.bookmarksArray[i].notEmpty && bookmarks.bookmarksArray[i].floatingPhase > 0) {
// tempBranchX += bookmarks.bookmarksArray[i].floatingPhase; txt[0] = i + '0';
// if (i == bookmarks.itemUnderMouse) txt[1] = 0;
// BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH, MOUSEOVER_DIGITS_SPRITESHEET_DY, SRCCOPY);
// else tempBranchX = branchCurrentX[i] - pxCharWidth/2;
// BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH, 0, SRCCOPY); tempBranchY = branchCurrentY[i] + pxCharHeight/2;
// }
// } if (i == currentBranch)
{
if (i == bookmarks->itemUnderMouse)
{
//BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH + BLUE_DIGITS_SPRITESHEET_DX, MOUSEOVER_DIGITS_SPRITESHEET_DY, SRCCOPY);
}
else
{
//BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH + BLUE_DIGITS_SPRITESHEET_DX, 0, SRCCOPY);
}
painter.setPen( QColor( 58, 179, 255 ) );
painter.drawText( tempBranchX, tempBranchY, tr(txt) );
}
else
{
painter.setPen( QColor( 0, 194, 64 ) );
if (!bookmarks->bookmarksArray[i].notEmpty && bookmarks->bookmarksArray[i].floatingPhase > 0)
{
tempBranchX += bookmarks->bookmarksArray[i].floatingPhase;
}
if (i == bookmarks->itemUnderMouse)
{
//BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH, MOUSEOVER_DIGITS_SPRITESHEET_DY, SRCCOPY);
}
else
{
//BitBlt(hBitmapDC, tempBranchX, tempBranchY, DIGIT_BITMAP_WIDTH, DIGIT_BITMAP_HEIGHT, hSpritesheetDC, i * DIGIT_BITMAP_WIDTH, 0, SRCCOPY);
}
painter.drawText( tempBranchX, tempBranchY, tr(txt) );
}
}
// if (isSafeToShowBranchesData()) // if (isSafeToShowBranchesData())
// { // {
// SetBkMode(hBitmapDC, TRANSPARENT); // SetBkMode(hBitmapDC, TRANSPARENT);
@ -1274,7 +1354,7 @@ void BRANCHES::recalculateBranchesTree()
} else } else
{ {
branchX[i] = EMPTY_BRANCHES_X_BASE; branchX[i] = EMPTY_BRANCHES_X_BASE;
branchY[i] = EMPTY_BRANCHES_Y_BASE + EMPTY_BRANCHES_Y_FACTOR * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS); branchY[i] = EMPTY_BRANCHES_Y_BASE + pxBoxHeight * ((i + TOTAL_BOOKMARKS - 1) % TOTAL_BOOKMARKS);
} }
if (max_x < branchX[i]) max_x = branchX[i]; if (max_x < branchX[i]) max_x = branchX[i];
} }
@ -1283,17 +1363,21 @@ void BRANCHES::recalculateBranchesTree()
// also set pixel position of "current_pos" // also set pixel position of "current_pos"
branchX[ITEM_UNDER_MOUSE_FIREBALL] = cloud_prefix + gridX[ITEM_UNDER_MOUSE_FIREBALL] * grid_width; branchX[ITEM_UNDER_MOUSE_FIREBALL] = cloud_prefix + gridX[ITEM_UNDER_MOUSE_FIREBALL] * grid_width;
branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y + gridY[ITEM_UNDER_MOUSE_FIREBALL] * grid_halfheight; branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y + gridY[ITEM_UNDER_MOUSE_FIREBALL] * grid_halfheight;
} else if (currentBranch >= 0) }
else if (currentBranch >= 0)
{ {
branchX[ITEM_UNDER_MOUSE_FIREBALL] = cloud_prefix + gridX[currentBranch] * grid_width; branchX[ITEM_UNDER_MOUSE_FIREBALL] = cloud_prefix + gridX[currentBranch] * grid_width;
branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y + gridY[currentBranch] * grid_halfheight; branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y + gridY[currentBranch] * grid_halfheight;
} else }
else
{ {
branchX[ITEM_UNDER_MOUSE_FIREBALL] = 0; branchX[ITEM_UNDER_MOUSE_FIREBALL] = 0;
branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y; branchY[ITEM_UNDER_MOUSE_FIREBALL] = BRANCHES_CLOUD_Y;
} }
if (max_x < branchX[ITEM_UNDER_MOUSE_FIREBALL]) if (max_x < branchX[ITEM_UNDER_MOUSE_FIREBALL])
{
max_x = branchX[ITEM_UNDER_MOUSE_FIREBALL]; max_x = branchX[ITEM_UNDER_MOUSE_FIREBALL];
}
// align whole tree horizontally // align whole tree horizontally
cloudX = (BRANCHES_BITMAP_WIDTH + BASE_HORIZONTAL_SHIFT - max_x) / 2; cloudX = (BRANCHES_BITMAP_WIDTH + BASE_HORIZONTAL_SHIFT - max_x) / 2;

View File

@ -3,6 +3,7 @@
#include <stdint.h> #include <stdint.h>
#include <vector> #include <vector>
#include <QFont>
#include <QWidget> #include <QWidget>
#define BRANCHES_ANIMATION_TICK 40 // animate at 25FPS #define BRANCHES_ANIMATION_TICK 40 // animate at 25FPS
@ -142,6 +143,7 @@ protected:
void paintEvent(QPaintEvent *event); void paintEvent(QPaintEvent *event);
private: private:
void calcFontData(void);
void setCurrentPosTimestamp(); void setCurrentPosTimestamp();
void recalculateParents(); void recalculateParents();
@ -186,8 +188,15 @@ private:
//GRADIENT_RECT gRect; //GRADIENT_RECT gRect;
//RECT branchesBitmapRect; //RECT branchesBitmapRect;
QFont font;
int viewWidth; int viewWidth;
int viewHeight; int viewHeight;
int pxCharWidth;
int pxCharHeight;
int pxLineSpacing;
int pxBoxWidth;
int pxBoxHeight;
// temps // temps
std::vector<int> gridX; // measured in grid units, not in pixels std::vector<int> gridX; // measured in grid units, not in pixels