added imgui to device renderer
This commit is contained in:
parent
c169fab420
commit
bdfaeea0d0
|
@ -11,8 +11,10 @@ public:
|
|||
DeviceRenderer(std::shared_ptr<Device> device, uint16_t x, uint16_t y);
|
||||
|
||||
void Render(SDL_Renderer* renderer) const;
|
||||
void Deselect();
|
||||
void RenderImGui() const;
|
||||
|
||||
void Deselect();
|
||||
inline bool Selected() const { return selected; }
|
||||
bool PropagateEvent(SDL_Event* event);
|
||||
|
||||
private:
|
||||
|
|
|
@ -10,6 +10,7 @@ public:
|
|||
|
||||
void AddDevice(std::shared_ptr<Device> device, uint16_t x, uint16_t y);
|
||||
void Render(SDL_Renderer* renderer) const;
|
||||
void RenderImGui() const;
|
||||
|
||||
void PropagateEvent(SDL_Event* event);
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
#include "DeviceRenderer.hpp"
|
||||
|
||||
#include <SDL.h>
|
||||
#include <imgui.h>
|
||||
|
||||
DeviceRenderer::DeviceRenderer(std::shared_ptr<Device> device, uint16_t x, uint16_t y) :
|
||||
device(device), selected(false), grabbed(false)
|
||||
|
@ -52,4 +53,12 @@ void DeviceRenderer::Render(SDL_Renderer* renderer) const {
|
|||
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
|
||||
SDL_RenderRect(renderer, &bbox);
|
||||
}
|
||||
}
|
||||
|
||||
void DeviceRenderer::RenderImGui() const {
|
||||
if (ImGui::Begin("Device")) {
|
||||
ImGui::InputScalarN("MAC Address", ImGuiDataType_U8, device->macAddress, 6, NULL, NULL, "%02X");
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
}
|
|
@ -30,4 +30,12 @@ void NetworkRenderer::Render(SDL_Renderer* renderer) const {
|
|||
for (const DeviceRenderer& device : devices) {
|
||||
device.Render(renderer);
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkRenderer::RenderImGui() const {
|
||||
for (const DeviceRenderer& device : devices) {
|
||||
if (device.Selected()) {
|
||||
device.RenderImGui();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,11 @@ int main(int argc, char** argv) {
|
|||
while (!shouldClose) {
|
||||
while (SDL_PollEvent(&event)) {
|
||||
ImGui_ImplSDL3_ProcessEvent(&event);
|
||||
|
||||
if (ImGui::GetIO().WantCaptureMouse) {
|
||||
continue;
|
||||
}
|
||||
|
||||
networkRenderer.PropagateEvent(&event);
|
||||
|
||||
switch (event.type) {
|
||||
|
@ -71,6 +76,8 @@ int main(int argc, char** argv) {
|
|||
ImGui::EndMainMenuBar();
|
||||
}
|
||||
|
||||
networkRenderer.RenderImGui();
|
||||
|
||||
ImGui::Render();
|
||||
ImGui_ImplSDLRenderer3_RenderDrawData(ImGui::GetDrawData());
|
||||
|
||||
|
|
|
@ -15,6 +15,6 @@ public:
|
|||
private:
|
||||
void parseAndSetMac(const std::string& macAddress);
|
||||
|
||||
private:
|
||||
public:
|
||||
uint8_t macAddress[6];
|
||||
};
|
Loading…
Reference in a new issue