Ejemplo n.º 1
0
void VScrollPanel::draw (NVGcontext * ctx)
{
   if (mChildren.empty())
      return;
   Widget * child = mChildren[0];
   mChildPreferredHeight = child->preferredSize (ctx).y();
   float scrollh = height() *
                   std::min (1.0f, height() / (float) mChildPreferredHeight);
   nvgSave (ctx);
   nvgTranslate (ctx, mPos.x(), mPos.y());
   nvgScissor (ctx, 0, 0, mSize.x(), mSize.y());
   nvgTranslate (ctx, 0, -mScroll * (mChildPreferredHeight - mSize.y()));
   if (child->visible())
      child->draw (ctx);
   nvgRestore (ctx);
   NVGpaint paint = nvgBoxGradient (
                       ctx, mPos.x() + mSize.x() - 12 + 1, mPos.y() + 4 + 1, 8,
                       mSize.y() - 8, 3, 4, Color (0, 32), Color (0, 92));
   nvgBeginPath (ctx);
   nvgRoundedRect (ctx, mPos.x() + mSize.x() - 12, mPos.y() + 4, 8,
                   mSize.y() - 8, 3);
   nvgFillPaint (ctx, paint);
   nvgFill (ctx);
   paint = nvgBoxGradient (
              ctx, mPos.x() + mSize.x() - 12 - 1,
              mPos.y() + 4 + (mSize.y() - 8 - scrollh) * mScroll - 1, 8, scrollh,
              3, 4, Color (220, 100), Color (128, 100));
   nvgBeginPath (ctx);
   nvgRoundedRect (ctx, mPos.x() + mSize.x() - 12 + 1,
                   mPos.x() + 4 + 1 + (mSize.y() - 8 - scrollh) * mScroll, 8 - 2,
                   scrollh - 2, 2);
   nvgFillPaint (ctx, paint);
   nvgFill (ctx);
}
void ProgressBar::draw(NVGcontext* ctx)
{
    Widget::draw(ctx);

    NVGpaint paint = nvgBoxGradient(
        ctx, mPos.x() + 1, mPos.y() + 1,
        mSize.x()-2, mSize.y(), 3, 4, Color(0, 32), Color(0, 92));
    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), 3);
    nvgFillPaint(ctx, paint);
    nvgFill(ctx);

    float value = std::min(std::max(0.0f, mValue), 1.0f);
    int barPos = (int) std::round((mSize.x() - 2) * value);

    paint = nvgBoxGradient(
        ctx, mPos.x(), mPos.y(),
        barPos+1.5f, mSize.y()-1, 3, 4,
        Color(220, 100), Color(128, 100));

    nvgBeginPath(ctx);
    nvgRoundedRect(
        ctx, mPos.x()+1, mPos.y()+1,
        barPos, mSize.y()-2, 3);
    nvgFillPaint(ctx, paint);
    nvgFill(ctx);
}
Ejemplo n.º 3
0
void drawWindow(struct NVGcontext* vg, const char* title, float x, float y, float w, float h)
{
	float cornerRadius = 3.0f;
	struct NVGpaint shadowPaint;
	struct NVGpaint headerPaint;

	nvgSave(vg);
	//	nvgClearState(vg);

	// Window
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x,y, w,h, cornerRadius);
	nvgFillColor(vg, nvgRGBA(28,30,34,192) );
	//	nvgFillColor(vg, nvgRGBA(0,0,0,128) );
	nvgFill(vg);

	// Drop shadow
	shadowPaint = nvgBoxGradient(vg, x,y+2, w,h, cornerRadius*2, 10, nvgRGBA(0,0,0,128), nvgRGBA(0,0,0,0) );
	nvgBeginPath(vg);
	nvgRect(vg, x-10,y-10, w+20,h+30);
	nvgRoundedRect(vg, x,y, w,h, cornerRadius);
	nvgPathWinding(vg, NVG_HOLE);
	nvgFillPaint(vg, shadowPaint);
	nvgFill(vg);

	// Header
	headerPaint = nvgLinearGradient(vg, x,y,x,y+15, nvgRGBA(255,255,255,8), nvgRGBA(0,0,0,16) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+1,y+1, w-2,30, cornerRadius-1);
	nvgFillPaint(vg, headerPaint);
	nvgFill(vg);
	nvgBeginPath(vg);
	nvgMoveTo(vg, x+0.5f, y+0.5f+30);
	nvgLineTo(vg, x+0.5f+w-1, y+0.5f+30);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,32) );
	nvgStroke(vg);

	nvgFontSize(vg, 18.0f);
	nvgFontFace(vg, "sans-bold");
	nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);

	nvgFontBlur(vg,2);
	nvgFillColor(vg, nvgRGBA(0,0,0,128) );
	nvgText(vg, x+w/2,y+16+1, title, NULL);

	nvgFontBlur(vg,0);
	nvgFillColor(vg, nvgRGBA(220,220,220,160) );
	nvgText(vg, x+w/2,y+16, title, NULL);

	nvgRestore(vg);
}
Ejemplo n.º 4
0
void Slider::draw(NVGcontext* ctx) {
    Vector2f center = mPos.cast<float>() + mSize.cast<float>() * 0.5f;
    Vector2f knobPos(mPos.x() + mValue * mSize.x(), center.y() + 0.5f);
    float kr = (int)(mSize.y()*0.5f);
    NVGpaint bg = nvgBoxGradient(ctx,
        mPos.x(), center.y() - 3 + 1, mSize.x(), 6, 3, 3, Color(0, mEnabled ? 32 : 10), Color(0, mEnabled ? 128 : 210));

    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, mPos.x(), center.y() - 3 + 1, mSize.x(), 6, 2);
    nvgFillPaint(ctx, bg);
    nvgFill(ctx);

    if (mHighlightedRange.second != mHighlightedRange.first) {
        nvgBeginPath(ctx);
        nvgRoundedRect(ctx, mPos.x() + mHighlightedRange.first * mSize.x(), center.y() - 3 + 1, mSize.x() * (mHighlightedRange.second-mHighlightedRange.first), 6, 2);
        nvgFillColor(ctx, mHighlightColor);
        nvgFill(ctx);
    }

    NVGpaint knobShadow = nvgRadialGradient(ctx,
        knobPos.x(), knobPos.y(), kr-3, kr+3, Color(0, 64), mTheme->mTransparent);

    nvgBeginPath(ctx);
    nvgRect(ctx, knobPos.x() - kr - 5, knobPos.y() - kr - 5, kr*2+10, kr*2+10+3);
    nvgCircle(ctx, knobPos.x(), knobPos.y(), kr);
    nvgPathWinding(ctx, NVG_HOLE);
    nvgFillPaint(ctx, knobShadow);
    nvgFill(ctx);

    NVGpaint knob = nvgLinearGradient(ctx,
        mPos.x(), center.y() - kr, mPos.x(), center.y() + kr,
        mTheme->mBorderLight, mTheme->mBorderMedium);
    NVGpaint knobReverse = nvgLinearGradient(ctx,
        mPos.x(), center.y() - kr, mPos.x(), center.y() + kr,
        mTheme->mBorderMedium,
        mTheme->mBorderLight);

    nvgBeginPath(ctx);
    nvgCircle(ctx, knobPos.x(), knobPos.y(), kr);
    nvgStrokeColor(ctx, mTheme->mBorderDark);
    nvgFillPaint(ctx, knob);
    nvgStroke(ctx);
    nvgFill(ctx);
    nvgBeginPath(ctx);
    nvgCircle(ctx, knobPos.x(), knobPos.y(), kr/2);
    nvgFillColor(ctx, Color(150, mEnabled ? 255 : 100));
    nvgStrokePaint(ctx, knobReverse);
    nvgStroke(ctx);
    nvgFill(ctx);
}
void CheckerboardGlyph::draw(const box2px& bounds, const Color& fgColor,
		const Color& bgColor, AlloyContext* context) {
	NVGcontext* nvg = context->nvgContext;
	NVGpaint imgPaint = nvgImagePattern(nvg, bounds.position.x,
			bounds.position.y, bounds.dimensions.x, bounds.dimensions.y, 0.f,
			handle, 1.0f);
	if (bgColor.a > 0) {
		nvgBeginPath(nvg);
		nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x,
				bounds.dimensions.y);
		nvgFillColor(nvg, Color(bgColor));
		nvgFill(nvg);
	}
	nvgBeginPath(nvg);
	nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x,
			bounds.dimensions.y);
	nvgFillPaint(nvg, imgPaint);
	nvgFill(nvg);
	if (fgColor.a > 0) {
		nvgBeginPath(nvg);
		nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x,
				bounds.dimensions.y);
		nvgFillColor(nvg, Color(fgColor));
		nvgFill(nvg);
	}

}
Ejemplo n.º 6
0
void Renderer2D::drawRectangle( const attributes_2d& attributes, const float32_t& width, const float32_t& height,
			const float32_t& border, const color_argb& color, const color_argb& borderColor,
			const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x,
			const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height,
			const float32_t& image_rotation )
{
	Context2D* context = _context2D;
	const float32_t sWidth = width * attributes.scale;
	const float32_t sHeight = height * attributes.scale;

	nvgSave( context );
	nvgBeginPath( context );
	nvgTranslate( context, attributes.position[0], attributes.position[1] );

	nvgSave( context );
	nvgRotate( context, attributes.rotation );
	nvgRect( context, -sWidth/2, -sHeight/2, sWidth, sHeight );
	if( image != 0 )
	{
		NVGpaint paint = nvgImagePattern( context, (-sWidth/2)+image_pos_x, (-sHeight/2)+image_pos_y,
				image_width, image_height, image_rotation, image, image_alpha );
		nvgFillPaint( context, paint);
	}
	else
	{
		nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	}
	nvgFill( context );
	nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) );
	nvgStrokeWidth( context, border );
	nvgStroke( context );
	nvgRestore( context );

	nvgRestore( context );
}
Ejemplo n.º 7
0
 virtual void updateGL( osg::State* state ) const
 {
     // Some test drawings...
     nvgBeginPath( _vg );
     nvgRect( _vg, 300, 300, 120, 30 );
     nvgFillColor( _vg, nvgRGBA(255, 192, 0, 255) );
     nvgFill( _vg );
     nvgClosePath( _vg );
     
     nvgBeginPath( _vg );
     nvgCircle( _vg, 400, 500, 50 );
     nvgFillColor( _vg, nvgRGBA(0, 192, 255, 100) );
     nvgFill( _vg );
     nvgClosePath( _vg );
     
     if ( _loadedImages.size()>0 )
     {
         NVGpaint imgPaint = nvgImagePattern( _vg, 600, 150, 300, 400, 0.0f,
                                              _loadedImages[0], 1.0f );
         nvgBeginPath( _vg );
         nvgRoundedRect( _vg, 600, 150, 300, 400, 5 );
         nvgFillPaint( _vg, imgPaint );
         nvgFill( _vg );
         nvgClosePath( _vg );
     }
 }
Ejemplo n.º 8
0
void Popup::draw(NVGcontext* ctx) {
    refreshRelativePlacement();

    if (!mVisible)
        return;

    int ds = mTheme->mWindowDropShadowSize, cr = mTheme->mWindowCornerRadius;

    /* Draw a drop shadow */
    NVGpaint shadowPaint = nvgBoxGradient(
        ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr*2, ds*2,
        mTheme->mDropShadow, mTheme->mTransparent);

    nvgBeginPath(ctx);
    nvgRect(ctx, mPos.x()-ds,mPos.y()-ds, mSize.x()+2*ds, mSize.y()+2*ds);
    nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr);
    nvgPathWinding(ctx, NVG_HOLE);
    nvgFillPaint(ctx, shadowPaint);
    nvgFill(ctx);

    /* Draw window */
    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), cr);

    nvgMoveTo(ctx, mPos.x()-15,mPos.y()+mAnchorHeight);
    nvgLineTo(ctx, mPos.x()+1,mPos.y()+mAnchorHeight-15);
    nvgLineTo(ctx, mPos.x()+1,mPos.y()+mAnchorHeight+15);

    nvgFillColor(ctx, mTheme->mWindowPopup);
    nvgFill(ctx);

    Widget::draw(ctx);
}
Ejemplo n.º 9
0
void Renderer2D::drawCircle( const attributes_2d& attributes, const float32_t& radius,
				const float32_t& border, const color_argb& color, const color_argb& borderColor,
				const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x,
				const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height,
				const float32_t& image_rotation )
{
	Context2D* context = _context2D;

	nvgSave( context );
	nvgBeginPath( context );
	nvgTranslate( context, attributes.position[0], attributes.position[1]);

	nvgSave( context );
	nvgRotate( context, attributes.rotation );
	nvgCircle( context, 0, 0, radius * attributes.scale );
	if( image != 0 )
	{
		NVGpaint paint = nvgImagePattern( context, image_pos_x-image_width/2,
				image_pos_y - image_height/2, image_width, image_height, image_rotation,
				image, image_alpha );
		nvgFillPaint( context, paint);
	}
	else
	{
		nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	}
	nvgFill(context);
	nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) );
	nvgStrokeWidth( context, border );
	nvgStroke( context );
	nvgRestore( context );

	nvgRestore( context );
}
Ejemplo n.º 10
0
void drawDropDown(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
	struct NVGpaint bg;
	char icon[8];
	float cornerRadius = 4.0f;

	bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,48) );
	nvgStroke(vg);

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,160) );
	nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL);

	nvgFontSize(vg, h*1.3f);
	nvgFontFace(vg, "icons");
	nvgFillColor(vg, nvgRGBA(255,255,255,64) );
	nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+w-h*0.5f, y+h*0.5f, cpToUTF8(ICON_CHEVRON_RIGHT,icon), NULL);
}
Ejemplo n.º 11
0
void CheckBox::draw(NVGcontext *ctx) {
    Widget::draw(ctx);

    nvgFontSize(ctx, fontSize());
    nvgFontFace(ctx, "sans");
    nvgFillColor(ctx,
                 mEnabled ? mTheme->mTextColor : mTheme->mDisabledTextColor);
    nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
    nvgText(ctx, mPos.x + 1.2f * mSize.y + 5, mPos.y + mSize.y * 0.5f,
            mCaption.c_str(), nullptr);

    NVGpaint bg = nvgBoxGradient(ctx, mPos.x + 1.5f, mPos.y + 1.5f,
                                 mSize.y - 2.0f, mSize.y - 2.0f, 3, 3,
                                 mPushed ? Color(0, 100) : Color(0, 32),
                                 Color(0, 0, 0, 180));

    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, mPos.x + 1.0f, mPos.y + 1.0f, mSize.y - 2.0f,
                   mSize.y - 2.0f, 3);
    nvgFillPaint(ctx, bg);
    nvgFill(ctx);

    if (mChecked) {
        nvgFontSize(ctx, 1.8 * mSize.y);
        nvgFontFace(ctx, "icons");
        nvgFillColor(ctx, mEnabled ? mTheme->mIconColor
                                   : mTheme->mDisabledTextColor);
        nvgTextAlign(ctx, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE);
        nvgText(ctx, mPos.x + mSize.y * 0.5f + 1,
                mPos.y + mSize.y * 0.5f, utf8(ENTYPO_ICON_CHECK).data(),
                nullptr);
    }
}
Ejemplo n.º 12
0
void drawCheckBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
	struct NVGpaint bg;
	char icon[8];
	NVG_NOTUSED(w);

	nvgFontSize(vg, 18.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,160) );

	nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+28,y+h*0.5f,text, NULL);

	bg = nvgBoxGradient(vg, x+1,y+(int)(h*0.5f)-9+1, 18,18, 3,3, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,92) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+1,y+(int)(h*0.5f)-9, 18,18, 3);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	nvgFontSize(vg, 40);
	nvgFontFace(vg, "icons");
	nvgFillColor(vg, nvgRGBA(255,255,255,128) );
	nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+9+2, y+h*0.5f, cpToUTF8(ICON_CHECK,icon), NULL);
}
Ejemplo n.º 13
0
void vsDropShadow(NVGcontext *ctx, float x, float y, float w, float h,
                  float r, float feather, float alpha) {

    nvgBeginPath(ctx);
    y += feather;
    h -= feather;

    nvgMoveTo(ctx, x - feather, y - feather);
    nvgLineTo(ctx, x, y - feather);
    nvgLineTo(ctx, x, y + h - feather);
    nvgArcTo(ctx, x, y + h, x + r, y + h, r);
    nvgArcTo(ctx, x + w, y + h, x + w, y + h - r, r);
    nvgLineTo(ctx, x + w, y - feather);
    nvgLineTo(ctx, x + w + feather, y - feather);
    nvgLineTo(ctx, x + w + feather, y + h + feather);
    nvgLineTo(ctx, x - feather, y + h + feather);
    nvgClosePath(ctx);

    nvgFillPaint(ctx, nvgBoxGradient(ctx,
                                     x - feather * 0.5f, y - feather * 0.5f,
                                     w + feather, h + feather,
                                     r + feather * 0.5f,
                                     feather,
                                     nvgRGBAf(0, 0, 0, alpha * alpha),
                                     nvgRGBAf(0, 0, 0, 0)));
    nvgFill(ctx);
}
Ejemplo n.º 14
0
void QNanoPainter::drawImage(QNanoImage &image, const QRectF sourceRect, const QRectF destinationRect)
{
    image.setParentPainter(this);
    float sx = sourceRect.x();
    float sy = sourceRect.y();
    float sw = sourceRect.width();
    float sh = sourceRect.height();
    float dx = destinationRect.x();
    float dy = destinationRect.y();
    float dw = destinationRect.width();
    float dh = destinationRect.height();
    _checkAlignPixelsAdjust(&dx, &dy);
    _checkAlignPixels(&dw, &dh);
    float startX = dx - sx * (dw/sw);
    float startY = dy - sy * (dh/sh);
    float endX = dw * image.width() / sw;
    float endY = dh * image.height() / sh;
    NVGpaint ip = nvgImagePattern(nvgCtx(), startX, startY, endX, endY, 0.0f, image.getID(nvgCtx()), 1.0f);
    nvgSave(nvgCtx());
    nvgBeginPath(nvgCtx());
    rect(dx, dy, dw, dh);
    nvgFillPaint(nvgCtx(), ip);
    nvgFill(nvgCtx());
    nvgRestore(nvgCtx());
}
Ejemplo n.º 15
0
void ImagePanel::draw (NVGcontext * ctx)
{
   ivec2 grid = gridSize();
   for (size_t i = 0; i < mImages.size(); ++i)
   {
      ivec2 p = mPos + ivec2 (mMargin) +
                ivec2 ((int)i % grid.x, (int)i / grid.x) * (mThumbSize + mSpacing);
      int imgw, imgh;
      nvgImageSize (ctx, mImages[i].first, &imgw, &imgh);
      float iw, ih, ix, iy;
      if (imgw < imgh)
      {
         iw = mThumbSize;
         ih = iw * (float)imgh / (float)imgw;
         ix = 0;
         iy = - (ih - mThumbSize) * 0.5f;
      }
      else
      {
         ih = mThumbSize;
         iw = ih * (float)imgw / (float)imgh;
         ix = - (iw - mThumbSize) * 0.5f;
         iy = 0;
      }
      NVGpaint imgPaint = nvgImagePattern (
                             ctx, p.x + ix, p.y + iy, iw, ih, 0, mImages[i].first,
                             mMouseIndex == (int)i ? 1.0 : 0.7);
      nvgBeginPath (ctx);
      nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 5);
      nvgFillPaint (ctx, imgPaint);
      nvgFill (ctx);
      NVGpaint shadowPaint =
         nvgBoxGradient (ctx, p.x - 1, p.y, mThumbSize + 2, mThumbSize + 2, 5, 3,
                         nvgRGBA (0, 0, 0, 128), nvgRGBA (0, 0, 0, 0));
      nvgBeginPath (ctx);
      nvgRect (ctx, p.x - 5, p.y - 5, mThumbSize + 10, mThumbSize + 10);
      nvgRoundedRect (ctx, p.x, p.y, mThumbSize, mThumbSize, 6);
      nvgPathWinding (ctx, NVG_HOLE);
      nvgFillPaint (ctx, shadowPaint);
      nvgFill (ctx);
      nvgBeginPath (ctx);
      nvgRoundedRect (ctx, p.x + 0.5f, p.y + 0.5f, mThumbSize - 1, mThumbSize - 1, 4 - 0.5f);
      nvgStrokeWidth (ctx, 1.0f);
      nvgStrokeColor (ctx, nvgRGBA (255, 255, 255, 80));
      nvgStroke (ctx);
   }
}
Ejemplo n.º 16
0
	void NanoInk::drawImage(int image, float left, float top, float width, float height, float imgx, float imgy, float imgw, float imgh)
	{
		NVGpaint imgPaint = nvgImagePattern(mCtx, imgx, imgy, imgw, imgh, 0.0f / 180.0f*NVG_PI, image, 1.f);
		nvgBeginPath(mCtx);
		nvgRect(mCtx, left, top, width, height);
		nvgFillPaint(mCtx, imgPaint);
		nvgFill(mCtx);
	}
Ejemplo n.º 17
0
void VScrollPanel::draw(NVGcontext *ctx) {
    if (m_children.empty())
        return;
    Widget *child = m_children[0];
    child->set_position(Vector2i(0, -m_scroll*(m_child_preferred_height - m_size.y())));
    m_child_preferred_height = child->preferred_size(ctx).y();
    float scrollh = height() *
        std::min(1.0f, height() / (float) m_child_preferred_height);

    if (m_update_layout) {
        m_update_layout = false;
        child->perform_layout(ctx);
    }

    nvgSave(ctx);
    nvgTranslate(ctx, m_pos.x(), m_pos.y());
    nvgIntersectScissor(ctx, 0, 0, m_size.x(), m_size.y());
    if (child->visible())
        child->draw(ctx);
    nvgRestore(ctx);

    if (m_child_preferred_height <= m_size.y())
        return;

    NVGpaint paint = nvgBoxGradient(
        ctx, m_pos.x() + m_size.x() - 12 + 1, m_pos.y() + 4 + 1, 8,
        m_size.y() - 8, 3, 4, Color(0, 32), Color(0, 92));
    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, m_pos.x() + m_size.x() - 12, m_pos.y() + 4, 8,
                   m_size.y() - 8, 3);
    nvgFillPaint(ctx, paint);
    nvgFill(ctx);

    paint = nvgBoxGradient(
        ctx, m_pos.x() + m_size.x() - 12 - 1,
        m_pos.y() + 4 + (m_size.y() - 8 - scrollh) * m_scroll - 1, 8, scrollh,
        3, 4, Color(220, 100), Color(128, 100));

    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, m_pos.x() + m_size.x() - 12 + 1,
                   m_pos.y() + 4 + 1 + (m_size.y() - 8 - scrollh) * m_scroll, 8 - 2,
                   scrollh - 2, 2);
    nvgFillPaint(ctx, paint);
    nvgFill(ctx);
}
Ejemplo n.º 18
0
void Console::draw(NVGcontext* ctx){
    Widget::draw(ctx);  

    //Screen *sc = dynamic_cast<Screen *>(this->window()->parent());

    // Draw rounded rectangel around text area ////////////////////
    NVGpaint paint = nvgBoxGradient(
        ctx, mPos.x() + 1, mPos.y() + 1,
        mSize.x()-2, mSize.y(), 3, 4, Color(0, 32), Color(0, 92));
    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, mPos.x(), mPos.y(), mSize.x(), mSize.y(), 3);
    nvgFillPaint(ctx, paint);
    nvgFill(ctx);
    ///////////////////////////////////////////////////////////////
    


    nvgFontSize(ctx, 18.0f);
    nvgFontFace(ctx, "sans");
    nvgTextAlign(ctx, NVG_ALIGN_LEFT|NVG_ALIGN_TOP);
    float x, y, linew, lineh;
    nvgTextMetrics(ctx, nullptr, nullptr, &lineh);
    x = mPos.x();
    y = mPos.y();
    linew = mSize.x();
    
    mNumRows = mSize.y()/lineh ; // make sure that the size of console is updated
    //setSize(Vector2i(mSize.x(), nrows*lineh)); // this code does not work. It
    //changes size each frame. Move from draw into one time function.
    
    // init console output 
    if(mInit) {
        initBuffer(ctx, linew);
        mInit = false;
    }
    //typedef std::deque<std::string> Buffer_t;

    //temp solution: when buffer is not full. Move this to updateFunction.
    for(auto it = mBuffer.begin();it!=mBuffer.end();++it) {

        nvgBeginPath(ctx);
        nvgFillColor(ctx, nvgRGBA(255,255,255,16));
        nvgRect(ctx, x, y, linew, lineh);
        nvgFill(ctx);

        nvgFillColor(ctx, nvgRGBA(255,255,255,255));
        nvgText(ctx, x, y, it->c_str(), nullptr);
        
        y += lineh;
    }
   
    updateCursor(ctx, lineh);
    //update cursor and draw
    //mCaret.onClick(ctx, lineh, mMouseDownPos - mPos);
    mCaret.draw(ctx, lineh, mPos);
}
Ejemplo n.º 19
0
static void
draw_image(NVGcontext *ctx, gui_handle img, float x, float y, float w, float h, float r)
{
    NVGpaint imgpaint;
    imgpaint = nvgImagePattern(ctx, x, y, w, h, 0, img.id, 1.0f);
    nvgBeginPath(ctx);
    nvgRoundedRect(ctx, x, y, w, h, r);
    nvgFillPaint(ctx, imgpaint);
    nvgFill(ctx);
}
Ejemplo n.º 20
0
void drawSlider(struct NVGcontext* vg, float pos, float x, float y, float w, float h)
{
	struct NVGpaint bg, knob;
	float cy = y+(int)(h*0.5f);
	float kr = (float)( (int)(h*0.25f) );

	nvgSave(vg);
	//	nvgClearState(vg);

	// Slot
	bg = nvgBoxGradient(vg, x,cy-2+1, w,4, 2,2, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,128) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x,cy-2, w,4, 2);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	// Knob Shadow
	bg = nvgRadialGradient(vg, x+(int)(pos*w),cy+1, kr-3,kr+3, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0) );
	nvgBeginPath(vg);
	nvgRect(vg, x+(int)(pos*w)-kr-5,cy-kr-5,kr*2+5+5,kr*2+5+5+3);
	nvgCircle(vg, x+(int)(pos*w),cy, kr);
	nvgPathWinding(vg, NVG_HOLE);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	// Knob
	knob = nvgLinearGradient(vg, x,cy-kr,x,cy+kr, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16) );
	nvgBeginPath(vg);
	nvgCircle(vg, x+(int)(pos*w),cy, kr-1);
	nvgFillColor(vg, nvgRGBA(40,43,48,255) );
	nvgFill(vg);
	nvgFillPaint(vg, knob);
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgCircle(vg, x+(int)(pos*w),cy, kr-0.5f);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,92) );
	nvgStroke(vg);

	nvgRestore(vg);
}
Ejemplo n.º 21
0
    //Render a rectangle
    bool renderRect(Skin::SkinClass::Attributes &skinClass, float x, float y, float sw, float sh) {
      if (!m_inited) return false;

      NVGcolor col = nvgRGBA(skinClass.fill.r, skinClass.fill.g, skinClass.fill.b, skinClass.fill.a);
      //NVGpaint bg = nvgLinearGradient(m_vg, pos.x, pos.y, pos.x, pos.y + size.y, nvgRGBA(255,255,255,isBlack(col)?16:64), nvgRGBA(0,0,0,isBlack(col)?16:64));

      nvgBeginPath(m_vg);
      nvgRoundedRect(m_vg, x, y, sw, sh, skinClass.cornerRadius);
 
      if (!skinClass.hasImage || skinClass.hasFill) {
        nvgFillColor(m_vg, col);
        nvgFill(m_vg);
      }

      if (skinClass.hasImage) {
        //int w = size.x, h= size.y;
        //nvgImageSize(m_vg, skinClass.imageHandle, &w, &h);
        NVGpaint img = nvgImagePattern(m_vg, x, y, sw, sh, 0.f, skinClass.imageHandle, col.a);
        nvgFillPaint(m_vg, img);
        nvgFill(m_vg);
      } 

      if (skinClass.hasGradient) {
        NVGpaint g = nvgLinearGradient(m_vg, x, y, x, y + sh, 
                          nvgRGBA(skinClass.gradientA.r, skinClass.gradientA.g, skinClass.gradientA.b, skinClass.gradientA.a),
                          nvgRGBA(skinClass.gradientB.r, skinClass.gradientB.g, skinClass.gradientB.b, skinClass.gradientB.a)
                     );
        nvgFillPaint(m_vg, g);
        nvgFill(m_vg);
      }

      if (skinClass.hasStroke) {
        nvgStrokeWidth(m_vg, skinClass.strokeWidth);
        nvgStrokeColor(m_vg, nvgRGBA(skinClass.stroke.r, skinClass.stroke.g, skinClass.stroke.b, skinClass.stroke.a));
        nvgStroke(m_vg);
      }

      return true;
    }
Ejemplo n.º 22
0
void QNanoPainter::setFillStyle(const QNanoBrush &brush)
{
    // If brush is QNanoImagePattern set its painter
    QNanoImagePattern *ip = dynamic_cast<QNanoImagePattern*>(const_cast<QNanoBrush*>(&brush));
    if (ip && ip->m_image) {
        ip->m_image->setParentPainter(this);
    }
    QNanoBrush* b = const_cast<QNanoBrush*>(&brush);
    if (b) {
        b->setParentPainter(this);
    }
    nvgFillPaint(nvgCtx(), brush.nvgPaint(nvgCtx()));
}
Ejemplo n.º 23
0
void QNanoPainter::drawImage(QNanoImage &image, float x, float y, float width, float height)
{
    _checkAlignPixelsAdjust(&x, &y);
    _checkAlignPixels(&width, &height);
    image.setParentPainter(this);
    NVGpaint ip = nvgImagePattern(nvgCtx(), x, y, width, height, 0.0f, image.getID(nvgCtx()), 1.0f);
    nvgSave(nvgCtx());
    nvgBeginPath(nvgCtx());
    nvgRect(nvgCtx(), x, y, width, height);
    nvgFillPaint(nvgCtx(), ip);
    nvgFill(nvgCtx());
    nvgRestore(nvgCtx());
}
Ejemplo n.º 24
0
void drawEditBoxBase(struct NVGcontext* vg, float x, float y, float w, float h)
{
	struct NVGpaint bg;
	// Edit
	bg = nvgBoxGradient(vg, x+1,y+1+1.5f, w-2,h-2, 3,4, nvgRGBA(255,255,255,32), nvgRGBA(32,32,32,32) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+1,y+1, w-2,h-2, 4-1);
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, 4-0.5f);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,48) );
	nvgStroke(vg);
}
Ejemplo n.º 25
0
void drawButton(struct NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, struct NVGcolor col)
{
	struct NVGpaint bg;
	char icon[8];
	float cornerRadius = 4.0f;
	float tw = 0, iw = 0;

	bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,isBlack(col)?16:32), nvgRGBA(0,0,0,isBlack(col)?16:32) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1);
	if (!isBlack(col) ) {
		nvgFillColor(vg, col);
		nvgFill(vg);
	}
	nvgFillPaint(vg, bg);
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f);
	nvgStrokeColor(vg, nvgRGBA(0,0,0,48) );
	nvgStroke(vg);

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans-bold");
	tw = nvgTextBounds(vg, 0,0, text, NULL, NULL);
	if (preicon != 0) {
		nvgFontSize(vg, h*1.3f);
		nvgFontFace(vg, "icons");
		iw = nvgTextBounds(vg, 0,0, cpToUTF8(preicon,icon), NULL, NULL);
		iw += h*0.15f;
	}

	if (preicon != 0) {
		nvgFontSize(vg, h*1.3f);
		nvgFontFace(vg, "icons");
		nvgFillColor(vg, nvgRGBA(255,255,255,96) );
		nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
		nvgText(vg, x+w*0.5f-tw*0.5f-iw*0.75f, y+h*0.5f, cpToUTF8(preicon,icon), NULL);
	}

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans-bold");
	nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
	nvgFillColor(vg, nvgRGBA(0,0,0,160) );
	nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f-1,text, NULL);
	nvgFillColor(vg, nvgRGBA(255,255,255,160) );
	nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL);
}
Ejemplo n.º 26
0
    void t2Image::drawInCircle(int x, int y, float radius, int angle /*= 0*/, int alpha /*= 255*/, bool bFill /*= true*/)
    {
        NVGpaint imgPaint = nvgImagePattern(t2GetContext(), x, y, width, height, angle / 255.0f, img, alpha / 255.0f);

        nvgBeginPath(t2GetContext());
        nvgCircle(t2GetContext(), x, y, radius);

        if(bFill)
        {
            nvgFillPaint(t2GetContext(), imgPaint);
            nvgFill(t2GetContext());
        }
        else
        {
            nvgStrokePaint(t2GetContext(), imgPaint);
            nvgStroke(t2GetContext());
        }
    }
Ejemplo n.º 27
0
void background(BATB& batb, run::World& run)
{
    auto* nvg = batb.gl.nanovg_begin( run.scene );
    auto wth = run.scene.wth;
    auto hth = run.scene.hth;

    //nvgTranslate( nvg, wth / 2, hth / 2 );
    
    float_t x = 0.5 * (wth - image_wth); 
    float_t y = 0.5 * (hth - image_hth); 
    image_paint = nvgImagePattern( nvg, x, y, image_wth, image_hth, 0.0, image, 1.0 );
    nvgBeginPath( nvg );
    //nvgRect( nvg, x, y, image_wth, image_hth );
    nvgRect( nvg, x, y, wth, hth );
    nvgFillPaint( nvg, image_paint );
    nvgFill( nvg );

    batb.gl.nanovg_end();
}
Ejemplo n.º 28
0
void Renderer2D::drawPath( const attributes_2d& attributes, const float32_t* path, const uint32_t& pathSize,
		const float32_t& border, const color_argb& color, const color_argb& borderColor,
		const Image2D& image, const float32_t& image_alpha, const float32_t& image_pos_x,
		const float32_t& image_pos_y, const float32_t& image_width, const float32_t& image_height,
		const float32_t& image_rotation )
{
	Context2D* context = _context2D;

	if( pathSize < 2 || pathSize % 2 != 0 )
		return;

	nvgSave( context );
	nvgBeginPath( context );
	nvgTranslate( context, attributes.position[0], attributes.position[1] );

	nvgSave( context );
	nvgRotate( context, attributes.rotation );
	nvgMoveTo( context, path[0], path[1]);
	for( uint32_t i=2; i<pathSize; i+=2 )
	{
		nvgLineTo( context, path[i] * attributes.scale, path[i+1] * attributes.scale);
	}
	nvgClosePath( context );
	if( image != 0 )
	{
		NVGpaint paint = nvgImagePattern( context, image_pos_x-image_width/2,
				image_pos_y-image_height/2, image_width, image_height, image_rotation, image, image_alpha );
		nvgFillPaint( context, paint);
	}
	else
	{
		nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	}
	nvgFill(context);
	nvgStrokeColor( context, nvgRGBA( borderColor.r, borderColor.g, borderColor.b, borderColor.a) );
	nvgStrokeWidth( context, border );
	nvgStroke( context );
	nvgRestore( context );

	nvgRestore( context );
}
Ejemplo n.º 29
0
void FHUD::Render(int w, int h)
{
	if(!Temp)
	{
		Temp = RC.Render->NewSGObject();
		Temp->LoadModelFromResource(RC.Engine->EnemyMesh1);
		Temp->SetScale(glm::vec3(1.2f));
		Temp->SetVisible(false);
	}
	if(Health <= 0)
	{
		nvgBeginPath(vg);
		nvgRect(vg, 0, 0, (float)w, (float)h);
		nvgFillColor(vg, nvgRGBA(255, 0, 0, 200));
		nvgFill(vg);
		Temp->SetVisible(true);
		Temp->SetRed(true);
	}
	else
	{
		Temp->SetVisible(false);
		nvgFillColor(vg, nvgRGB(0, 0, 0));
		nvgFontSize(vg, 36);
		nvgFontFace(vg, "normal");
		nvgText(vg, 0, 50, "Health", nullptr);

		nvgBeginPath(vg);
		nvgRect(vg, 100, 23, (float)Health * 10, 35);
		nvgStrokeColor(vg, nvgRGBA(0, 0, 0, 255));
		NVGpaint redPaint = nvgLinearGradient(vg, 100, 23, 100, 35, nvgRGBA(255, 255, 255, 255), nvgRGBA(255, 0, 0, 100));
		//nvgFillColor(vg, nvgRGBA(255, 0, 0, 128));
		nvgFillPaint(vg, redPaint);
		nvgFill(vg);

		nvgBeginPath(vg);
		nvgRect(vg, 100, 23, (float)MaxHealth * 10, 35);
		nvgStrokeColor(vg, nvgRGBA(0, 0, 0, 255));
		nvgStroke(vg);
	}
}
Ejemplo n.º 30
0
void VectorRenderer::fillTexture(TextureID id, Loom2D::Matrix transform, bool repeat, bool smooth, float alpha) {

	TextureInfo *tinfo = Texture::getTextureInfo(id);

	// Setup flags
	int flags = NVG_IMAGE_NODELETE;
	if (tinfo->mipmaps) flags |= NVG_IMAGE_GENERATE_MIPMAPS;
	if (repeat) {
		flags |= NVG_IMAGE_REPEATX;
		flags |= NVG_IMAGE_REPEATY;
	}
	if (smooth) flags |= NVG_IMAGE_BILINEAR;

	// Key based on id and flags
	utIntHashKey key = utIntHashKey(utIntHashKey(id).hash() ^ utIntHashKey(flags).hash());

	int *stored = imageLookup.get(key);
	int nvgImage;
	if (stored == NULL) {
		nvgImage = nvglCreateImageFromHandle(nvg, tinfo->getHandleID(), tinfo->width, tinfo->height, flags);
		imageLookup.insert(key, nvgImage);
	} else {
		nvgImage = *stored;
	}

	// Save transform
	float xform[6];
	nvgCurrentTransform(nvg, xform);
	
	// Apply fill transform
	nvgTransform(nvg, (float)transform.a, (float)transform.b, (float)transform.c, (float)transform.d, (float)transform.tx, (float)transform.ty);

	// Set paint
	nvgFillPaint(nvg, nvgImagePattern(nvg, 0.f, 0.f, (float) tinfo->width, (float) tinfo->height, 0.f, nvgImage, alpha));
	
	// Restore transform
	nvgSetTransform(nvg, xform);
}