Skip to content
Permalink
Browse files

CanvasProperty: renamed AlternativeValue to CachedValue

  • Loading branch information...
paraboul committed Apr 20, 2017
1 parent 0a51ef7 commit 60946e8b6969e670558721df84b5e40e8b64d1c5
Showing with 58 additions and 53 deletions.
  1. +6 −6 src/Binding/JSCanvas.cpp
  2. +5 −0 src/Embed/lib/Elements.js
  3. +37 −37 src/Graphics/CanvasHandler.cpp
  4. +10 −10 src/Graphics/CanvasHandler.h
@@ -415,9 +415,9 @@ bool JSCanvas::JS_getContext(JSContext *cx, JS::CallArgs &args)
case CanvasContext::CONTEXT_2D: {
Canvas2DContext *ctx2d = new Canvas2DContext(
m_CanvasHandler, cx,
m_CanvasHandler->p_Width.getAlternativeValue()
m_CanvasHandler->p_Width.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2),
m_CanvasHandler->p_Height.getAlternativeValue()
m_CanvasHandler->p_Height.getCachedValue()
+ (m_CanvasHandler->p_Coating * 2),
ui);

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

@@ -961,15 +961,15 @@ bool JSCanvas::JSGetter_cursor(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));

return true;
}

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));

return true;
@@ -407,6 +407,11 @@ Elements.flexcanvas = class extends NidiumNode {
this._color = attributes.color || "red";
}

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

paint(ctx, width, height) {
ctx.fillStyle = this._color;
ctx.fillRect(0, 0, width, height);
@@ -42,12 +42,12 @@ CanvasHandler::CanvasHandler(float width,

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

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

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

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

if (layerContext.m_Clip) {

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

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


deviceSetSize(nwidth, nheight);
}

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


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

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

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

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

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

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

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

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

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

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

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

/* fireEvent returns false if a stopPropagation is detected */
@@ -115,7 +115,7 @@ class CanvasHandlerBase
static constexpr float kUndefined_Value = NAN;

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();
m_Canvas->m_PropertyList.push_back((void *)this);
@@ -136,8 +136,8 @@ class CanvasHandlerBase
return m_Value;
}

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


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

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

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

T m_AlternativeValue;
T m_CachedValue;

State m_State = State::kDefault;

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

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

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

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

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

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

Frontend::Context *getNidiumContext() const

0 comments on commit 60946e8

Please sign in to comment.
You can’t perform that action at this time.