diff --git a/NodeKittenX.podspec b/NodeKittenX.podspec index e5d14b9..6dbe2bf 100644 --- a/NodeKittenX.podspec +++ b/NodeKittenX.podspec @@ -25,7 +25,7 @@ s.source_files = "blocks/leif/NodeKittenX/*.{h}","blocks/leif/NodeKittenX/Platfo s.subspec "freetypegl" do |freetypegl| freetypegl.source_files = "deps/leif/freetype-gl/*.{h,c,cpp}" - #freetypegl.ios.vendored_libraries = "libs/ios/libFreetype2/libFreetype2.a" + freetypegl.subspec "freetype" do |freetype| freetype.osx.source_files = "deps/miguel/freetype/src/base/*.{h,c}" freetype.ios.source_files = "deps/miguel/freetype/src/base/ftadvanc.c", @@ -87,10 +87,8 @@ s.subspec "freetypegl" do |freetypegl| "deps/miguel/freetype/src/type42/type42.{h,c}", "deps/miguel/freetype/src/winfonts/winfnt.{h,c}" freetype.compiler_flags = '-DFT2_BUILD_LIBRARY=1 -DDARWIN_NO_CARBON -DFT_CONFIG_OPTION_SYSTEM_ZLIB=1' - freetype.xcconfig = { "HEADER_SEARCH_PATHS" => "/Users/leif/ClionProjects/NodeKittenX/deps/miguel/freetype/include" } - #freetype.xcconfig = { "HEADER_SEARCH_PATHS" => " + freetype.xcconfig = { "HEADER_SEARCH_PATHS" => "$(PODS_ROOT)/deps/miguel/freetype/include" } end - freetypegl.xcconfig = { "HEADER_SEARCH_PATHS" => "/Users/leif/ClionProjects/NodeKittenX/libs/ios/libFreetype2/include" } end s.subspec "picojpeg" do |picojpeg| @@ -98,7 +96,14 @@ picojpeg.source_files = "deps/leif/picojpeg/*.{h,c,cpp}" end s.subspec "kiwi" do |kiwi| - kiwi.source_files = "deps/leif/kiwi/kiwi/*.{h}" + kiwi.source_files = "deps/leif/kiwi/kiwi/*.{h, hpp}" +end + +s.subspec "underscore" do |underscore| +underscore.source_files = "deps/leif/underscore/_.hpp", + "deps/leif/underscore/underscore/underscore.h", + "deps/leif/underscore/underscorehpp/*.hpp" +underscore.xcconfig = { "HEADER_SEARCH_PATHS" => "$(PODS_ROOT)/deps/leif/underscore" } end s.subspec "png" do |png| diff --git a/blocks/leif/NodeKittenX/Examples/LayoutExample.cpp b/blocks/leif/NodeKittenX/Examples/LayoutExample.cpp index 3410a0f..dc6c610 100644 --- a/blocks/leif/NodeKittenX/Examples/LayoutExample.cpp +++ b/blocks/leif/NodeKittenX/Examples/LayoutExample.cpp @@ -6,18 +6,35 @@ // // - #include "LayoutExample.h" void LayoutExample::moveToView() { - auto container = ContainerView::viewWithSize(size.get().xy); - container - ->addRow(V2{.5, .5}) - ->addColumn(V2{.5, .5}); - container->addRow(V2{.5, .5})->setBackgroundColor(Color{.3, .3, .3}); - addChild(container); + setLayoutMethod(Layout::Method::Vertical); + + addChild(View::view())->setBackgroundColor(Color("red")); + addChild(View::view())->setBackgroundColor(Color("orange")); + addChild(View::view())->setBackgroundColor(Color("yellow")); + addChild(View::view())->setBackgroundColor(Color("green")); + addChild(View::view())->setBackgroundColor(Color("blue")); + auto row = addChild(View::view())->setBackgroundColor(Color("violet")); + + row->setLayoutMethod(Layout::Method::Horizontal); + row->addChild(View::view())->setBackgroundColor(Color("red")); + row->addChild(View::view())->setBackgroundColor(Color("orange")); + row->addChild(View::view())->setBackgroundColor(Color("yellow")); + row->addChild(View::view())->setBackgroundColor(Color("green")); + row->addChild(View::view())->setBackgroundColor(Color("blue")); + auto col = row->addChild(View::view())->setBackgroundColor(Color("violet")); + + col->setLayoutMethod(Layout::Method::Vertical); + col->addChild(View::view())->setBackgroundColor(Color("red")); + col->addChild(View::view())->setBackgroundColor(Color("orange")); + col->addChild(View::view())->setBackgroundColor(Color("yellow")); + col->addChild(View::view())->setBackgroundColor(Color("green")); + col->addChild(View::view())->setBackgroundColor(Color("blue")); + col->addChild(View::view())->setBackgroundColor(Color("violet")); } void LayoutExample::handleUXEvent(shared_ptr event){ - + } \ No newline at end of file diff --git a/blocks/leif/NodeKittenX/Generic/Layout.h b/blocks/leif/NodeKittenX/Generic/Layout.h index dfeb0e6..5ff783c 100644 --- a/blocks/leif/NodeKittenX/Generic/Layout.h +++ b/blocks/leif/NodeKittenX/Generic/Layout.h @@ -5,145 +5,205 @@ #include "kiwi.h" // non-raw literal operator -constexpr double operator"" _percent( long double val) { return val / 100 ; } - -//namespace underscore { -// template -// void each(Container container, Function fn) -// { -// auto first = cbegin(container); -// auto last = cend(container); -// -// while (first!=last) { -// fn (*first); -// ++first; -// } -// } -//} - -typedef enum : U1t { - LayoutManual, - LayoutContainer, - LayoutRow, - LayoutColumn, - LayoutCollection -} LayoutMethod; - -enum class ConstraintType {size, margin}; - -class LayoutUnit : public Reactive::Observable { - using Reactive::Observable::Observable; -}; - -class LayoutUnitPixel : public LayoutUnit { -}; - -class LayoutUnitPercent : public LayoutUnit { -public: - class DoubleIsPercent{}; // a tag - explicit LayoutUnitPercent(DoubleIsPercent, double pct) : LayoutUnit(pct/100.0) {} -}; - -static LayoutUnitPercent operator "" _pct( long double pct ) -{ - return LayoutUnitPercent{LayoutUnitPercent::DoubleIsPercent{}, static_cast(pct)}; -} - -class Constraint { - ConstraintType _type; - std::vector constraints; - -public: - const ConstraintType type() const {return _type;} - void setType(ConstraintType type) {_type = type;} - - F1t solve(){ - - } - - -}; - - - -class Solver { - std::vector constraints; - kiwi::Solver kSolver; - kiwi::Variable x {"x"}; - kiwi::Variable y {"y"}; - -public: - - Solver(){ - - // x = 20 - kSolver.addConstraint(x == 20); - - // x + 2 == y + 10 - kSolver.addConstraint(x + 2 == y + 20); - // these all have strength 'required - - kSolver.updateVariables(); - - nkLog("x + %f + y + %f", x.value(), y.value()); - -// x == 20 -// y == 12 - +constexpr double operator"" _pct( long double val) { return val / 100.0f ; } + +namespace Layout { + + enum class Method { + None, + Horizontal, + Vertical, + Container, + Row, + Column, + Collection }; - ~Solver(){}; - - F1t solve(){ - - } -}; - -template -class Layout : public T { - - bool horizontalMajor {false}; - - T* _selectedElement; - T* _element; - - V4 anchor; - - V2 Offset; - LayoutMethod _layoutMethod {LayoutContainer}; - - Constraint _constraint; - -public: - using T::T; - - void layout(){ -// _::each(this->children(), [](auto& child){ -// nkLog(child->); -// }); + + enum class Unit { + none, + Pixels, + Percent, + ConstrainPixels, + ConstrainPct }; - - const T* selectedElement() const {return _selectedElement;} - void setSelectedElement(T* selectedElement) {_selectedElement = selectedElement;} - - const LayoutMethod layoutMethod() const {return _layoutMethod;} - void setLayoutMethod(LayoutMethod layoutMethod) {_layoutMethod = layoutMethod;} - - // LAYOUT - virtual V2 sizeForViewAtIndex(IndexPath indexPath){ - - } - virtual V2 positionForViewAtIndexPath(IndexPath indexPath, T* view){ - - } - virtual V2 spacingForViewAtIndexPath(IndexPath indexPath, T* view){ - - } - - // SCROLLING - virtual V2 targetPositionForEstimatedPosition(V2 position){ - + + enum class ConstraintType {size, margin}; + + class LayoutUnit : public Reactive::Observable { + using Reactive::Observable::Observable; + }; + + class LayoutUnitPixel : public LayoutUnit { + }; + + class LayoutUnitPercent : public LayoutUnit { + public: + class DoubleIsPercent{}; // a tag + explicit LayoutUnitPercent(DoubleIsPercent, double pct) : LayoutUnit(pct/100.0) {} + }; + + static LayoutUnitPercent operator "" _pct( long double pct ) + { + return LayoutUnitPercent{LayoutUnitPercent::DoubleIsPercent{}, static_cast(pct)}; } - -}; + + class Constraint { + ConstraintType _type; + std::vector constraints; + + public: + const ConstraintType type() const {return _type;} + void setType(ConstraintType type) {_type = type;} + + F1t solve(){ + + } + + + }; + + + + class Solver { + std::vector constraints; + kiwi::Solver kSolver; + kiwi::Variable x {"x"}; + kiwi::Variable y {"y"}; + + public: + + Solver(){ + + // x = 20 + kSolver.addConstraint(x == 20); + + // x + 2 == y + 10 + kSolver.addConstraint(x + 2 == y + 20); + // these all have strength 'required + + kSolver.updateVariables(); + + nkLog("x + %f + y + %f", x.value(), y.value()); + + // x == 20 + // y == 12 + + }; + ~Solver(){}; + + F1t solve(){ + + } + }; + + template + class Delegate { + + }; + + template + class Manager { + std::vector _selectedElements; + + Delegate* _delegate; + + bool _descending {true}; + V2 _anchorPoint {0,0}; + V2 _offset {0,0}; + V4 _spacing {0,0,0,0}; + + Method _method {Method::None}; + Unit _unit {Unit::Percent}; + Constraint _constraint; + + public: + const Method layoutMethod() const {return _method;} + Manager* setLayoutMethod(Method layoutMethod) {_method = layoutMethod; return this;} + + const V2 anchorPoint() const {return _anchorPoint;} + Manager* setAnchorPoint(V2 anchorPoint) {_anchorPoint = anchorPoint; return this;} + + const V2 spacing() const {return _spacing;} + Manager* setSpacing(V2 spacing) {_spacing = spacing; return this;} + + // LAYOUT + virtual V2 sizeForViewAtIndex(IndexPath indexPath){ + return {0,0}; + } + + virtual V2 positionForViewAtIndexPath(IndexPath indexPath, T* view){ + return {0,0}; + } + virtual V2 spacingForViewAtIndexPath(IndexPath indexPath, T* view){ + return {0,0}; + } + + virtual int numberOfSections(){ + return 1; + } + + virtual int numberOfChildrenInSection(const unsigned int section){ + return 0; + } + + // SCROLLING + virtual V2 targetPositionForEstimatedPosition(V2 position){ + return {0,0}; + } + + void staticLayout(T* element, bool vertical, bool descending){ + auto invert = descending ? -1.0f : 1.0f; + + auto spacing = V2{_spacing.left + _spacing.right, _spacing.top + _spacing.bottom}; + + auto origin = element->size.get().xy * (_anchorPoint - (V2{.5,.5} * invert)); + + V2 csize; + + if (vertical) { + csize = (element->size.get().xy * V2{1.0f, 1.0f / element->children().size()}) - spacing; + origin += (csize * .5) * invert; + if (descending) origin.y -= _spacing.top; + else origin.y += _spacing.bottom; + origin.x -= _spacing.right; + } + else { + csize = (element->size.get().xy * V2{1.0f / element->children().size(), 1.0f}) - spacing; + origin += (csize * .5) * invert; + if (descending) origin.x -= _spacing.right; + else origin.x += _spacing.left; + origin.y += _spacing.bottom; + } + + auto step = (csize + spacing) * invert; + + if (vertical) step.x = 0; + else step.y = 0; + + for (auto& child : element->children()){ + child->position.set(origin); + child->size.set(csize); + origin += step; + } + } + + virtual void layout(T* element) { + switch (_method){ + case Method::None: default: + for (auto& child : element->children()){ + child->afterTransform(); + } + case Method::Vertical: + staticLayout(element, true, true); + break; + case Method::Horizontal: + staticLayout(element, false, false); + break; + } + }; + + }; + +} #endif \ No newline at end of file diff --git a/blocks/leif/NodeKittenX/Generic/Nodal.h b/blocks/leif/NodeKittenX/Generic/Nodal.h index 6b2ebc9..8afe852 100644 --- a/blocks/leif/NodeKittenX/Generic/Nodal.h +++ b/blocks/leif/NodeKittenX/Generic/Nodal.h @@ -19,20 +19,23 @@ class Nodal { return _children[0]; } - T* addChild(std::shared_ptr& child) { + template + C* addChild(std::shared_ptr& child) { addChild(std::move(child)); return child.get(); } - T* addChild(std::shared_ptr&& child) { + template + C* addChild(std::shared_ptr&& child) { child->_siblingPosition = (int)_children.size(); _children.push_back(child); child->setParent(static_cast(this)); afterChildrenChanged(); - return child.get(); + return static_cast(child.get()); } - T* insertChild(std::shared_ptr& child, int atIndex){ + template + C* insertChild(std::shared_ptr& child, int atIndex){ if (!_children.size()) { addChild(child); } @@ -54,7 +57,7 @@ class Nodal { return nullptr; } - T* nextSibling() { + T* nextSibling() const { if (_parent){ auto next = _parent->childAtSiblingPosition(_siblingPosition+1); if (next) return next; @@ -64,7 +67,7 @@ class Nodal { return this; }; - T* previousSibling() { + T* previousSibling() const { if (_parent){ if (_siblingPosition-1 > 0){ auto next = _parent->childAtSiblingPosition(_siblingPosition-1); @@ -79,7 +82,8 @@ class Nodal { virtual void afterChildrenChanged(){ } - virtual void setParent(T *parent){ + + virtual T* setParent(T *parent){ if (_parent) { beforeParentChanged(); _parent->removeChild(static_cast(this)); @@ -89,6 +93,7 @@ class Nodal { else { _parent = parent; } + return static_cast(this); } virtual void beforeParentChanged(){}; diff --git a/blocks/leif/NodeKittenX/Generic/Reactive.h b/blocks/leif/NodeKittenX/Generic/Reactive.h index dc6b476..3d1d8f8 100644 --- a/blocks/leif/NodeKittenX/Generic/Reactive.h +++ b/blocks/leif/NodeKittenX/Generic/Reactive.h @@ -5,167 +5,155 @@ #include "GLState.h" namespace Reactive { - + using std::function; - + template class Pullable { - static std::unordered_map> functions; protected: mutable bool _dirty; mutable T _cache; + std::function pull; public: Pullable() : _dirty{true} { } - + Pullable(const T &initial) : _cache(initial), _dirty{false} { } - + virtual ~Pullable() { - functions.erase(this); } - + void setPullFunction(std::function &&func) { - functions[this] = func; + pull = func; } - - T pull() const { - return functions[this](); - } - + T get() const { if (!_dirty) return _cache; Pullable::set(pull()); return _cache; }; - + T ref() const { return _cache; } - + virtual void set(const T &value) const { _cache = value; _dirty = false; }; - + void setDirty(bool dirty = true) { _dirty = dirty; }; }; - - template - std::unordered_map> Pullable::functions; - + + template class Variable : public Pullable { - static std::unordered_map>> - afterFuncs; + std::vector> afterFuncs; public: void afterSet(function &&callback) { - afterFuncs[this].push_back(callback); + afterFuncs.push_back(callback); } - + void set(const T &value) const override { Pullable::set(value); - for (auto &callback : afterFuncs[this]) { + for (auto &callback : afterFuncs) { callback(); } } - + virtual ~Variable() { - afterFuncs.erase(this); - } - }; - - template - std::unordered_map>> - Variable::afterFuncs; - - template - class ObserverHandle; - - template - class Observable : public Pullable { - using Pullable::Pullable; - std::vector *> observers; - public: - void set(const T &value) const override; - - void addObserver(ObserverHandle *observer) { - observers.push_back(observer); - } - - void removeObserver(ObserverHandle *observer) { - _::erase(observers, observer); } - }; - - template - class PropertyObserver { - std::vector >> observers; - public: - void addObserver(const Observable &property, function &&observeCallback) { - observers.emplace_back(property, observeCallback); - } - }; - - template - class ObserverHandle { - Observable &_property; - function _observeCallback; - public: - ObserverHandle(const Observable &property, function observeCallback) : + }; + + + template + class ObserverHandle; + + template + class Observable : public Pullable { + using Pullable::Pullable; + std::vector *> observers; + public: + void set(const T &value) const override; + + void addObserver(ObserverHandle *observer) { + observers.push_back(observer); + } + + void removeObserver(ObserverHandle *observer) { + _::erase(observers, observer); + } + }; + + template + class PropertyObserver { + std::vector >> observers; + public: + void addObserver(const Observable &property, function &&observeCallback) { + observers.emplace_back(property, observeCallback); + } + }; + + template + class ObserverHandle { + Observable &_property; + function _observeCallback; + public: + ObserverHandle(const Observable &property, function observeCallback) : _property(property), _observeCallback(observeCallback) { - _property->addObserver(this); - } - - ~ObserverHandle() { - _property->removeObserver(this); - } - - void observe(T changedValue) { - _observeCallback(changedValue); - } - }; - - template - void Observable::set(const T &value) const { - Pullable::set(value); - for (auto &p : observers) { - p->observe(Pullable::get()); - } - } - - template - class Vector : public Variable { - public: - void setX(F1t elem) { - T ex = Pullable::_cache; - ex.v[0] = elem; - Pullable::set(ex); - }; - - void setY(F1t elem) { - T ex = Pullable::_cache; - ex.v[1] = elem; - Pullable::set(ex); + _property->addObserver(this); + } + + ~ObserverHandle() { + _property->removeObserver(this); + } + + void observe(T changedValue) { + _observeCallback(changedValue); + } }; - - void setZ(F1t elem) { - T ex = Pullable::_cache; - ex.v[2] = elem; - Pullable::set(ex); + + template + void Observable::set(const T &value) const { + Pullable::set(value); + for (auto &p : observers) { + p->observe(Pullable::get()); + } + } + + template + class Vector : public Variable { + public: + void setX(F1t elem) { + T ex = Pullable::_cache; + ex.v[0] = elem; + Pullable::set(ex); + }; + + void setY(F1t elem) { + T ex = Pullable::_cache; + ex.v[1] = elem; + Pullable::set(ex); + }; + + void setZ(F1t elem) { + T ex = Pullable::_cache; + ex.v[2] = elem; + Pullable::set(ex); + }; }; - }; - - template<> - void Vector::setY(float position) = delete; - - template<> - void Vector::setZ(float position) = delete; - - template<> - void Vector::setZ(float position) = delete; - -} - + + template<> + void Vector::setY(float position) = delete; + + template<> + void Vector::setZ(float position) = delete; + + template<> + void Vector::setZ(float position) = delete; + + } + #endif \ No newline at end of file diff --git a/blocks/leif/NodeKittenX/Node/Mesh.cpp b/blocks/leif/NodeKittenX/Node/Mesh.cpp index 12640a7..a08a94e 100644 --- a/blocks/leif/NodeKittenX/Node/Mesh.cpp +++ b/blocks/leif/NodeKittenX/Node/Mesh.cpp @@ -554,23 +554,17 @@ void Mesh::customDraw(){ void Mesh::setupViewMatrix() const { if (!GLState::activeShader()) return; - if (forceOrthographic()) { - GLState::activeShader()->uniformNamed(NKS_M16_MVP).bindM16(M16Multiply(scene()->orthographicMatrix(), - M16Multiply(M16MakeLookAt(V3(0, 0, 1), V3(0), V3(0, 1, 0)), - M16ScaleWithV3(globalTransform.get(), size.get())))); + if(GLState::activeShader()->hasUniformNamed(NKS_M16_MV) ){ + GLState::activeShader()->uniformNamed(NKS_M16_MV).bindM16(modelViewMatrix.get()); } - else { - if(GLState::activeShader()->hasUniformNamed(NKS_M16_MV) ){ - GLState::activeShader()->uniformNamed(NKS_M16_MV).bindM16(modelViewMatrix.get()); - } - - if(GLState::activeShader()->hasUniformNamed(NKS_M9_NORMAL) ){ - GLState::activeShader()->uniformNamed(NKS_M9_NORMAL).bindM9(M16GetInverseNormalMatrix(modelViewMatrix.get())); - } - - GLState::activeShader()->uniformNamed(NKS_M16_MVP).bindM16(modelViewProjectionMatrix.get()); + + if(GLState::activeShader()->hasUniformNamed(NKS_M9_NORMAL) ){ + GLState::activeShader()->uniformNamed(NKS_M9_NORMAL).bindM9(M16GetInverseNormalMatrix(modelViewMatrix.get())); } + GLState::activeShader()->uniformNamed(NKS_M16_MVP).bindM16(modelViewProjectionMatrix.get()); + + nkGetGLError(); } diff --git a/blocks/leif/NodeKittenX/Node/Node.cpp b/blocks/leif/NodeKittenX/Node/Node.cpp index c9fbf78..74d7103 100644 --- a/blocks/leif/NodeKittenX/Node/Node.cpp +++ b/blocks/leif/NodeKittenX/Node/Node.cpp @@ -40,14 +40,16 @@ Node::Node(Color color, V3t size_) globalTransform.afterSet([this]{ modelViewMatrix.setDirty(); }); - modelViewMatrix.setPullFunction([this]{ - return M16Multiply(scene()->camera->viewMatrix.get(),M16ScaleWithV3(globalTransform.get(), size.get())); - }); modelViewMatrix.afterSet([this]{ modelViewProjectionMatrix.setDirty(); }); + modelViewMatrix.setPullFunction([this]{ + M16t v = forceOrthographic() ? M16MakeLookAt({0,0,1}, {0,0,0}, {0,1,0}) : scene()->camera->viewMatrix.get(); + return M16Multiply(v,M16ScaleWithV3(globalTransform.get(), size.get())); + }); modelViewProjectionMatrix.setPullFunction([this]{ - return M16Multiply(scene()->camera->projectionMatrix.get(), modelViewMatrix.get()); + M16t p = forceOrthographic() ? scene()->orthographicMatrix() : scene()->camera->projectionMatrix.get(); + return M16Multiply(p, modelViewMatrix.get()); }); } diff --git a/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaDeviceTools.mm b/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaDeviceTools.mm index 17d3356..8958907 100644 --- a/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaDeviceTools.mm +++ b/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaDeviceTools.mm @@ -10,6 +10,8 @@ #include "CocoaDeviceTools.h" +using namespace std; + string NSToCppString(NSString *s){ return string([s cStringUsingEncoding:NSUTF8StringEncoding]); diff --git a/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaViews.mm b/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaViews.mm index 5707980..482ed50 100644 --- a/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaViews.mm +++ b/blocks/leif/NodeKittenX/Platform/Cocoa/CocoaViews.mm @@ -12,6 +12,8 @@ #include "SceneController.h" #include "Node.h" +using namespace std; + bool isIpad(){ #if TARGET_OS_IPHONE if ( UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) diff --git a/blocks/leif/NodeKittenX/Shader/ShaderProgram.cpp b/blocks/leif/NodeKittenX/Shader/ShaderProgram.cpp index c52323a..ed4896a 100644 --- a/blocks/leif/NodeKittenX/Shader/ShaderProgram.cpp +++ b/blocks/leif/NodeKittenX/Shader/ShaderProgram.cpp @@ -50,8 +50,8 @@ namespace Shader { shared_ptr Program::fill = nullptr; shared_ptr Program::textureFill = nullptr; - map> programCache; - map nodeMap; + map> Program::programCache; + map Program::nodeMap; static GLubyte GLUBYTE_MAX = UCHAR_MAX; diff --git a/blocks/leif/NodeKittenX/Shader/ShaderTools.h b/blocks/leif/NodeKittenX/Shader/ShaderTools.h index 03dd0da..a1327f0 100644 --- a/blocks/leif/NodeKittenX/Shader/ShaderTools.h +++ b/blocks/leif/NodeKittenX/Shader/ShaderTools.h @@ -292,7 +292,7 @@ namespace Shader { #pragma mark - NKSHADER VARIABLE - class Shader; + class Program; class ShaderVariable { @@ -306,7 +306,7 @@ namespace Shader { GLuint arraySize{0}; GLuint glLocation{0}; - Shader *program{nullptr}; + Program *program{nullptr}; ShaderVariable() { } diff --git a/blocks/leif/NodeKittenX/Texture/FrameBuffer.h b/blocks/leif/NodeKittenX/Texture/FrameBuffer.h index fc74c7f..a7d8c5e 100644 --- a/blocks/leif/NodeKittenX/Texture/FrameBuffer.h +++ b/blocks/leif/NodeKittenX/Texture/FrameBuffer.h @@ -16,61 +16,65 @@ class Texture; class FrameBuffer { - + + bool _dirty; + public: - - static std::vector stack; - - // INIT - FrameBuffer(){} // DEFAULT FOR APPLE - FrameBuffer(GLuint width, GLuint height, bool allocate = true); - FrameBuffer(V2 size) : FrameBuffer(size.width, size.height){}; - ~FrameBuffer(); - - // IVARS - - GLuint glName {0}; - - std::shared_ptr renderTexture; - std::shared_ptr renderTexture2; - std::shared_ptr depthTexture; - - // METHODS - - - void bind(); - - void addSecondRenderTexture(); - void bindPing(); - void bindPong(); - - void clear(Color = CLEAR); - - void unbind(); - void unload(); - - GLuint bindTexture(int glname); - - GLuint renderBuffer {0}; - GLuint depthBuffer {0}; - I1t width {0}; - I1t height {0}; - - bool dirty {true}; - + + static std::vector stack; + + // INIT + FrameBuffer(){} // DEFAULT FOR APPLE + FrameBuffer(GLuint width, GLuint height, bool allocate = true); + FrameBuffer(V2 size) : FrameBuffer(size.width, size.height){}; + ~FrameBuffer(); + + // IVARS + + GLuint glName {0}; + + std::shared_ptr renderTexture; + std::shared_ptr renderTexture2; + std::shared_ptr depthTexture; + + // METHODS + + + void bind(); + + void addSecondRenderTexture(); + void bindPing(); + void bindPong(); + + void clear(Color = CLEAR); + + void unbind(); + void unload(); + + GLuint bindTexture(int glname); + + GLuint renderBuffer {0}; + GLuint depthBuffer {0}; + I1t width {0}; + I1t height {0}; + + const bool dirty() const {return _dirty;} + void setDirty(bool dirty = true) {_dirty = dirty;} + + #pragma mark - DEBUG - - static unsigned int createdObjects; - static unsigned int destroyedObjects; - static unsigned int liveObjects(){return createdObjects - destroyedObjects;}; - + + static unsigned int createdObjects; + static unsigned int destroyedObjects; + static unsigned int liveObjects(){return createdObjects - destroyedObjects;}; + protected: - - - void destroyFbo(int glname); - void deleteFboAttachment(GLenum attachment); - - + + + void destroyFbo(int glname); + void deleteFboAttachment(GLenum attachment); + + }; #endif diff --git a/blocks/leif/NodeKittenX/Types/VectorTypes.h b/blocks/leif/NodeKittenX/Types/VectorTypes.h index 2a7d498..ea7c0af 100644 --- a/blocks/leif/NodeKittenX/Types/VectorTypes.h +++ b/blocks/leif/NodeKittenX/Types/VectorTypes.h @@ -514,6 +514,7 @@ union _V4t struct { F1t r, g, b, a; }; struct { F1t s, t, p, q; }; + struct { F1t top, right, bottom, left;}; struct { F1t m00, m01, m10, m11;}; _V4t(const F1t r,const F1t g,const F1t b,const F1t a){ diff --git a/blocks/leif/NodeKittenX/View/ContainerView.h b/blocks/leif/NodeKittenX/View/ContainerView.h index ce1602f..0cebf95 100644 --- a/blocks/leif/NodeKittenX/View/ContainerView.h +++ b/blocks/leif/NodeKittenX/View/ContainerView.h @@ -23,16 +23,16 @@ class ContainerView : public ScrollView { } ContainerView* addRow(V2 vunits){ - return addLayout(vunits, LayoutRow); + return addLayout(vunits, Layout::Method::Row); } ContainerView* addColumn(V2 vunits){ - return addLayout(vunits, LayoutColumn); + return addLayout(vunits, Layout::Method::Column); } - ContainerView* addLayout(V2 vunits, LayoutMethod l){ + ContainerView* addLayout(V2 vunits, Layout::Method l){ auto child = std::make_shared(vunits); - child->setLayoutMethod(l); + child->layoutManager()->setLayoutMethod(l); return static_cast(addChild(child)); } diff --git a/blocks/leif/NodeKittenX/View/Label.cpp b/blocks/leif/NodeKittenX/View/Label.cpp index d9825b8..daf9345 100644 --- a/blocks/leif/NodeKittenX/View/Label.cpp +++ b/blocks/leif/NodeKittenX/View/Label.cpp @@ -8,206 +8,214 @@ #include "Label.h" #include "ShaderProgram.h" +#include "Scene.h" +#include "Camera.h" using namespace std; using namespace Shader; -shared_ptr