void RCImageButton::ccTouchEnded(CCTouch *pTouch, CCEvent *pEvent) { CCPoint realitivePoint = convertToNodeSpace(pTouch->getLocation()); if(realitivePoint.x >= 0 && realitivePoint.y >= 0 && m_obContentSize.width> realitivePoint.x && m_obContentSize.height>realitivePoint.y) { m_isTouched = false; updateTextureRect(); if(m_pListener && m_pfnSelector) { (m_pListener->*m_pfnSelector)(this); } } else { struct cc_timeval now; CCTime::gettimeofdayCocos2d(&now, NULL); long timeNow = now.tv_sec * 1000 + now.tv_usec / 1000; if (timeNow - m_touchTimer < m_touchUpOutDelay) { if (m_pListener && m_pfnSelector) { (m_pListener->*m_pfnSelector)(this); } } } if (m_isTouched) { m_isTouched = false; updateTextureRect(); } }
void RCImageButton::setImageDisplayFrame(CCSpriteFrame* frame) { if (!frame) { return; } m_pButtonSprite->setDisplayFrame(frame); CCSize size = m_pButtonSprite->getContentSize(); m_pButtonSprite->setAnchorPoint(ccp(0,0)); setContentSize(size); setAnchorPoint(ccp(0.5,0.5)); updateTextureRect(); }
void SfxMutebox::update(bool isButtonRelease, const sf::Vector2f &mousePosition) { resetHover(); if (this->shape->getGlobalBounds().contains(mousePosition)) { hover(); if (isButtonRelease) { this->isChecked = !this->isChecked; updateTextureRect(); } } }
void RCImageButton::ccTouchMoved(CCTouch *pTouch, CCEvent *pEvent) { if (!m_isTouched) { return; } CCPoint realitivePoint = convertToNodeSpace(pTouch->getLocation()); if(realitivePoint.x >= 0 && realitivePoint.y >= 0 && m_obContentSize.width> realitivePoint.x && m_obContentSize.height>realitivePoint.y) { m_isTouched = true; } else { m_isTouched = false; } updateTextureRect(); }
bool RCImageButton::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent) { if (!isVisible() || !getParent()->isVisible()) { return false; } CCPoint realitivePoint = convertToNodeSpace(pTouch->getLocation()); if(realitivePoint.x >= 0 && realitivePoint.y >= 0 && m_obContentSize.width> realitivePoint.x && m_obContentSize.height>realitivePoint.y) { struct cc_timeval now; CCTime::gettimeofdayCocos2d(&now, NULL); m_touchTimer = now.tv_sec * 1000 + now.tv_usec / 1000; m_isTouched = true; updateTextureRect(); return true; } return false; }
void ContentLayerChromium::updateContents() { RenderLayerBacking* backing = static_cast<RenderLayerBacking*>(m_owner->client()); if (!backing || backing->paintingGoesToWindow()) return; ASSERT(drawsContent()); ASSERT(layerRenderer()); void* pixels = 0; IntRect dirtyRect; IntRect updateRect; IntSize requiredTextureSize; IntSize bitmapSize; // FIXME: Remove this test when tiled layers are implemented. if (requiresClippedUpdateRect()) { // A layer with 3D transforms could require an arbitrarily large number // of texels to be repainted, so ignore these layers until tiling is // implemented. if (!drawTransform().isIdentityOrTranslation()) { m_skipsDraw = true; return; } calculateClippedUpdateRect(dirtyRect, m_largeLayerDrawRect); if (!layerRenderer()->checkTextureSize(m_largeLayerDrawRect.size())) { m_skipsDraw = true; return; } // If the portion of the large layer that's visible hasn't changed // then we don't need to update it, _unless_ its contents have changed // in which case we only update the dirty bits. if (m_largeLayerDirtyRect == dirtyRect) { if (!m_dirtyRect.intersects(dirtyRect)) return; dirtyRect.intersect(IntRect(m_dirtyRect)); updateRect = dirtyRect; requiredTextureSize = m_largeLayerDirtyRect.size(); } else { m_largeLayerDirtyRect = dirtyRect; requiredTextureSize = dirtyRect.size(); updateRect = IntRect(IntPoint(0, 0), dirtyRect.size()); } } else { dirtyRect = IntRect(m_dirtyRect); IntRect boundsRect(IntPoint(0, 0), m_bounds); requiredTextureSize = m_bounds; // If the texture needs to be reallocated then we must redraw the entire // contents of the layer. if (requiredTextureSize != m_allocatedTextureSize) dirtyRect = boundsRect; else { // Clip the dirtyRect to the size of the layer to avoid drawing // outside the bounds of the backing texture. dirtyRect.intersect(boundsRect); } updateRect = dirtyRect; } if (dirtyRect.isEmpty()) return; #if PLATFORM(SKIA) const SkBitmap* skiaBitmap = 0; OwnPtr<skia::PlatformCanvas> canvas; OwnPtr<PlatformContextSkia> skiaContext; OwnPtr<GraphicsContext> graphicsContext; canvas.set(new skia::PlatformCanvas(dirtyRect.width(), dirtyRect.height(), false)); skiaContext.set(new PlatformContextSkia(canvas.get())); // This is needed to get text to show up correctly. // FIXME: Does this take us down a very slow text rendering path? skiaContext->setDrawingToImageBuffer(true); graphicsContext.set(new GraphicsContext(reinterpret_cast<PlatformGraphicsContext*>(skiaContext.get()))); // Bring the canvas into the coordinate system of the paint rect. canvas->translate(static_cast<SkScalar>(-dirtyRect.x()), static_cast<SkScalar>(-dirtyRect.y())); m_owner->paintGraphicsLayerContents(*graphicsContext, dirtyRect); const SkBitmap& bitmap = canvas->getDevice()->accessBitmap(false); skiaBitmap = &bitmap; ASSERT(skiaBitmap); SkAutoLockPixels lock(*skiaBitmap); SkBitmap::Config skiaConfig = skiaBitmap->config(); // FIXME: do we need to support more image configurations? if (skiaConfig == SkBitmap::kARGB_8888_Config) { pixels = skiaBitmap->getPixels(); bitmapSize = IntSize(skiaBitmap->width(), skiaBitmap->height()); } #elif PLATFORM(CG) Vector<uint8_t> tempVector; int rowBytes = 4 * dirtyRect.width(); tempVector.resize(rowBytes * dirtyRect.height()); memset(tempVector.data(), 0, tempVector.size()); RetainPtr<CGColorSpaceRef> colorSpace(AdoptCF, CGColorSpaceCreateDeviceRGB()); RetainPtr<CGContextRef> contextCG(AdoptCF, CGBitmapContextCreate(tempVector.data(), dirtyRect.width(), dirtyRect.height(), 8, rowBytes, colorSpace.get(), kCGImageAlphaPremultipliedFirst | kCGBitmapByteOrder32Host)); CGContextTranslateCTM(contextCG.get(), 0, dirtyRect.height()); CGContextScaleCTM(contextCG.get(), 1, -1); GraphicsContext graphicsContext(contextCG.get()); // Translate the graphics context into the coordinate system of the dirty rect. graphicsContext.translate(-dirtyRect.x(), -dirtyRect.y()); m_owner->paintGraphicsLayerContents(graphicsContext, dirtyRect); pixels = tempVector.data(); bitmapSize = dirtyRect.size(); #else #error "Need to implement for your platform." #endif unsigned textureId = m_contentsTexture; if (!textureId) textureId = layerRenderer()->createLayerTexture(); if (pixels) updateTextureRect(pixels, bitmapSize, requiredTextureSize, updateRect, textureId); }
void RCImageButton::ccTouchCancelled(CCTouch *pTouch, CCEvent *pEvent) { m_isTouched = false; updateTextureRect(); }
void RCCheckButton::setSelected(bool var) { m_selected = var; updateTextureRect(); }
void SfxMutebox::fitStateToVolume() { this->isChecked = (this->soundManager->getEffectsVolume() < 0.1f); updateTextureRect(); }
void SfxMutebox::setState(bool value) { this->isChecked = value; updateTextureRect(); }