예제 #1
0
파일: VsGFX.hpp 프로젝트: solpie/linAnil
void vsColoredNodeWire(NVGcontext *ctx, float x0, float y0, float x1, float y1,
                       NVGcolor color0, NVGcolor color1) {
    float length = bnd_fmaxf(fabsf(x1 - x0), fabsf(y1 - y0));
    // how much a noodle curves (0 to 10)
    int noodleCurving = 3;
    float delta = length * (float) noodleCurving / 10.0f;

    nvgBeginPath(ctx);
    nvgMoveTo(ctx, x0, y0);
    nvgBezierTo(ctx,
                x0 + delta, y0,
                x1 - delta, y1,
                x1, y1);
    NVGcolor colorw = nvgRGB(52, 22, 99);
    colorw.a = (color0.a < color1.a) ? color0.a : color1.a;
    nvgStrokeColor(ctx, colorw);
    nvgStrokeWidth(ctx, BND_NODE_WIRE_OUTLINE_WIDTH);
    nvgStroke(ctx);
    nvgStrokePaint(ctx, nvgLinearGradient(ctx,
                                          x0, y0, x1, y1,
                                          color0,
                                          color1));
    nvgStrokeWidth(ctx, BND_NODE_WIRE_WIDTH);
    nvgStroke(ctx);
}
예제 #2
0
QNanoLinearGradient::QNanoLinearGradient(const QPointF &start, const QPointF &end)
    : m_changed(true)
    , m_sx(start.x())
    , m_sy(start.y())
    , m_ex(end.x())
    , m_ey(end.y())
{
    m_icol = nvgRGB(255, 255, 255);
    m_ocol = nvgRGBA(0, 0, 0, 0);
}
예제 #3
0
QNanoLinearGradient::QNanoLinearGradient(float startX, float startY, float endX, float endY)
    : m_changed(true)
    , m_sx(startX)
    , m_sy(startY)
    , m_ex(endX)
    , m_ey(endY)
{
    m_icol = nvgRGB(255, 255, 255);
    m_ocol = nvgRGBA(0, 0, 0, 0);
}
예제 #4
0
QNanoLinearGradient::QNanoLinearGradient()
    : m_changed(true)
    , m_sx(0.0f)
    , m_sy(0.0f)
    , m_ex(0.0f)
    // TODO: Could we have height of QNanoPainter (item) as default?
    , m_ey(100.0f)
{
    m_icol = nvgRGB(255, 255, 255);
    m_ocol = nvgRGBA(0, 0, 0, 0);
}
예제 #5
0
파일: Button.cpp 프로젝트: foxik0169/ui
bool Button::Draw(NVGcontext *context, float deltaTime)
{
	if (Widget::Draw(context, deltaTime)) return true;

	// Draw the default button here 
	nvgBeginPath(context);

	nvgRoundedRect(context, bounds.position.x, bounds.position.y, bounds.size.x - 4, bounds.size.y - 4, 20);
	nvgStrokeWidth(context, 2);
	nvgStrokeColor(context, nvgRGB(100, 100, 100));
	nvgFillColor(context, nvgRGB(240, 240, 240));

	if (mouseInsideWidgetBounds())
	{
		nvgFillColor(context, nvgRGB(220, 220, 220));
	}

	nvgFill(context);
	nvgStroke(context);

	return true;
}
예제 #6
0
파일: Timeline.hpp 프로젝트: solpie/linAnil
    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);
        }

    }
예제 #7
0
	void Render() override
	{
		nvgBeginPath(GNvg);
		if (EdgePainter.Points.size() >= 4)
		{
			glm::vec2 temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[0], EdgePainter.Points[1]));
			nvgMoveTo(GNvg, temp[0], temp[1]);
			for (int i = 2; i < EdgePainter.Points.size(); i += 2)
			{
				temp = camera.WorldToScreen(glm::vec2(EdgePainter.Points[i], EdgePainter.Points[i + 1]));
				nvgLineTo(GNvg, temp[0], temp[1]);
			}
		}
		nvgStrokeColor(GNvg, nvgRGB(255, 255, 255));
		nvgStrokeWidth(GNvg, 5);
		nvgStroke(GNvg);
	}
예제 #8
0
파일: HUD.cpp 프로젝트: cyj0912/Construct3
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);
	}
}
JNIEXPORT void JNICALL Java_org_lwjgl_nanovg_NanoVG_nnvgRGB(JNIEnv *__env, jclass clazz, jbyte r, jbyte g, jbyte b, jlong __result) {
	UNUSED_PARAMS(__env, clazz)
	*((NVGcolor*)(intptr_t)__result) = nvgRGB(r, g, b);
}
예제 #10
0
void drawClock(NVGcontext* vg, int screenWidth, int screenHeight) {
	int clockRadius = (fmin(screenWidth, screenHeight) - 10) / 2;

	NVGcolor baseColor = nvgRGB(145, 100, 0);
	NVGcolor lighterColor = nvgRGB(200, 140, 0);
	NVGcolor dblLighterColor = nvgRGB(255, 177, 0);
	NVGcolor lightestColor = nvgRGB(255, 195, 60);

	int widthLight = fmax(clockRadius * 0.0075, 1);
	int widthMedium = fmax(clockRadius * 0.013, 1);
	int widthHeavy = fmax(clockRadius * 0.025, 1);


	time_t t = time(NULL);
	struct tm localTime = *localtime(&t);

	nvgTranslate(vg, screenWidth / 2, screenHeight / 2);
	nvgStrokeColor(vg, baseColor);

	// Frame
	nvgSave(vg);
	nvgBeginPath(vg);
	nvgCircle(vg, 0, 0, clockRadius);
	nvgStrokeWidth(vg, widthMedium);
	nvgStroke(vg);
	nvgBeginPath(vg);
	nvgStrokeColor(vg, lighterColor);
	for (int i = 0; i < 12; i++) {
		nvgMoveTo(vg, 0, -clockRadius * 0.98);
		nvgLineTo(vg, 0, -clockRadius * 0.90);
		for (int j = 0; j < 5; j++) {
			nvgRotate(vg, 2 * M_PI / 12 / 5);
			nvgMoveTo(vg, 0, -clockRadius * 0.98);
			nvgLineTo(vg, 0, -clockRadius * 0.95);
		}
	}
	nvgStroke(vg);

	nvgBeginPath(vg);
	nvgFontFace(vg, "bold");

	int digitsRadius = clockRadius * 0.79;
	int digitLargeSize = clockRadius * 0.29;
	int digitSmallSize = clockRadius * 0.2;

	int clockTitleSize = clockRadius * 0.06;

	nvgFillColor(vg, dblLighterColor);

	char* nineTitle = "9";
	nvgFontSize(vg, digitLargeSize);
	nvgTranslate(vg, -digitsRadius, 0);
	nvgRotate(vg, - 3 * 2 * M_PI / 12);
	//nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, nineTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, lighterColor);

	char* tenTitle = "10";
	nvgFontSize(vg, digitSmallSize);
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, tenTitle, 0, 0);
	nvgFill(vg);

	char* elevenTitle = "11";
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, elevenTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, dblLighterColor);

	char* twelveTitle = "12";
	nvgFontSize(vg, digitLargeSize);
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, twelveTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, lighterColor);

	char* oneTitle = "1";
	nvgFontSize(vg, digitSmallSize);
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, oneTitle, 0, 0);
	nvgFill(vg);

	char* twoTitle = "2";
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, twoTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, dblLighterColor);

	char* threeTitle = "3";
	nvgFontSize(vg, digitLargeSize);
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, -digitsRadius);
	drawTextCenter(vg, threeTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, lighterColor);

	char* fourTitle = "4";
	nvgFontSize(vg, digitSmallSize);
	nvgTranslate(vg, 0, digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12 - M_PI);
	nvgTranslate(vg, 0, digitsRadius);
	drawTextCenter(vg, fourTitle, 0, 0);
	nvgFill(vg);

	char* fiveTitle = "5";
	nvgTranslate(vg, 0, -digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, digitsRadius);
	drawTextCenter(vg, fiveTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, dblLighterColor);

	char* sixTitle = "6";
	nvgFontSize(vg, digitLargeSize);
	nvgTranslate(vg, 0, -digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, digitsRadius);
	drawTextCenter(vg, sixTitle, 0, 0);
	nvgFill(vg);

	nvgFillColor(vg, lighterColor);

	char* sevenTitle = "7";
	nvgFontSize(vg, digitSmallSize);
	nvgTranslate(vg, 0, -digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, digitsRadius);
	drawTextCenter(vg, sevenTitle, 0, 0);
	nvgFill(vg);

	char* eightTitle = "8";
	nvgTranslate(vg, 0, -digitsRadius);
	nvgRotate(vg, 2 * M_PI / 12);
	nvgTranslate(vg, 0, digitsRadius);
	drawTextCenter(vg, eightTitle, 0, 0);
	nvgFill(vg);

	nvgRestore(vg);

	nvgSave(vg);
	nvgFontFace(vg, "black");
	char* clockTitle = "ALPHA";
	nvgFontSize(vg, clockTitleSize);
	nvgFillColor(vg, baseColor);
	nvgTranslate(vg, 0, clockTitleSize);
	nvgTextLetterSpacing(vg, clockTitleSize);
	drawTextCenter(vg, clockTitle, 0, -2 * clockTitleSize);
	nvgFill(vg);
	nvgRestore(vg);

	double secAngle = 2 * M_PI / 60 * localTime.tm_sec;
	double minAngle = 2 * M_PI / 60 * localTime.tm_min + secAngle / 60;
	double hrAngle = 2 * M_PI / 12 * localTime.tm_hour + minAngle / 60;

	// Hour hand
	nvgStrokeColor(vg, lighterColor);
	nvgSave(vg);
	nvgRotate(vg, hrAngle);
	nvgBeginPath(vg);
	nvgMoveTo(vg, 0, clockRadius * 0.02);
	nvgLineTo(vg, 0, -clockRadius * 0.5);
	nvgStrokeWidth(vg, widthHeavy);
	nvgStroke(vg);
	nvgRestore(vg);

	// Minute hand
	nvgStrokeColor(vg, lighterColor);
	nvgSave(vg);
	nvgRotate(vg, minAngle);
	nvgBeginPath(vg);
	nvgMoveTo(vg, 0, clockRadius * 0.04);
	nvgLineTo(vg, 0, -clockRadius * 0.8);
	nvgStrokeWidth(vg, widthMedium);
	nvgStroke(vg);
	nvgRestore(vg);

	// Second hand
	nvgStrokeColor(vg, lightestColor);
	nvgSave(vg);
	nvgRotate(vg, secAngle);
	nvgBeginPath(vg);
	nvgMoveTo(vg, 0, clockRadius * 0.05);
	nvgLineTo(vg, 0, -clockRadius * 0.9);
	nvgStrokeWidth(vg, widthLight);
	nvgStroke(vg);
	nvgRestore(vg);
}
예제 #11
0
파일: basic-ny.cpp 프로젝트: nyorain/vvg
int main()
{
	constexpr auto width = 1200u;
	constexpr auto height = 800u;

	// init ny app
	auto& backend = ny::Backend::choose();
	if(!backend.vulkan()) {
		dlg_error("ny backend has no vulkan support!");
		return 0;
	}

	auto ac = backend.createAppContext();

	// basic vpp init
	auto iniExtensions = ac->vulkanExtensions();
	iniExtensions.push_back(VK_EXT_DEBUG_REPORT_EXTENSION_NAME);
	vk::ApplicationInfo appInfo ("vpp-intro", 1, "vpp", 1, VK_API_VERSION_1_0);
	vk::InstanceCreateInfo instanceInfo;
	instanceInfo.pApplicationInfo = &appInfo;
	instanceInfo.enabledExtensionCount = iniExtensions.size();
	instanceInfo.ppEnabledExtensionNames = iniExtensions.data();

#ifdef WithLayers
	constexpr auto layer = "VK_LAYER_LUNARG_standard_validation";
	instanceInfo.enabledLayerCount = 1;
	instanceInfo.ppEnabledLayerNames = &layer;
#endif

	vpp::Instance instance(instanceInfo);

#ifdef WithLayers
	vpp::DebugCallback debugCallback(instance);
#endif

	// ny init
	auto run = true;

	auto listener = MyWindowListener {};
	listener.run = &run;

	auto vkSurface = vk::SurfaceKHR {};
	auto ws = ny::WindowSettings {};
	ws.surface = ny::SurfaceType::vulkan;
	ws.listener = &listener;
	ws.size = {width, height};
	ws.vulkan.instance = (VkInstance) instance.vkHandle();
	ws.vulkan.storeSurface = &(std::uintptr_t&) (vkSurface);
	auto wc = ac->createWindowContext(ws);

	// further vpp init
	const vpp::Queue* presentQueue;
	vpp::Device device(instance, vkSurface, presentQueue);
	vpp::Swapchain swapchain(device, vkSurface, {width, height}, {});

	// vvg setup
	auto nvgContext = vvg::createContext(swapchain);
	auto font = nvgCreateFont(nvgContext, "sans", "Roboto-Regular.ttf");

	using Clock = std::chrono::high_resolution_clock;
	auto lastFrameTimer = Clock::now();
	unsigned int framesCount = 0;
	std::string fpsString = "420 fps";

	// main loop
	while(run) {
		if(!ac->dispatchEvents())
			break;

		nvgBeginFrame(nvgContext, width, height, width / (float) height);

		nvgBeginPath(nvgContext);
		nvgMoveTo(nvgContext, 10, 10);
		nvgLineTo(nvgContext, 10, 400);
		nvgLineTo(nvgContext, 100, 400);
		nvgQuadTo(nvgContext, 100, 50, 400, 120);
		nvgLineTo(nvgContext, 450, 10);
		nvgClosePath(nvgContext);

		nvgFillColor(nvgContext, nvgRGBAf(0.5, 0.8, 0.7, 1.0));
		nvgFill(nvgContext);

		nvgBeginPath(nvgContext);
		nvgFontFaceId(nvgContext, font);
		nvgFontSize(nvgContext, 100.f);
		nvgFontBlur(nvgContext, .8f);
		nvgFillColor(nvgContext, nvgRGBAf(1.0, 1.0, 1.0, 1.0));
		nvgTextBox(nvgContext, 200, 200, width - 200, "Hello Vulkan Vector Graphics World", nullptr);

		nvgFontSize(nvgContext, 30.f);
		nvgFontBlur(nvgContext, .2f);
		nvgText(nvgContext, 10, height - 20, fpsString.c_str(), nullptr);

		nvgBeginPath(nvgContext);
		nvgRect(nvgContext, 700, 400, 300, 300);
		nvgPathWinding(nvgContext, NVG_HOLE);
		nvgRect(nvgContext, 750, 450, 50, 50);
		// auto paint = nvgRadialGradient(nvgContext, 750, 425,20, 50, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		// auto paint = nvgRadialGradient(nvgContext, 0.0, 0.0, 0.2, 100.0, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		auto paint = nvgLinearGradient(nvgContext, 700, 400, 800, 450, nvgRGB(0, 0, 200), nvgRGB(200, 200, 0));
		nvgFillPaint(nvgContext, paint);
		// nvgFillColor(nvgContext, nvgRGBA(200, 200, 0, 200));
		nvgClosePath(nvgContext);
		nvgFill(nvgContext);

		nvgEndFrame(nvgContext);

		// only refresh frame timer every second
		framesCount++;
		if(Clock::now() - lastFrameTimer >= std::chrono::seconds(1)) {
			fpsString = std::to_string(framesCount) + " fps";
			lastFrameTimer = Clock::now();
			framesCount = 0;
		}
	}

	vvg::destroyContext(*nvgContext);
}