visual look changes

This commit is contained in:
milek7
2019-09-25 17:54:44 +02:00
parent 3c9111bb25
commit a92037d2b2
5 changed files with 167 additions and 87 deletions

View File

@@ -407,6 +407,8 @@ timetable_panel::render() {
if( false == is_open ) { return; }
if( true == text_lines.empty() ) { return; }
ImGui::PushFont(ui_layer::font_mono);
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
@@ -436,6 +438,8 @@ timetable_panel::render() {
}
}
ImGui::End();
ImGui::PopFont();
}
void
@@ -494,6 +498,8 @@ debug_panel::render() {
if( false == is_open ) { return; }
ImGui::PushFont(ui_layer::font_mono);
auto flags =
ImGuiWindowFlags_NoFocusOnAppearing
| ImGuiWindowFlags_NoCollapse
@@ -546,6 +552,8 @@ debug_panel::render() {
ImGui::Checkbox( "Debug Mode", &DebugModeFlag );
}
ImGui::End();
ImGui::PopFont();
}
void

View File

@@ -28,6 +28,8 @@ http://mozilla.org/MPL/2.0/.
GLFWwindow *ui_layer::m_window{nullptr};
ImGuiIO *ui_layer::m_imguiio{nullptr};
bool ui_layer::m_cursorvisible;
ImFont *ui_layer::font_default{nullptr};
ImFont *ui_layer::font_mono{nullptr};
ui_panel::ui_panel(std::string const &Identifier, bool const Isopen) : m_name(Identifier), is_open(Isopen) {}
@@ -83,10 +85,14 @@ void ui_expandable_panel::render_contents()
void ui_log_panel::render_contents()
{
ImGui::PushFont(ui_layer::font_mono);
for (const std::string &s : log_scrollback)
ImGui::TextUnformatted(s.c_str());
if (ImGui::GetScrollY() == ImGui::GetScrollMaxY())
ImGui::SetScrollHereY(1.0f);
ImGui::PopFont();
}
ui_layer::~ui_layer() {}
@@ -122,9 +128,64 @@ ui_layer::ui_layer()
m_logpanel.size = { 700, 400 };
}
static ImVec4 imvec_lerp(const ImVec4& a, const ImVec4& b, float t)
{
return ImVec4(a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t, a.z + (b.z - a.z) * t, a.w + (b.w - a.w) * t);
}
void ui_layer::imgui_style()
{
ImGui::StyleColorsDark();
ImVec4* colors = ImGui::GetStyle().Colors;
colors[ImGuiCol_Text] = ImVec4(1.00f, 1.00f, 1.00f, 1.00f);
colors[ImGuiCol_TextDisabled] = ImVec4(0.35f, 0.35f, 0.35f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.04f, 0.04f, 0.04f, 0.94f);
colors[ImGuiCol_ChildBg] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_PopupBg] = ImVec4(0.06f, 0.06f, 0.06f, 0.94f);
colors[ImGuiCol_Border] = ImVec4(0.31f, 0.34f, 0.31f, 0.50f);
colors[ImGuiCol_BorderShadow] = ImVec4(0.00f, 0.00f, 0.00f, 0.00f);
colors[ImGuiCol_FrameBg] = ImVec4(0.21f, 0.28f, 0.17f, 0.54f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.42f, 0.64f, 0.23f, 0.40f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.42f, 0.64f, 0.23f, 0.67f);
colors[ImGuiCol_TitleBg] = ImVec4(0.03f, 0.03f, 0.03f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.21f, 0.28f, 0.17f, 1.00f);
colors[ImGuiCol_TitleBgCollapsed] = ImVec4(0.00f, 0.00f, 0.00f, 0.51f);
colors[ImGuiCol_MenuBarBg] = ImVec4(0.10f, 0.10f, 0.10f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.01f, 0.01f, 0.01f, 0.53f);
colors[ImGuiCol_ScrollbarGrab] = ImVec4(0.22f, 0.22f, 0.22f, 1.00f);
colors[ImGuiCol_ScrollbarGrabHovered] = ImVec4(0.29f, 0.29f, 0.29f, 1.00f);
colors[ImGuiCol_ScrollbarGrabActive] = ImVec4(0.36f, 0.36f, 0.36f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.42f, 0.64f, 0.23f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.37f, 0.53f, 0.25f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.42f, 0.64f, 0.23f, 1.00f);
colors[ImGuiCol_Button] = ImVec4(0.42f, 0.64f, 0.23f, 0.40f);
colors[ImGuiCol_ButtonHovered] = ImVec4(0.42f, 0.64f, 0.23f, 1.00f);
colors[ImGuiCol_ButtonActive] = ImVec4(0.37f, 0.54f, 0.19f, 1.00f);
colors[ImGuiCol_Header] = ImVec4(0.42f, 0.64f, 0.23f, 0.31f);
colors[ImGuiCol_HeaderHovered] = ImVec4(0.42f, 0.64f, 0.23f, 0.80f);
colors[ImGuiCol_HeaderActive] = ImVec4(0.42f, 0.64f, 0.23f, 1.00f);
colors[ImGuiCol_SeparatorHovered] = ImVec4(0.29f, 0.41f, 0.18f, 0.78f);
colors[ImGuiCol_SeparatorActive] = ImVec4(0.29f, 0.41f, 0.18f, 1.00f);
colors[ImGuiCol_ResizeGrip] = ImVec4(0.42f, 0.64f, 0.23f, 0.25f);
colors[ImGuiCol_ResizeGripHovered] = ImVec4(0.42f, 0.64f, 0.23f, 0.67f);
colors[ImGuiCol_ResizeGripActive] = ImVec4(0.42f, 0.64f, 0.23f, 0.95f);
colors[ImGuiCol_PlotLines] = ImVec4(0.43f, 0.43f, 0.43f, 1.00f);
colors[ImGuiCol_PlotLinesHovered] = ImVec4(0.29f, 0.24f, 0.71f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.40f, 0.16f, 0.47f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.39f, 0.18f, 0.52f, 1.00f);
colors[ImGuiCol_TextSelectedBg] = ImVec4(0.42f, 0.64f, 0.23f, 0.35f);
colors[ImGuiCol_DragDropTarget] = ImVec4(0.52f, 0.18f, 0.52f, 0.90f);
colors[ImGuiCol_NavHighlight] = ImVec4(0.42f, 0.64f, 0.23f, 1.00f);
colors[ImGuiCol_NavWindowingHighlight] = ImVec4(1.00f, 1.00f, 1.00f, 0.70f);
colors[ImGuiCol_NavWindowingDimBg] = ImVec4(0.56f, 0.56f, 0.56f, 0.20f);
colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.56f, 0.56f, 0.56f, 0.35f);
colors[ImGuiCol_Separator] = colors[ImGuiCol_Border];
colors[ImGuiCol_Tab] = imvec_lerp(colors[ImGuiCol_Header], colors[ImGuiCol_TitleBgActive], 0.80f);
colors[ImGuiCol_TabHovered] = colors[ImGuiCol_HeaderHovered];
colors[ImGuiCol_TabActive] = imvec_lerp(colors[ImGuiCol_HeaderActive], colors[ImGuiCol_TitleBgActive], 0.60f);
colors[ImGuiCol_TabUnfocused] = imvec_lerp(colors[ImGuiCol_Tab], colors[ImGuiCol_TitleBg], 0.80f);
colors[ImGuiCol_TabUnfocusedActive] = imvec_lerp(colors[ImGuiCol_TabActive], colors[ImGuiCol_TitleBg], 0.40f);
}
bool ui_layer::init(GLFWwindow *Window)
@@ -148,7 +209,17 @@ bool ui_layer::init(GLFWwindow *Window)
0,
};
m_imguiio->Fonts->AddFontFromFileTTF("fonts/dejavusansmono.ttf", 13.0f, nullptr, &ranges[0]);
if (FileExists("fonts/dejavusans.ttf"))
font_default = m_imguiio->Fonts->AddFontFromFileTTF("fonts/dejavusans.ttf", 13.0f, nullptr, &ranges[0]);
if (FileExists("fonts/dejavusansmono.ttf"))
font_mono = m_imguiio->Fonts->AddFontFromFileTTF("fonts/dejavusansmono.ttf", 13.0f, nullptr, &ranges[0]);
if (!font_default && !font_mono)
font_default = font_mono = m_imguiio->Fonts->AddFontDefault();
else if (!font_default)
font_default = font_mono;
else if (!font_mono)
font_mono = font_default;
imgui_style();
ImGui_ImplGlfw_InitForOpenGL(m_window);

View File

@@ -70,6 +70,7 @@ class ui_log_panel : public ui_panel {
void render_contents() override;
};
class ImFont;
class ui_layer {
public:
@@ -145,6 +146,8 @@ public:
static bool scroll_callback(double xoffset, double yoffset);
static bool mouse_button_callback(int button, int action, int mods);
static ImFont *font_default;
static ImFont *font_mono;
protected:
// members

View File

@@ -16,6 +16,86 @@ void screen_window_callback(ImGuiSizeCallbackData *data) {
data->DesiredSize.y = data->DesiredSize.x * (float)config->size.y / (float)config->size.x;
}
void ui::vehicleparams_panel::draw_infobutton(const char *str, ImVec2 pos, const ImVec4 color)
{
if (pos.x != -1.0f) {
ImVec2 window_size = ImGui::GetWindowSize();
ImGuiStyle &style = ImGui::GetStyle();
ImVec2 text_size = ImGui::CalcTextSize(str);
ImVec2 button_size = ImVec2(
text_size.x + style.FramePadding.x * 2.0f,
text_size.y + style.FramePadding.y * 2.0f);
pos.x = pos.x * window_size.x / 512.0f - button_size.x / 2.0f;
pos.y = pos.y * window_size.y / 118.0f - button_size.y / 2.0f;
ImGui::SetCursorPos(pos);
}
if ((color.x + color.y + color.z) / 3.0f < 0.5f)
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
else
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Button, color);
ImGui::PushStyleColor(ImGuiCol_ButtonActive, color);
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, color);
ImGui::Button(str);
ImGui::SameLine();
ImGui::PopStyleColor(4);
}
void ui::vehicleparams_panel::draw_mini(const TMoverParameters &mover)
{
if (vehicle_mini == null_handle)
return;
opengl_texture &tex = GfxRenderer.Texture(vehicle_mini);
tex.create();
ImVec2 size = ImGui::GetContentRegionAvail();
float x = size.x;
float y = x * ((float)tex.height() / tex.width());
if (ImGui::BeginChild("mini", ImVec2(x, y)))
{
ImGui::Image(reinterpret_cast<void*>(tex.id), ImVec2(x, y), ImVec2(0, 1), ImVec2(1, 0));
if (mover.PantRearUp)
draw_infobutton(u8"╨╨╨", ImVec2(126, 10));
if (mover.PantFrontUp)
draw_infobutton(u8"╨╨╨", ImVec2(290, 10));
if (mover.Battery)
draw_infobutton(STR_C("bat."), ImVec2(120, 55));
if (mover.Mains)
draw_infobutton(STR_C("main."));
if (mover.ConverterFlag)
draw_infobutton(STR_C("conv."));
if (mover.CompressorFlag)
draw_infobutton(STR_C("comp."));
if (mover.WarningSignal)
draw_infobutton(STR_C("horn"), ImVec2(361, 11));
if (mover.iLights[end::front] & light::redmarker_left)
draw_infobutton("o", ImVec2(490, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
else if (mover.iLights[end::front] & light::headlight_left)
draw_infobutton("O", ImVec2(490, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
if (mover.iLights[end::front] & light::redmarker_right)
draw_infobutton("o", ImVec2(443, 71), ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
else if (mover.iLights[end::front] & light::headlight_right)
draw_infobutton("O", ImVec2(443, 71), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
if (mover.iLights[end::front] & light::headlight_upper)
draw_infobutton("O", ImVec2(467, 18), ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
}
ImGui::EndChild();
}
void ui::vehicleparams_panel::render_contents()
{
TDynamicObject *vehicle_ptr = simulation::Vehicles.find(m_vehicle_name);
@@ -197,91 +277,7 @@ void ui::vehicleparams_panel::render_contents()
ImGui::TextUnformatted(buffer.data());
if (vehicle_mini != null_handle) {
opengl_texture &tex = GfxRenderer.Texture(vehicle_mini);
tex.create();
ImVec2 size = ImGui::GetContentRegionAvail();
float x = size.x;
float y = x * ((float)tex.height() / tex.width());
float sx = size.x / 512.0f;
float sy = y / 118.0f;
ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.0f, 0.0f, 0.0f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
if (ImGui::BeginChild("mini", ImVec2(x, y)))
{
ImGui::Image(reinterpret_cast<void*>(tex.id), ImVec2(x, y), ImVec2(0, 1), ImVec2(1, 0));
if (mover.PantRearUp) {
ImGui::SetCursorPos(ImVec2(sx * 110, sy * 2));
ImGui::Button(u8"╨╨╨");
}
if (mover.PantFrontUp) {
ImGui::SetCursorPos(ImVec2(sx * 280, sy * 2));
ImGui::Button(u8"╨╨╨");
}
ImGui::SetCursorPos(ImVec2(sx * 100, sy * 40));
if (mover.Battery) {
ImGui::Button(u8"BAT.");
ImGui::SameLine();
}
if (mover.Mains) {
ImGui::Button(u8"WS");
ImGui::SameLine();
}
if (mover.ConverterFlag) {
ImGui::Button(u8"PRZETW.");
ImGui::SameLine();
}
if (mover.CompressorFlag) {
ImGui::Button(u8"SPRĘŻ.");
}
ImGui::SetCursorPos(ImVec2(sx * 355, sy * 5));
if (mover.WarningSignal) {
ImGui::Button(u8"SYRENA");
}
ImGui::SetCursorPos(ImVec2(sx * 438, sy * 68));
if (mover.iLights[end::front] & light::redmarker_left) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::Button(u8"o");
ImGui::PopStyleColor();
}
else if (mover.iLights[end::front] & light::headlight_left) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::Button(u8"O");
ImGui::PopStyleColor();
}
ImGui::SetCursorPos(ImVec2(sx * 484, sy * 68));
if (mover.iLights[end::front] & light::redmarker_right) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 0.0f, 0.0f, 1.0f));
ImGui::Button(u8"o");
ImGui::PopStyleColor();
}
else if (mover.iLights[end::front] & light::headlight_right) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::Button(u8"O");
ImGui::PopStyleColor();
}
ImGui::SetCursorPos(ImVec2(sx * 460, sy * 15));
if (mover.iLights[end::front] & light::headlight_upper) {
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(1.0f, 1.0f, 1.0f, 1.0f));
ImGui::Button(u8"O");
ImGui::PopStyleColor();
}
}
ImGui::EndChild();
ImGui::PopStyleColor(4);
}
draw_mini(mover);
if (ImGui::Button(STR_C("Radiostop")))
m_relay.post(user_command::radiostop, 0.0, 0.0, GLFW_PRESS, 0, vehicle_ptr->GetPosition());

View File

@@ -11,6 +11,8 @@ class vehicleparams_panel : public ui_panel
command_relay m_relay;
texture_handle vehicle_mini;
void draw_infobutton(const char *str, ImVec2 pos = ImVec2(-1.0f, -1.0f), const ImVec4 color = ImVec4(1.0f, 1.0f, 0.0f, 1.0f));
void draw_mini(const TMoverParameters &mover);
public:
vehicleparams_panel(const std::string &vehicle);