mirror of
https://github.com/huderlem/porymap.git
synced 2026-08-26 10:35:55 -05:00
Merge pull request #750 from GriffinRichards/update-cursor-rects
Cursor refactoring
This commit is contained in:
@@ -23,11 +23,11 @@ public:
|
||||
QSpinBox * selectedElevation;
|
||||
qreal *opacity;
|
||||
void updateMovementPermissionSelection(QGraphicsSceneMouseEvent *event);
|
||||
virtual void paint(QGraphicsSceneMouseEvent*);
|
||||
virtual void floodFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void magicFill(QGraphicsSceneMouseEvent*);
|
||||
virtual void pick(QGraphicsSceneMouseEvent*);
|
||||
void draw(bool ignoreCache = false);
|
||||
virtual void paint(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void floodFill(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void magicFill(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void pick(QGraphicsSceneMouseEvent*) override;
|
||||
void draw(bool ignoreCache = false) override;
|
||||
|
||||
private:
|
||||
unsigned actionId_ = 0;
|
||||
@@ -36,16 +36,17 @@ private:
|
||||
|
||||
signals:
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, CollisionPixmapItem *);
|
||||
void hoveredMapMovementPermissionChanged(int, int);
|
||||
void hoveredMapMovementPermissionCleared();
|
||||
void hoverEntered(const QPoint &pos);
|
||||
void hoverChanged(const QPoint &pos);
|
||||
void hoverCleared();
|
||||
|
||||
protected:
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
};
|
||||
|
||||
#endif // COLLISIONPIXMAPITEM_H
|
||||
|
||||
@@ -8,78 +8,55 @@
|
||||
class CursorTileRect : public QGraphicsItem
|
||||
{
|
||||
public:
|
||||
CursorTileRect(bool *enabled, QRgb color);
|
||||
QRectF boundingRect() const override
|
||||
{
|
||||
int width = this->width;
|
||||
int height = this->height;
|
||||
if (this->singleTileMode) {
|
||||
width = 16;
|
||||
height = 16;
|
||||
} else if (!this->rightClickSelectionAnchored && this->smartPathMode && this->selectionHeight == 3 && this->selectionWidth == 3) {
|
||||
width = 32;
|
||||
height = 32;
|
||||
}
|
||||
CursorTileRect(const QSize &tileSize, const QRgb &color, QGraphicsItem *parent = nullptr);
|
||||
|
||||
QSize size() const;
|
||||
|
||||
QRectF boundingRect() const override {
|
||||
auto s = size();
|
||||
qreal penWidth = 4;
|
||||
return QRectF(-penWidth,
|
||||
-penWidth,
|
||||
width + penWidth * 2,
|
||||
height + penWidth * 2);
|
||||
s.width() + penWidth * 2,
|
||||
s.height() + penWidth * 2);
|
||||
}
|
||||
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override
|
||||
{
|
||||
if (!(*enabled)) return;
|
||||
int width = this->width;
|
||||
int height = this->height;
|
||||
if (this->singleTileMode) {
|
||||
width = 16;
|
||||
height = 16;
|
||||
} else if (this->smartPathInEffect()) {
|
||||
width = 32;
|
||||
height = 32;
|
||||
}
|
||||
|
||||
painter->setPen(this->color);
|
||||
painter->drawRect(x() - 1, y() - 1, width + 2, height + 2);
|
||||
void paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *) override {
|
||||
if (!isVisible()) return;
|
||||
auto rect = QRectF(pos(), size());
|
||||
painter->setPen(m_color);
|
||||
painter->drawRect(rect + QMargins(1,1,1,1)); // Fill
|
||||
painter->setPen(QColor(0, 0, 0));
|
||||
painter->drawRect(x() - 2, y() - 2, width + 4, height + 4);
|
||||
painter->drawRect(x(), y(), width, height);
|
||||
painter->drawRect(rect + QMargins(2,2,2,2)); // Outer border
|
||||
painter->drawRect(rect); // Inner border
|
||||
}
|
||||
|
||||
void initAnchor(int coordX, int coordY);
|
||||
void stopAnchor();
|
||||
void initRightClickSelectionAnchor(int coordX, int coordY);
|
||||
void stopRightClickSelectionAnchor();
|
||||
|
||||
void setSmartPathMode(bool enable) { this->smartPathMode = enable; }
|
||||
bool getSmartPathMode() const { return this->smartPathMode; }
|
||||
void setSmartPathMode(bool enable) { m_smartPathMode = enable; }
|
||||
bool getSmartPathMode() const { return m_smartPathMode; }
|
||||
|
||||
void setStraightPathMode(bool enable) { this->straightPathMode = enable; }
|
||||
bool getStraightPathMode() const { return this->straightPathMode; }
|
||||
|
||||
void setSingleTileMode(bool enable) { this->singleTileMode = enable; }
|
||||
bool getSingleTileMode() const { return this->singleTileMode; }
|
||||
void setSingleTileMode(bool enable) { m_singleTileMode = enable; }
|
||||
bool getSingleTileMode() const { return m_singleTileMode; }
|
||||
|
||||
void updateLocation(int x, int y);
|
||||
void updateSelectionSize(int width, int height);
|
||||
void setActive(bool active);
|
||||
bool getActive();
|
||||
bool *enabled;
|
||||
|
||||
private:
|
||||
bool active;
|
||||
int width;
|
||||
int height;
|
||||
bool anchored;
|
||||
bool rightClickSelectionAnchored;
|
||||
bool smartPathMode;
|
||||
bool straightPathMode;
|
||||
bool singleTileMode;
|
||||
int anchorCoordX;
|
||||
int anchorCoordY;
|
||||
int selectionWidth;
|
||||
int selectionHeight;
|
||||
QRgb color;
|
||||
bool smartPathInEffect();
|
||||
const QSize m_tileSize;
|
||||
QSize m_selectionSize;
|
||||
QPoint m_anchorCoord;
|
||||
QRgb m_color;
|
||||
|
||||
bool m_anchored = false;
|
||||
bool m_rightClickSelectionAnchored = false;
|
||||
bool m_smartPathMode = false;
|
||||
bool m_singleTileMode = false;
|
||||
|
||||
bool smartPathInEffect() const;
|
||||
};
|
||||
|
||||
|
||||
|
||||
@@ -86,9 +86,6 @@ public:
|
||||
void lockNondominantAxis(QGraphicsSceneMouseEvent *event);
|
||||
QPoint adjustCoords(QPoint pos);
|
||||
|
||||
void setEditsEnabled(bool enabled) { this->editsEnabled = enabled; }
|
||||
bool getEditsEnabled() { return this->editsEnabled; }
|
||||
|
||||
private:
|
||||
void paintSmartPath(int x, int y, bool fromScriptCall = false);
|
||||
static QList<int> smartPathTable;
|
||||
@@ -96,22 +93,21 @@ private:
|
||||
|
||||
unsigned actionId_ = 0;
|
||||
|
||||
bool editsEnabled = true;
|
||||
|
||||
signals:
|
||||
void startPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void endPaint(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void mouseEvent(QGraphicsSceneMouseEvent *, LayoutPixmapItem *);
|
||||
void hoveredMapMetatileChanged(const QPoint &pos);
|
||||
void hoveredMapMetatileCleared();
|
||||
void hoverEntered(const QPoint &pos);
|
||||
void hoverChanged(const QPoint &pos);
|
||||
void hoverCleared();
|
||||
|
||||
protected:
|
||||
void hoverMoveEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverEnterEvent(QGraphicsSceneHoverEvent*);
|
||||
void hoverLeaveEvent(QGraphicsSceneHoverEvent*);
|
||||
void mousePressEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseMoveEvent(QGraphicsSceneMouseEvent*);
|
||||
void mouseReleaseEvent(QGraphicsSceneMouseEvent*);
|
||||
virtual void hoverMoveEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void hoverEnterEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void hoverLeaveEvent(QGraphicsSceneHoverEvent*) override;
|
||||
virtual void mousePressEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseMoveEvent(QGraphicsSceneMouseEvent*) override;
|
||||
virtual void mouseReleaseEvent(QGraphicsSceneMouseEvent*) override;
|
||||
};
|
||||
|
||||
#endif // MAPPIXMAPITEM_H
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
class MovableRect : public QGraphicsRectItem
|
||||
{
|
||||
public:
|
||||
MovableRect(bool *enabled, const QRectF &rect, const QRgb &color);
|
||||
MovableRect(const QRectF &rect, const QRgb &color);
|
||||
QRectF boundingRect() const override {
|
||||
qreal penWidth = 4;
|
||||
return QRectF(-penWidth,
|
||||
@@ -29,12 +29,7 @@ public:
|
||||
}
|
||||
void updateLocation(int x, int y);
|
||||
|
||||
void setActive(bool active);
|
||||
bool getActive() const { return this->active; }
|
||||
|
||||
protected:
|
||||
bool *enabled = nullptr;
|
||||
bool active = true;
|
||||
QRectF baseRect;
|
||||
QRgb color;
|
||||
|
||||
@@ -48,7 +43,7 @@ class ResizableRect : public QObject, public MovableRect
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ResizableRect(QObject *parent, bool *enabled, int width, int height, QRgb color);
|
||||
ResizableRect(QObject *parent, int width, int height, QRgb color);
|
||||
|
||||
QRectF boundingRect() const override {
|
||||
return QRectF(this->rect() + QMargins(lineWidth, lineWidth, lineWidth, lineWidth));
|
||||
|
||||
Reference in New Issue
Block a user