vec2 Control::getHitPercent( const vec2 &pt ) { vec2 hp; Rectf r = mHitRect; r.offset( getOrigin() ); hp = ( pt - r.getUpperLeft() ) / r.getSize(); return hp; }
Rectf View::getBounds( bool bIncludeSubviews ) { Rectf bounds = Rectf( 0.0f, 0.0f, getWidth(), getHeight() ); if( bIncludeSubviews ) { for ( auto &it : mSubViews ) { bounds.include( it->getBounds( bIncludeSubviews ) ); } bounds.offset( getOrigin( false ) ); } else { bounds.offset( getOrigin() ); } return bounds; }
vec2 View::getHitPercent( const vec2 &pt ) { vec2 hp; Rectf r; r.set( 0, 0, getWidth(), getHeight() ); r.offset( getOrigin() ); hp = ( pt - r.getUpperLeft() ) / r.getSize(); return hp; }
bool Control::isHit( const glm::vec2 &pt ) { if( mVisible ) { Rectf r = mHitRect; r.offset( getOrigin() ); return r.contains( pt ); } return false; }
void TextInput::drawFill( std::vector<RenderData> &data, const ci::ColorA &color ) { if( mClicked ) { Rectf rect = mHitRect; rect.offset( vec2( mLabelRef->getStringWidth( mDisplayValue.substr( 0, mCursorPosition ) ) + mPadding.mLeft, mPadding.mTop ) ); if( mCursorPosition > 0 ) { rect.offset( vec2( mLabelRef->getSpacing(), 0.0f ) ); } rect.y1 -= mPadding.mTop * 0.5f; rect.x2 = rect.x1 + 1.0f; rect.y2 = rect.y1 + (int)mFormat.mFontSize + mPadding.mBottom; addRect( data, color, rect ); } else { addRect( data, mColorClear, mHitRect ); } }
bool View::isHit( const vec2 &pt ) { if( mVisible ) { Rectf r; r.set( 0, 0, getWidth(), getHeight() ); r.offset( getOrigin() ); return r.contains( pt ); } return false; }
Rectf Control::getBounds( bool bIncludeSubviews ) { Rectf bounds = Rectf( 0.0f, 0.0f, getWidth(), getHeight() ); Rectf hitRect = mHitRect; hitRect.x1-=mPadding.mLeft; hitRect.y1-=mPadding.mTop; hitRect.x2+=mPadding.mRight; hitRect.y2+=mPadding.mBottom; bounds.include( hitRect ); if( bIncludeSubviews ) { for ( auto &it : mSubViews ) { bounds.include( it->getBounds( bIncludeSubviews ) ); } bounds.offset( getOrigin( false ) ); } else { bounds.offset( getOrigin() ); } return bounds; }
vec2 DialerT<T>::getHitPercent( const vec2 &pt ) { vec2 hp; Rectf r = mHitRect; r.offset( getOrigin() ); r.x1 += mPadding.mLeft; r.x2 -= mPadding.mRight; r.y1 += mPadding.mTop; r.y2 -= mPadding.mBottom; hp = ( pt - r.getUpperLeft() ) / r.getSize(); return hp; }
void FalagardMultiLineEditbox::cacheCaretImagery(const Rectf& textArea) { MultiLineEditbox* w = (MultiLineEditbox*)d_window; const Font* fnt = w->getFont(); // require a font so that we can calculate caret position. if (fnt) { // get line that caret is in size_t caretLine = w->getLineNumberFromIndex(w->getCaretIndex()); const MultiLineEditbox::LineList& d_lines = w->getFormattedLines(); // if caret line is valid. if (caretLine < d_lines.size()) { // calculate pixel offsets to where caret should be drawn size_t caretLineIdx = w->getCaretIndex() - d_lines[caretLine].d_startIdx; float ypos = caretLine * fnt->getLineSpacing(); float xpos = fnt->getTextAdvance(w->getText().substr(d_lines[caretLine].d_startIdx, caretLineIdx)); // // get base offset to target layer for cursor. // Renderer* renderer = System::getSingleton().getRenderer(); // float baseZ = renderer->getZLayer(7) - renderer->getCurrentZ(); // get WidgetLookFeel for the assigned look. const WidgetLookFeel& wlf = getLookNFeel(); // get caret imagery const ImagerySection& caretImagery = wlf.getImagerySection("Caret"); // calculate finat destination area for caret Rectf caretArea; caretArea.left(textArea.left() + xpos); caretArea.top(textArea.top() + ypos); caretArea.setWidth(caretImagery.getBoundingRect(*w).getSize().d_width); caretArea.setHeight(fnt->getLineSpacing()); caretArea.offset(Vector2f(-w->getHorzScrollbar()->getScrollPosition(), -w->getVertScrollbar()->getScrollPosition())); // cache the caret image for rendering. caretImagery.render(*w, caretArea, 0, &textArea); } } }
void View::addBoundsOutline( vector<RenderData> &data, const ColorA &color, float lineWidth ) { Rectf rect = getBounds( true ); rect.offset(-getOrigin(false)); addRectOutline( data, color, rect, lineWidth ); }
void View::addBounds( vector<RenderData> &data, const ColorA &color ) { Rectf rect = getBounds( true ); rect.offset(-getOrigin(false)); addRect( data, color, rect ); }
void TextFragment::drawFragment(const vec2& baseline_location, float text_alpha) { vec2 location = baseline_location + vec2(0,g_skin.getFontBaslineOffset(m_font_type, m_small, m_bold, m_italic)); const gl::TextureFontRef& texture_font = getTextureFont(); if(m_is_spoiler) { float brighten_amount = (m_clicked ? 0.2f : 0.1f) * m_hover_percent; for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { ci::ColorA color(g_skin.getColor(Skin::SPOILER), text_alpha); if(m_hovered || m_clicked || m_hover_percent != 0.0f) { gl::color(ColorA(math<float>::min(1, color.r + brighten_amount), math<float>::min(1, color.g + brighten_amount), math<float>::min(1, color.b + brighten_amount), math<float>::min(1, color.a))); } else { gl::color(color); } Rectf rect = m_rect_array[i]; rect.offset(baseline_location); gl::drawSolidRect(rect); } } } if(!m_is_spoiler || !m_spoiled) { if((m_hovered || m_clicked || m_hover_percent != 0.0f) && m_spoiled) { for(int y = -2; y <= 2; y++) { for(int x = -2; x <= 2; x++) { gl::color(ColorA(m_color, (m_clicked ? 0.05f : 0.025f) * m_hover_percent * text_alpha)); texture_font->drawGlyphs(m_glyph_rendering_array, location + vec2(x, y)); if(m_underline) { gl::color(ColorA(m_underline_color, (m_clicked ? 0.05f : 0.025f) * m_hover_percent * text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getUnderlineOffset()); offset += vec2(x, y); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } if(m_strike) { gl::color(ColorA(m_strike_color, (m_clicked ? 0.05f : 0.025f) * m_hover_percent * text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getStrikeOffset(m_small)); offset += vec2(x, y); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } } } // brighten main color slightly float brighten_amount = (m_clicked ? 0.2f : 0.1f) * m_hover_percent; gl::color(ColorA(math<float>::min(1, m_color.r + brighten_amount), math<float>::min(1, m_color.g + brighten_amount), math<float>::min(1, m_color.b + brighten_amount), text_alpha)); texture_font->drawGlyphs(m_glyph_rendering_array, location); if(m_underline) { gl::color(ColorA(math<float>::min(1, m_underline_color.r + brighten_amount), math<float>::min(1, m_underline_color.g + brighten_amount), math<float>::min(1, m_underline_color.b + brighten_amount), text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getUnderlineOffset()); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } if(m_strike) { gl::color(ColorA(math<float>::min(1, m_strike_color.r + brighten_amount), math<float>::min(1, m_strike_color.g + brighten_amount), math<float>::min(1, m_strike_color.b + brighten_amount), text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getStrikeOffset(m_small)); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } } else { // this bit here is to show font rendering location. if(g_debug_text_rect_draw) { gl::ScopedLineWidth scopedLW(1); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::color(ci::ColorA(g_skin.getColor(Skin::LOL_WTF), text_alpha)); Rectf rect = m_rect_array[i]; rect.offset(baseline_location); gl::drawStrokedRect(rect); gl::color(ci::ColorA(g_skin.getColor(Skin::LOL_INF), text_alpha)); vec2 offset(0, g_skin.getBaselineDrop()); gl::drawLine(baseline_location + m_rect_array[i].getUpperLeft() + offset, baseline_location + m_rect_array[i].getUpperRight() + offset); } } } gl::color(ci::ColorA(m_color, text_alpha)); texture_font->drawGlyphs(m_glyph_rendering_array, location); if(m_underline) { gl::color(ci::ColorA(m_underline_color, text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getUnderlineOffset()); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } if(m_strike) { gl::color(ci::ColorA(m_strike_color, text_alpha)); gl::ScopedLineWidth scopedLW(g_skin.getLineThickness()); vec2 offset(0, -g_skin.getStrikeOffset(m_small)); for(size_t i = 0; i < m_rect_array.size(); i++) { if(m_rect_array[i].getWidth() > 0) { gl::drawLine(baseline_location + m_rect_array[i].getLowerLeft() + offset, baseline_location + m_rect_array[i].getLowerRight() + offset); } } } } } if(advanceHoverPercent()) { needsRedraw(); } }