/*
 * Dear ImGui for DPF, converted to VCV
 * Copyright (C) 2021-2022 Filipe Coelho <falktx@falktx.com>
 * Copyright (C) 2021 Jean Pierre Cimalando <jp-dev@inbox.ru>
 *
 * Permission to use, copy, modify, and/or distribute this software for any purpose with
 * or without fee is hereby granted, provided that the above copyright notice and this
 * permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD
 * TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN
 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
 * IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
 * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

#pragma once

#include "Widgets.hpp"
#include "DearImGui/imgui.h"

struct ImGuiWidget : OpenGlWidgetWithBrowserPreview {
    struct PrivateData;
    PrivateData* const imData;

    ImGuiWidget();
    ~ImGuiWidget() override;

    float getScaleFactor() const noexcept;

protected:
    void onContextCreate(const ContextCreateEvent& e) override;
    void onContextDestroy(const ContextDestroyEvent& e) override;
    void onHover(const HoverEvent& e) override;
    void onDragHover(const DragHoverEvent& e) override;
    void onDragLeave(const DragLeaveEvent& e) override;
    void onHoverScroll(const HoverScrollEvent& e) override;
    void onButton(const ButtonEvent& e) override;
    void onSelectKey(const SelectKeyEvent& e) override;
    void onSelectText(const SelectTextEvent& e) override;

    void setAsCurrentContext();
    void setUseMonospaceFont(bool useMonoFont = true);

    virtual void drawImGui()
    {
        ImGui::SetNextWindowPos(ImVec2(0, 0));
        ImGui::SetNextWindowSize(ImVec2(box.size.x, box.size.y));
        ImGui::ShowDemoWindow();
    }

private:
    void drawFramebuffer() override;
    void drawFramebufferForBrowserPreview() override;
    void drawFramebufferCommon(const Vec& fbSize, float scaleFactor);
};
