Exemplo n.º 1
0
ivec2 Button::preferredSize(NVGcontext * ctx) const
{
	int fontSize = mFontSize == -1 ? mTheme->mButtonFontSize : mFontSize;
	nvgFontSize(ctx, fontSize);
	nvgFontFace(ctx, "sans-bold");
	float tw = nvgTextBounds(ctx, 0, 0, mCaption.c_str(), nullptr, nullptr);
	float iw = 0.0f, ih = fontSize;
	if (mIcon)
	{
		if (nvgIsFontIcon(mIcon))
		{
			ih *= 1.5f;
			nvgFontFace(ctx, "icons");
			nvgFontSize(ctx, ih);
			iw = nvgTextBounds(ctx, 0, 0, utf8(mIcon).data(), nullptr, nullptr)
				+ mSize.y * 0.15f;
		}
		else
		{
			int w, h;
			ih *= 0.9f;
			nvgImageSize(ctx, mIcon, &w, &h);
			iw = w * ih / h;
		}
	}
	return ivec2((int)(tw + iw) + 20, fontSize + 10);
}
Exemplo n.º 2
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);
}
Exemplo n.º 3
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);
}
Exemplo n.º 4
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);
    }
}
Exemplo n.º 5
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);
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
void Renderer2D::drawText( const attributes_2d& attributes,Font2D font, const char* text, const float32_t& fontSize,
			const color_argb& color, const float32_t& blur, const float32_t& spacing,
			const float32_t& lineHeight, const TextAlignment& alignment )
{
	Context2D* context = _context2D;

	nvgSave( context );
	nvgBeginPath( context );

	nvgRotate( context, attributes.rotation );

	nvgFontSize( context, fontSize * attributes.scale );
	nvgFontBlur( context, blur );
	nvgTextLetterSpacing(context, spacing);
	nvgTextLineHeight(context, lineHeight);
	nvgTextAlign(context, alignment.value );
	nvgFontFaceId(context, font);

	nvgFillColor( context, nvgRGBA( color.r, color.g, color.b, color.a) );
	nvgFill(context);

	nvgText(context, attributes.position[0], attributes.position[1], text, NULL);

	nvgRestore( context );
}
Exemplo n.º 8
0
int QNanoFont::getID(NVGcontext* nvg)
{
    if (m_fontPropertiesChanged) {
        nvgFontSize(nvg, m_size);
        nvgFontBlur(nvg, m_blur);
        nvgTextLetterSpacing(nvg, m_spacing);
        nvgTextLineHeight(nvg, m_lineHeight);
    }

    if (m_filename.isEmpty()) {
        // No font file set, so loading the default font
        setFontId(QNanoFont::DEFAULT_FONT_NORMAL);
    }
    m_id = nvgFindFont(nvg,m_filename.toUtf8().constData());
    if (m_id == -1) {
        // Font is not yet in cache, so load and add it
        QFile file(m_filename);
        if (!file.open(QFile::ReadOnly))
        {
            qWarning() << "Could not open font file: " << m_filename;
        } else {
            qint64 length = file.bytesAvailable();
            char * data = static_cast<char*>(malloc(length));
            file.read(data,length);
            m_id = nvgCreateFontMem(nvg, m_filename.toUtf8().constData(), reinterpret_cast<unsigned char*>(data), length, 1);
            file.close();
        }
    }
    return m_id;
}
	box2px TreeItem::update(AlloyContext* context, const pixel2& offset) {
		NVGcontext* nvg = context->nvgContext;
		nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
		nvgFontSize(nvg, fontSize);
		nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold));
		spaceWidth = fontSize + PADDING * 2;
		float textWidth = nvgTextBounds(nvg, 0, 0, name.c_str(), nullptr, nullptr);
		nvgFontFaceId(nvg, context->getFontHandle(FontType::Icon));
		float iconWidth =
			(iconCodeString.length() == 0) ?
			0 :
			nvgTextBounds(nvg, 0, 0, iconCodeString.c_str(), nullptr,
				nullptr) + PADDING * 2;
		float th = (name.length() > 0) ? fontSize + PADDING * 2 : 0;
		selectionBounds = box2px(offset,
			pixel2(textWidth + iconWidth + spaceWidth + PADDING, th));
		bounds = selectionBounds;
		if (isExpanded()) {
			pixel2 pt = offset + pixel2((name.length() > 0) ? spaceWidth : 0, th);
			for (TreeItemPtr& item : children) {
				box2px cdims = item->update(context, pt);
				bounds.dimensions = aly::max(bounds.max(), cdims.max())
					- aly::min(bounds.min(), cdims.min());
				pt += pixel2(0.0f, cdims.dimensions.y);
			}
		}
		return bounds;
	}
Exemplo n.º 10
0
void Screen::drawWidgets() {
    if (!mVisible)
        return;

    glfwMakeContextCurrent(mGLFWWindow);
    glfwGetFramebufferSize(mGLFWWindow, &mFBSize[0], &mFBSize[1]);
    glfwGetWindowSize(mGLFWWindow, &mSize[0], &mSize[1]);
    glViewport(0, 0, mFBSize[0], mFBSize[1]);

    /* Calculate pixel ratio for hi-dpi devices. */
    mPixelRatio = (float) mFBSize[0] / (float) mSize[0];
    nvgBeginFrame(mNVGContext, mSize[0], mSize[1], mPixelRatio);

    draw(mNVGContext);

    double elapsed = glfwGetTime() - mLastInteraction;

    if (elapsed > 0.5f) {
        /* Draw tooltips */
        const Widget *widget = findWidget(mMousePos);
        if (widget && !widget->tooltip().empty()) {
            int tooltipWidth = 150;

            float bounds[4];
            nvgFontFace(mNVGContext, "sans");
            nvgFontSize(mNVGContext, 15.0f);
            nvgTextAlign(mNVGContext, NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
            nvgTextLineHeight(mNVGContext, 1.1f);
            Vector2i pos = widget->absolutePosition() +
                           Vector2i(widget->width() / 2, widget->height() + 10);

            nvgTextBoxBounds(mNVGContext, pos.x(), pos.y(), tooltipWidth,
                             widget->tooltip().c_str(), nullptr, bounds);

            nvgGlobalAlpha(mNVGContext,
                           std::min(1.0, 2 * (elapsed - 0.5f)) * 0.8);

            nvgBeginPath(mNVGContext);
            nvgFillColor(mNVGContext, Color(0, 255));
            int h = (bounds[2] - bounds[0]) / 2;
            nvgRoundedRect(mNVGContext, bounds[0] - 4 - h, bounds[1] - 4,
                           (int) (bounds[2] - bounds[0]) + 8,
                           (int) (bounds[3] - bounds[1]) + 8, 3);

            int px = (int) ((bounds[2] + bounds[0]) / 2) - h;
            nvgMoveTo(mNVGContext, px, bounds[1] - 10);
            nvgLineTo(mNVGContext, px + 7, bounds[1] + 1);
            nvgLineTo(mNVGContext, px - 7, bounds[1] + 1);
            nvgFill(mNVGContext);

            nvgFillColor(mNVGContext, Color(255, 255));
            nvgFontBlur(mNVGContext, 0.0f);
            nvgTextBox(mNVGContext, pos.x() - h, pos.y(), tooltipWidth,
                       widget->tooltip().c_str(), nullptr);
        }
    }

    nvgEndFrame(mNVGContext);
}
Exemplo n.º 11
0
    float getTextHeight(Skin::SkinClass::Attributes &skinClass, const std::string& text) {
      nvgFontSize(m_vg, skinClass.textSize);
      nvgFontFace(m_vg, skinClass.font.c_str());

      float ascender, descender, lineh;
      nvgTextMetrics(m_vg, &ascender, &descender, &lineh);
      return lineh;
    }
Exemplo n.º 12
0
Arquivo: gui.cpp Projeto: fatto/banana
void Label::on_draw()
{
	nvgFontSize(vg, 18.0f);
	nvgFontFace(vg, "sans");
	nvgTextAlign(vg, NVG_ALIGN_RIGHT | NVG_ALIGN_MIDDLE);
	nvgFillColor(vg, nvgRGBA(240, 240, 240, 255));
	nvgText(vg, x,y, text.c_str(), NULL);
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
void IterationRunWork::output(run::World& run)
{
    // draw background
    demo::background( batb, run );

    if ( item_ )
    {
        switch ( item_->mode )
        {
        case WorkItem::Mode::Definite:
        {

            //tb_widget_->set( item_->alpha, item_->tag );
            const auto& tag = item_->tag;
            auto alpha = item_->alpha;

            // draw progressbar. FIXME
            auto nvg = batb.gl.nanovg_begin( run.scene );
            float_t w = 512;
            float_t h = 22;
            float_t x = 0.5 * (run.scene.wth - w);
            float_t y = 0.5 * run.scene.hth + 112; 
            float_t r = 11;
            nvgBeginPath( nvg );
            nvgRoundedRect( nvg, x, y, w, h, r );
            nvgFillColor( nvg, nvgRGBf( 1.0, 1.0, 1.0 ) );
            nvgFill( nvg );

            nvgBeginPath( nvg );
            nvgRoundedRect( nvg, x, y, alpha * w, h, r );
            nvgFillColor( nvg, nvgRGBf( 1.0, 0.22, 0.0 ) );
            nvgFill( nvg );
            
            static int font = -1;
            if ( font == -1 )
            {
               font = batb.gl.nanovg_font( "sans", file::static_data( "batb/Ubuntu-Title.ttf" ) );
            }
            nvgFontSize( nvg, 20 );
            nvgTextAlign( nvg, NVG_ALIGN_CENTER | NVG_ALIGN_MIDDLE );
            
            nvgFontFaceId( nvg, font );
            nvgFillColor( nvg, nvgRGBf( 0.0, 0.0, 0.0 ) );
            //nvgFillColor( nvg, nvgRGBf( 0.11, 0.64, 0.04 ) );
            nvgText( nvg, x + 0.5 * w, y + 0.5 * h, tag.c_str(), nullptr );

            batb.gl.nanovg_end();
        }    
        break;
        case WorkItem::Mode::Indefinite:
            // FIXME: draw a finite progressbar/spinner

        break;
        }
    } 

}
void AwesomeGlyph::draw(const box2px& bounds, const Color& fgColor,
		const Color& bgColor, AlloyContext* context) {
	NVGcontext* nvg = context->nvgContext;
	nvgFontFaceId(nvg, context->getFontHandle(FontType::Icon));
	nvgFontSize(nvg, height);
	nvgTextAlign(nvg, NVG_ALIGN_MIDDLE | NVG_ALIGN_CENTER);
	drawText(nvg, bounds.position + HALF_PIX(bounds.dimensions), name, style,
			fgColor, bgColor, nullptr);
}
	void TreeItem::draw(ExpandTree* tree, AlloyContext* context,
		const pixel2& offset) {
		box2px bounds = getBounds();
		NVGcontext* nvg = context->nvgContext;
		nvgFontFaceId(nvg, context->getFontHandle(FontType::Icon));
		float spaceWidth = fontSize + PADDING * 2;
		float iconWidth = 0;
		static const std::string rightArrow = CodePointToUTF8(0xf0da);
		static const std::string downArrow = CodePointToUTF8(0xf0d7);
		pixel2 pt = bounds.position + offset;
		bool selected = (tree->getSelectedItem() == this)&&!tree->isOverArrow();
		nvgFontSize(nvg, fontSize);

		if (iconCodeString.length() > 0) {
			iconWidth = nvgTextBounds(nvg, 0, 0, iconCodeString.c_str(), nullptr,
				nullptr) + PADDING * 2;

			if (children.size() > 0 || onExpand) {
				nvgTextAlign(nvg, NVG_ALIGN_CENTER | NVG_ALIGN_TOP);
				if (tree->isOverArrow()) {
					nvgFillColor(nvg, context->theme.LIGHTEST);
				}
				else {
					nvgFillColor(nvg, context->theme.LIGHTER);
				}
				nvgText(nvg, pt.x + spaceWidth * 0.5f, pt.y + PADDING,
					(expanded) ? downArrow.c_str() : rightArrow.c_str(),
					nullptr);
			}
			if (selected) {
				nvgFillColor(nvg, context->theme.LIGHTEST);
			}
			else {
				nvgFillColor(nvg, context->theme.LIGHTER);
			}
			nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
			nvgText(nvg, pt.x + spaceWidth, pt.y + PADDING, iconCodeString.c_str(),
				nullptr);
		}
		if (name.length() > 0) {
			if (selected) {
				nvgFillColor(nvg, context->theme.LIGHTEST);
			}
			else {
				nvgFillColor(nvg, context->theme.LIGHTER);
			}
			nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
			nvgFontFaceId(nvg, context->getFontHandle(FontType::Bold));
			nvgText(nvg, pt.x + iconWidth + spaceWidth, pt.y + PADDING,
				name.c_str(), nullptr);
		}
		if (expanded) {
			for (TreeItemPtr& item : children) {
				item->draw(tree, context, offset);
			}
		}
	}
Exemplo n.º 17
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);
}
Exemplo n.º 18
0
void drawEditBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
	drawEditBoxBase(vg, x,y, w,h);

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,64) );
	nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+h*0.3f,y+h*0.5f,text, NULL);
}
AwesomeGlyph::AwesomeGlyph(int codePoint, AlloyContext* context,
		const FontStyle& style, pixel height) :
		Glyph(CodePointToUTF8(codePoint), GlyphType::Awesome, 0, height), codePoint(
				codePoint), style(style) {
	NVGcontext* nvg = context->nvgContext;
	nvgFontSize(nvg, height);
	nvgFontFaceId(nvg, context->getFontHandle(FontType::Icon));
	width = nvgTextBounds(nvg, 0, 0, name.c_str(), nullptr, nullptr);

}
Exemplo n.º 20
0
Vector2i CheckBox::preferredSize(NVGcontext *ctx) {
    if (mFixedSize != Vector2i(0))
        return mFixedSize;
    nvgFontSize(ctx, fontSize());
    nvgFontFace(ctx, "sans");
    return Vector2i(
        nvgTextBounds(ctx, 0, 0, mCaption.c_str(), nullptr, nullptr) +
            1.7f * fontSize(),
        fontSize() * 1.3f);
}
Exemplo n.º 21
0
void TextNode::setupContext(NVGcontext& nanoVgContext) const
{
    nvgFontFaceId(&nanoVgContext, mFontHandle);
    nvgFontSize(&nanoVgContext, mFontSize);
    nvgFontBlur(&nanoVgContext, mFontBlur);
    nvgTextLetterSpacing(&nanoVgContext, mFontLetterSpacing);
    nvgTextLineHeight(&nanoVgContext, mFontLineHeight);

    int alignment = static_cast<int>(mHorizontalAlignment) | static_cast<int>(mVerticalAlignment);
    nvgTextAlign(&nanoVgContext, alignment);
}
Exemplo n.º 22
0
/* =================================================================
 *
 *                          APP
 *
 * ================================================================= */
static size_t
font_get_width(zr_handle handle, float height, const char *text, size_t len)
{
    size_t width;
    float bounds[4];
    NVGcontext *ctx = (NVGcontext*)handle.ptr;
    nvgFontSize(ctx, (float)height);
    nvgTextBounds(ctx, 0, 0, text, &text[len], bounds);
    width = (size_t)(bounds[2] - bounds[0]);
    return width;
}
Exemplo n.º 23
0
void drawLabel(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
	NVG_NOTUSED(w);

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

	nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x,y+h*0.5f,text, NULL);
}
Exemplo n.º 24
0
Vector2i Window::preferredSize(NVGcontext *ctx) const {
    Vector2i result = Widget::preferredSize(ctx);

    nvgFontSize(ctx, 18.0f);
    nvgFontFace(ctx, "sans-bold");
    float bounds[4];
    nvgTextBounds(ctx, 0, 0, mTitle.c_str(), nullptr, bounds);

    return result.cwiseMax(Vector2i(
        bounds[2]-bounds[0] + 20, bounds[3]-bounds[1]
    ));
}
Exemplo n.º 25
0
void drawEditBoxNum(struct NVGcontext* vg,
		const char* text, const char* units, float x, float y, float w, float h)
{
	float uw;

	drawEditBoxBase(vg, x,y, w,h);

	uw = nvgTextBounds(vg, 0,0, units, NULL, NULL);

	nvgFontSize(vg, 18.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,64) );
	nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+w-h*0.3f,y+h*0.5f,units, NULL);

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,128) );
	nvgTextAlign(vg,NVG_ALIGN_RIGHT|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+w-uw-h*0.5f,y+h*0.5f,text, NULL);
}
Exemplo n.º 26
0
void Label::draw(NVGcontext *ctx) {
    Widget::draw(ctx);
    nvgFontFace(ctx, mFont.c_str());
    nvgFontSize(ctx, fontSize());
    nvgFillColor(ctx, mColor);
    if (mFixedSize.x() > 0) {
        nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
        nvgTextBox(ctx, mPos.x(), mPos.y(), mFixedSize.x(), mCaption.c_str(), nullptr);
    } else {
        nvgTextAlign(ctx, NVG_ALIGN_LEFT | NVG_ALIGN_MIDDLE);
        nvgText(ctx, mPos.x(), mPos.y() + mSize.y() * 0.5f, mCaption.c_str(), nullptr);
    }
}
Exemplo n.º 27
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);
}
Exemplo n.º 28
0
size_t NvgFont::get_cursor_location(const std::string & text, float fontSize, int xCoord) const
{
    std::vector<NVGglyphPosition> positions(text.size());
    nvgFontSize(nvg, fontSize);
    nvgFontFaceId(nvg, id);
    nvgTextAlign(nvg, NVG_ALIGN_LEFT | NVG_ALIGN_TOP);
    positions.resize(nvgTextGlyphPositions(nvg, 0, 0, text.data(), text.data() + (int) text.size(), positions.data(), (int) positions.size()));
    for (size_t i = 0; i<positions.size(); ++i)
    {
        if(xCoord < positions[i].maxx)
            return i;
    }
    return positions.size();
}
Exemplo n.º 29
0
void drawSearchBox(struct NVGcontext* vg, const char* text, float x, float y, float w, float h)
{
	struct NVGpaint bg;
	char icon[8];
	float cornerRadius = h/2-1;

	// Edit
	bg = nvgBoxGradient(vg, x,y+1.5f, w,h, h/2,5, nvgRGBA(0,0,0,16), nvgRGBA(0,0,0,92) );
	nvgBeginPath(vg);
	nvgRoundedRect(vg, x,y, w,h, cornerRadius);
	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, h*1.3f);
	nvgFontFace(vg, "icons");
	nvgFillColor(vg, nvgRGBA(255,255,255,64) );
	nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+h*0.55f, y+h*0.55f, cpToUTF8(ICON_SEARCH,icon), NULL);

	nvgFontSize(vg, 20.0f);
	nvgFontFace(vg, "sans");
	nvgFillColor(vg, nvgRGBA(255,255,255,32) );

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

	nvgFontSize(vg, h*1.3f);
	nvgFontFace(vg, "icons");
	nvgFillColor(vg, nvgRGBA(255,255,255,32) );
	nvgTextAlign(vg,NVG_ALIGN_CENTER|NVG_ALIGN_MIDDLE);
	nvgText(vg, x+w-h*0.55f, y+h*0.55f, cpToUTF8(ICON_CIRCLED_CROSS,icon), NULL);
}
Exemplo n.º 30
0
    //Render text - the implementation should keep track of loaded fonts etc.
    bool renderText(Skin::SkinClass::Attributes &skinClass, const std::string& text, float x, float y, float bx, float by) {
      if (!m_inited) return false;


      static int alignment = 0;
      alignment = 0;

      if (skinClass.hTextAlign == HA_LEFT) {
        alignment |= NVG_ALIGN_LEFT;
      } else if (skinClass.hTextAlign == HA_RIGHT) {
        alignment |= NVG_ALIGN_RIGHT;
        x += bx;
      } else if (skinClass.hTextAlign == HA_CENTER) {
        alignment |= NVG_ALIGN_CENTER;
        x += (bx / 2.f);
      }

      if (skinClass.vTextAlign == VA_TOP) {
        alignment |= NVG_ALIGN_TOP;
      } else if (skinClass.vTextAlign == VA_MIDDLE) {
        alignment |= NVG_ALIGN_MIDDLE;
        y += (by / 2.f);
      } else if (skinClass.vTextAlign == VA_BOTTOM) {
        alignment |= NVG_ALIGN_BOTTOM;
        y += by;
      } 

      nvgTextAlign(m_vg, alignment);
      
      nvgFontFace(m_vg, skinClass.font.c_str());

      if (skinClass.hasTextStroke) {
        //nvgStrokeWidth(m_vg, skinClass.strokeWidth);
       /* nvgFillColor(m_vg, nvgRGBA(skinClass.stroke.r, skinClass.stroke.g, skinClass.stroke.b, skinClass.stroke.a));
        //nvgFontBlur(m_vg, skinClass.strokeWidth);
        nvgFontSize(m_vg, skinClass.textSize + 2);
        nvgText(m_vg, p.x - 1, p.y - 1, text.c_str(), NULL);
        nvgFontBlur(m_vg, 0.f);*/
       // nvgStroke(m_vg);
      }

      nvgFontSize(m_vg, skinClass.textSize);

      nvgFillColor(m_vg, nvgRGBA(skinClass.textFill.r, skinClass.textFill.g, skinClass.textFill.b, skinClass.textFill.a));
    
      nvgText(m_vg, x, y, text.c_str(), NULL);
      return true;
    }