TyomaVader / ImGuiNotify

A (very) simple notification wrapper for Dear ImGui
MIT License
89 stars 11 forks source link

Wont render outside not inside #16

Open GamebP opened 4 days ago

GamebP commented 4 days ago

I still have the same issue like last time from #7 . Maybe I need to change somere specific. Changing NOTIFY_RENDER_OUTSIDE_MAIN_WINDOW to true it will not show it outside But changing it to false will show in the menu

image

GamebP commented 4 days ago

image

GamebP commented 4 days ago

image

OlegSirenko commented 3 days ago

What branch of ImGui are you using? What backend is used for your app?

GamebP commented 2 days ago

Yesterday I changed to recent updated ImGui Docking.https://github.com/ocornut/imgui/commit/793773209bb0fdeb8ccb756052e770457193c9f2

TyomaVader commented 2 days ago

Could this be caused by an old DirectX version ?

GamebP commented 2 days ago

How to know witch one I am using?

GamebP commented 2 days ago

@TyomaVader I think you still have the viewing perms to my private project on my side. Maybe I don't know....

TyomaVader commented 2 days ago

@TyomaVader I think you still have the viewing perms to my private project on my side. Maybe I don't know....

You're using DirectX 9 right now, it's pretty outdated, try upgrading to 11 or 12 from the Dear ImGui examples and check if this solves the issue

GamebP commented 2 days ago

Isnt d3d11 gonna break my project?

TyomaVader commented 2 days ago

Isnt d3d11 gonna break my project?

I don't think you're using any DirectX 9 specific functions, so updating ImGui backend and main.cpp files should be enough

GamebP commented 2 days ago

I'll try later

GamebP commented 1 day ago

idk, image

OlegSirenko commented 16 hours ago

Maybe try other backend like SDL? It's also not clear what code are you using for showing notifications. Are you enabled docking flag of ImGui?

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;         // Enable Docking
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;       // Enable Multi-Viewport / Platform Windows
GamebP commented 13 hours ago

i am currently using d3d9

GamebP commented 13 hours ago

doing this in d3d9, will be same

io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

It show's a movable black imgui not the one i want to be moved from:

void gui::CreateHWindow(const char* windowName) noexcept
{
    windowClass.cbSize = sizeof(WNDCLASSEX);
    windowClass.style = CS_CLASSDC;
    windowClass.lpfnWndProc = WindowProcess;
    windowClass.cbClsExtra = 0;
    windowClass.cbWndExtra = 0;
    windowClass.hInstance = GetModuleHandleA(0);
    windowClass.hIcon = 0;
    windowClass.hCursor = 0;
    windowClass.hbrBackground = 0;
    windowClass.lpszMenuName = 0;
    windowClass.lpszClassName = "class001";
    windowClass.hIconSm = 0;

    RegisterClassEx(&windowClass);

    window = CreateWindowEx(
        0,
        "class001",
        windowName,
        WS_POPUP,
        100,
        100,
        WIDTH,
        HEIGHT,
        0,
        0,
        windowClass.hInstance,
        0
    );

    ShowWindow(window, SW_SHOWDEFAULT);
    UpdateWindow(window);
}

Here are some defines:

bool gui::CreateDevice() noexcept
{
    d3d = Direct3DCreate9(D3D_SDK_VERSION);

    if (!d3d)
        return false;

    ZeroMemory(&presentParameters, sizeof(presentParameters));

    presentParameters.Windowed = TRUE;
    presentParameters.SwapEffect = D3DSWAPEFFECT_DISCARD;
    presentParameters.BackBufferFormat = D3DFMT_UNKNOWN;
    presentParameters.EnableAutoDepthStencil = TRUE;
    presentParameters.AutoDepthStencilFormat = D3DFMT_D16;
    presentParameters.PresentationInterval = D3DPRESENT_INTERVAL_ONE;

    if (d3d->CreateDevice(
        D3DADAPTER_DEFAULT,
        D3DDEVTYPE_HAL,
        window,
        D3DCREATE_HARDWARE_VERTEXPROCESSING,
        &presentParameters,
        &device) < 0)
        return false;

    return true;
}
void gui::CreateImGui() noexcept
{
    IMGUI_CHECKVERSION();
    ImGui::CreateContext();
    ImGuiIO& io = ImGui::GetIO();

    // Enable multi-viewport support
    io.ConfigFlags |= ImGuiConfigFlags_DockingEnable;
    io.ConfigFlags |= ImGuiConfigFlags_ViewportsEnable;

// ...
static const ImWchar icons_Ranges[] = { ICON_MIN_FA, ICON_MAX_FA, 0 }; // Icons
static ImWchar emoji_ranges[] =     { 0x1, 0x1FFFF, 0 }; // Emojis

cfg.OversampleH = cfg.OversampleV = 1;
cfg.MergeMode = true;
cfg.PixelSnapH = true;
cfg.GlyphMinAdvanceX = iconFontSize;
cfg.FontBuilderFlags |= ImGuiFreeTypeBuilderFlags_LoadColor;

io.Fonts->AddFontFromFileTTF("Resources\\Fonts\\Emoji.ttf", 18.0f, &cfg, emoji_ranges); // Emojis 
io.Fonts->AddFontFromFileTTF(FONT_ICON_FILE_NAME_FAS, iconFontSize, &cfg, icons_Ranges); // Icons
io.Fonts->Build();
// ...
    ImGui_ImplDX9_Init(device);
#pragma once
#include <d3d9.h>

namespace gui
{
    constexpr int WIDTH = 500;
    constexpr int HEIGHT = 300;

    // when this changes, exit threads and close menu :)
    inline bool isRunning = true;

    // winapi window vars
    inline HWND window = nullptr;
    inline WNDCLASSEX windowClass = { };

    // points for window movement
    inline POINTS position = { };

    // direct x state vars
    inline PDIRECT3D9 d3d = nullptr;
    inline LPDIRECT3DDEVICE9 device = nullptr;
    inline D3DPRESENT_PARAMETERS presentParameters = { };

    // Handle window creation & destruction
    void CreateHWindow(const char* windowName) noexcept;
    void DestroyHWindow() noexcept;

    // Handle device creation & destruction
    bool CreateDevice() noexcept;
    void ResetDevice() noexcept;
    void DestroyDevice() noexcept;

    // Handle ImGui creation & destruction
    void CreateImGui() noexcept;
    void DestroyImGui() noexcept;

    // Begin and end rendering
    void BeginRender() noexcept;
    void EndRender() noexcept;

    // Render GUI elements
    void Render() noexcept;
}
void gui::Render() noexcept
{
// Loads the imgui data
if (ImGui::Begin(
    TitleName_Show.c_str(),
    &isRunning,
    ImGuiWindowFlags_NoResize |
    ImGuiWindowFlags_NoSavedSettings |
    ImGuiWindowFlags_NoCollapse |
    ImGuiWindowFlags_NoMove
))
{
// ...
void gui::BeginRender() noexcept
{
    MSG message;
    while (PeekMessage(&message, 0, 0, 0, PM_REMOVE))
    {
        TranslateMessage(&message);
        DispatchMessage(&message);

        if (message.message == WM_QUIT)
        {
            isRunning = !isRunning;
            return;
        }
    }

    ImGui_ImplDX9_NewFrame();
    ImGui_ImplWin32_NewFrame();
    ImGui::NewFrame();
}
void gui::EndRender() noexcept
{
    ImGui::EndFrame(); // End ImGui frame

    // Clear the device and set render state
    device->SetRenderState(D3DRS_ZENABLE, FALSE);
    device->SetRenderState(D3DRS_ALPHABLENDENABLE, FALSE);
    device->SetRenderState(D3DRS_SCISSORTESTENABLE, FALSE);
    device->Clear(0, 0, D3DCLEAR_TARGET | D3DCLEAR_ZBUFFER, D3DCOLOR_RGBA(0, 0, 0, 255), 1.0f, 0);

    // Begin the scene
    if (device->BeginScene() >= 0)
    {
        ImGui::Render(); // Render ImGui data
        ImGui_ImplDX9_RenderDrawData(ImGui::GetDrawData()); // Draw ImGui elements
        device->EndScene(); // End the scene
    }

    // Present the back buffer to the screen
    const auto result = device->Present(0, 0, 0, 0);

    // Check for lost device
    if (result == D3DERR_DEVICELOST && device->TestCooperativeLevel() == D3DERR_DEVICENOTRESET)
        ResetDevice();
}
GamebP commented 13 hours ago

CreateHWindow creates and is only movable not the imgui menu image