Navigation Menu

Skip to content

Commit

Permalink
CanvasProperty: renamed AlternativeValue to CachedValue
Browse files Browse the repository at this point in the history
  • Loading branch information
paraboul committed Apr 20, 2017
1 parent 0a51ef7 commit 60946e8
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 53 deletions.
12 changes: 6 additions & 6 deletions src/Binding/JSCanvas.cpp
Expand Up @@ -415,9 +415,9 @@ bool JSCanvas::JS_getContext(JSContext *cx, JS::CallArgs &args)
case CanvasContext::CONTEXT_2D: { case CanvasContext::CONTEXT_2D: {
Canvas2DContext *ctx2d = new Canvas2DContext( Canvas2DContext *ctx2d = new Canvas2DContext(
m_CanvasHandler, cx, m_CanvasHandler, cx,
m_CanvasHandler->p_Width.getAlternativeValue() m_CanvasHandler->p_Width.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2), + (m_CanvasHandler->p_Coating * 2),
m_CanvasHandler->p_Height.getAlternativeValue() m_CanvasHandler->p_Height.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2), + (m_CanvasHandler->p_Coating * 2),
ui); ui);


Expand All @@ -439,9 +439,9 @@ bool JSCanvas::JS_getContext(JSContext *cx, JS::CallArgs &args)
case CanvasContext::CONTEXT_WEBGL: case CanvasContext::CONTEXT_WEBGL:
JSWebGLRenderingContext *ctxWebGL = new JSWebGLRenderingContext( JSWebGLRenderingContext *ctxWebGL = new JSWebGLRenderingContext(
m_CanvasHandler, cx, m_CanvasHandler, cx,
m_CanvasHandler->p_Width.getAlternativeValue() m_CanvasHandler->p_Width.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2), + (m_CanvasHandler->p_Coating * 2),
m_CanvasHandler->p_Height.getAlternativeValue() m_CanvasHandler->p_Height.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2), + (m_CanvasHandler->p_Coating * 2),
ui); ui);


Expand Down Expand Up @@ -961,15 +961,15 @@ bool JSCanvas::JSGetter_cursor(JSContext *cx, JS::MutableHandleValue vp)


bool JSCanvas::JSGetter_clientWidth(JSContext *cx, JS::MutableHandleValue vp) bool JSCanvas::JSGetter_clientWidth(JSContext *cx, JS::MutableHandleValue vp)
{ {
vp.setInt32(m_CanvasHandler->p_Width.getAlternativeValue() + vp.setInt32(m_CanvasHandler->p_Width.getCachedValue() +
(m_CanvasHandler->p_Coating * 2)); (m_CanvasHandler->p_Coating * 2));


return true; return true;
} }


bool JSCanvas::JSGetter_clientHeight(JSContext *cx, JS::MutableHandleValue vp) bool JSCanvas::JSGetter_clientHeight(JSContext *cx, JS::MutableHandleValue vp)
{ {
vp.setInt32(m_CanvasHandler->p_Height.getAlternativeValue() + vp.setInt32(m_CanvasHandler->p_Height.getCachedValue() +
(m_CanvasHandler->p_Coating * 2)); (m_CanvasHandler->p_Coating * 2));


return true; return true;
Expand Down
5 changes: 5 additions & 0 deletions src/Embed/lib/Elements.js
Expand Up @@ -407,6 +407,11 @@ Elements.flexcanvas = class extends NidiumNode {
this._color = attributes.color || "red"; this._color = attributes.color || "red";
} }


set color(val) {
this._color = val;
this.requestPaint();
}

paint(ctx, width, height) { paint(ctx, width, height) {
ctx.fillStyle = this._color; ctx.fillStyle = this._color;
ctx.fillRect(0, 0, width, height); ctx.fillRect(0, 0, width, height);
Expand Down
74 changes: 37 additions & 37 deletions src/Graphics/CanvasHandler.cpp
Expand Up @@ -42,12 +42,12 @@ CanvasHandler::CanvasHandler(float width,


if (!isnan(width)) { if (!isnan(width)) {
p_Width = nidium_max(width, 0); p_Width = nidium_max(width, 0);
p_Width.setAlternativeValue(p_Width); p_Width.setCachedValue(p_Width);
} }


if (!isnan(height)) { if (!isnan(height)) {
p_Height = nidium_max(height, 0); p_Height = nidium_max(height, 0);
p_Height.setAlternativeValue(p_Height); p_Height.setCachedValue(p_Height);
} }


m_YogaRef = YGNodeNewWithConfig(nctx->m_YogaConfig); m_YogaRef = YGNodeNewWithConfig(nctx->m_YogaConfig);
Expand Down Expand Up @@ -419,10 +419,10 @@ void CanvasHandler::dispatchMouseEvents(LayerizeContext &layerContext)
} }


Rect actualRect; Rect actualRect;
actualRect.m_fLeft = p_Left.getAlternativeValue() - p_Coating; actualRect.m_fLeft = p_Left.getCachedValue() - p_Coating;
actualRect.m_fTop = p_Top.getAlternativeValue() - p_Coating; actualRect.m_fTop = p_Top.getCachedValue() - p_Coating;
actualRect.m_fRight = p_Width.getAlternativeValue() + p_Left.getAlternativeValue(); actualRect.m_fRight = p_Width.getCachedValue() + p_Left.getCachedValue();
actualRect.m_fBottom = p_Height.getAlternativeValue() + p_Top.getAlternativeValue(); actualRect.m_fBottom = p_Height.getCachedValue() + p_Top.getCachedValue();


if (layerContext.m_Clip) { if (layerContext.m_Clip) {


Expand Down Expand Up @@ -503,18 +503,18 @@ void CanvasHandler::layerize(LayerizeContext &layerContext,
This will trigger an onResize event on the element This will trigger an onResize event on the element
*/ */
if (nwidth != p_Width.getAlternativeValue() if (nwidth != p_Width.getCachedValue()
|| nheight != p_Height.getAlternativeValue()) { || nheight != p_Height.getCachedValue()) {


p_Width.setAlternativeValue(nwidth); p_Width.setCachedValue(nwidth);
p_Height.setAlternativeValue(nheight); p_Height.setCachedValue(nheight);




deviceSetSize(nwidth, nheight); deviceSetSize(nwidth, nheight);
} }


int maxChildrenWidth = p_Width.getAlternativeValue(), int maxChildrenWidth = p_Width.getCachedValue(),
maxChildrenHeight = p_Height.getAlternativeValue(); maxChildrenHeight = p_Height.getCachedValue();




/* /*
Expand All @@ -533,17 +533,17 @@ void CanvasHandler::layerize(LayerizeContext &layerContext,
/* /*
Set the absolute position Set the absolute position
*/ */
p_Left.setAlternativeValue(cleft + tmpLeft); p_Left.setCachedValue(cleft + tmpLeft);
p_Top.setAlternativeValue(ctop + tmpTop); p_Top.setCachedValue(ctop + tmpTop);


/* /*
draw current context on top of the root layer draw current context on top of the root layer
*/ */
willDraw = (!layerContext.m_Clip || m_CoordPosition == COORD_ABSOLUTE willDraw = (!layerContext.m_Clip || m_CoordPosition == COORD_ABSOLUTE
|| (layerContext.m_Clip->checkIntersect( || (layerContext.m_Clip->checkIntersect(
p_Left.getAlternativeValue() - p_Coating, p_Top.getAlternativeValue() - p_Coating, p_Left.getCachedValue() - p_Coating, p_Top.getCachedValue() - p_Coating,
p_Left.getAlternativeValue() + p_Coating + YGNodeLayoutGetWidth(m_YogaRef), p_Left.getCachedValue() + p_Coating + YGNodeLayoutGetWidth(m_YogaRef),
p_Top.getAlternativeValue() + p_Coating + YGNodeLayoutGetHeight(m_YogaRef)))); p_Top.getCachedValue() + p_Coating + YGNodeLayoutGetHeight(m_YogaRef))));


if (willDraw && !m_Loaded) { if (willDraw && !m_Loaded) {
m_Loaded = true; m_Loaded = true;
Expand All @@ -554,8 +554,8 @@ void CanvasHandler::layerize(LayerizeContext &layerContext,


ComposeContext compctx = { ComposeContext compctx = {
.handler = this, .handler = this,
.left = p_Left.getAlternativeValue() - p_Coating, .left = p_Left.getCachedValue() - p_Coating,
.top = p_Top.getAlternativeValue() - p_Coating, .top = p_Top.getCachedValue() - p_Coating,
.opacity = popacity, .opacity = popacity,
.zoom = m_Zoom, .zoom = m_Zoom,
.needClip = (m_CoordPosition != COORD_ABSOLUTE && layerContext.m_Clip), .needClip = (m_CoordPosition != COORD_ABSOLUTE && layerContext.m_Clip),
Expand Down Expand Up @@ -587,20 +587,20 @@ void CanvasHandler::layerize(LayerizeContext &layerContext,
if (!m_Overflow) { if (!m_Overflow) {
if (layerContext.m_Clip == NULL) { if (layerContext.m_Clip == NULL) {
layerContext.m_Clip = &nclip; layerContext.m_Clip = &nclip;
layerContext.m_Clip->m_fLeft = p_Left.getAlternativeValue(); layerContext.m_Clip->m_fLeft = p_Left.getCachedValue();
layerContext.m_Clip->m_fTop = p_Top.getAlternativeValue(); layerContext.m_Clip->m_fTop = p_Top.getCachedValue();
layerContext.m_Clip->m_fRight = getComputedWidth() + p_Left.getAlternativeValue(); layerContext.m_Clip->m_fRight = getComputedWidth() + p_Left.getCachedValue();
layerContext.m_Clip->m_fBottom = getComputedHeight() + p_Top.getAlternativeValue(); layerContext.m_Clip->m_fBottom = getComputedHeight() + p_Top.getCachedValue();
/* /*
if clip is not null, reduce it to intersect the current rect. if clip is not null, reduce it to intersect the current rect.
/!\ clip->intersect changes "clip" /!\ clip->intersect changes "clip"
*/ */


} else if (!layerContext.m_Clip->intersect( } else if (!layerContext.m_Clip->intersect(
p_Left.getAlternativeValue(), p_Left.getCachedValue(),
p_Top.getAlternativeValue(), p_Top.getCachedValue(),
p_Width.getAlternativeValue() + p_Left.getAlternativeValue(), p_Width.getCachedValue() + p_Left.getCachedValue(),
p_Height.getAlternativeValue() + p_Top.getAlternativeValue())) { p_Height.getCachedValue() + p_Top.getCachedValue())) {


/* don't need to draw children (out of bounds) */ /* don't need to draw children (out of bounds) */
return; return;
Expand Down Expand Up @@ -722,8 +722,8 @@ bool CanvasHandler::isDisplayed() const
void CanvasHandler::computeAbsolutePosition() void CanvasHandler::computeAbsolutePosition()
{ {
if (m_CoordPosition == COORD_ABSOLUTE) { if (m_CoordPosition == COORD_ABSOLUTE) {
p_Top.setAlternativeValue(this->getPropTop()); p_Top.setCachedValue(this->getPropTop());
p_Left.setAlternativeValue(this->getPropLeft()); p_Left.setCachedValue(this->getPropLeft());
return; return;
} }


Expand All @@ -743,8 +743,8 @@ void CanvasHandler::computeAbsolutePosition()
cparent = cparent->getParent(); cparent = cparent->getParent();
} }


p_Top.setAlternativeValue(ctop); p_Top.setCachedValue(ctop);
p_Left.setAlternativeValue(cleft); p_Left.setCachedValue(cleft);
} }


bool CanvasHandler::isOutOfBound() bool CanvasHandler::isOutOfBound()
Expand Down Expand Up @@ -985,8 +985,8 @@ void CanvasHandler::onDrag(InputEvent *ev, CanvasHandler *target, bool end)
arg[2].set(ev->m_y); arg[2].set(ev->m_y);
arg[3].set(ev->m_data[0]); arg[3].set(ev->m_data[0]);
arg[4].set(ev->m_data[1]); arg[4].set(ev->m_data[1]);
arg[5].set(ev->m_x - p_Left.getAlternativeValue()); // layerX arg[5].set(ev->m_x - p_Left.getCachedValue()); // layerX
arg[6].set(ev->m_y - p_Top.getAlternativeValue()); // layerY arg[6].set(ev->m_y - p_Top.getCachedValue()); // layerY
arg[7].set(target); // target arg[7].set(target); // target


if (!end && (m_Flags & kDrag_Flag) == 0) { if (!end && (m_Flags & kDrag_Flag) == 0) {
Expand All @@ -1011,8 +1011,8 @@ void CanvasHandler::onDrop(InputEvent *ev, CanvasHandler *drop)
arg[2].set(ev->m_y); arg[2].set(ev->m_y);
arg[3].set((int64_t)0); arg[3].set((int64_t)0);
arg[4].set((int64_t)0); arg[4].set((int64_t)0);
arg[5].set(ev->m_x - p_Left.getAlternativeValue()); // layerX arg[5].set(ev->m_x - p_Left.getCachedValue()); // layerX
arg[6].set(ev->m_y - p_Top.getAlternativeValue()); // layerY arg[6].set(ev->m_y - p_Top.getCachedValue()); // layerY
arg[7].set(drop); arg[7].set(drop);


this->fireEvent<CanvasHandler>(CanvasHandler::MOUSE_EVENT, arg); this->fireEvent<CanvasHandler>(CanvasHandler::MOUSE_EVENT, arg);
Expand Down Expand Up @@ -1078,8 +1078,8 @@ bool CanvasHandler::_handleEvent(InputEvent *ev)
arg[2].set(ev->m_y); arg[2].set(ev->m_y);
arg[3].set(ev->m_data[0]); // xrel arg[3].set(ev->m_data[0]); // xrel
arg[4].set(ev->m_data[1]); // yrel arg[4].set(ev->m_data[1]); // yrel
arg[5].set(ev->m_x - p_Left.getAlternativeValue()); // layerX arg[5].set(ev->m_x - p_Left.getCachedValue()); // layerX
arg[6].set(ev->m_y - p_Top.getAlternativeValue()); // layerY arg[6].set(ev->m_y - p_Top.getCachedValue()); // layerY
arg[7].set(this); // target arg[7].set(this); // target


/* fireEvent returns false if a stopPropagation is detected */ /* fireEvent returns false if a stopPropagation is detected */
Expand Down
20 changes: 10 additions & 10 deletions src/Graphics/CanvasHandler.h
Expand Up @@ -115,7 +115,7 @@ class CanvasHandlerBase
static constexpr float kUndefined_Value = NAN; static constexpr float kUndefined_Value = NAN;


CanvasProperty(const char *name, T val, State state, CanvasHandlerBase *h) : CanvasProperty(const char *name, T val, State state, CanvasHandlerBase *h) :
m_Name(name), m_Canvas(h), m_Value(val), m_AlternativeValue(val) { m_Name(name), m_Canvas(h), m_Value(val), m_CachedValue(val) {


position = m_Canvas->m_PropertyList.size(); position = m_Canvas->m_PropertyList.size();
m_Canvas->m_PropertyList.push_back((void *)this); m_Canvas->m_PropertyList.push_back((void *)this);
Expand All @@ -136,8 +136,8 @@ class CanvasHandlerBase
return m_Value; return m_Value;
} }


inline T getAlternativeValue() const { inline T getCachedValue() const {
return m_AlternativeValue; return m_CachedValue;
} }




Expand All @@ -150,8 +150,8 @@ class CanvasHandlerBase
m_Value = val; m_Value = val;
} }


inline void setAlternativeValue(T val) { inline void setCachedValue(T val) {
m_AlternativeValue = val; m_CachedValue = val;
} }


/* Change the user value */ /* Change the user value */
Expand Down Expand Up @@ -187,7 +187,7 @@ class CanvasHandlerBase
/* Value set by the user */ /* Value set by the user */
T m_UserValue; T m_UserValue;


T m_AlternativeValue; T m_CachedValue;


State m_State = State::kDefault; State m_State = State::kDefault;


Expand Down Expand Up @@ -335,12 +335,12 @@ class CanvasHandler : public CanvasHandlerBase, public Core::Events


inline float getPropLeftAbsolute() inline float getPropLeftAbsolute()
{ {
return p_Left.getAlternativeValue(); return p_Left.getCachedValue();
} }


inline float getPropTopAbsolute() inline float getPropTopAbsolute()
{ {
return p_Top.getAlternativeValue(); return p_Top.getCachedValue();
} }


float getTopScrolled() float getTopScrolled()
Expand Down Expand Up @@ -417,11 +417,11 @@ class CanvasHandler : public CanvasHandlerBase, public Core::Events
} }


inline float getComputedAbsoluteLeft() const { inline float getComputedAbsoluteLeft() const {
return p_Left.getAlternativeValue(); return p_Left.getCachedValue();
} }


inline float getComputedAbsoluteTop() const { inline float getComputedAbsoluteTop() const {
return p_Top.getAlternativeValue(); return p_Top.getCachedValue();
} }


Frontend::Context *getNidiumContext() const Frontend::Context *getNidiumContext() const
Expand Down

0 comments on commit 60946e8

Please sign in to comment.