-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
47 changed files
with
2,035 additions
and
282 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
{ | ||
"files.associations": { | ||
"utility": "cpp" | ||
"utility": "cpp", | ||
"__locale": "cpp", | ||
"*.inc": "cpp" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <functional> | ||
#include <tools/SharedBase.hpp> | ||
|
||
namespace NXKit { | ||
|
||
class CADisplayLink { | ||
public: | ||
explicit CADisplayLink(std::function<void()> func); | ||
~CADisplayLink(); | ||
|
||
void invalidate(); | ||
private: | ||
bool isRunning = true; | ||
std::function<void()> func; | ||
static std::vector<CADisplayLink*> activeLinks; | ||
friend class DispatchQueue; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
#pragma once | ||
|
||
#include "include/core/SkCanvas.h" | ||
|
||
#include <Geometry.h> | ||
#include <NXTransform3D.h> | ||
#include <NXAffineTransform.h> | ||
#include <ContentsGravityTransformation.h> | ||
#include <CGImage.h> | ||
#include <UIColor.h> | ||
|
||
#include <tools/SharedBase.hpp> | ||
#include <optional> | ||
#include <vector> | ||
|
||
namespace NXKit { | ||
|
||
class CALayer: public enable_shared_from_this<CALayer> { | ||
public: | ||
CALayer(); | ||
~CALayer() {} | ||
|
||
// Getter Setters | ||
void setContentsGravity(CALayerContentsGravity contentsGravity) { _contentsGravity = contentsGravity; } | ||
[[nodiscard]] CALayerContentsGravity contentsGravity() const { return _contentsGravity; } | ||
|
||
void setContentsScale(NXFloat contentsScale) { _contentsScale = contentsScale; } | ||
[[nodiscard]] NXFloat contentsScale() const { return _contentsScale; } | ||
|
||
void setAnchorPoint(NXPoint anchorPoint); | ||
[[nodiscard]] NXPoint anchorPoint() const { return _anchorPoint; } | ||
|
||
void setOpacity(NXFloat opacity); | ||
[[nodiscard]] NXFloat opacity() const { return _opacity; } | ||
|
||
void setBounds(NXRect bounds); | ||
[[nodiscard]] NXRect bounds() const { return _bounds; } | ||
|
||
void setPosition(NXPoint position); | ||
[[nodiscard]] NXPoint position() const { return _position; } | ||
|
||
void setZPosition(NXFloat position); | ||
[[nodiscard]] NXFloat zPosition() { return _zPosition; } | ||
|
||
void setBackgroundColor(std::optional<UIColor> backgroundColor); | ||
[[nodiscard]] std::optional<UIColor> backgroundColor() const { return _backgroundColor; } | ||
|
||
void setCornerRadius(NXFloat cornerRadius); | ||
[[nodiscard]] NXFloat cornerRadius() const { return _cornerRadius; } | ||
|
||
void setTransform(NXTransform3D transform); | ||
[[nodiscard]] NXTransform3D transform() const { return _transform; } | ||
|
||
void setMask(std::shared_ptr<CALayer> mask); | ||
[[nodiscard]] std::shared_ptr<CALayer> mask() const { return _mask; } | ||
|
||
void setContents(std::shared_ptr<CGImage> contents); | ||
[[nodiscard]] std::shared_ptr<CGImage> contents() { return _contents; } | ||
|
||
NXRect getFrame(); | ||
void setFrame(NXRect frame); | ||
|
||
// Layers | ||
[[nodiscard]] std::vector<std::shared_ptr<CALayer>> sublayers() { return _sublayers; } | ||
|
||
void addSublayer(const std::shared_ptr<CALayer>& layer); | ||
void insertSublayerAt(const std::shared_ptr<CALayer>& layer, int index); | ||
void insertSublayerAbove(const std::shared_ptr<CALayer>& layer, const std::shared_ptr<CALayer>& sibling); | ||
void insertSublayerBelow(const std::shared_ptr<CALayer>& layer, const std::shared_ptr<CALayer>& sibling); | ||
|
||
void removeFromSuperlayer(); | ||
|
||
void onWillSet(std::string keyPath); | ||
|
||
void skiaRender(SkCanvas* canvas); | ||
private: | ||
|
||
/// Defaults to 1.0 but if the layer is associated with a view, | ||
/// the view sets this value to match the screen. | ||
NXFloat _contentsScale = 1.0f; | ||
CALayerContentsGravity _contentsGravity = CALayerContentsGravity::resize; | ||
|
||
std::weak_ptr<CALayer> _superlayer; | ||
std::vector<std::shared_ptr<CALayer>> _sublayers; | ||
std::shared_ptr<CALayer> _mask; | ||
|
||
std::shared_ptr<CGImage> _contents; | ||
|
||
// Animatable | ||
NXPoint _anchorPoint = NXPoint(0.5, 0.5); | ||
NXPoint _position; | ||
NXFloat _opacity = 1; | ||
NXFloat _zPosition = 0.0; | ||
NXRect _bounds; | ||
NXFloat _cornerRadius = 0; | ||
std::optional<UIColor> _backgroundColor; | ||
NXTransform3D _transform = NXTransform3D::identity; | ||
|
||
/** | ||
Indicates whether a layer somewhere has changed since the last render pass. | ||
The current implementation of this is quite simple and doesn't check whether the layer is actually in | ||
the layer hierarchy or not. In theory this means that we're wasting render passes if users frequently | ||
update layers that aren't in the tree. In practice it's not expected that UIKit users would do that | ||
often enough for us to care about it. | ||
**/ | ||
static bool layerTreeIsDirty; | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <SDL.h> | ||
//#include <SDL_gpu.h> | ||
#include <optional> | ||
#include <memory> | ||
#include <NXData.h> | ||
#include <Geometry.h> | ||
|
||
#include "include/core/SkImage.h" | ||
|
||
namespace NXKit { | ||
|
||
class CGImage { | ||
public: | ||
sk_sp<SkImage> pointee; | ||
|
||
// CGImage(NXSize size); | ||
CGImage(const NXData& sourceData); | ||
// CGImage(SDL_Surface* surface); | ||
CGImage(sk_sp<SkImage> image, std::optional<NXData> sourceData); | ||
CGImage(sk_sp<SkImage> image): CGImage(image, std::nullopt) {} | ||
~CGImage(); | ||
|
||
[[nodiscard]] NXSize size() const; | ||
private: | ||
std::optional<NXData> sourceData; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#pragma once | ||
|
||
#include <Geometry.h> | ||
|
||
namespace NXKit { | ||
|
||
enum class CALayerContentsGravity { | ||
bottom, bottomLeft, bottomRight, | ||
center, left, right, | ||
top, topLeft, topRight, | ||
resize, resizeAspect, resizeAspectFill | ||
}; | ||
|
||
class CALayer; | ||
struct ContentsGravityTransformation { | ||
NXPoint offset; | ||
NXSize scale; | ||
|
||
ContentsGravityTransformation(CALayer* layer); | ||
|
||
private: | ||
NXSize defaultScale = NXSize(1.0, 1.0); | ||
}; | ||
|
||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#pragma once | ||
|
||
#include <queue> | ||
#include <string> | ||
#include <functional> | ||
#include <thread> | ||
#include <mutex> | ||
|
||
#ifdef main | ||
#undef main | ||
#endif | ||
|
||
namespace NXKit { | ||
|
||
class DispatchQueue { | ||
public: | ||
DispatchQueue(const std::string& tag); | ||
~DispatchQueue(); | ||
|
||
static std::shared_ptr<DispatchQueue> main(); | ||
static std::shared_ptr<DispatchQueue> global(); | ||
|
||
std::string tag() const { return _tag; } | ||
void async(const std::function<void()>& task); | ||
|
||
bool isActive() { return _task_loop_active; } | ||
private: | ||
static std::shared_ptr<DispatchQueue> _main; | ||
static std::shared_ptr<DispatchQueue> _global; | ||
std::queue<std::function<void()>> _queue; | ||
std::string _tag; | ||
|
||
pthread_t _task_loop_thread = nullptr; | ||
std::mutex _m_async_mutex; | ||
volatile bool _task_loop_active = true; | ||
static void* task_loop(void* a); | ||
|
||
void performAll(); | ||
|
||
friend bool applicationRunLoop(); | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// NXAffineTransform.h | ||
// NXKit | ||
// | ||
// Created by Даниил Виноградов on 19.07.2022. | ||
// | ||
|
||
#pragma once | ||
|
||
#include "Geometry.h" | ||
#include <optional> | ||
|
||
namespace NXKit { | ||
|
||
struct NXAffineTransform { | ||
public: | ||
float m11, m12, m21, m22, tX, tY; | ||
|
||
NXAffineTransform(); | ||
NXAffineTransform(NXFloat m11, NXFloat m12, NXFloat m21, NXFloat m22, NXFloat tX, NXFloat tY); | ||
|
||
static NXAffineTransform translationBy(NXFloat x, NXFloat y); | ||
static NXAffineTransform scaleBy(NXFloat x, NXFloat y); | ||
static NXAffineTransform scale(NXFloat factor); | ||
static NXAffineTransform rotationBy(NXFloat angle); | ||
|
||
std::optional<NXAffineTransform> inverted() const; | ||
bool isIdentity() const; | ||
|
||
static const NXAffineTransform identity; | ||
|
||
bool operator==(const NXAffineTransform& rhs) const; | ||
NXAffineTransform operator*(const NXAffineTransform& rhs) const; | ||
}; | ||
|
||
} |
Oops, something went wrong.