Add scroll wheel support to input hex fields
This commit is contained in:
@@ -351,34 +351,44 @@ void OverworldEditor::DrawOverworldMapSettings() {
|
|||||||
ImGui::Combo("##world", ¤t_world_, kWorldList.data(), 3);
|
ImGui::Combo("##world", ¤t_world_, kWorldList.data(), 3);
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte(
|
gui::InputHexByte(
|
||||||
"Gfx",
|
"Gfx",
|
||||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_graphics(),
|
overworld_.mutable_overworld_map(current_map_)->mutable_area_graphics(),
|
||||||
kInputFieldSize);
|
kInputFieldSize);
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte(
|
gui::InputHexByte(
|
||||||
"Palette",
|
"Palette",
|
||||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_palette(),
|
overworld_.mutable_overworld_map(current_map_)->mutable_area_palette(),
|
||||||
kInputFieldSize);
|
kInputFieldSize);
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte("Spr Gfx",
|
gui::InputHexByte("Spr Gfx",
|
||||||
overworld_.mutable_overworld_map(current_map_)
|
overworld_.mutable_overworld_map(current_map_)
|
||||||
->mutable_sprite_graphics(game_state_),
|
->mutable_sprite_graphics(game_state_),
|
||||||
kInputFieldSize);
|
kInputFieldSize);
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
ImGui::BeginGroup();
|
||||||
gui::InputHexByte("Spr Palette",
|
gui::InputHexByte("Spr Palette",
|
||||||
overworld_.mutable_overworld_map(current_map_)
|
overworld_.mutable_overworld_map(current_map_)
|
||||||
->mutable_sprite_palette(game_state_),
|
->mutable_sprite_palette(game_state_),
|
||||||
kInputFieldSize);
|
kInputFieldSize);
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
|
ImGui::BeginGroup();
|
||||||
gui::InputHexWord(
|
gui::InputHexWord(
|
||||||
"Msg Id",
|
"Msg Id",
|
||||||
overworld_.mutable_overworld_map(current_map_)->mutable_message_id(),
|
overworld_.mutable_overworld_map(current_map_)->mutable_message_id(),
|
||||||
kInputFieldSize);
|
kInputFieldSize + 20);
|
||||||
|
ImGui::EndGroup();
|
||||||
|
|
||||||
TableNextColumn();
|
TableNextColumn();
|
||||||
ImGui::SetNextItemWidth(100.f);
|
ImGui::SetNextItemWidth(100.f);
|
||||||
@@ -707,16 +717,10 @@ void OverworldEditor::CheckForCurrentMap() {
|
|||||||
ow_map_canvas_.DrawOutline(parent_map_x * small_map_size,
|
ow_map_canvas_.DrawOutline(parent_map_x * small_map_size,
|
||||||
parent_map_x * small_map_size, large_map_size,
|
parent_map_x * small_map_size, large_map_size,
|
||||||
large_map_size);
|
large_map_size);
|
||||||
// ow_map_canvas_.mutable_points()->push_back(
|
|
||||||
// ImVec2(parent_map_x * small_map_size, parent_map_y *
|
|
||||||
// small_map_size));
|
|
||||||
} else {
|
} else {
|
||||||
ow_map_canvas_.DrawOutline(current_map_x * small_map_size,
|
ow_map_canvas_.DrawOutline(current_map_x * small_map_size,
|
||||||
current_map_y * small_map_size, small_map_size,
|
current_map_y * small_map_size, small_map_size,
|
||||||
small_map_size);
|
small_map_size);
|
||||||
// ow_map_canvas_.mutable_points()->push_back(
|
|
||||||
// ImVec2(current_map_x * small_map_size, current_map_y *
|
|
||||||
// small_map_size));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int prev_map_;
|
static int prev_map_;
|
||||||
@@ -748,7 +752,7 @@ void OverworldEditor::DrawOverworldCanvas() {
|
|||||||
DrawOverworldEntrances(ow_map_canvas_.zero_point(),
|
DrawOverworldEntrances(ow_map_canvas_.zero_point(),
|
||||||
ow_map_canvas_.scrolling());
|
ow_map_canvas_.scrolling());
|
||||||
DrawOverworldExits(ow_map_canvas_.zero_point(), ow_map_canvas_.scrolling());
|
DrawOverworldExits(ow_map_canvas_.zero_point(), ow_map_canvas_.scrolling());
|
||||||
if (flags()->kDrawOverworldSprites) {
|
if (flags()->overworld.kDrawOverworldSprites) {
|
||||||
DrawOverworldSprites();
|
DrawOverworldSprites();
|
||||||
}
|
}
|
||||||
CheckForCurrentMap();
|
CheckForCurrentMap();
|
||||||
@@ -905,18 +909,13 @@ absl::Status OverworldEditor::LoadGraphics() {
|
|||||||
maps_bmp_[i], palette);
|
maps_bmp_[i], palette);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (flags()->kDrawOverworldSprites) {
|
if (flags()->overworld.kDrawOverworldSprites) {
|
||||||
RETURN_IF_ERROR(LoadSpriteGraphics());
|
RETURN_IF_ERROR(LoadSpriteGraphics());
|
||||||
}
|
}
|
||||||
|
|
||||||
return absl::OkStatus();
|
return absl::OkStatus();
|
||||||
}
|
}
|
||||||
|
|
||||||
absl::Status OverworldEditor::SaveOverworldMaps() {
|
|
||||||
RETURN_IF_ERROR(overworld_.SaveOverworldMaps());
|
|
||||||
return absl::OkStatus();
|
|
||||||
}
|
|
||||||
|
|
||||||
absl::Status OverworldEditor::LoadSpriteGraphics() {
|
absl::Status OverworldEditor::LoadSpriteGraphics() {
|
||||||
// Render the sprites for each Overworld map
|
// Render the sprites for each Overworld map
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
|
|||||||
@@ -87,7 +87,6 @@ class OverworldEditor : public Editor,
|
|||||||
}
|
}
|
||||||
|
|
||||||
absl::Status LoadGraphics();
|
absl::Status LoadGraphics();
|
||||||
absl::Status SaveOverworldMaps();
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
absl::Status UpdateOverworldEdit();
|
absl::Status UpdateOverworldEdit();
|
||||||
|
|||||||
@@ -17,7 +17,6 @@ static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(
|
|||||||
? ImGuiInputTextFlags_CharsHexadecimal
|
? ImGuiInputTextFlags_CharsHexadecimal
|
||||||
: ImGuiInputTextFlags_CharsDecimal;
|
: ImGuiInputTextFlags_CharsDecimal;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
||||||
const void* p_step, const void* p_step_fast,
|
const void* p_step, const void* p_step_fast,
|
||||||
const char* format, float input_width,
|
const char* format, float input_width,
|
||||||
@@ -70,6 +69,27 @@ bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
|||||||
g.LastItemData.ID, label,
|
g.LastItemData.ID, label,
|
||||||
g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable);
|
g.LastItemData.StatusFlags | ImGuiItemStatusFlags_Inputable);
|
||||||
|
|
||||||
|
// Mouse wheel support
|
||||||
|
if (IsItemHovered() && g.IO.MouseWheel != 0.0f) {
|
||||||
|
float scroll_amount = g.IO.MouseWheel;
|
||||||
|
float scroll_speed = 0.25f; // Adjust the scroll speed as needed
|
||||||
|
|
||||||
|
if (g.IO.KeyCtrl && p_step_fast)
|
||||||
|
scroll_amount *= *(const float*)p_step_fast;
|
||||||
|
else
|
||||||
|
scroll_amount *= *(const float*)p_step;
|
||||||
|
|
||||||
|
if (scroll_amount > 0.0f) {
|
||||||
|
scroll_amount *= scroll_speed; // Adjust the scroll speed as needed
|
||||||
|
DataTypeApplyOp(data_type, '+', p_data, p_data, &scroll_amount);
|
||||||
|
value_changed = true;
|
||||||
|
} else if (scroll_amount < 0.0f) {
|
||||||
|
scroll_amount *= -scroll_speed; // Adjust the scroll speed as needed
|
||||||
|
DataTypeApplyOp(data_type, '-', p_data, p_data, &scroll_amount);
|
||||||
|
value_changed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Step buttons
|
// Step buttons
|
||||||
const ImVec2 backup_frame_padding = style.FramePadding;
|
const ImVec2 backup_frame_padding = style.FramePadding;
|
||||||
style.FramePadding.x = style.FramePadding.y;
|
style.FramePadding.x = style.FramePadding.y;
|
||||||
@@ -129,7 +149,7 @@ bool InputHexWord(const char* label, uint16_t* data, float input_width) {
|
|||||||
|
|
||||||
bool InputHexByte(const char* label, uint8_t* data, uint8_t step,
|
bool InputHexByte(const char* label, uint8_t* data, uint8_t step,
|
||||||
float input_width) {
|
float input_width) {
|
||||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &step,
|
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &kStepOneHex,
|
||||||
&kStepFastHex, "%02X", input_width,
|
&kStepFastHex, "%02X", input_width,
|
||||||
ImGuiInputTextFlags_CharsHexadecimal);
|
ImGuiInputTextFlags_CharsHexadecimal);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,6 +16,10 @@ namespace gui {
|
|||||||
constexpr ImVec2 kDefaultModalSize = ImVec2(200, 0);
|
constexpr ImVec2 kDefaultModalSize = ImVec2(200, 0);
|
||||||
constexpr ImVec2 kZeroPos = ImVec2(0, 0);
|
constexpr ImVec2 kZeroPos = ImVec2(0, 0);
|
||||||
|
|
||||||
|
IMGUI_API bool InputHexWithScrollwheel(const char* label, uint32_t* data,
|
||||||
|
uint32_t step = 0x01,
|
||||||
|
float input_width = 50.f);
|
||||||
|
|
||||||
IMGUI_API bool InputHex(const char* label, uint64_t* data);
|
IMGUI_API bool InputHex(const char* label, uint64_t* data);
|
||||||
IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
|
IMGUI_API bool InputHexShort(const char* label, uint32_t* data);
|
||||||
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
||||||
|
|||||||
Reference in New Issue
Block a user