void HTMLCanvasElement::reset() { if (m_ignoreReset) return; resetDirtyRect(); bool ok; bool hadImageBuffer = hasImageBuffer(); int w = getAttribute(widthAttr).toInt(&ok); if (!ok || w < 0) w = DefaultWidth; int h = getAttribute(heightAttr).toInt(&ok); if (!ok || h < 0) h = DefaultHeight; if (m_contextStateSaver) { // Reset to the initial graphics context state. m_contextStateSaver->restore(); m_contextStateSaver->save(); } if (m_context && m_context->is2d()) toCanvasRenderingContext2D(m_context.get())->reset(); IntSize oldSize = size(); IntSize newSize(w, h); // If the size of an existing buffer matches, we can just clear it instead of reallocating. // This optimization is only done for 2D canvases for now. if (hadImageBuffer && oldSize == newSize && m_context && m_context->is2d()) { if (!m_didClearImageBuffer) clearImageBuffer(); return; } setSurfaceSize(newSize); if (m_context && m_context->is3d() && oldSize != size()) toWebGLRenderingContext(m_context.get())->reshape(width(), height()); if (RenderObject* renderer = this->renderer()) { if (renderer->isCanvas()) { if (oldSize != size()) { toRenderHTMLCanvas(renderer)->canvasSizeChanged(); if (renderBox() && renderBox()->hasAcceleratedCompositing()) renderBox()->contentChanged(CanvasChanged); } if (hadImageBuffer) renderer->setShouldDoFullPaintInvalidation(true); } } WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator end = m_observers.end(); for (WillBeHeapHashSet<RawPtrWillBeWeakMember<CanvasObserver> >::iterator it = m_observers.begin(); it != end; ++it) (*it)->canvasResized(this); }
void SliderThumbElement::setPositionFromPoint(const LayoutPoint& absolutePoint) { RefPtr<HTMLInputElement> input = hostInput(); if (!input || !input->renderer() || !renderBox()) return; HTMLElement* trackElement = input->sliderTrackElement(); if (!trackElement->renderBox()) return; // Do all the tracking math relative to the input's renderer's box. RenderBox& inputRenderer = downcast<RenderBox>(*input->renderer()); RenderBox& trackRenderer = *trackElement->renderBox(); bool isVertical = hasVerticalAppearance(input.get()); bool isLeftToRightDirection = renderBox()->style().isLeftToRightDirection(); LayoutPoint offset(inputRenderer.absoluteToLocal(absolutePoint, UseTransforms)); FloatRect trackBoundingBox = trackRenderer.localToContainerQuad(FloatRect(0, 0, trackRenderer.width(), trackRenderer.height()), &inputRenderer).enclosingBoundingBox(); LayoutUnit trackLength; LayoutUnit position; if (isVertical) { trackLength = trackRenderer.contentHeight() - renderBox()->height(); position = offset.y() - renderBox()->height() / 2 - trackBoundingBox.y() - renderBox()->marginBottom(); } else { trackLength = trackRenderer.contentWidth() - renderBox()->width(); position = offset.x() - renderBox()->width() / 2 - trackBoundingBox.x(); position -= isLeftToRightDirection ? renderBox()->marginLeft() : renderBox()->marginRight(); } position = std::max<LayoutUnit>(0, std::min(position, trackLength)); const Decimal ratio = Decimal::fromDouble(static_cast<double>(position) / trackLength); const Decimal fraction = isVertical || !isLeftToRightDirection ? Decimal(1) - ratio : ratio; StepRange stepRange(input->createStepRange(RejectAny)); Decimal value = stepRange.clampValue(stepRange.valueFromProportion(fraction)); #if ENABLE(DATALIST_ELEMENT) const LayoutUnit snappingThreshold = renderer()->theme().sliderTickSnappingThreshold(); if (snappingThreshold > 0) { Decimal closest = input->findClosestTickMarkValue(value); if (closest.isFinite()) { double closestFraction = stepRange.proportionFromValue(closest).toDouble(); double closestRatio = isVertical || !isLeftToRightDirection ? 1.0 - closestFraction : closestFraction; LayoutUnit closestPosition = trackLength * closestRatio; if ((closestPosition - position).abs() <= snappingThreshold) value = closest; } } #endif String valueString = serializeForNumberType(value); if (valueString == input->value()) return; // FIXME: This is no longer being set from renderer. Consider updating the method name. input->setValueFromRenderer(valueString); if (renderer()) renderer()->setNeedsLayout(); }
bool HTMLCanvasElement::paintsIntoCanvasBuffer() const { ASSERT(m_context); if (!m_context->isAccelerated()) return true; if (renderBox() && renderBox()->hasAcceleratedCompositing()) return false; return true; }
void BinNode::render( u32 *screen, const u32 width, const u32 height, const TCameraSimple &camera ) { if ( leaf() ) { if ( members.size() > 0 ) renderBox( screen, width, height, min, max, 0x00ff00ff, camera ); else renderBox( screen, width, height, min, max, 0x0000ffff, camera ); } if ( child[0] != NULL ) child[0]->render( screen, width, height, camera ); if ( child[1] != NULL ) child[1]->render( screen, width, height, camera ); }
// Most common render function for this TextViewer void CTextViewer::process() { // Normal Keys/Axes if( g_pInput->getHoldedCommand(IC_DOWN) ) { m_timer++; if(m_timer >= 2) scrollDown(); } if( g_pInput->getHoldedCommand(IC_UP) ) { m_timer++; if(m_timer >= 2) scrollUp(); } // Page Keys if( g_pInput->getPressedKey(KPGDN) ) setPosition(m_linepos+16); if( g_pInput->getPressedKey(KPGUP) ) setPosition(m_linepos-16); if(m_timer>=8) m_timer=0; if(g_pInput->getPressedKey(KQUIT) || g_pInput->getPressedKey(KQ) ) m_mustclose = true; renderBox(); // This comes after, because it does transparent overlay }
void CTextViewer::render() { renderBox(); // This comes after, because it does use semi-transparent overlay SDL_BlitSurface(mpTextVSfc.get(), NULL, g_pVideoDriver->getBlitSurface(), NULL); }
int Element::scrollTop() { document()->updateLayoutIgnorePendingStylesheets(); if (RenderBox* rend = renderBox()) return adjustForAbsoluteZoom(rend->scrollTop(), rend); return 0; }
void drawGeom( dGeomID g, int colored = 0 ) { if( !g ) //If the geometry object is missing, end the function. return; const dReal *position; //Define pointers to internal positions and orientations. const dReal *orientation; //Pointers to constant objects (so the objects will not change). int type = dGeomGetClass( g ); //Get the type of geometry. position = dGeomGetPosition( g ); //Then, get the geometry position. orientation = dGeomGetRotation( g ); //And get existing geometry orientation. if( type == dBoxClass ) //Is it a box? { dReal sides[3]; dGeomBoxGetLengths( g, sides ); //Get length of sides. renderBox( sides, position, orientation, colored ); //Render the actual box in environment. } else if (type == dCylinderClass) { dReal radius, length; dGeomCylinderGetParams(g, &radius, &length); renderCylinder(radius, length, position, orientation); } else if (type == dCapsuleClass) { dReal radius, length; dGeomCapsuleGetParams(g, &radius, &length); renderCapsule(radius, length, position, orientation); } }
int Element::offsetTop() { document()->updateLayoutIgnorePendingStylesheets(); if (RenderBox* rend = renderBox()) return adjustForLocalZoom(rend->offsetTop(), rend); return 0; }
void HTMLBodyElement::setScrollTop(int scrollTop) { Document& document = this->document(); document.updateLayoutIgnorePendingStylesheets(); if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { RenderBox* render = renderBox(); if (!render) return; if (render->hasOverflowClip()) { // FIXME: Investigate how are other browsers casting to int (rounding, ceiling, ...). render->setScrollTop(static_cast<int>(scrollTop * render->style()->effectiveZoom())); return; } if (!document.inQuirksMode()) return; } LocalFrame* frame = document.frame(); if (!frame) return; FrameView* view = frame->view(); if (!view) return; view->setScrollPosition(IntPoint(view->scrollX(), static_cast<int>(scrollTop * frame->pageZoomFactor()))); }
int Element::clientHeight() { document().updateLayout(); if (RenderBox* renderer = renderBox()) return renderer->pixelSnappedClientHeight(); return 0; }
int Element::clientTop() { document().updateLayout(); if (RenderBox* renderer = renderBox()) return roundToInt(renderer->clientTop()); return 0; }
Element* Element::offsetParent() { document()->updateLayoutIgnorePendingStylesheets(); if (RenderBox* rend = renderBox()) if (RenderObject* offsetParent = rend->offsetParent()) return static_cast<Element*>(offsetParent->element()); return 0; }
void Element::setWidth(double width) { if (RenderBox* box = renderBox()) { box->setWidth(width); // TODO(ojan): Remove override widths once we remove box layout from the C++ code. box->setOverrideLogicalContentWidth(width); } }
int Element::scrollHeight() { document()->updateLayoutIgnorePendingStylesheets(); if (RenderBox* rend = renderBox()) { if (rend->hasOverflowClip() || !rend->isRenderInline()) return adjustForAbsoluteZoom(rend->scrollHeight(), rend); } return 0; }
// Update based on events int Counter::update(SDL_Event event) { string newMessage; ostringstream convert; convert << getCountValue(); newMessage = convert.str(); setMessage(newMessage); renderBox(); }
/******************************************************************************* Function to draw a geometry object. *******************************************************************************/ void GOdeObject::drawGeom( dGeomID g, const dReal *position, const dReal *orientation ) const { if( !g ) //If the geometry object is missing, end the function. return; if( !position ) //Position was not passed? position = dGeomGetPosition( g ); //Then, get the geometry position. if( !orientation ) //Orientation was not given? orientation = dGeomGetRotation( g ); //And get existing geometry orientation. int type = dGeomGetClass( g ); //Get the type of geometry. if( type == dBoxClass ) //Is it a box? { dReal sides[3]; dGeomBoxGetLengths( g, sides ); //Get length of sides. renderBox( sides, position, orientation ); //Render the actual box in environment. } if( type == dSphereClass ) //Is it a sphere? { dReal radius; radius = dGeomSphereGetRadius( g ); //Get the radius. renderSphere( radius, position, orientation ); //Render sphere in environment. } if( type == dCapsuleClass ) { dReal radius; dReal length; dGeomCapsuleGetParams( g, &radius, &length ); //Get both radius and length. renderCapsule( radius, length, position, orientation ); //Render capsule in environment. } if( type == dGeomTransformClass ) //Is it an embeded geom in a composite body. { dGeomID g2 = dGeomTransformGetGeom( g ); //Get the actual geometry inside the wrapper. const dReal *position2 = dGeomGetPosition( g2 ); //Get position and orientation of wrapped geometry. const dReal *orientation2 = dGeomGetRotation( g2 ); dVector3 actualPosition; //Real world coordinated position and orientation dMatrix3 actualOrientation; //of the wrapped geometry. dMultiply0_331( actualPosition, orientation, position2 ); //Get world coordinates of geometry position. actualPosition[0] += position[0]; actualPosition[1] += position[1]; actualPosition[2] += position[2]; dMultiply0_333( actualOrientation, orientation, orientation2 ); //Get world coordinates of geom orientation. drawGeom( g2, actualPosition, actualOrientation ); //Draw embeded geometry. } }
Text::Text(int newWidth, int newHeight, int newX, int newY, int newFontSize, string newMessage) { setWidth(newWidth); //setting text box height, width, x coord, and y coord setHeight(newHeight); setX(newX); setY(newY); setFontSize(newFontSize); //setting font size setMessage(newMessage); //setting the string to be displayed renderBox(); //drawing the text box on the screen }
// Constructor Button::Button(int newWidth, int newHeight, int newX, int newY, int newFontSize, string newMessage) { setWidth(newWidth); setHeight(newHeight); setX(newX); setY(newY); setFontSize(newFontSize); setMessage(newMessage); renderBox(); }
// Constructor Counter::Counter(int newWidth, int newHeight, int newX, int newY, int newFontSize, string newMessage, int newCountValue) { setWidth(newWidth); setHeight(newHeight); setX(newX); setY(newY); setFontSize(newFontSize); setMessage(newMessage); renderBox(); setCountValue(newCountValue); }
void SpinButtonElement::defaultEventHandler(Event* evt) { if (!evt->isMouseEvent()) { if (!evt->defaultHandled()) HTMLDivElement::defaultEventHandler(evt); return; } const MouseEvent* mevt = static_cast<MouseEvent*>(evt); if (mevt->button() != LeftButton) { if (!evt->defaultHandled()) HTMLDivElement::defaultEventHandler(evt); return; } HTMLInputElement* input = static_cast<HTMLInputElement*>(shadowAncestorNode()); IntPoint local = roundedIntPoint(renderBox()->absoluteToLocal(mevt->absoluteLocation(), false, true)); if (evt->type() == eventNames().clickEvent) { if (renderBox()->borderBoxRect().contains(local)) { input->focus(); input->select(); if (local.y() < renderBox()->y() + renderBox()->height() / 2) input->stepUpFromRenderer(1); else input->stepUpFromRenderer(-1); evt->setDefaultHandled(); } } else if (evt->type() == eventNames().mousemoveEvent) { if (renderBox()->borderBoxRect().contains(local)) { if (!m_capturing) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(input); m_capturing = true; } } bool oldOnUpButton = m_onUpButton; m_onUpButton = local.y() < renderBox()->y() + renderBox()->height() / 2; if (m_onUpButton != oldOnUpButton) renderer()->repaint(); } else { if (m_capturing) { if (Frame* frame = document()->frame()) { frame->eventHandler()->setCapturingMouseEventsNode(0); m_capturing = false; } } } } if (!evt->defaultHandled()) HTMLDivElement::defaultEventHandler(evt); }
void HTMLCanvasElement::didFinalizeFrame() { if (m_dirtyRect.isEmpty()) return; // Propagate the m_dirtyRect accumulated so far to the compositor // before restarting with a blank dirty rect. FloatRect srcRect(0, 0, size().width(), size().height()); m_dirtyRect.intersect(srcRect); if (RenderBox* ro = renderBox()) { FloatRect mappedDirtyRect = mapRect(m_dirtyRect, srcRect, ro->contentBoxRect()); ro->invalidatePaintRectangle(enclosingIntRect(mappedDirtyRect)); } notifyObserversCanvasChanged(m_dirtyRect); m_finalizeFrameTask.Cancel(); m_dirtyRect = FloatRect(); }
int HTMLBodyElement::scrollTop() { Document& document = this->document(); document.updateLayoutIgnorePendingStylesheets(); if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { RenderBox* render = renderBox(); if (!render) return 0; if (render->hasOverflowClip()) return adjustForAbsoluteZoom(render->scrollTop(), render); if (!document.inQuirksMode()) return 0; } FrameView* view = document.view(); return view ? adjustForZoom(view->scrollY(), &document) : 0; }
double HTMLBodyElement::scrollTop() { Document& document = this->document(); document.updateLayoutIgnorePendingStylesheets(); if (RuntimeEnabledFeatures::scrollTopLeftInteropEnabled()) { RenderBox* render = renderBox(); if (!render) return 0; if (render->hasOverflowClip()) return adjustLayoutUnitForAbsoluteZoom(render->scrollTop(), *render); if (!document.inQuirksMode()) return 0; } if (FrameView* view = document.view()) return adjustScrollForAbsoluteZoom(view->scrollY(), document.frame()->pageZoomFactor()); return 0; }
void HTMLCanvasElement::didFinalizeFrame() { if (m_dirtyRect.isEmpty()) return; // Propagate the m_dirtyRect accumulated so far to the compositor // before restarting with a blank dirty rect. FloatRect srcRect(0, 0, size().width(), size().height()); m_dirtyRect.intersect(srcRect); if (RenderBox* ro = renderBox()) { FloatRect mappedDirtyRect = mapRect(m_dirtyRect, srcRect, ro->contentBoxRect()); // For querying RenderLayer::compositingState() // FIXME: is this invalidation using the correct compositing state? DisableCompositingQueryAsserts disabler; ro->invalidatePaintRectangle(enclosingIntRect(mappedDirtyRect)); } notifyObserversCanvasChanged(m_dirtyRect); blink::Platform::current()->currentThread()->removeTaskObserver(this); m_dirtyRect = FloatRect(); }
int Element::clientHeight() { document()->updateLayoutIgnorePendingStylesheets(); // When in strict mode, clientHeight for the document element should return the height of the containing frame. // When in quirks mode, clientHeight for the body element should return the height of the containing frame. bool inCompatMode = document()->inCompatMode(); if ((!inCompatMode && document()->documentElement() == this) || (inCompatMode && isHTMLElement() && document()->body() == this)) { if (FrameView* view = document()->view()) return view->layoutHeight(); } if (RenderBox* rend = renderBox()) { if (!rend->isRenderInline()) return adjustForAbsoluteZoom(rend->clientHeight(), rend); } return 0; }
void sprite::render() { if ( animation >= animations.size() ) return; if ( ++intcount >= animations[animation].interval ) { frame++; intcount = 0; if ( frame >= animations[animation].frames.size() ) { frame = 0; if ( !animations[animation].loop ) { animation = animations[animation].next; } } } struct frame * f = &(frames[animations[animation].frames[frame]]); /* printf("animation %02d, frame(%02d/%02d)=%02d\n", animation, frame, animations[animation].frames.size(), animations[animation].frames[frame]);*/ g->r->addQuad(tex->getTexture(), 1.0, &(g->c), x+f->ox, y+f->oy, qw, qh, f->x, f->y, f->w, f->h, 1.0f, 1.0f, 1.0f, 1.0f, flip_x, flip_y); if ( g->drawBoxes() ) renderBox(); }
void renderAll(Game& game) { SDL_RenderClear(game.renderer); if (game.bonusItem.alive) renderItem(game.renderer, game.bonusItem); for (unsigned int i = 0; i < game.daMissiles.size(); i++) renderMissile(game.renderer, game.daMissiles[i]); for (unsigned int i = 0; i < game.daEnemies.size(); i++) renderEnemy(game.renderer, game.daEnemies[i]); for (unsigned int i = 0; i < game.daBlasts.size(); i++) renderBlast(game.renderer, game.daBlasts[i]); if (game.daBox.alive) renderBox(game.renderer, game.daBox); for (unsigned int i = 0; i < game.lives.size(); i++) renderBlast(game.renderer, game.lives[i]); renderScore(game); SDL_UpdateWindowSurface(game.window); }
void SliderThumbElement::setPositionFromPoint(const LayoutPoint& point) { HTMLInputElement* input = hostInput(); if (!input->renderer() || !renderer()) return; LayoutPoint offset = roundedLayoutPoint(input->renderer()->absoluteToLocal(point, false, true)); bool isVertical = hasVerticalAppearance(input); LayoutUnit trackSize; LayoutUnit position; LayoutUnit currentPosition; // We need to calculate currentPosition from absolute points becaue the // renderer for this node is usually on a layer and renderBox()->x() and // y() are unusable. // FIXME: This should probably respect transforms. LayoutPoint absoluteThumbOrigin = renderBox()->absoluteBoundingBoxRectIgnoringTransforms().location(); LayoutPoint absoluteSliderContentOrigin = roundedLayoutPoint(input->renderer()->localToAbsolute()); if (isVertical) { trackSize = input->renderBox()->contentHeight() - renderBox()->height(); position = offset.y() - renderBox()->height() / 2; currentPosition = absoluteThumbOrigin.y() - absoluteSliderContentOrigin.y(); } else { trackSize = input->renderBox()->contentWidth() - renderBox()->width(); position = offset.x() - renderBox()->width() / 2; currentPosition = absoluteThumbOrigin.x() - absoluteSliderContentOrigin.x(); } position = max<LayoutUnit>(0, min(position, trackSize)); if (position == currentPosition) return; StepRange range(input); double fraction = static_cast<double>(position) / trackSize; if (isVertical || !renderBox()->style()->isLeftToRightDirection()) fraction = 1 - fraction; double value = range.clampValue(range.valueFromProportion(fraction)); // FIXME: This is no longer being set from renderer. Consider updating the method name. input->setValueFromRenderer(serializeForNumberType(value)); renderer()->setNeedsLayout(true); input->dispatchFormControlChangeEvent(); }
void SliderThumbElement::setPositionFromPoint(const IntPoint& point) { HTMLInputElement* input = hostInput(); ASSERT(input); if (!input->renderer() || !renderer()) return; IntPoint offset = roundedIntPoint(input->renderer()->absoluteToLocal(point, false, true)); RenderStyle* sliderStyle = input->renderer()->style(); bool isVertical = sliderStyle->appearance() == SliderVerticalPart || sliderStyle->appearance() == MediaVolumeSliderPart; int trackSize; int position; int currentPosition; if (isVertical) { trackSize = input->renderBox()->contentHeight() - renderBox()->height(); position = offset.y() - renderBox()->height() / 2; currentPosition = renderBox()->y() - input->renderBox()->contentBoxRect().y(); } else { trackSize = input->renderBox()->contentWidth() - renderBox()->width(); position = offset.x() - renderBox()->width() / 2; currentPosition = renderBox()->x() - input->renderBox()->contentBoxRect().x(); } position = max(0, min(position, trackSize)); if (position == currentPosition) return; StepRange range(input); double fraction = static_cast<double>(position) / trackSize; if (isVertical) fraction = 1 - fraction; double value = range.clampValue(range.valueFromProportion(fraction)); // FIXME: This is no longer being set from renderer. Consider updating the method name. input->setValueFromRenderer(serializeForNumberType(value)); renderer()->setNeedsLayout(true); input->dispatchFormControlChangeEvent(); }