virtual void onDraw(SkCanvas* canvas) { #ifdef SK_BUILD_FOR_MAC CGContextRef cg = 0; { SkImageInfo info; size_t rowBytes; const void* addr = canvas->peekPixels(&info, &rowBytes); if (addr) { cg = makeCG(info, addr, rowBytes); } } #endif drawGrad(canvas); const SkColor fg[] = { 0xFFFFFFFF, 0xFFFFFF00, 0xFFFF00FF, 0xFF00FFFF, 0xFFFF0000, 0xFF00FF00, 0xFF0000FF, 0xFF000000, }; const char* text = "Hamburgefons"; size_t len = strlen(text); SkPaint paint; setFont(&paint, "Times"); paint.setTextSize(SkIntToScalar(16)); paint.setAntiAlias(true); paint.setLCDRenderText(true); SkScalar x = SkIntToScalar(10); for (size_t i = 0; i < SK_ARRAY_COUNT(fg); ++i) { paint.setColor(fg[i]); SkScalar y = SkIntToScalar(40); SkScalar stopy = SkIntToScalar(HEIGHT); while (y < stopy) { if (true) { canvas->drawText(text, len, x, y, paint); } #ifdef SK_BUILD_FOR_MAC else { cgDrawText(cg, text, len, SkScalarToFloat(x), static_cast<float>(HEIGHT) - SkScalarToFloat(y), paint); } #endif y += paint.getTextSize() * 2; } x += SkIntToScalar(1024) / SK_ARRAY_COUNT(fg); } #ifdef SK_BUILD_FOR_MAC CGContextRelease(cg); #endif }
void CGLabel::paint(cairo_t *cr) { CGFrame::paint(cr); float offx=m_textOffset; float offy=m_textOffset; if (m_horizontalAlignment!=cgalLeft) offx=0; if (m_verticalAlignment!=cgalTop) offy=0; //drawText(cr, m_border+offx, m_border+offy, m_width-m_frameWidth*2-offx*2, m_height-m_frameWidth*2-offy*2, m_text); cgDrawText(cr, m_border+offx, m_border+offy, m_width-m_frameWidth*2-offx*2, m_height-m_frameWidth*2-offy*2, m_text, m_fontFace, m_fontSize, m_italic, m_bold, m_textColor, m_lineSpacing, m_horizontalAlignment, m_verticalAlignment); }
void CGMarqueeLabel::paint(cairo_t *c) { CGFrame::paint(c); cairo_save(c); cairo_translate(c, m_border, m_border); cairo_rectangle(c, 0,0, m_width-2.0*m_border, m_height-2.0*m_border); cairo_clip (c); if (m_text!=m_lastCalcText) { m_lastCalcWidth=cgSingleLineTextExtent(c, m_text, m_fontFace, m_fontSize, m_italic, m_bold).width; } int deltaMS=std::chrono::duration_cast<std::chrono::duration<float,std::milli> >(std::chrono::steady_clock::now() - m_start).count(); if (deltaMS>m_stepDurationMS) { m_start=std::chrono::steady_clock::now(); if (m_lastCalcWidth>(long)m_width) { m_lastOffset = m_lastOffset + m_lastDirection*std::max<int>(1, ceil(float(deltaMS)/float(m_stepDurationMS))); if (m_lastOffset>15 || m_lastOffset<-fabs(m_lastCalcWidth-m_width)-15) { m_lastDirection=-1*m_lastDirection; } //std::cout<<" SET m_lastOffset="<<m_lastOffset<<"\n\n"; } else { m_lastOffset=0; //std::cout<<" RESET m_lastOffset="<<m_lastOffset<<"\n\n"; } } //std::cout<<"deltaMS="<<deltaMS<<" m_stepDurationMS="<<m_stepDurationMS<<" m_lastOffset="<<m_lastOffset<<" m_lastDirection="<<m_lastDirection<<" m_lastCalcWidth="<<m_lastCalcWidth<<" m_width="<<m_width<<"\n"; float offx=m_textOffset; float offy=m_textOffset; if (m_horizontalAlignment!=cgalLeft) offx=0; if (m_verticalAlignment!=cgalTop) offy=0; //drawText(cr, m_border+offx, m_border+offy, m_width-m_frameWidth*2-offx*2, m_height-m_frameWidth*2-offy*2, m_text); cairo_save(c); cairo_translate(c, m_lastOffset, 0); cgDrawText(c, offx, offy, m_width-m_frameWidth*2-offx*2, m_height-m_frameWidth*2-offy*2, m_text, m_fontFace, m_fontSize, m_italic, m_bold, m_textColor, m_lineSpacing, m_horizontalAlignment, m_verticalAlignment); cairo_restore(c); cairo_restore(c); }