Skip to content

Instantly share code, notes, and snippets.

View paulmasri's full-sized avatar

Paul Masri-Stone paulmasri

View GitHub Profile
@paulmasri
paulmasri / AppDataLocation.cpp
Created January 20, 2025 10:53
Get UWP app local data location
#include "AppDataLocation.h"
#ifdef NEEDS_UWP_APP_DATA_LOCATION
#include <winrt/Windows.Storage.h>
#include <winrt/Windows.Foundation.h>
#endif
QString appDataLocationPath()
{
static QString path; // calculate it only once and store it here
@paulmasri
paulmasri / CMakeLists.txt
Last active April 25, 2025 21:18
CMake for Qt 6 + Xcode (target iOS)
# This is an anonymised and annotated version of my CMake
# This enabled me to build / archive / validate / distribute my app in Xcode
# without having to manually edit any configuration in Xcode
cmake_minimum_required(VERSION 3.24)
# Some variables needed more than once below
set(MY_APP_PROJECT_NAME "My App")
set(PROJECT_VERSION 1.2.3)
set(MY_APP_REVERSE_DNS_IDENTIFIER "com.mycompany.myapp")
@paulmasri
paulmasri / CMakeLists.txt
Created May 16, 2022 13:49
CMake using qt_add_qml_module: how to handle dependency on QtMultimedia (or other Qt non-core module)
cmake_minimum_required(VERSION 3.16)
project(minimalSynthesizer VERSION 0.1 LANGUAGES CXX)
set(CMAKE_AUTOMOC ON)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
find_package(Qt6 6.2 COMPONENTS Quick Multimedia REQUIRED)
qt_add_executable(appSynth
@paulmasri
paulmasri / Utility2D.cs
Created March 29, 2021 14:49
Unity Utility2D.cs
using UnityEngine;
using System.Collections.Generic;
namespace PaulMasriStone.Utility2D
{
public static class Utility2D
{
public static bool IsPointWithinCollider2D(Vector2 targetPoint, Vector2 externalPoint, int layerMask = Physics2D.DefaultRaycastLayers)
{
var direction = (targetPoint - externalPoint).normalized;
@paulmasri
paulmasri / LateFixedUpdate.cs
Last active March 22, 2021 15:42
Equivalent of LateUpdate() but for FixedUpdate() in Unity
// Based on code by James Frowen https://james-frowen.github.io/unity_tips/latefixedupdate/
// but with order of execution switched so that LateFixedUpdate() is not called during OnEnable()
public void OnEnable()
{
StartCoroutine(RunLateFixedUpdate());
}
public void OnDisable()
{
@paulmasri
paulmasri / MyClass.cpp
Created February 12, 2020 15:31
Emit a signal from the main thread or the QThread thread
#include "MyClass.h"
MyClass::MyClass(QObject *parent)
: QThread(parent)
{
start();
}
MyClass::~MyClass()
{
#pragma once
#include <QNetworkAccessManager>
class QNetworkAccessManagerWithPatch : public QNetworkAccessManager
{
Q_OBJECT
public:
explicit QNetworkAccessManagerWithPatch(QObject *parent = Q_NULLPTR)
@paulmasri
paulmasri / .gitignore
Last active April 15, 2019 14:40
QML MouseArea.containsMouse error
/.qmake.cache
/.qmake.stash
*.pro.user
*.pro.user.*
*.qbs.user
*.qbs.user.*
*.moc
moc_*.cpp
qrc_*.cpp
ui_*.h
@paulmasri
paulmasri / qml-sync-animations.qml
Last active February 19, 2018 09:33
QML sync animations problem
/*
Problem: I have two objects that have animations. I want the animations to be synchronised.
However one of the animations depends on an asynchronous function `grabToImage()`
Below are 3 versions of the script.
The first one is out of sync.
The second one is in-sync but is a horribly messy solution. I posed the question: Is there a neater way to achieve this?
The third one uses promises, using Ben Lau's QuickPromise
VERSION 1: out of sync