Example #1
3
/**
 \brief Draw a target circle and threshold along with the current pad position.
 \param idX the ID of the horizontal axis
 \param idY the ID of the vertical axis
 \param axesValues the axes raw values
 \param threshRadius the radius of the filtering threshold
 \ingroup ControllerTest
 */
void drawPadTarget(const int idX, const int idY, const std::vector<float> & axesValues, const float threshRadius){
	const ImU32 whiteColor = IM_COL32(255,255,255, 255);
	const int aidRX = idX;
	const int aidRY = idY;
	const float magRX = aidRX >= 0 ? axesValues[aidRX] : 0.0f;
	const float magRY = aidRY >= 0 ? axesValues[aidRY] : 0.0f;
	// Detect overflow on each axis.
	const bool overflow = (std::abs(magRX) > 1.0) || (std::abs(magRY) > 1.0);
	// Get current rendering position on screen.
	const ImVec2 posR = ImGui::GetCursorScreenPos();
	ImDrawList * drawListR = ImGui::GetWindowDrawList();
	// Draw "safe" region.
	drawListR->AddRectFilled(posR, ImVec2(posR.x + 200, posR.y + 200), overflow ? IM_COL32(30,0,0,255) : IM_COL32(0,30,0, 255));
	drawListR->AddCircleFilled(ImVec2(posR.x + 100, posR.y + 100), threshRadius, IM_COL32(0, 0, 0, 255), 32);
	// Draw frame and cross lines.
	drawListR->AddRect(posR, ImVec2(posR.x + 200, posR.y + 200), overflow ? IM_COL32(255,0,0, 255) : whiteColor);
	drawListR->AddLine(ImVec2(posR.x + 100, posR.y), ImVec2(posR.x + 100, posR.y+200), whiteColor);
	drawListR->AddLine(ImVec2(posR.x, posR.y + 100), ImVec2(posR.x + 200, posR.y+100), whiteColor);
	// Draw threshold and unit radius circles.
	drawListR->AddCircle(ImVec2(posR.x + 100, posR.y + 100), threshRadius, IM_COL32(0, 255, 0, 255), 32);
	drawListR->AddCircle(ImVec2(posR.x + 100, posR.y + 100), 100, whiteColor, 32);
	// Current axis position.
	drawListR->AddCircleFilled(ImVec2(posR.x + magRX * 100 + 100, posR.y + magRY * 100 + 100), 10, whiteColor);
}
Example #2
0
bool ImGui::Image(cocos2d::Texture2D* texture, const cocos2d::Rect cropSize, const ImVec2& displaySize, int borderSize)
{
	ImGuiWindow* window = GetCurrentWindow();
	if (window->SkipItems)
		return false;
	const ImVec4& tint_col = ImVec4(1, 1, 1, 1);
	const ImVec4& border_col = ImVec4(0.95f, 0.12f, 0.04f, 1);
	
	GLuint textureID = texture->getName();
	ImRect bb(window->DC.CursorPos, window->DC.CursorPos + displaySize);
	if (border_col.w > 0.0f)
		bb.Max += ImVec2(2, 2);
	ItemSize(bb);
	if (!ItemAdd(bb, NULL))
		return false;

	ImGui::PushID((void *)textureID);
	const ImGuiID id = window->GetID("#image");
	ImGui::PopID();

	bool hovered, held;
	bool pressed = ButtonBehavior(bb, id, &hovered, &held);

	float focus_x = cropSize.origin.x;
	float focus_y = cropSize.origin.y;
	ImVec2 uv0 = ImVec2((focus_x) / texture->getContentSize().width, (focus_y) / texture->getContentSize().height);
	ImVec2 uv1 = ImVec2((focus_x + cropSize.size.width) / texture->getContentSize().width, (focus_y + cropSize.size.height) / texture->getContentSize().height);

	if (border_col.w > 0.0f)
	{
		window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(border_col));
		window->DrawList->AddImage((ImTextureID)textureID, bb.Min + ImVec2(borderSize, borderSize), bb.Max - ImVec2(borderSize, borderSize), uv0, uv1, GetColorU32(tint_col));
	}
	else
	{
		window->DrawList->AddRectFilled(bb.Min, bb.Max, GetColorU32(border_col));
		window->DrawList->AddImage((ImTextureID)textureID, bb.Min + ImVec2(borderSize, borderSize), bb.Max - ImVec2(borderSize, borderSize), uv0, uv1, GetColorU32(tint_col));
	}

	return pressed;
}
Example #3
0
void ImGui_ImplSdl_NewFrame(SDL_Window *window)
{
    if (!g_FontTexture)
        ImGui_ImplSdl_CreateDeviceObjects();

    ImGuiIO& io = ImGui::GetIO();

    // Setup display size (every frame to accommodate for window resizing)
    int w, h;
	SDL_GetWindowSize(window, &w, &h);
    io.DisplaySize = ImVec2((float)w, (float)h);

    // Setup time step
	Uint32	time = SDL_GetTicks();
	double current_time = time / 1000.0;
    io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
    g_Time = current_time;

    // Setup inputs
    // (we already got mouse wheel, keyboard keys & characters from glfw callbacks polled in glfwPollEvents())
    int mx, my;
    Uint32 mouseMask = SDL_GetMouseState(&mx, &my);
    if (SDL_GetWindowFlags(window) & SDL_WINDOW_MOUSE_FOCUS)
    	io.MousePos = ImVec2((float)mx, (float)my);   // Mouse position, in pixels (set to -1,-1 if no mouse / on another screen, etc.)
    else
    	io.MousePos = ImVec2(-1,-1);
   
	io.MouseDown[0] = g_MousePressed[0] || (mouseMask & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;		// If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
	io.MouseDown[1] = g_MousePressed[1] || (mouseMask & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
	io.MouseDown[2] = g_MousePressed[2] || (mouseMask & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
    g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;

    io.MouseWheel = g_MouseWheel;
    g_MouseWheel = 0.0f;

    // Hide OS mouse cursor if ImGui is drawing it
    SDL_ShowCursor(io.MouseDrawCursor ? 0 : 1);

    // Start the frame
    ImGui::NewFrame();
}
void CEditorLights::RenderInMenu()
{
	ImGui::SetNextWindowSize(ImVec2(512, 512), ImGuiSetCond_FirstUseEver);
	if (m_activated_editor) {
		ImGui::Begin("LightsEditor", &m_activated_editor);
		RenderGeneral();
		RenderNewLight();
		RenderAllLights();
		RenderMultiEdit();
		ImGui::End();
	}
}
Example #5
0
void AssetBrowser::onToolbar()
{
	auto pos = ImGui::GetCursorScreenPos();
	if (ImGui::BeginToolbar("asset_browser_toolbar", pos, ImVec2(0, 24)))
	{
		if (m_history_index > 0) m_back_action->toolbarButton();
		if (m_history_index < m_history.size() - 1) m_forward_action->toolbarButton();
		m_auto_reload_action->toolbarButton();
		m_refresh_action->toolbarButton();
	}
	ImGui::EndToolbar();
}
Example #6
0
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
{
    ImGuiIO& io = ImGui::GetIO();

    // Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
    if (io.WantSetMousePos)
        SDL_WarpMouseInWindow(g_Window, (int)io.MousePos.x, (int)io.MousePos.y);
    else
        io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);

    int mx, my;
    Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
    io.MouseDown[0] = g_MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0;  // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
    io.MouseDown[1] = g_MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
    io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
    g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;

#if SDL_HAS_CAPTURE_AND_GLOBAL_MOUSE && !defined(__EMSCRIPTEN__) && !defined(__ANDROID__) && !(defined(__APPLE__) && TARGET_OS_IOS)
    SDL_Window* focused_window = SDL_GetKeyboardFocus();
    if (g_Window == focused_window)
    {
        // SDL_GetMouseState() gives mouse position seemingly based on the last window entered/focused(?)
        // The creation of a new windows at runtime and SDL_CaptureMouse both seems to severely mess up with that, so we retrieve that position globally.
        int wx, wy;
        SDL_GetWindowPosition(focused_window, &wx, &wy);
        SDL_GetGlobalMouseState(&mx, &my);
        mx -= wx;
        my -= wy;
        io.MousePos = ImVec2((float)mx, (float)my);
    }

    // SDL_CaptureMouse() let the OS know e.g. that our imgui drag outside the SDL window boundaries shouldn't e.g. trigger the OS window resize cursor.
    // The function is only supported from SDL 2.0.4 (released Jan 2016)
    bool any_mouse_button_down = ImGui::IsAnyMouseDown();
    SDL_CaptureMouse(any_mouse_button_down ? SDL_TRUE : SDL_FALSE);
#else
    if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
        io.MousePos = ImVec2((float)mx, (float)my);
#endif
}
		void NotificationOSDLayer::Draw(RenderWindowOSD* OSD, ImGuiDX9* GUI)
		{
			if (Tick() == false)
				return;

			ImGui::SetNextWindowPos(ImVec2(10, *TESRenderWindow::ScreenHeight - 150));
			ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0);
			ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
			ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
			ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
			if (!ImGui::Begin("Notification Overlay", nullptr,
							  ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize |
							  ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |
							  ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoInputs))
			{
				ImGui::End();
				ImGui::PopStyleVar(4);
				return;
			}

			const Notification& Current = GetNextNotification();
			float RemainingTime = Current.GetRemainingTicks() / (float)Current.Duration;

			ImGui::Text("  %s  ", Current.Message.c_str());
			ImGui::Dummy(ImVec2(10, 15));
			ImGui::ProgressBar(RemainingTime, ImVec2(-1, 1));
			ImGui::End();
			ImGui::PopStyleVar(4);
		}
Example #8
0
	void beginFrame(int32_t _mx, int32_t _my, uint8_t _button, int32_t _scroll, int _width, int _height, char _inputChar, uint8_t _viewId)
	{
		m_viewId = _viewId;

		ImGuiIO& io = ImGui::GetIO();
		if (_inputChar < 0x7f)
		{
			io.AddInputCharacter(_inputChar); // ASCII or GTFO! :(
		}

		io.DisplaySize = ImVec2( (float)_width, (float)_height);

		const int64_t now = bx::getHPCounter();
		const int64_t frameTime = now - m_last;
		m_last = now;
		const double freq = double(bx::getHPFrequency() );
		io.DeltaTime = float(frameTime/freq);

		io.MousePos = ImVec2( (float)_mx, (float)_my);
		io.MouseDown[0] = 0 != (_button & IMGUI_MBUT_LEFT);
		io.MouseDown[1] = 0 != (_button & IMGUI_MBUT_RIGHT);
		io.MouseDown[2] = 0 != (_button & IMGUI_MBUT_MIDDLE);
		io.MouseWheel = (float)(_scroll - m_lastScroll);
		m_lastScroll = _scroll;

#if defined(SCI_NAMESPACE)
		uint8_t modifiers = inputGetModifiersState();
		io.KeyShift = 0 != (modifiers & (entry::Modifier::LeftShift | entry::Modifier::RightShift) );
		io.KeyCtrl  = 0 != (modifiers & (entry::Modifier::LeftCtrl  | entry::Modifier::RightCtrl ) );
		io.KeyAlt   = 0 != (modifiers & (entry::Modifier::LeftAlt   | entry::Modifier::RightAlt  ) );
		for (int32_t ii = 0; ii < (int32_t)entry::Key::Count; ++ii)
		{
			io.KeysDown[ii] = inputGetKeyState(entry::Key::Enum(ii) );
		}
#endif // defined(SCI_NAMESPACE)

		ImGui::NewFrame();
		ImGuizmo::BeginFrame();
		ImGui::PushStyleVar(ImGuiStyleVar_ViewId, (float)_viewId);
	}
void GUISelectAdapterWindow::draw(const sf::Vector2u& windowSize) {

    if (!this->isEnabled) return;

    int winFlags = ImGuiWindowFlags_NoMove |
                   ImGuiWindowFlags_NoResize |
                   ImGuiWindowFlags_NoCollapse |
                   ImGuiWindowFlags_NoTitleBar |
                   ImGuiWindowFlags_AlwaysAutoResize;

    // temp bool for state etc

    ImGui::Begin("Select Network Adapter Device", &this->isEnabled, winFlags);

    ImGui::Text("Select Network Adapter Device");

    ImGui::Spacing();
    ImGui::Separator();
    ImGui::Spacing();

    std::vector<AdapterDevice>& adapters = *state.adapters;

    for (unsigned i = 0; i < adapters.size(); i++) {

        ImGui::RadioButton(
            adapters[i].name.c_str(),
            state.selectedAdapter,
            i );

        ImGui::Text(adapters[i].description.c_str());

        ImGui::Spacing();
    }

    ImGui::Separator();
    ImGui::Spacing();
    ImGui::Spacing();

    ImGui::SameLine(ImGui::GetWindowContentRegionMax().x - 55);
    if (ImGui::Button("Select")) {

        Event aEvent(this, EventType::AdapterChosen, *state.selectedAdapter);
        adapterChosenDispatcher.fire(aEvent);
    }

    // center the window
    ImVec2 thisSize = ImGui::GetWindowSize();
    ImGui::SetWindowPos(ImVec2(windowSize.x / 2 - thisSize.x / 2,
                               windowSize.y / 2 - thisSize.y / 2));

    ImGui::End();
}
Example #10
0
bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
{
    g_Display = display;

    // Setup back-end capabilities flags
    ImGuiIO& io = ImGui::GetIO();
    io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;       // We can honor GetMouseCursor() values (optional)
    io.BackendPlatformName = io.BackendRendererName = "imgui_impl_allegro5";

    // Create custom vertex declaration.
    // Unfortunately Allegro doesn't support 32-bits packed colors so we have to convert them to 4 floats.
    // We still use a custom declaration to use 'ALLEGRO_PRIM_TEX_COORD' instead of 'ALLEGRO_PRIM_TEX_COORD_PIXEL' else we can't do a reliable conversion.
    ALLEGRO_VERTEX_ELEMENT elems[] =
    {
        { ALLEGRO_PRIM_POSITION, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, pos) },
        { ALLEGRO_PRIM_TEX_COORD, ALLEGRO_PRIM_FLOAT_2, IM_OFFSETOF(ImDrawVertAllegro, uv) },
        { ALLEGRO_PRIM_COLOR_ATTR, 0, IM_OFFSETOF(ImDrawVertAllegro, col) },
        { 0, 0, 0 }
    };
    g_VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro));

    io.KeyMap[ImGuiKey_Tab] = ALLEGRO_KEY_TAB;
    io.KeyMap[ImGuiKey_LeftArrow] = ALLEGRO_KEY_LEFT;
    io.KeyMap[ImGuiKey_RightArrow] = ALLEGRO_KEY_RIGHT;
    io.KeyMap[ImGuiKey_UpArrow] = ALLEGRO_KEY_UP;
    io.KeyMap[ImGuiKey_DownArrow] = ALLEGRO_KEY_DOWN;
    io.KeyMap[ImGuiKey_PageUp] = ALLEGRO_KEY_PGUP;
    io.KeyMap[ImGuiKey_PageDown] = ALLEGRO_KEY_PGDN;
    io.KeyMap[ImGuiKey_Home] = ALLEGRO_KEY_HOME;
    io.KeyMap[ImGuiKey_End] = ALLEGRO_KEY_END;
    io.KeyMap[ImGuiKey_Insert] = ALLEGRO_KEY_INSERT;
    io.KeyMap[ImGuiKey_Delete] = ALLEGRO_KEY_DELETE;
    io.KeyMap[ImGuiKey_Backspace] = ALLEGRO_KEY_BACKSPACE;
    io.KeyMap[ImGuiKey_Space] = ALLEGRO_KEY_SPACE;
    io.KeyMap[ImGuiKey_Enter] = ALLEGRO_KEY_ENTER;
    io.KeyMap[ImGuiKey_Escape] = ALLEGRO_KEY_ESCAPE;
    io.KeyMap[ImGuiKey_A] = ALLEGRO_KEY_A;
    io.KeyMap[ImGuiKey_C] = ALLEGRO_KEY_C;
    io.KeyMap[ImGuiKey_V] = ALLEGRO_KEY_V;
    io.KeyMap[ImGuiKey_X] = ALLEGRO_KEY_X;
    io.KeyMap[ImGuiKey_Y] = ALLEGRO_KEY_Y;
    io.KeyMap[ImGuiKey_Z] = ALLEGRO_KEY_Z;
    io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);

#if ALLEGRO_HAS_CLIPBOARD
    io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
    io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;
    io.ClipboardUserData = NULL;
#endif

    return true;
}
Example #11
0
void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
{
    ImGuiIO& io = ImGui::GetIO();
    io.MousePos = ImVec2((float)x, (float)y);
    int button = -1;
    if (glut_button == GLUT_LEFT_BUTTON) button = 0;
    if (glut_button == GLUT_RIGHT_BUTTON) button = 1;
    if (glut_button == GLUT_MIDDLE_BUTTON) button = 2;
    if (button != -1 && state == GLUT_DOWN)
        io.MouseDown[button] = true;
    if (button != -1 && state == GLUT_UP)
        io.MouseDown[button] = false;
}
Example #12
0
void RoR::DrawImGuiSpinner(float& counter, const ImVec2 size, const float spacing, const float step_sec)
{
    // Hardcoded to 4 segments, counter is reset after full round (4 steps)
    // --------------------------------------------------------------------

    const ImU32 COLORS[] = { ImColor(255,255,255,255), ImColor(210,210,210,255), ImColor(120,120,120,255), ImColor(60,60,60,255) };

    // Update counter, determine coloring
    counter += ImGui::GetIO().DeltaTime;
    int color_start = 0; // Index to GUI_SPINNER_COLORS array for the top middle segment (segment 0)
    while (counter > (step_sec*4.f))
    {
        counter -= (step_sec*4.f);
    }

    if (counter > (step_sec*3.f))
    {
        color_start = 3;
    }
    else if (counter > (step_sec*2.f))
    {
        color_start = 2;
    }
    else if (counter > (step_sec))
    {
        color_start = 1;
    }

    // Draw segments
    ImDrawList* draw_list = ImGui::GetWindowDrawList();
    const ImVec2 pos = ImGui::GetCursorScreenPos();
    const float left = pos.x;
    const float top = pos.y;
    const float right = pos.x + size.x;
    const float bottom = pos.y + size.y;
    const float mid_x = pos.x + (size.x / 2.f);
    const float mid_y = pos.y + (size.y / 2.f);

    // NOTE: Enter vertices in clockwise order, otherwise anti-aliasing doesn't work and polygon is rasterized larger! -- Observed under OpenGL2 / OGRE 1.9

    // Top triangle, vertices: mid, left, right
    draw_list->AddTriangleFilled(ImVec2(mid_x, mid_y-spacing),   ImVec2(left + spacing, top),     ImVec2(right - spacing, top),     COLORS[color_start]);
    // Right triangle, vertices: mid, top, bottom
    draw_list->AddTriangleFilled(ImVec2(mid_x+spacing, mid_y),   ImVec2(right, top + spacing),    ImVec2(right, bottom - spacing),  COLORS[(color_start+3)%4]);
    // Bottom triangle, vertices: mid, right, left
    draw_list->AddTriangleFilled(ImVec2(mid_x, mid_y+spacing),   ImVec2(right - spacing, bottom), ImVec2(left + spacing, bottom),   COLORS[(color_start+2)%4]);
    // Left triangle, vertices: mid, bottom, top
    draw_list->AddTriangleFilled(ImVec2(mid_x-spacing, mid_y),   ImVec2(left, bottom - spacing),  ImVec2(left, top + spacing),      COLORS[(color_start+1)%4]);
}
Example #13
0
void ImGui_ImplNyan_NewFrame(void)
{
    unsigned int winx, winy;
    int mx, my;
    ImGuiIO &io = ImGui::GetIO();
    wchar_t *inputstr;

    winx = nvGetStatusi(NV_STATUS_WINX);
    winy = nvGetStatusi(NV_STATUS_WINY);

    mx = nvGetStatusi(NV_STATUS_WINMX);
    my = nvGetStatusi(NV_STATUS_WINMY);

    inputstr = nvGetStatusw(NV_STATUS_WINTEXTINPUTBUF);

    io.DisplaySize = ImVec2((float)winx, (float)winy);
    io.DeltaTime = (float)nGetspf();
    io.MousePos = ImVec2((float)mx, (float)my);
    io.MouseDown[0] = (nvGetStatusi(NV_STATUS_WINMBL)==1)?true:false;
    io.MouseDown[1] = (nvGetStatusi(NV_STATUS_WINMBR)==1)?true:false;
    io.MouseDown[2] = (nvGetStatusi(NV_STATUS_WINMBM)==1)?true:false;

    for(int i = 0; i < 256; i++)
        io.KeysDown[i] = (nvGetKey(i) == 1)?true:false;

    io.KeyCtrl = io.KeysDown[NK_CONTROL];
    io.KeyShift = io.KeysDown[NK_SHIFT];
    io.KeyAlt = io.KeysDown[NK_ALT];
    io.KeySuper = io.KeysDown[NK_LWIN] || io.KeysDown[NK_RWIN];

    while(*inputstr) {
        if(*inputstr > 0 && *inputstr < 0x10000)
            io.AddInputCharacter(*inputstr);

        inputstr++;
    }

    ImGui::NewFrame();
}
Example #14
0
extern "C" void dc_debug(void)
{
	static DebugMemoryState memory_ctx_sat;

	ImGui::SetNextWindowPos(ImVec2(0.0f, 0.0f), ImGuiSetCond_FirstUseEver);
	ImGui::Begin("Dreamcast", NULL, ImGuiWindowFlags_NoMove);

	if(ImGui::CollapsingHeader("Memory", NULL, true, true)) {
		static DebugMemoryState memory_state;
		debug_memory("DC RAM", &memory_state, dc_ram, sizeof(dc_ram));
	}
	ImGui::End();
}
Example #15
0
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
{
    ImGuiIO& io = ImGui::GetIO();
    IM_ASSERT(io.Fonts->IsBuilt());     // Font atlas needs to be built, call renderer _NewFrame() function e.g. ImGui_ImplOpenGL3_NewFrame() 

    // Setup display size (every frame to accommodate for window resizing)
    int w, h;
    int display_w, display_h;
    SDL_GetWindowSize(window, &w, &h);
    SDL_GL_GetDrawableSize(window, &display_w, &display_h);
    io.DisplaySize = ImVec2((float)w, (float)h);
    io.DisplayFramebufferScale = ImVec2(w > 0 ? ((float)display_w / w) : 0, h > 0 ? ((float)display_h / h) : 0);

    // Setup time step (we don't use SDL_GetTicks() because it is using millisecond resolution)
    static Uint64 frequency = SDL_GetPerformanceFrequency();
    Uint64 current_time = SDL_GetPerformanceCounter();
    io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
    g_Time = current_time;

    ImGui_ImplSDL2_UpdateMousePosAndButtons();
    ImGui_ImplSDL2_UpdateMouseCursor();
}
Example #16
0
void DialogControlsModels::contextModelDelete() {
//    ImGui::SetNextWindowPos(ImGui::GetIO().MouseClickedPos[0]);

    ImGui::OpenPopup("Delete?");

    ImGui::BeginPopupModal("Delete?", NULL, ImGuiWindowFlags_AlwaysAutoResize);

    ImGui::Text("Are you sure?\n");
    //ImGui::Text("(%s)", (*meshModelFaces)[static_cast<size_t>(this->selectedObject)]->meshModel.ModelTitle.c_str());

    if (ImGui::Button("OK", ImVec2(ImGui::GetContentRegionAvailWidth() * 0.5f,0))) {
        this->funcDeleteModel(this->selectedObject);
        ImGui::CloseCurrentPopup();
        this->cmenu_deleteYn = false;
    }
    ImGui::SameLine();
    if (ImGui::Button("No", ImVec2(ImGui::GetContentRegionAvailWidth(),0))) {
        ImGui::CloseCurrentPopup();
        this->cmenu_deleteYn = false;
    }

    ImGui::EndPopup();
}
Example #17
0
void game_system::on_resize_viewport(const uint2& size)
{
	if (size.x == 0 || size.y == 0) {
		viewport_is_visible_ = false;
		return;
	}

	ImGui::GetIO().DisplaySize = ImVec2(float(size.x), float(size.y));

	viewport_is_visible_ = true;
	frame_.projection_matrix = math::perspective_matrix_directx(game_system::projection_fov, 
		aspect_ratio(size), game_system::projection_near, game_system::projection_far);
	render_system_.resize_viewport(size);
}
Example #18
0
void
updateInput()
{
   auto &io = ImGui::GetIO();
   io.MousePos = ImVec2(sMousePosX, sMousePosY);

   for (int i = 0; i < 3; i++) {
      io.MouseDown[i] = sMouseClicked[i] || sMousePressed[i];
      sMouseClicked[i] = false;
   }

   io.MouseWheel = sMouseWheel;
   sMouseWheel = 0.0;
}
Example #19
0
extern "C" void _VenomModuleLoad(GameMemory *memory) {
#ifdef VENOM_HOTLOAD
#define _(returnType, name, ...) name = memory->engineAPI.name;
EngineAPIList
#undef _
#define _(signature, name) name = memory->engineAPI.name;
#include "opengl_procedures.h"
#undef _ 
#endif//VENOM_HOTLOAD
	
	ImGuiIO& io = ImGui::GetIO();
  
	SystemInfo *system = &memory->systemInfo;
  io.KeyMap[ImGuiKey_Enter] = KEYCODE_ENTER;
	io.KeyMap[ImGuiKey_Escape] = KEYCODE_ESCAPE;
	io.KeyMap[ImGuiKey_Tab] = KEYCODE_TAB;
	io.KeyMap[ImGuiKey_Backspace] = KEYCODE_BACKSPACE;
	io.KeyMap[ImGuiKey_LeftArrow] = KEYCODE_LEFT;
	io.KeyMap[ImGuiKey_RightArrow] = KEYCODE_RIGHT;
	io.KeyMap[ImGuiKey_DownArrow] = KEYCODE_DOWN;
	io.KeyMap[ImGuiKey_UpArrow] = KEYCODE_UP;

  io.KeyMap[ImGuiKey_A] = KEYCODE_A;
  io.KeyMap[ImGuiKey_C] = KEYCODE_C;
  io.KeyMap[ImGuiKey_V] = KEYCODE_V;
  io.KeyMap[ImGuiKey_X] = KEYCODE_X;
  io.KeyMap[ImGuiKey_Y] = KEYCODE_Y; 
  io.KeyMap[ImGuiKey_Z] = KEYCODE_Z; 
  memory->keyEventCallback = HackVenomKeyEventCallback;

	io.RenderDrawListsFn = RenderImGuiDrawList;
	io.DisplaySize = ImVec2(system->screenWidth, system->screenHeight);
	io.UserData = memory;

  U8* pixels;
  int width, height, components;
  //io.Fonts->AddFontFromFileTTF("/usr/share/fonts/TTF/DejaVuSans.ttf", 14);
  io.Fonts->GetTexDataAsRGBA32(&pixels, &width, &height, &components);
	io.Fonts->TexID = (void *)(size_t)memory->renderState.imguiFontTexture;

#if 0
  { //Reload the MaterialList Why the hell are we doing this?
    MaterialAssetList* list = &memory->assets.materialAssetList;
    LoadMaterialList(list);
  }
#endif

  InitalizeEditor(&memory->editor);
  VenomModuleLoad(memory);
}
Example #20
0
void UpdateImGui()
{
	ImGuiIO& io = ImGui::GetIO();

	// Setup resolution (every frame to accommodate for window resizing)
	io.DisplaySize = ImVec2((float)800, (float)400); 

	// Setup time step
	static double time = 0.0f;
	const double current_time = SDL_GetTicks() / 1000.0;
	if (current_time == time)
		return;
	io.DeltaTime = (float)(current_time - time);
	time = current_time;

	io.MousePos = ImVec2((float)gUIState.mousex, (float)gUIState.mousey);
	io.MouseDown[0] = gUIState.mousedown != 0;
	io.MouseDown[1] = 0;

	if (gUIState.scroll)
	{
		io.MouseWheel += (float)gUIState.scroll * 0.5f;
		gUIState.scroll = 0;
	}

	if (gUIState.textinput[0])
	{
		io.AddInputCharactersUTF8(gUIState.textinput);
		gUIState.textinput[0] = 0;
	}

	for (int n = 0; n < 256; n++)
		io.KeysDown[n] = gPressed[n] != 0;
    io.KeyShift = ((SDL_GetModState() & KMOD_SHIFT) != 0);
    io.KeyCtrl = ((SDL_GetModState() & KMOD_CTRL) != 0);
    io.KeyAlt = ((SDL_GetModState() & KMOD_ALT) != 0);
}
Example #21
0
bool GameLoopSystem::startup() {
  RESOLVE_DEPENDENCY(m_settings);
  RESOLVE_DEPENDENCY(m_events);
  RESOLVE_DEPENDENCY(m_window);
  RESOLVE_DEPENDENCY(m_renderer);
  RESOLVE_DEPENDENCY(m_audio);

  m_targetFrameRate = m_settings->getTargetFps();

  m_events->subscribe<"DrawUI"_sh>([this] {
    static bool opened = true;
    ImGui::SetNextWindowPos(ImVec2(10, 10));
    if (!ImGui::Begin("Frame Statistics", &opened, ImVec2(275, 0), 0.3f, ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings)) {
      ImGui::End();
      return;
    }

    static auto prev = SDL_GetPerformanceCounter();
    auto now = SDL_GetPerformanceCounter();

    static int frameTimeIndex = 0;
    double totalFrameTime = (double)((now - prev)*1000) / SDL_GetPerformanceFrequency();
    prev = now;

    m_frameTimeHistory[frameTimeIndex] = (float)totalFrameTime;
    frameTimeIndex = (frameTimeIndex + 1) % m_frameTimeHistory.size();
    
    ImGui::Text("FPS:          %d", (int)(1000.0f/(totalFrameTime)));
    ImGui::Separator();
    ImGui::PlotHistogram("", m_frameTimeHistory.data(), m_frameTimeHistory.size(), 0, NULL, 0, 100, glm::vec2(250, 100));
    ImGui::Separator();
    ImGui::Text("Mouse Position: (%.1f,%.1f)", ImGui::GetIO().MousePos.x, ImGui::GetIO().MousePos.y);
    ImGui::End();
  });

  return true;
}
Example #22
0
MainWindow::MainWindow() {
    // Setup window
    glfwSetErrorCallback(on_error);
    if (!glfwInit())
        exit(1);

    glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
    glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
    glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);

    GLFWwindow* window = glfwCreateWindow(1280, 720, "xds", NULL, NULL);

	if (window)
	{

		glfwMakeContextCurrent(window);
		gl3wInit();

		ImGui_ImplGlfwGL3_Init(window, true);


		while (!glfwWindowShouldClose(window))
		{
			ImGuiIO& io = ImGui::GetIO();
			glfwPollEvents();
			ImGui_ImplGlfwGL3_NewFrame();

			ImGui::SetNextWindowSize(ImVec2(400, 100), ImGuiSetCond_FirstUseEver);
			ImGui::Begin("Test Window");
			ImGui::Text("TODO: Move this to new thread so xds can run in the background.");
			ImGui::Text("Close the window to continue xds execution.");
			ImGui::End();

			// Rendering
			glViewport(0, 0, (int)io.DisplaySize.x, (int)io.DisplaySize.y);
			ImVec4 clear_color = ImColor(114, 144, 154);
			glClearColor(clear_color.x, clear_color.y, clear_color.z, clear_color.w);
			glClear(GL_COLOR_BUFFER_BIT);
			ImGui::Render();

			glfwSwapBuffers(window);
		}

		// Cleanup
		ImGui_ImplGlfwGL3_Shutdown();
		glfwTerminate();

	}
}
Example #23
0
void UI::KeyBindButton(ButtonCode_t* key)
{
	const char* text = inputSystem->ButtonCodeToString(*key);

	if (SetKeyCodeState::shouldListen && SetKeyCodeState::keyOutput == key)
		text = "-- press a key --";
	else
		text = Util::ToUpper(std::string(text)).c_str();

	if (ImGui::Button(text, ImVec2(-1, 0)))
	{
		SetKeyCodeState::shouldListen = true;
		SetKeyCodeState::keyOutput = key;
	}
}
Example #24
0
void MeshCollider::Inspector() {
	ImGui::Begin("Inspector");
	ImGui::BeginChild("Component", ImVec2(0, 0), false);
	if (ImGui::TreeNode("MeshCollider")) {
		// Settings go here
		ImGui::Checkbox("Enabled", &enabled);
		ImGui::Checkbox("isTrigger", &isTrigger);
		ImGui::DragFloat3("Center", (float*)&bounds.center);
		ImGui::DragFloat3("Size", (float*)&bounds.size);
		
		ImGui::TreePop();
	}
	ImGui::EndChild();
	ImGui::End();
}
Example #25
0
	void DebugWidget::DrawUI ()
	{
		ImGui::SetNextWindowPos(ImVec2(0, 0), ImGuiSetCond_Always);

		ImVec2 const & display = ImGui::GetIO().DisplaySize;
		ImGui::SetNextWindowSize(display, ImGuiSetCond_Always);

		char name[256];
		codecvt_utf16_utf8(GetNameW(), name, 256);
		ImGui::Begin(name, &m_config.m_show, ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize);

		ImGui::Text("%.1f ms", 1000.0f / ImGui::GetIO().Framerate);
		ImGui::Text("%.1f fps", ImGui::GetIO().Framerate);

		ImGui::End();
	}
void ShaderEditor::onGUILeftColumn()
{
	ImGui::BeginChild("left_col", ImVec2(120, 0));
	ImGui::PushItemWidth(120);

	ImGui::Separator();
	ImGui::Text("Textures");
	ImGui::Separator();
	for (int i = 0; i < Lumix::lengthOf(m_textures); ++i)
	{
		ImGui::InputText(StringBuilder<10>("###tex", i), m_textures[i], sizeof(m_textures[i]));
	}

	ImGui::PopItemWidth();
	ImGui::EndChild();
}
Example #27
0
void OgreImGui::NewFrame(float deltaTime, float displayWidth, float displayHeight, bool ctrl, bool alt, bool shift)
{
    ImGuiIO& io = ImGui::GetIO();
    io.DeltaTime = deltaTime;

     // Read keyboard modifiers inputs
    io.KeyCtrl = ctrl;
    io.KeyShift = shift;
    io.KeyAlt = alt;
    io.KeySuper = false;

    // Setup display size (every frame to accommodate for window resizing)
    io.DisplaySize = ImVec2(displayWidth, displayHeight);

    // Start the frame
    ImGui::NewFrame();
}
Example #28
0
void GUI_ImGui::popupRecentFileImportedDoesntExists() {
    ImGui::OpenPopup("Warning");
    ImGui::BeginPopupModal("Warning", NULL, ImGuiWindowFlags_AlwaysAutoResize);
    ImGui::Text("This file no longer exists!");
    if (ImGui::Button("OK", ImVec2(ImGui::GetContentRegionAvailWidth(),0))) {
        std::vector<FBEntity> recents;
        for (size_t i=0; i<this->recentFilesImported.size(); i++) {
            if (boost::filesystem::exists(this->recentFilesImported[i].path))
                recents.push_back(this->recentFilesImported[i]);
        }
        this->recentFilesImported = recents;
        Settings::Instance()->saveRecentFilesImported(this->recentFilesImported);
        this->showRecentFileImportedDoesntExists = false;
        ImGui::CloseCurrentPopup();
    }
    ImGui::EndPopup();
}
Example #29
0
void Update()
{
    ImGuiIO& io = ImGui::GetIO();
    io.DisplaySize = getDisplaySize();
    io.DeltaTime = s_deltaClock.restart().asSeconds(); // restart the clock and get delta

    // update mouse
    assert(s_window);
    sf::Vector2f mousePos = static_cast<sf::Vector2f>(sf::Mouse::getPosition(*s_window));
    io.MousePos = ImVec2(mousePos.x, mousePos.y);
    io.MouseDown[0] = s_mousePressed[0] || sf::Mouse::isButtonPressed(sf::Mouse::Left);
    io.MouseDown[1] = s_mousePressed[1] || sf::Mouse::isButtonPressed(sf::Mouse::Right);
    io.MouseDown[2] = s_mousePressed[2] || sf::Mouse::isButtonPressed(sf::Mouse::Middle);
    s_mousePressed[0] = s_mousePressed[1] = s_mousePressed[2] = false;

    ImGui::NewFrame();
}
Example #30
0
void OgreImGui::NewFrame(float deltaTime,const Ogre::Rect & windowRect, bool ctrl, bool alt, bool shift)
{
    mFrameEnded=false;
    ImGuiIO& io = ImGui::GetIO();
    io.DeltaTime = deltaTime;

     // Read keyboard modifiers inputs
    io.KeyCtrl = ctrl;
    io.KeyShift = shift;
    io.KeyAlt = alt;
    io.KeySuper = false;

    // Setup display size (every frame to accommodate for window resizing)
    io.DisplaySize = ImVec2((float)(windowRect.right - windowRect.left), (float)(windowRect.bottom - windowRect.top));

    // Start the frame
    ImGui::NewFrame();
}