Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- HurricanePootis - AUR maintainer
- lunairekitty - Additional CLI creation messages
- partyvan - Distance mapping support, initial big-endian support
- mikesk8r - Touchscreen support

## Artists
- [pastacrylic](https://linktr.ee/pastacrylic) - Splashscreen
Expand Down
35 changes: 31 additions & 4 deletions src/gui/widgets/QMareTextureWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#include <QApplication>
#include <QClipboard>
#include <QFileDialog>
#include <QEvent>
#include <QMenu>
#include <QMessageBox>
#include <QMouseEvent>
Expand Down Expand Up @@ -44,6 +45,7 @@ namespace {

QMareTextureWidget::QMareTextureWidget(QWidget* parent) : QWidget{parent} {
this->setContextMenuPolicy(Qt::CustomContextMenu);
this->setAttribute(Qt::WA_AcceptTouchEvents);

auto* contextMenu = new QMenu{this};

Expand Down Expand Up @@ -238,7 +240,7 @@ uint8_t QMareTextureWidget::getCurrentMip() const {
}

void QMareTextureWidget::setCurrentMip(uint8_t mip) {
this->currentMip = std::clamp<uint8_t>(mip, 0, this->vtf.getMipCount() - 1);
this->currentMip = qBound<uint8_t>(0, mip, this->vtf.getMipCount() - 1);
this->reloadCurrentTexture();
}

Expand All @@ -247,7 +249,7 @@ uint16_t QMareTextureWidget::getCurrentFrame() const {
}

void QMareTextureWidget::setCurrentFrame(uint16_t frame) {
this->currentFrame = std::clamp<uint16_t>(frame, 0, this->vtf.getFrameCount() - 1);
this->currentFrame = qBound<uint16_t>(0, frame, this->vtf.getFrameCount() - 1);
this->reloadCurrentTexture();
}

Expand All @@ -256,7 +258,7 @@ uint8_t QMareTextureWidget::getCurrentFace() const {
}

void QMareTextureWidget::setCurrentFace(uint8_t face) {
this->currentFace = std::clamp<uint8_t>(face, 0, this->vtf.getFaceCount() - 1);
this->currentFace = qBound<uint8_t>(0, face, this->vtf.getFaceCount() - 1);
this->reloadCurrentTexture();
}

Expand All @@ -265,7 +267,7 @@ uint16_t QMareTextureWidget::getCurrentDepth() const {
}

void QMareTextureWidget::setCurrentDepth(uint16_t depth) {
this->currentDepth = std::clamp<uint16_t>(depth, 0, this->vtf.getDepth() - 1);
this->currentDepth = qBound<uint16_t>(0, depth, this->vtf.getDepth() - 1);
this->reloadCurrentTexture();
}

Expand Down Expand Up @@ -328,6 +330,31 @@ QMareTextureWidget::operator bool() const {
return !this->path.isEmpty() && !this->textureCurrent.isNull();
}

bool QMareTextureWidget::event(QEvent* e) {
if (
QTouchEvent* touch;
(e->type() == QEvent::TouchBegin || e->type() == QEvent::TouchUpdate || e->type() == QEvent::TouchEnd) && ((touch = dynamic_cast<QTouchEvent*>(e)))
) {
if (const auto& points = touch->points(); points.length() >= 2) {
const auto point0 = points[0].position();
const auto point1 = points[1].position();
const auto rawDistance = static_cast<float>(qSqrt(qPow(point1.x() - point0.x(), 2) + qPow(point1.y() - point0.y(), 2)));

if (e->type() == QEvent::TouchBegin) {
this->previousDistance = rawDistance;
}
const auto distance = qBound(0.5f, rawDistance / this->previousDistance, 5.f);
this->previousDistance = rawDistance;
this->textureZoom *= distance;

this->update();
e->accept();
return true;
}
}
return this->QWidget::event(e);
}

void QMareTextureWidget::mouseMoveEvent(QMouseEvent* e) {
if (!(e->buttons() & Qt::LeftButton || e->buttons() & Qt::MiddleButton)) {
return;
Expand Down
4 changes: 4 additions & 0 deletions src/gui/widgets/QMareTextureWidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <QWidget>
#include <vtfpp/VTF.h>

class QEvent;
class QMouseEvent;
class QPaintEvent;
class QResizeEvent;
Expand Down Expand Up @@ -73,6 +74,8 @@ class QMareTextureWidget : public QWidget {
explicit operator bool() const;

protected:
bool event(QEvent* e) override;

void mouseMoveEvent(QMouseEvent* e) override;

void mousePressEvent(QMouseEvent* e) override;
Expand All @@ -91,6 +94,7 @@ class QMareTextureWidget : public QWidget {
QImage textureCurrent;
QPointF textureOffset;
float textureZoom = 1.f;
float previousDistance = 1.f;
uint8_t currentMip = 0;
uint8_t currentFace = 0;
uint16_t currentFrame = 0;
Expand Down