Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New color picker (drop tool) + macOS support #284

Merged
merged 25 commits into from
Oct 28, 2024
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,6 @@ svgo-linux
svgo-win.exe
skia-build
qt-*
sdk
build-release

21 changes: 18 additions & 3 deletions BUILD.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,30 @@ Generic instructions for building Friction on supported systems.
* `cmake` must be available in `PATH`
* `python3` must be available in `PATH`
* [LLVM](https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/LLVM-15.0.7-win64.exe) installed to default location
* Qt 5.15.14 libraries and headers in `friction\sdk`
* Qt 5.15 libraries and headers in `friction\sdk`
* See [configure_qt5.bat](src/scripts/configure_qt5.bat) and [build_qt5.bat](src/scripts/build_qt5.bat)
* QScintilla 2.14.1 libraries and headers in `friction\sdk`
* QScintilla libraries and headers in `friction\sdk`
* See [build_qscintilla.bat](src/scripts/build_qscintilla.bat)
* FFmpeg 4.2.9 libraries and headers in `friction\sdk`
* FFmpeg 4.2 libraries and headers in `friction\sdk`
* See [build_mxe_ffmpeg.sh](src/scripts/build_mxe_ffmpeg.sh) and [mxe](https://github.com/friction2d/mxe)

Binary SDK available [here](https://github.com/friction2d/friction-sdk/releases).

## Requirements on macOS

* macOS Monterey 12.7 x86-64
* Xcode 14.2 *(Apple clang 14)*

Install required packages from macports:

```
sudo port install qt5-qtbase qt5-qttools qt5-qtmultimedia qt5-qtdeclarative qscintilla-qt5 ffmpeg pkgconfig ninja
```
### Notes

* FFmpeg in macports is not supported *(render issues)*, a custom Portfile or build will be made available.
* `python` and `python3` must be available in `PATH` and point to a Python 3 install.

## Get Source

```
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ endif()
if(${BUILD_ENGINE})
add_subdirectory(src/engine)
endif()
if(UNIX)
if(UNIX AND NOT APPLE)
option(BUILD_TESTING "Don't build gperftools tests" OFF)
add_subdirectory(src/gperftools)
endif()
Expand Down
6 changes: 5 additions & 1 deletion src/app/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@ if(${LINUX_DEPLOY})
endif()

option(USE_SKIA_SYSTEM_LIBS "Use skia (third-party) system libraries on Linux" ON)
if(APPLE)
set(USE_SKIA_SYSTEM_LIBS OFF)
endif()

if(${USE_SKIA_SYSTEM_LIBS} AND UNIX)
pkg_check_modules(EXPAT REQUIRED expat)
pkg_check_modules(FREETYPE REQUIRED freetype2)
Expand All @@ -54,7 +58,7 @@ endif()

if(APPLE)
set(ICON_FILE ${CMAKE_CURRENT_SOURCE_DIR}/icons/${PROJECT_NAME}.icns)
set(MACOSX_BUNDLE_BUNDLE_NAME ${PROJECT_NAME})
set(MACOSX_BUNDLE_BUNDLE_NAME "Friction")
set(MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION})
set(MACOSX_BUNDLE_LONG_VERSION_STRING ${PROJECT_VERSION})
set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")
Expand Down
38 changes: 38 additions & 0 deletions src/app/GUI/canvaswindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ void CanvasWindow::setCanvasMode(const CanvasMode mode)
setCursor(Qt::ArrowCursor);
break;
case CanvasMode::pickFillStroke:
case CanvasMode::pickFillStrokeEvent:
setCursor(Qt::PointingHandCursor);
break;
case CanvasMode::circleCreate:
Expand Down Expand Up @@ -311,6 +312,26 @@ void CanvasWindow::mouseMoveEvent(QMouseEvent *event)

void CanvasWindow::wheelEvent(QWheelEvent *event)
{
#ifdef Q_OS_MAC
const bool alt = event->modifiers() & Qt::AltModifier;
if (!alt) { // handle event as pan gesture if not alt modifier
if (event->phase() == Qt::ScrollUpdate ||
event->phase() == Qt::ScrollMomentum) {
auto pos = mPrevMousePos;
if (event->angleDelta().y() != 0) {
pos.setY(pos.y() + event->angleDelta().y());
}
if (event->angleDelta().x() != 0) {
pos.setX(pos.x() + event->angleDelta().x());
}
translateView(pos - mPrevMousePos);
mPrevMousePos = pos;
update();
}
return;
}
if (event->angleDelta().y() == 0) { return; }
#endif
if (!mCurrentCanvas) { return; }
const auto ePos = event->position();
if (event->angleDelta().y() > 0) {
Expand Down Expand Up @@ -552,6 +573,23 @@ bool CanvasWindow::handleSelectAllKeyPress(QKeyEvent* event)
return true;
}

#ifdef Q_OS_MAC
bool CanvasWindow::handleNativeGestures(QNativeGestureEvent *event)
{
if (!event || !mCurrentCanvas) { return false; }
if (event->gestureType() == Qt::ZoomNativeGesture) {
const auto ePos = event->localPos();
if (event->value() == 0) { return false; }
if (event->value() > 0) { zoomView(1.1, ePos); }
else { zoomView(0.9, ePos); }
update();
} else if (event->gestureType() == Qt::SmartZoomNativeGesture) {
fitCanvasToSize(event->value() == 0 ? true : false);
} else { return false; }
return true;
}
#endif

// This does nothing ...
/*bool CanvasWindow::handleShiftKeysKeyPress(QKeyEvent* event) {
if(event->modifiers() & Qt::ControlModifier &&
Expand Down
8 changes: 7 additions & 1 deletion src/app/GUI/canvaswindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
#define CANVASWINDOW_H

#include <QWidget>
#ifdef Q_OS_MAC
#include <QNativeGestureEvent>
#endif
#include "widgets/glwindow.h"
#include "singlewidgettarget.h"
#include "misc/keyfocustarget.h"
Expand Down Expand Up @@ -158,6 +161,9 @@ class CanvasWindow : public GLWindow, public KeyFocusTarget
bool handleStartTransformKeyPress(const eKeyEvent &e);
bool handleSelectAllKeyPress(QKeyEvent *event);
//bool handleShiftKeysKeyPress(QKeyEvent *event);
#ifdef Q_OS_MAC
bool handleNativeGestures(QNativeGestureEvent *event);
#endif

signals:
void changeCanvasFrameRange(FrameRange);
Expand All @@ -171,7 +177,7 @@ class CanvasWindow : public GLWindow, public KeyFocusTarget
void zoomView(const qreal scaleBy,
const QPointF &absOrigin);

void fitCanvasToSize();
void fitCanvasToSize(const bool &fitWidth = false);
void resetTransformation();
void zoomInView();
void zoomOutView();
Expand Down
16 changes: 13 additions & 3 deletions src/app/GUI/canvaswindowevents.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void CanvasWindow::resizeEvent(QResizeEvent *e)
GLWindow::resizeEvent(e);
}

void CanvasWindow::fitCanvasToSize()
void CanvasWindow::fitCanvasToSize(const bool &fitWidth)
{
if (mFitToSizeBlocked) {
mFitToSizeBlocked = false;
Expand All @@ -83,7 +83,7 @@ void CanvasWindow::fitCanvasToSize()
const qreal widHeight = height() * pixelRatio;
const qreal widthScale = (widWidth - eSizesUI::widget) / canvasSize.width();
const qreal heightScale = (widHeight - eSizesUI::widget) / canvasSize.height();
const qreal minScale = qMin(widthScale, heightScale);
const qreal minScale = fitWidth ? widthScale : qMin(widthScale, heightScale);
translateView({(widWidth - canvasSize.width() * minScale) * 0.5,
(widHeight - canvasSize.height() * minScale) * 0.5});
mViewTransform.scale(minScale, minScale);
Expand All @@ -92,7 +92,7 @@ void CanvasWindow::fitCanvasToSize()

void CanvasWindow::zoomInView()
{
if (!mCurrentCanvas) { }return;
if (!mCurrentCanvas) { return; }
const auto canvasSize = mCurrentCanvas->getCanvasSize();
mViewTransform.translate(canvasSize.width() * 0.5, canvasSize.height() * 0.5);
mViewTransform.scale(1.1, 1.1);
Expand All @@ -112,6 +112,16 @@ bool CanvasWindow::event(QEvent *e)
{
if (e->type() == QEvent::ShowToParent) { fitCanvasToSize(); }
else if (e->type() == QEvent::Show) { KFT_setFocus(); }
#ifdef Q_OS_MAC
if (e->type() == QEvent::NativeGesture) {
auto g = dynamic_cast<QNativeGestureEvent*>(e);
if (g->gestureType() == Qt::ZoomNativeGesture) {
return handleNativeGestures(g);
} else if (g->gestureType() == Qt::SmartZoomNativeGesture) {
handleNativeGestures(g);
}
}
#endif
return QWidget::event(e);
}

Expand Down
6 changes: 5 additions & 1 deletion src/app/GUI/graphboxeslist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,11 @@ void KeysView::graphDeletePressed() {
mGPressedPoint = nullptr;
}

void KeysView::graphWheelEvent(QWheelEvent *event) {
void KeysView::graphWheelEvent(QWheelEvent *event)
{
#ifdef Q_OS_MAC
if (event->angleDelta().y() == 0) { return; }
#endif
if(event->modifiers() & Qt::ControlModifier) {
qreal valUnderMouse;
qreal frame;
Expand Down
44 changes: 41 additions & 3 deletions src/app/GUI/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,7 @@ MainWindow::MainWindow(Document& document,
, mViewFillStrokeAct(nullptr)
, mRenderWindow(nullptr)
, mRenderWindowAct(nullptr)
, mColorPickLabel(nullptr)
{
Q_ASSERT(!sInstance);
sInstance = this;
Expand Down Expand Up @@ -188,6 +189,8 @@ MainWindow::MainWindow(Document& document,
this, &MainWindow::openApplyExpressionDialog);
connect(&mDocument, &Document::newVideo,
this, &MainWindow::handleNewVideoClip);
connect(&mDocument, &Document::currentPixelColor,
this, &MainWindow::handleCurrentPixelColor);

setWindowIcon(QIcon::fromTheme(AppSupport::getAppName()));

Expand Down Expand Up @@ -327,6 +330,10 @@ MainWindow::MainWindow(Document& document,

statusBar()->addPermanentWidget(mCanvasToolBar);

mColorPickLabel = new QLabel(this);
mColorPickLabel->setVisible(false);
statusBar()->addWidget(mColorPickLabel);

// final layout
mUI = new UILayout(this);
std::vector<UILayout::Item> docks;
Expand Down Expand Up @@ -1045,13 +1052,19 @@ void MainWindow::setupMenuBar()
});

help->addSeparator();

QString cmdDefKey = "Ctrl+Space";
#ifdef Q_OS_MAC
cmdDefKey = "Alt+Space";
#endif

help->addAction(QIcon::fromTheme("cmd"),
tr("Command Palette"), this, [this]() {
CommandPalette dialog(mDocument, this);
dialog.exec();
}, QKeySequence(AppSupport::getSettings("shortcuts",
"cmdPalette",
"Ctrl+Space").toString()));
cmdDefKey).toString()));

help->addSeparator();
help->addAction(QIcon::fromTheme("renderlayers"),
Expand All @@ -1075,6 +1088,7 @@ void MainWindow::setupMenuBar()

setMenuBar(mMenuBar);

#ifndef Q_OS_MAC
const auto frictionButton = new QPushButton(this);
frictionButton->setFlat(true);
frictionButton->setIcon(QIcon::fromTheme(AppSupport::getAppID()));
Expand All @@ -1086,6 +1100,7 @@ void MainWindow::setupMenuBar()

mMenuBar->setCornerWidget(frictionButton,
Qt::TopRightCorner);
#endif
}

BoundingBox *MainWindow::getCurrentBox()
Expand Down Expand Up @@ -1325,8 +1340,11 @@ void MainWindow::setupToolBar()
mToolbar->setFocusPolicy(Qt::NoFocus);
mToolbar->setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
mToolbar->setMovable(false);
#ifdef Q_OS_MAC
mToolbar->setStyleSheet(QString("font-size: %1pt;").arg(font().pointSize()));
#endif
eSizesUI::widget.add(mToolbar, [this](const int size) {
mToolbar->setIconSize(QSize(size, size));
mToolbar->setIconSize({size, size});
});
addToolBar(Qt::TopToolBarArea, mToolbar);
}
Expand All @@ -1349,6 +1367,12 @@ void MainWindow::updateCanvasModeButtonsChecked()
mToolBoxDraw->setEnabled(drawMode);
mToolBoxDraw->setVisible(drawMode);
mLocalPivotAct->setEnabled(pointMode || boxMode);

if (mColorPickLabel) {
mColorPickLabel->clear();
mColorPickLabel->setVisible(mode == CanvasMode::pickFillStroke ||
mode == CanvasMode::pickFillStrokeEvent);
}
}

void MainWindow::setResolutionValue(const qreal value)
Expand Down Expand Up @@ -2090,4 +2114,18 @@ void MainWindow::handleNewVideoClip(const VideoBox::VideoSpecs &specs)
// open dialog if ask
AdjustSceneDialog dialog(scene, specs, this);
dialog.exec();
}
}

void MainWindow::handleCurrentPixelColor(const QColor &color)
{
if (!color.isValid()) {
mColorPickLabel->clear();
return;
}
mColorPickLabel->setText(QString("&nbsp;&nbsp;<span style=\"background-color: %4;\">"
"&nbsp;&nbsp;&nbsp;&nbsp;</span>&nbsp;&nbsp;"
"<b>RGB</b> %1, %2, %3").arg(QString::number(color.redF()),
QString::number(color.greenF()),
QString::number(color.blueF()),
color.name()));
}
4 changes: 4 additions & 0 deletions src/app/GUI/mainwindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ class MainWindow : public QMainWindow

void handleNewVideoClip(const VideoBox::VideoSpecs &specs);

void handleCurrentPixelColor(const QColor &color);

TimelineDockWidget *mTimeline;
RenderWidget *mRenderWidget;

Expand Down Expand Up @@ -380,6 +382,8 @@ class MainWindow : public QMainWindow
void initRenderPresets(const bool reinstall = false);
void askInstallRenderPresets();

QLabel *mColorPickLabel;

protected:
void keyPressEvent(QKeyEvent *event);
bool eventFilter(QObject *obj, QEvent *e);
Expand Down
10 changes: 6 additions & 4 deletions src/app/GUI/toolbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,8 @@ void MainWindow::setupToolBoxMain()
mToolBoxGroupMain->addAction(nullModeAct);

// pickMode
/*QAction *pickModeAct = new QAction(QIcon::fromTheme("pick"),
tr("Pick Mode"),
QAction *pickModeAct = new QAction(QIcon::fromTheme("pick"),
tr("Color Pick Mode"),
this);
pickModeAct->setCheckable(true);
pickModeAct->setShortcut(QKeySequence(AppSupport::getSettings("shortcuts",
Expand All @@ -265,11 +265,13 @@ void MainWindow::setupToolBoxMain()
&Document::canvasModeSet,
this,
[this, pickModeAct]() {
if (mDocument.fCanvasMode == CanvasMode::pickFillStroke) {
if (mDocument.fCanvasMode == CanvasMode::pickFillStroke ||
mDocument.fCanvasMode == CanvasMode::pickFillStrokeEvent) {
pickModeAct->setChecked(true);
}
});
mToolBoxGroupMain->addAction(pickModeAct);*/

mToolBoxGroupMain->addAction(pickModeAct);

mToolBoxMain->addActions(mToolBoxGroupMain->actions());

Expand Down
2 changes: 1 addition & 1 deletion src/app/icons
Submodule icons updated 212 files
Loading
Loading