diff options
Diffstat (limited to 'gui')
-rw-r--r-- | gui/CMakeLists.txt | 8 | ||||
-rw-r--r-- | gui/fpgaviewwidget.cc | 54 | ||||
-rw-r--r-- | gui/fpgaviewwidget.h | 4 |
3 files changed, 62 insertions, 4 deletions
diff --git a/gui/CMakeLists.txt b/gui/CMakeLists.txt index 2e8e367e..a818640f 100644 --- a/gui/CMakeLists.txt +++ b/gui/CMakeLists.txt @@ -12,6 +12,12 @@ if (BUILD_PYTHON) ../3rdparty/python-console/modified/pyredirector.cc ../3rdparty/python-console/modified/pyinterpreter.cc + ../3rdparty/imgui/imgui_widgets.cpp + ../3rdparty/imgui/imgui_draw.cpp + ../3rdparty/imgui/imgui.cpp + ../3rdparty/imgui/imgui_demo.cpp + ../3rdparty/qtimgui/ImGuiRenderer.cpp + ../3rdparty/qtimgui/QtImGui.cpp ) endif() @@ -27,7 +33,7 @@ set(GUI_LIBRARY_FILES_${ufamily} Qt5::Widgets Qt5::OpenGL ${OPENGL_LIBRARIES} Qt add_library(gui_${family} STATIC ${GUI_SOURCE_FILES} ${PYTHON_CONSOLE_SRC} ${GUI_RESOURCE_FILES}) include(${family}/family.cmake) -target_include_directories(gui_${family} PRIVATE ../${family} ${family} ../3rdparty/QtPropertyBrowser/src) +target_include_directories(gui_${family} PRIVATE ../${family} ${family} ../3rdparty/QtPropertyBrowser/src ../3rdparty/imgui ../3rdparty/qtimgui/) if (BUILD_PYTHON) target_include_directories(gui_${family} PRIVATE ../3rdparty/python-console ../3rdparty/python-console/modified) endif() diff --git a/gui/fpgaviewwidget.cc b/gui/fpgaviewwidget.cc index 0d6319c5..a6552ec9 100644 --- a/gui/fpgaviewwidget.cc +++ b/gui/fpgaviewwidget.cc @@ -25,6 +25,9 @@ #include <QMouseEvent> #include <QWidget> +#include "QtImGui.h" +#include "imgui.h" + #include "fpgaviewwidget.h" #include "log.h" #include "mainwindow.h" @@ -57,7 +60,7 @@ FPGAViewWidget::FPGAViewWidget(QWidget *parent) auto fmt = format(); fmt.setMajorVersion(3); - fmt.setMinorVersion(1); + fmt.setMinorVersion(2); setFormat(fmt); fmt = format(); @@ -65,8 +68,8 @@ FPGAViewWidget::FPGAViewWidget(QWidget *parent) printf("Could not get OpenGL 3.0 context. Aborting.\n"); log_abort(); } - if (fmt.minorVersion() < 1) { - printf("Could not get OpenGL 3.1 context - trying anyway...\n "); + if (fmt.minorVersion() < 2) { + printf("Could not get OpenGL 3.2 context - trying anyway...\n "); } connect(&paintTimer_, SIGNAL(timeout()), this, SLOT(update())); @@ -103,6 +106,7 @@ void FPGAViewWidget::initializeGL() log_error("Could not compile shader.\n"); } initializeOpenGLFunctions(); + QtImGui::initialize(this); glClearColor(colors_.background.red() / 255, colors_.background.green() / 255, colors_.background.blue() / 255, 0.0); @@ -358,6 +362,18 @@ void FPGAViewWidget::paintGL() } } } + QtImGui::newFrame(); + QMutexLocker lock(&rendererArgsLock_); + if (!(rendererArgs_->hoveredDecal == DecalXY())) + { + ImGui::SetNextWindowPos(ImVec2(rendererArgs_->x, rendererArgs_->y)); + ImGui::BeginTooltip(); + ImGui::PushTextWrapPos(ImGui::GetFontSize() * 35.0f); + ImGui::TextUnformatted(rendererArgs_->hintText.c_str()); + ImGui::PopTextWrapPos(); + ImGui::EndTooltip(); + } + ImGui::Render(); } void FPGAViewWidget::pokeRenderer(void) { renderRunner_->poke(); } @@ -644,6 +660,9 @@ boost::optional<FPGAViewWidget::PickedElement> FPGAViewWidget::pickElement(float void FPGAViewWidget::mousePressEvent(QMouseEvent *event) { + ImGuiIO &io = ImGui::GetIO(); + if (io.WantCaptureMouse) return; + if (event->buttons() & Qt::RightButton || event->buttons() & Qt::MidButton) { lastDragPos_ = event->pos(); } @@ -677,6 +696,9 @@ void FPGAViewWidget::mousePressEvent(QMouseEvent *event) void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event) { + ImGuiIO &io = ImGui::GetIO(); + if (io.WantCaptureMouse) return; + if (event->buttons() & Qt::RightButton || event->buttons() & Qt::MidButton) { const int dx = event->x() - lastDragPos_.x(); const int dy = event->y() - lastDragPos_.y(); @@ -696,6 +718,7 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event) QMutexLocker locked(&rendererArgsLock_); rendererArgs_->hoveredDecal = DecalXY(); rendererArgs_->changed = true; + rendererArgs_->hintText = ""; pokeRenderer(); return; } @@ -706,6 +729,27 @@ void FPGAViewWidget::mouseMoveEvent(QMouseEvent *event) QMutexLocker locked(&rendererArgsLock_); rendererArgs_->hoveredDecal = closest.decal(ctx_); rendererArgs_->changed = true; + rendererArgs_->x = event->x(); + rendererArgs_->y = event->y(); + if (closest.type == ElementType::BEL) { + rendererArgs_->hintText = std::string("BEL\n") + ctx_->getBelName(closest.bel).c_str(ctx_); + CellInfo *cell = ctx_->getBoundBelCell(closest.bel); + if (cell!=nullptr) + rendererArgs_->hintText += std::string("\nCELL\n") +ctx_->nameOf(cell); + } else if (closest.type == ElementType::WIRE) { + rendererArgs_->hintText = std::string("WIRE\n") + ctx_->getWireName(closest.wire).c_str(ctx_); + NetInfo *net = ctx_->getBoundWireNet(closest.wire); + if (net!=nullptr) + rendererArgs_->hintText += std::string("\nNET\n") +ctx_->nameOf(net); + } else if (closest.type == ElementType::PIP) { + rendererArgs_->hintText = std::string("PIP\n") + ctx_->getPipName(closest.pip).c_str(ctx_); + NetInfo *net = ctx_->getBoundPipNet(closest.pip); + if (net!=nullptr) + rendererArgs_->hintText += std::string("\nNET\n") +ctx_->nameOf(net); + } else if (closest.type == ElementType::GROUP) { + rendererArgs_->hintText = std::string("GROUP\n") + ctx_->getGroupName(closest.group).c_str(ctx_); + } else rendererArgs_->hintText = ""; + pokeRenderer(); } update(); @@ -754,6 +798,9 @@ QVector4D FPGAViewWidget::mouseToWorldDimensions(float x, float y) void FPGAViewWidget::wheelEvent(QWheelEvent *event) { + ImGuiIO &io = ImGui::GetIO(); + if (io.WantCaptureMouse) return; + QPoint degree = event->angleDelta() / 8; if (!degree.isNull()) @@ -829,6 +876,7 @@ void FPGAViewWidget::leaveEvent(QEvent *event) QMutexLocker locked(&rendererArgsLock_); rendererArgs_->hoveredDecal = DecalXY(); rendererArgs_->changed = true; + rendererArgs_->hintText = ""; pokeRenderer(); } diff --git a/gui/fpgaviewwidget.h b/gui/fpgaviewwidget.h index 697ace21..e76e6f32 100644 --- a/gui/fpgaviewwidget.h +++ b/gui/fpgaviewwidget.h @@ -268,6 +268,10 @@ class FPGAViewWidget : public QOpenGLWidget, protected QOpenGLFunctions // Flags to pass back into the RendererData. PassthroughFlags flags; + // Hint text + std::string hintText; + // cursor pos + int x,y; }; std::unique_ptr<RendererArgs> rendererArgs_; QMutex rendererArgsLock_; |