Pioneer
Loading...
Searching...
No Matches
SystemEditorHelpers.h
Go to the documentation of this file.
1// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details
2// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt
3
4#pragma once
5
6#include "EditorIcons.h"
7#include "MathUtil.h"
8#include "imgui/imgui.h"
9#include "imgui/imgui_stdlib.h"
10
11#include "fixed.h"
12
13namespace ImGui {
14 inline bool InputFixed(const char *str, fixed *val, double step = 0.01, double step_fast = 0.1, const char *format = "%.4f", ImGuiInputTextFlags flags = 0)
15 {
16 double val_d = val->ToDouble();
17 bool changed = ImGui::InputDouble(str, &val_d, step, step_fast, format, flags | ImGuiInputTextFlags_EnterReturnsTrue);
18 if (changed)
19 *val = fixed::FromDouble(val_d);
20
21 return changed;
22 }
23
24 inline bool InputInt(const char* label, int* v, int step, int step_fast, const char *format, ImGuiInputTextFlags flags = 0)
25 {
26 return InputScalar(label, ImGuiDataType_S32, (void*)v, (void*)(step > 0 ? &step : NULL), (void*)(step_fast > 0 ? &step_fast : NULL), format, flags);
27 }
28}
29
30namespace Editor::Draw {
31
32 // Subtract the currently used space on this line and apply it to the next drawn item
33 void SubtractItemWidth();
34
35 inline bool RandomButton()
36 {
37 ImGuiStyle &style = ImGui::GetStyle();
38 bool ret = ImGui::Button(EICON_RANDOM);
39
40 ImGui::SameLine(0.f, style.ItemInnerSpacing.x);
42
43 return ret;
44 }
45
46 bool InputFixedSlider(const char *str, fixed *val, double val_min = 0.0, double val_max = 1.0, const char *format = "%.4f", ImGuiSliderFlags flags = ImGuiSliderFlags_AlwaysClamp);
47 bool InputFixedDegrees(const char *str, fixed *val, double val_min = -360.0, double val_max = 360.0, ImGuiInputTextFlags flags = 0);
48 bool InputFixedDistance(const char *str, fixed *val, ImGuiInputTextFlags flags = 0);
49 bool InputFixedMass(const char *str, fixed *val, bool is_solar, ImGuiInputTextFlags flags = 0);
50 bool InputFixedRadius(const char *str, fixed *val, bool is_solar, ImGuiInputTextFlags flags = 0);
51
52};
#define EICON_RANDOM
Definition: EditorIcons.h:31
double val
Definition: PrecalcPath.cpp:40
static fixedf FromDouble(const double val)
Definition: fixed.h:194
Definition: EditorDraw.h:19
void SubtractItemWidth()
Definition: SystemEditorHelpers.cpp:110
bool InputFixedMass(const char *str, fixed *val, bool is_solar, ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.cpp:188
bool RandomButton()
Definition: SystemEditorHelpers.h:35
bool InputFixedDistance(const char *str, fixed *val, ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.cpp:142
bool InputFixedDegrees(const char *str, fixed *val, double val_min=-360.0, double val_max=360.0, ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.cpp:129
bool InputFixedRadius(const char *str, fixed *val, bool is_solar, ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.cpp:244
bool InputFixedSlider(const char *str, fixed *val, double val_min=0.0, double val_max=1.0, const char *format="%.4f", ImGuiSliderFlags flags=ImGuiSliderFlags_AlwaysClamp)
Definition: SystemEditorHelpers.cpp:117
Definition: SystemEditorHelpers.cpp:84
bool InputFixed(const char *str, fixed *val, double step=0.01, double step_fast=0.1, const char *format="%.4f", ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.h:14
bool InputInt(const char *label, int *v, int step, int step_fast, const char *format, ImGuiInputTextFlags flags=0)
Definition: SystemEditorHelpers.h:24