Ejemplo n.º 1
0
void drawCaps(struct NVGcontext* vg, float x, float y, float width)
{
	int i;
	int caps[3] = {NVG_BUTT, NVG_ROUND, NVG_SQUARE};
	float lineWidth = 8.0f;

	nvgSave(vg);

	nvgBeginPath(vg);
	nvgRect(vg, x-lineWidth/2, y, width+lineWidth, 40);
	nvgFillColor(vg, nvgRGBA(255,255,255,32));
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgRect(vg, x, y, width, 40);
	nvgFillColor(vg, nvgRGBA(255,255,255,32));
	nvgFill(vg);

	nvgStrokeWidth(vg, lineWidth);
	for (i = 0; i < 3; i++) {
		nvgLineCap(vg, caps[i]);
		nvgStrokeColor(vg, nvgRGBA(0,0,0,255));
		nvgBeginPath(vg);
		nvgMoveTo(vg, x, y + i*10 + 5);
		nvgLineTo(vg, x+width, y + i*10 + 5);
		nvgStroke(vg);
	}

	nvgRestore(vg);
}
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.º 3
0
void Application::Impl_::paintEvent(NVGcontext* context){

	int winWidth, winHeight;
	glfwGetWindowSize(window_.get(), &winWidth, &winHeight);
	int fWidth, fHeight;
	glfwGetFramebufferSize(window_.get(), &fWidth, &fHeight);
	float pxRatio = (float)fWidth / (float)winWidth;
	nvgBeginFrame(context, winWidth, winHeight, pxRatio);

	Rect textRect(0.f,10.f,winWidth,20.f);
	Rect boardMaxRect(0.f,textRect.height + textRect.y,winWidth,winHeight - textRect.height);

	float boardSizeMin = std::min(boardMaxRect.width,boardMaxRect.height);
	Rect boardRect(20.f, 20.f + textRect.height,boardSizeMin-40.f, boardSizeMin-40.f);

	if (boardMaxRect.height > boardMaxRect.width){
		boardRect.move(0,(boardMaxRect.height - boardMaxRect.width)/2.f);
	}else{
		boardRect.move((boardMaxRect.width - boardMaxRect.height)/2.f,0);
	}

	// draw the text rect
	nvgBeginPath(context);
	nvgFillColor(context, nvgRGBA(0,0,0,50));
	nvgRect(context,textRect);
	nvgFill(context);
	nvgClosePath(context);

	// draw the board
	boardView_->paint(context,boardRect);

	if (isEnd_){

		// change the color of the board
		nvgBeginPath(context);
		nvgFillColor(context, nvgRGBA(0,0,0,30));
		nvgRect(context,boardMaxRect);
		nvgFill(context);
		nvgClosePath(context);

		// & display the game over
		std::string text("GAME OVER");
		nvgBeginPath(context);
		float x= 0;
		float y= 0;
		textRect.center(x,y);
		nvgFontSize(context, 20);
		nvgFontFace(context, "sans");
		nvgTextAlign(context, NVG_ALIGN_MIDDLE|NVG_ALIGN_CENTER);
		nvgFill(context);
		nvgFillColor(context, nvgRGBA(0,0,0,255));
		nvgText(context,x+1,y+1,text.c_str(),NULL);
		nvgFillColor(context, nvgRGBA(200,20,20,255));
		nvgText(context,x,y,text.c_str(),NULL);
	}

	nvgEndFrame(context);
}
Ejemplo n.º 4
0
void Graph::draw(NVGcontext *ctx) {
	Widget::draw(ctx);

	nvgBeginPath(ctx);
	nvgRect(ctx, mPos.x, mPos.y, mSize.x, mSize.y);
	nvgFillColor(ctx, mBackgroundColor);
	nvgFill(ctx);

	if (mValues.size() < 2)
		return;

	nvgBeginPath(ctx);
	nvgMoveTo(ctx, mPos.x, mPos.y + mSize.y);
	for (size_t i = 0; i < (size_t)mValues.size(); i++) {
		float value = mValues[i];
		float vx = mPos.x + i * mSize.x / (float)(mValues.size() - 1);
		float vy = mPos.y + (1 - value) * mSize.y;
		nvgLineTo(ctx, vx, vy);
	}

	nvgLineTo(ctx, mPos.x + mSize.x, mPos.y + mSize.y);
	nvgStrokeColor(ctx, Colour(100, 255));
	nvgStroke(ctx);
	nvgFillColor(ctx, mForegroundColor);
	nvgFill(ctx);

	nvgFontFace(ctx, "sans");

	if (!mCaption.empty()) {
		nvgFontSize(ctx, 14.0f);
		nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
		nvgFillColor(ctx, mTextColor);
		nvgText(ctx, mPos.x + 3, mPos.y + 1, mCaption.c_str(), NULL);
	}

	if (!mHeader.empty()) {
		nvgFontSize(ctx, 18.0f);
		nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_TOP);
		nvgFillColor(ctx, mTextColor);
		nvgText(ctx, mPos.x + mSize.x - 3, mPos.y + 1, mHeader.c_str(), NULL);
	}

	if (!mFooter.empty()) {
		nvgFontSize(ctx, 15.0f);
		nvgTextAlign(ctx, NVG_ALIGN_RIGHT | NVG_ALIGN_BOTTOM);
		nvgFillColor(ctx, mTextColor);
		nvgText(ctx, mPos.x + mSize.x - 3, mPos.y + mSize.y - 1, mFooter.c_str(), NULL);
	}

	nvgBeginPath(ctx);
	nvgRect(ctx, mPos.x, mPos.y, mSize.x, mSize.y);
	nvgStrokeColor(ctx, Colour(100, 255));
	nvgStroke(ctx);
}
Ejemplo n.º 5
0
static void drawRect(float x, float y, float w, float h, float fth, unsigned int col)
{
    nvgBeginPath(vg::ctx);
    nvgFillColor(vg::ctx, nvgRGBA(col&0xff, (col>>8)&0xff, (col>>16)&0xff, (col>>24)&0xff));
    nvgRect(vg::ctx, x, y, w, h);
    nvgFill(vg::ctx);
}
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 NanoInk::drawImage()
	{
#if 1 // DEBUG
		if(sDebugDraw && mVisible)
		{
			float left = mFrame.dabsolute(DIM_X) + mFrame.cleft();
			float top = mFrame.dabsolute(DIM_Y) + mFrame.ctop();
			float width = mFrame.cwidth();
			float height = mFrame.cheight();

			nvgBeginPath(mCtx);
			nvgRect(mCtx, left + 0.5f, top + 0.5f, width - 1.f, height - 1.f);
			nvgStrokeWidth(mCtx, 1.f);
			nvgStrokeColor(mCtx, nvgColour(Colour::Red));
			nvgStroke(mCtx);
		}
#endif

		if(this->skin().mEmpty || !mVisible)
			return;

		++sDebugBatch;

		if(!mImageCache)
			mImageCache = nvgCreateDisplayList(11);

		if(mImageUpdate)
			this->redrawImage();

		this->drawCache(mImageCache);
		mImageUpdate = false;
	}
Ejemplo n.º 10
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.º 11
0
void QNanoPainter::strokeRect(float x, float y, float width, float height)
{
    _checkAlignPixelsAdjust(&x, &y);
    _checkAlignPixels(&width, &height);
    nvgBeginPath(nvgCtx());
    nvgRect(nvgCtx(), x, y, width, height);
    nvgStroke(nvgCtx());
}
Ejemplo n.º 12
0
void testrect(NVGcontext *vg, UIrect rect) {
#if 0    
    nvgBeginPath(vg);
    nvgRect(vg,rect.x+0.5,rect.y+0.5,rect.w-1,rect.h-1);
    nvgStrokeColor(vg,nvgRGBf(1,0,0));
    nvgStrokeWidth(vg,1);
    nvgStroke(vg);    
#endif    
}
Ejemplo n.º 13
0
void vsLineTo(NVGcontext *vg, int x, int y) {
    if (y == _lineInfo.y) {
        if (x > _lineInfo.x)
            nvgRect(vg, _lineInfo.x, _lineInfo.y, x - _lineInfo.x, _lineInfo.width);
        else if (x < _lineInfo.x)
            nvgRect(vg, x, y, _lineInfo.x - x + 1, _lineInfo.width);
    }
    else if (x == _lineInfo.x) {
        if (y > _lineInfo.y)
            nvgRect(vg, _lineInfo.x, _lineInfo.y, _lineInfo.width, y - _lineInfo.y);
        else if (y < _lineInfo.y)
            nvgRect(vg, x, y, _lineInfo.width, _lineInfo.y - y);

    }

    _lineInfo.x = x;
    _lineInfo.y = y;
}
Ejemplo n.º 14
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.º 15
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.º 16
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.º 17
0
    virtual void render() override {

//        fillRect(_3RGB(29), gX(), gY(), width, height)

        VsObjContainer::render();
        {   //border
            nvgBeginPath(vg);
            nvgRect(vg, gX() + TIMELINE_TRACK_PANEL_DEF_WIDTH - 3, gY(), 3, height);
            nvgFillColor(vg, nvgRGB(29, 29, 29));
            nvgFill(vg);
        }

    }
Ejemplo n.º 18
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.º 19
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);
}
Ejemplo n.º 20
0
Archivo: gui.cpp Proyecto: fatto/banana
void FPScounter::on_draw()
{
	head = (head+1) % FPS_HISTORY_COUNT;
	float new_time = time();
	values[head] = new_time - current_time;
	current_time = new_time;

	size_t i, _head;
	float avg, w, h;

	avg = 0;
	_head = head;
	for (i = 0; i < 10; i++) {
		avg += values[head];
		_head = (head+FPS_HISTORY_COUNT-1) % FPS_HISTORY_COUNT;
	}
	avg /= 10.0f;

	w = 200;
	h = 30;

	nvgBeginPath(vg);
	nvgRect(vg, x,y, w,h);
	nvgFillColor(vg, nvgRGBA(0,0,0,128));
	nvgFill(vg);

	nvgBeginPath(vg);
	nvgMoveTo(vg, x, y+h);
	for (i = 0; i < FPS_HISTORY_COUNT; i++) {
		float v = 1.0f / (0.00001f + values[(head+i) % FPS_HISTORY_COUNT]);
		if (v > 80.0f) v = 80.0f;
		float vx = x + ((float)i/(FPS_HISTORY_COUNT-1)) * w;
		float vy = y + h - ((v / 80.0f) * h);
		nvgLineTo(vg, vx, vy);
	}
	nvgLineTo(vg, x+w, y+h);
	nvgFillColor(vg, nvgRGBA(255,192,0,128));
	nvgFill(vg);

	label.setText(std::to_string(1.f/avg) + " FPS");
	label.setPosition(x+w-5, y+h/2);

	// nvgFontSize(vg, 18.0f);
	// nvgFontFace(vg, "sans");
	// nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE);
	// nvgFillColor(vg, nvgRGBA(240,240,240,255));
	// sprintf(str, "%.2f FPS", 1.0f / avg);
	// nvgText(vg, x+w-5,y+h/2, str, NULL);
}
Ejemplo n.º 21
0
void ImageNode::renderItself(RenderContext& renderContext)
{
    NVGcontext& nanoVgContext = renderContext.getNanoVgContext();
    NVGpaint paint = nvgImagePattern(&nanoVgContext, mImagePatternRect.getX(),
            mImagePatternRect.getY(), mImagePatternRect.getWidth(), mImagePatternRect.getHeight(),
            0, mImage.getHandle(), 1);
    nvgBeginPath(&nanoVgContext);
    nvgRect(&nanoVgContext, mRect.getX(), mRect.getY(), mRect.getWidth(), mRect.getHeight());
    nvgFillPaint(&nanoVgContext, paint);
    nvgFill(&nanoVgContext);

    if(! renderContext.getBlendColors().empty())
    {
        std::pair<Color, float> blendResult = renderContext.getBlendResult();
        const Color& blendColor = blendResult.first;
        nvgBeginPath(&nanoVgContext);
        nvgRect(&nanoVgContext, mRect.getX(), mRect.getY(), mRect.getWidth(), mRect.getHeight());
        nvgFillColor(&nanoVgContext, nvgRGBAf(blendColor.getRed(), blendColor.getGreen(),
                blendColor.getBlue(), blendColor.getAlpha() * blendResult.second));
        nvgFill(&nanoVgContext);
    }

    Node::renderItself(renderContext);
}
	void ExpandTree::drawDebug(AlloyContext* context) {
		if (selectedItem) {
			NVGcontext* nvg = context->nvgContext;
			nvgStrokeWidth(nvg, 1.0f);
			nvgStrokeColor(nvg, Color(220, 64, 64));
			nvgBeginPath(nvg);
			box2px bounds = selectedItem->getBounds();
			box2px pbounds = drawRegion->getBounds();
			bounds.position += pbounds.position;
			bounds.intersect(getBounds());
			nvgRect(nvg, bounds.position.x, bounds.position.y, bounds.dimensions.x,
				bounds.dimensions.y);
			nvgStroke(nvg);
		}
		Composite::drawDebug(context);
	}
Ejemplo n.º 23
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.º 24
0
void Widget::draw(NVGcontext *ctx) {
    #if NANOGUI_SHOW_WIDGET_BOUNDS
        nvgStrokeWidth(ctx, 1.0f);
        nvgBeginPath(ctx);
        nvgRect(ctx, mPos.x() - 0.5f, mPos.y() - 0.5f, mSize.x() + 1, mSize.y() + 1);
        nvgStrokeColor(ctx, nvgRGBA(255, 0, 0, 255));
        nvgStroke(ctx);
    #endif

    if (mChildren.empty())
        return;

    nvgTranslate(ctx, mPos.x(), mPos.y());
    for (auto child : mChildren)
        if (child->visible())
            child->draw(ctx);
    nvgTranslate(ctx, -mPos.x(), -mPos.y());
}
Ejemplo n.º 25
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.º 26
0
    void t2Image::drawInRect(int x, int y, int width, int height, 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());

        nvgRect(t2GetContext(), x, y, width, height);

        if(bFill)
        {
            nvgFillPaint(t2GetContext(), imgPaint);
            nvgFill(t2GetContext());
        }
        else
        {
            nvgStrokePaint(t2GetContext(), imgPaint);
            nvgStroke(t2GetContext());
        }
    }
Ejemplo n.º 27
0
void Caret::draw(NVGcontext *ctx, float lineh, Vector2i offset) {
    
    //std::cout << "Cursor("<< mCursorPos.x()<< ","<< mCursorPos.y() <<")" << std::endl;

    if(isVisible()) {
        //float caretx = cursorIndex2Position(mCursorPos.x(), textBound[2], glyphs, nglyphs);
        //mPosition = getCursorPosition(ctx, mCursorPos, lineh);

        // draw cursor
        nvgBeginPath(ctx);
        nvgMoveTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y()  );
        nvgLineTo(ctx, offset.x() + mPos.x(), offset.y()+ mPos.y()+ lineh );
        
        nvgStrokeColor(ctx, nvgRGBA(255, 192, 0, 255));
        nvgStrokeWidth(ctx, 1.0f);
        nvgStroke(ctx);
    }

    if(mSelectionState) {
        // draw selection
        int linew = mConsole->mSize.x();
        nvgBeginPath(ctx);
        nvgFillColor(ctx, nvgRGBA(255, 255, 255, 80));
        if(mIdx.y() == mSelectionIdx.y()) {
            int x = std::min(mPos.x(),mSelectionPos.x());
            x += offset.x();
            nvgRect(ctx, x, offset.y()+ mPos.y(), std::abs(mSelectionPos.x()-mPos.x()), lineh);
        } else if(mIdx.y() > mSelectionIdx.y()) {
            nvgRect(ctx, offset.x()+mSelectionPos.x(), offset.y()+ mSelectionPos.y(), 
                    linew-mSelectionPos.x(), lineh);
            if(mIdx.y()-mSelectionIdx.y()>1)
                nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y()+lineh, 
                    linew, mPos.y()-mSelectionPos.y()-lineh);
            nvgRect(ctx, offset.x(), offset.y()+ mPos.y(), mPos.x(), lineh);
        } else {
            nvgRect(ctx, offset.x(), offset.y()+ mSelectionPos.y(), 
                    mSelectionPos.x(), lineh);
            if(mSelectionIdx.y()-mIdx.y()>1)
                nvgRect(ctx, offset.x(), offset.y()+ mPos.y()+lineh, 
                    linew, mSelectionPos.y()-mPos.y()-lineh);
            nvgRect(ctx, offset.x()+mPos.x(), offset.y()+ mPos.y(), linew-mPos.x(), lineh);
        }
        nvgFill(ctx);
    }
}
Ejemplo n.º 28
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.º 29
0
void nvgRect(NVGcontext* ctx, Rect rect){
	nvgRect(ctx,rect.x,rect.y,rect.width,rect.height);
}
Ejemplo n.º 30
0
void NanoVG::rect( float x, float y, float w, float h )
{
    nvgRect( m_context(), x, y, w, h );
}