示例#1
0
	void build(CanvasPtr canvas) final
	{
		Vec4 oldBackground = ImGui::GetStyle().Colors[ImGuiCol_WindowBg];
		ImGui::GetStyle().Colors[ImGuiCol_WindowBg].w = 0.8f;

		ImGui::Begin("ImGui Demo", nullptr);

		if(!m_windowInitialized)
		{
			ImGui::SetWindowPos(Vec2(20, 10));
			ImGui::SetWindowSize(Vec2(200, 500));
			m_windowInitialized = true;
		}

		ImGui::Text("Label default size");

		canvas->pushFont(canvas->getDefaultFont(), 30);
		ImGui::Text("Label size 30");
		ImGui::PopFont();

		m_buttonClickCount += ImGui::Button("Toggle");
		if(m_buttonClickCount & 1)
		{
			ImGui::Button("Toggled");
		}

		ImGui::End();
		ImGui::GetStyle().Colors[ImGuiCol_WindowBg] = oldBackground;
	}
示例#2
0
	int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas)
	{
		if (use_glyph_program != false)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = false;
		}

		if (position == 0 || position + 6 > max_vertices)
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return RenderBatchTriangle::max_textures;
	}
ScreenViewController::ScreenViewController(const CanvasPtr &canvas)
{
	texture_view = std::make_shared<uicore::TextureWindow>(canvas);
	texture_view->set_viewport(canvas->size());
	texture_view->set_clear_background(false);
	texture_view->set_always_render(true);
}
void ScreenViewController::render_scene(const CanvasPtr &canvas, const ScenePtr &scene)
{
	using namespace uicore;

	canvas->end();

	GraphicContextPtr gc = canvas->gc();

	Pointf viewport_pos = Vec2f(canvas->transform() * Vec4f(0.0f, 0.0f, 0.0f, 1.0f));
	Sizef viewport_size = gc->size();
	Size viewport_size_i = Size(viewport_size);

	scene->set_viewport(viewport_size_i);
	scene->render(gc);

	canvas->begin();
}
示例#5
0
	int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas, int num_vertices)
	{
		if (use_glyph_program != false)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = false;
		}

		if (position + num_vertices > max_vertices)
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();

		if (num_vertices > max_vertices)
			throw Exception("Too many vertices for RenderBatchTriangle");

		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return RenderBatchTriangle::max_textures;
	}
示例#6
0
	int RenderBatchTriangle::set_batcher_active(const CanvasPtr &canvas, const Texture2DPtr &texture, bool glyph_program, const Colorf &new_constant_color)
	{
		if (use_glyph_program != glyph_program || constant_color != new_constant_color)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			use_glyph_program = glyph_program;
			constant_color = new_constant_color;
		}

		int texindex = -1;
		for (int i = 0; i < num_current_textures; i++)
		{
			if (current_textures[i] == texture)
			{
				texindex = i;
				break;
			}
		}
		if (texindex == -1 && num_current_textures < max_textures)
		{
			texindex = num_current_textures;
			current_textures[num_current_textures++] = texture;
			tex_sizes[texindex] = Sizef((float)current_textures[texindex]->width(), (float)current_textures[texindex]->height());
		}

		if (position == 0 || position + 6 > max_vertices || texindex == -1)
		{
			static_cast<CanvasImpl*>(canvas.get())->batcher.flush();
			texindex = 0;
			current_textures[texindex] = texture;
			num_current_textures = 1;
			tex_sizes[texindex] = Sizef((float)current_textures[texindex]->width(), (float)current_textures[texindex]->height());
		}
		static_cast<CanvasImpl*>(canvas.get())->set_batcher(this);
		return texindex;
	}
示例#7
0
	void Font_DrawFlat::draw_text(const CanvasPtr &canvas, const Pointf &position, const std::string &text, const Colorf &color, float line_spacing)
	{
		float offset_x = 0;
		float offset_y = 0;
		UTF8_Reader reader(text.data(), text.length());
		RenderBatchTriangle *batcher = static_cast<CanvasImpl*>(canvas.get())->batcher.get_triangle_batcher();

		while (!reader.is_end())
		{
			unsigned int glyph = reader.character();
			reader.next();

			if (glyph == '\n')
			{
				offset_x = 0;
				offset_y += line_spacing;
				continue;
			}

			Font_TextureGlyph *gptr = glyph_cache->get_glyph(canvas, font_engine, glyph);
			if (gptr)
			{
				if (gptr->texture)
				{
					float xp = offset_x + position.x + gptr->offset.x;
					float yp = offset_y + position.y + gptr->offset.y;
					Pointf pos = canvas->grid_fit(Pointf(xp, yp));

					Rectf dest_size(pos, gptr->size);
					batcher->draw_image(canvas, gptr->geometry, dest_size, color, gptr->texture);
				}
				offset_x += gptr->metrics.advance.width;
				offset_y += gptr->metrics.advance.height;
			}
		}
	}
示例#8
0
	void GlyphCache::insert_glyph(const CanvasPtr &canvas, FontPixelBuffer &pb)
	{
		auto font_glyph = std::unique_ptr<Font_TextureGlyph>(new Font_TextureGlyph());

		font_glyph->glyph = pb.glyph;
		font_glyph->offset = pb.offset;
		font_glyph->metrics = pb.metrics;

		if (!pb.empty_buffer)
		{
			PixelBufferPtr buffer_with_border = PixelBuffer::add_border(pb.buffer, glyph_border_size, pb.buffer_rect);
			GraphicContextPtr gc = canvas->gc();
			TextureGroupImage sub_texture = texture_group->add(gc, buffer_with_border->size());
			font_glyph->texture = sub_texture.texture();
			font_glyph->geometry = Rect(sub_texture.geometry().left + glyph_border_size, sub_texture.geometry().top + glyph_border_size, pb.buffer_rect.size());
			font_glyph->size = pb.size;
			sub_texture.texture()->set_subimage(gc, sub_texture.geometry().left, sub_texture.geometry().top, buffer_with_border, buffer_with_border->size());
		}

		glyph_list.push_back(std::move(font_glyph));
	}
示例#9
0
void SoundNode::connect(CanvasPtr pCanvas)
{
    checkReload();
    AreaNode::connect(pCanvas);
    pCanvas->registerFrameEndListener(this);
}
示例#10
0
void ColorDepthShaderEffect::addUI(CanvasPtr canvas)
{
	ofxUISlider* slider = new ofxUISlider("Saturation", 0.0f, 255.0f, m_saturationValue, 100.0f, 25.0f);
	canvas->addWidgetDown(slider);
	m_widgets.push_back(slider);
	
	ofxUISpacer* spacer = new ofxUISpacer(100, 2);
	canvas->addWidgetDown(spacer);
	m_widgets.push_back(spacer);

	ofxUISlider* slider2 = new ofxUISlider("Brightness", 0.0f, 255.0f, m_brightnessValue, 100.0f, 25.0f);
	canvas->addWidgetDown(slider2);
	m_widgets.push_back(slider2);

	ofxUISpacer* spacer2 = new ofxUISpacer(100, 2);
	canvas->addWidgetDown(spacer2);
	m_widgets.push_back(spacer2);

	ofxUISlider* slider3 = new ofxUISlider("Step Size", 1.0f, 100.0f, m_lookupStepSize, 100.0f, 25.0f);
	canvas->addWidgetDown(slider3);
	m_widgets.push_back(slider3);

	ofxUISpacer* spacer5 = new ofxUISpacer(100, 2);
	canvas->addWidgetDown(spacer5);
	m_widgets.push_back(spacer5);

	ofxUISlider* slider6 = new ofxUISlider("Offset", 0.0f, 255.0f, m_lookupOffset, 100.0f, 25.0f);
	canvas->addWidgetDown(slider6);
	m_widgets.push_back(slider6);

	ofxUISpacer* spacer3 = new ofxUISpacer(100, 2);
	canvas->addWidgetDown(spacer3);
	m_widgets.push_back(spacer3);

	ofxUISlider* slider4 = new ofxUISlider("Near Clip", 0.0f, 500.0f, m_nearClip, 100.0f, 25.0f);
	canvas->addWidgetDown(slider4);
	m_widgets.push_back(slider4);

	ofxUISpacer* spacer4 = new ofxUISpacer(100, 2);
	canvas->addWidgetDown(spacer4);
	m_widgets.push_back(spacer4);

	ofxUISlider* slider5 = new ofxUISlider("Far Clip", 501.0f, 8000.0f, m_farClip, 100.0f, 25.0f);
	canvas->addWidgetDown(slider5);
	m_widgets.push_back(slider5);

	m_event = &canvas->newGUIEvent;
	
	ofAddListener(*m_event,this,&ColorDepthShaderEffect::guiEvent);

	canvas->loadSettings("GUI/ColorDepthSettings.xml");
}
示例#11
0
ANKI_TEST(Ui, Ui)
{
	Config cfg;
	initConfig(cfg);
	cfg.set("window.vsync", 1);
	cfg.set("window.debugContext", 0);
	cfg.set("width", 1024);
	cfg.set("height", 760);
	cfg.set("rsrc.dataPaths", "engine_data");

	NativeWindow* win = createWindow(cfg);
	Input* in = new Input();
	GrManager* gr = createGrManager(cfg, win);
	PhysicsWorld* physics;
	ResourceFilesystem* fs;
	ResourceManager* resource = createResourceManager(cfg, gr, physics, fs);
	UiManager* ui = new UiManager();

	ANKI_TEST_EXPECT_NO_ERR(in->init(win));

	StagingGpuMemoryManager* stagingMem = new StagingGpuMemoryManager();
	ANKI_TEST_EXPECT_NO_ERR(stagingMem->init(gr, cfg));

	HeapAllocator<U8> alloc(allocAligned, nullptr);
	ANKI_TEST_EXPECT_NO_ERR(ui->init(allocAligned, nullptr, resource, gr, stagingMem, in));

	{
		FontPtr font;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(font, "UbuntuRegular.ttf", std::initializer_list<U32>{10, 20, 30, 60}));

		CanvasPtr canvas;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(canvas, font, 20, win->getWidth(), win->getHeight()));

		IntrusivePtr<Label> label;
		ANKI_TEST_EXPECT_NO_ERR(ui->newInstance(label));

		Bool done = false;
		while(!done)
		{
			ANKI_TEST_EXPECT_NO_ERR(in->handleEvents());
			HighRezTimer timer;
			timer.start();

			canvas->handleInput();
			if(in->getKey(KeyCode::ESCAPE))
			{
				done = true;
			}

			canvas->beginBuilding();
			label->build(canvas);

			TexturePtr presentTex = gr->acquireNextPresentableTexture();
			FramebufferPtr fb;
			{
				TextureViewInitInfo init;
				init.m_texture = presentTex;
				TextureViewPtr view = gr->newTextureView(init);

				FramebufferInitInfo fbinit;
				fbinit.m_colorAttachmentCount = 1;
				fbinit.m_colorAttachments[0].m_clearValue.m_colorf = {{1.0, 0.0, 1.0, 1.0}};
				fbinit.m_colorAttachments[0].m_textureView = view;

				fb = gr->newFramebuffer(fbinit);
			}

			CommandBufferInitInfo cinit;
			cinit.m_flags = CommandBufferFlag::GRAPHICS_WORK | CommandBufferFlag::SMALL_BATCH;
			CommandBufferPtr cmdb = gr->newCommandBuffer(cinit);

			cmdb->setTextureBarrier(presentTex,
				TextureUsageBit::NONE,
				TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
				TextureSubresourceInfo());

			cmdb->beginRenderPass(fb, {{TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE}}, {});
			canvas->appendToCommandBuffer(cmdb);
			cmdb->endRenderPass();

			cmdb->setTextureBarrier(presentTex,
				TextureUsageBit::FRAMEBUFFER_ATTACHMENT_WRITE,
				TextureUsageBit::PRESENT,
				TextureSubresourceInfo());

			cmdb->flush();

			gr->swapBuffers();
			stagingMem->endFrame();

			timer.stop();
			const F32 TICK = 1.0 / 30.0;
			if(timer.getElapsedTime() < TICK)
			{
				HighRezTimer::sleep(TICK - timer.getElapsedTime());
			}
		}
	}

	delete ui;
	delete stagingMem;
	delete resource;
	delete physics;
	delete fs;
	GrManager::deleteInstance(gr);
	delete in;
	delete win;
}