all repos — mgba @ f6f3cb5d3d8b91dd603772ea0eebb2513562a0cf

mGBA Game Boy Advance Emulator

src/platform/qt/MemoryModel.h (view raw)

  1/* Copyright (c) 2013-2015 Jeffrey Pfau
  2 *
  3 * This Source Code Form is subject to the terms of the Mozilla Public
  4 * License, v. 2.0. If a copy of the MPL was not distributed with this
  5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
  6#ifndef QGBA_MEMORY_MODEL
  7#define QGBA_MEMORY_MODEL
  8
  9#include <QAbstractScrollArea>
 10#include <QFont>
 11#include <QSize>
 12#include <QStaticText>
 13#include <QVector>
 14#include <memory>
 15
 16#include <mgba-util/text-codec.h>
 17
 18struct mCore;
 19
 20namespace QGBA {
 21
 22class GameController;
 23
 24class MemoryModel : public QAbstractScrollArea {
 25Q_OBJECT
 26
 27public:
 28	MemoryModel(QWidget* parent = nullptr);
 29
 30	void setController(GameController* controller);
 31
 32	void setRegion(uint32_t base, uint32_t size, const QString& name = QString(), int segment = -1);
 33	void setSegment(int segment);
 34
 35	void setAlignment(int);
 36	int alignment() const { return m_align; }
 37
 38	QByteArray serialize();
 39	void deserialize(const QByteArray&);
 40	QString decodeText(const QByteArray&);
 41
 42public slots:
 43	void jumpToAddress(const QString& hex);
 44	void jumpToAddress(uint32_t);
 45
 46	void loadTBLFromPath(const QString& path);
 47	void loadTBL();
 48
 49	void copy();
 50	void paste();
 51	void save();
 52	void load();
 53
 54signals:
 55	void selectionChanged(uint32_t start, uint32_t end);
 56
 57protected:
 58	void resizeEvent(QResizeEvent*) override;
 59	void paintEvent(QPaintEvent*) override;
 60	void wheelEvent(QWheelEvent*) override;
 61	void mousePressEvent(QMouseEvent*) override;
 62	void mouseMoveEvent(QMouseEvent*) override;
 63	void keyPressEvent(QKeyEvent*) override;
 64
 65private:
 66	void boundsCheck();
 67
 68	bool isInSelection(uint32_t address);
 69	bool isEditing(uint32_t address);
 70	void drawEditingText(QPainter& painter, const QPointF& origin);
 71
 72	void adjustCursor(int adjust, bool shift);
 73
 74	class TextCodecFree {
 75	public:
 76		void operator()(TextCodec*);
 77	};
 78
 79	mCore* m_core = nullptr;
 80	std::unique_ptr<TextCodec, TextCodecFree> m_codec;
 81	QFont m_font;
 82	int m_cellHeight;
 83	int m_letterWidth;
 84	uint32_t m_base;
 85	uint32_t m_size;
 86	int m_top = 0;
 87	int m_align = 1;
 88	QMargins m_margins;
 89	QVector<QStaticText> m_staticNumbers;
 90	QVector<QStaticText> m_staticLatin1;
 91	QStaticText m_regionName;
 92	QSizeF m_cellSize;
 93	QPair<uint32_t, uint32_t> m_selection{0, 0};
 94	uint32_t m_selectionAnchor = 0;
 95	uint32_t m_buffer;
 96	int m_bufferedNybbles;
 97	int m_currentBank;
 98};
 99
100}
101
102#endif