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);
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::BeginGroup();
|
||||
gui::InputHexByte(
|
||||
"Gfx",
|
||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_graphics(),
|
||||
kInputFieldSize);
|
||||
ImGui::EndGroup();
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::BeginGroup();
|
||||
gui::InputHexByte(
|
||||
"Palette",
|
||||
overworld_.mutable_overworld_map(current_map_)->mutable_area_palette(),
|
||||
kInputFieldSize);
|
||||
ImGui::EndGroup();
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::BeginGroup();
|
||||
gui::InputHexByte("Spr Gfx",
|
||||
overworld_.mutable_overworld_map(current_map_)
|
||||
->mutable_sprite_graphics(game_state_),
|
||||
kInputFieldSize);
|
||||
ImGui::EndGroup();
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::BeginGroup();
|
||||
gui::InputHexByte("Spr Palette",
|
||||
overworld_.mutable_overworld_map(current_map_)
|
||||
->mutable_sprite_palette(game_state_),
|
||||
kInputFieldSize);
|
||||
ImGui::EndGroup();
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::BeginGroup();
|
||||
gui::InputHexWord(
|
||||
"Msg Id",
|
||||
overworld_.mutable_overworld_map(current_map_)->mutable_message_id(),
|
||||
kInputFieldSize);
|
||||
kInputFieldSize + 20);
|
||||
ImGui::EndGroup();
|
||||
|
||||
TableNextColumn();
|
||||
ImGui::SetNextItemWidth(100.f);
|
||||
@@ -707,16 +717,10 @@ void OverworldEditor::CheckForCurrentMap() {
|
||||
ow_map_canvas_.DrawOutline(parent_map_x * small_map_size,
|
||||
parent_map_x * small_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 {
|
||||
ow_map_canvas_.DrawOutline(current_map_x * small_map_size,
|
||||
current_map_y * 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_;
|
||||
@@ -748,7 +752,7 @@ void OverworldEditor::DrawOverworldCanvas() {
|
||||
DrawOverworldEntrances(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();
|
||||
}
|
||||
CheckForCurrentMap();
|
||||
@@ -905,18 +909,13 @@ absl::Status OverworldEditor::LoadGraphics() {
|
||||
maps_bmp_[i], palette);
|
||||
}
|
||||
|
||||
if (flags()->kDrawOverworldSprites) {
|
||||
if (flags()->overworld.kDrawOverworldSprites) {
|
||||
RETURN_IF_ERROR(LoadSpriteGraphics());
|
||||
}
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status OverworldEditor::SaveOverworldMaps() {
|
||||
RETURN_IF_ERROR(overworld_.SaveOverworldMaps());
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status OverworldEditor::LoadSpriteGraphics() {
|
||||
// Render the sprites for each Overworld map
|
||||
for (int i = 0; i < 3; i++)
|
||||
|
||||
@@ -87,7 +87,6 @@ class OverworldEditor : public Editor,
|
||||
}
|
||||
|
||||
absl::Status LoadGraphics();
|
||||
absl::Status SaveOverworldMaps();
|
||||
|
||||
private:
|
||||
absl::Status UpdateOverworldEdit();
|
||||
|
||||
@@ -17,7 +17,6 @@ static inline ImGuiInputTextFlags InputScalar_DefaultCharsFilter(
|
||||
? ImGuiInputTextFlags_CharsHexadecimal
|
||||
: ImGuiInputTextFlags_CharsDecimal;
|
||||
}
|
||||
|
||||
bool InputScalarLeft(const char* label, ImGuiDataType data_type, void* p_data,
|
||||
const void* p_step, const void* p_step_fast,
|
||||
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.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
|
||||
const ImVec2 backup_frame_padding = style.FramePadding;
|
||||
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,
|
||||
float input_width) {
|
||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &step,
|
||||
return ImGui::InputScalarLeft(label, ImGuiDataType_U8, data, &kStepOneHex,
|
||||
&kStepFastHex, "%02X", input_width,
|
||||
ImGuiInputTextFlags_CharsHexadecimal);
|
||||
}
|
||||
|
||||
@@ -16,6 +16,10 @@ namespace gui {
|
||||
constexpr ImVec2 kDefaultModalSize = ImVec2(200, 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 InputHexShort(const char* label, uint32_t* data);
|
||||
IMGUI_API bool InputHexWord(const char* label, uint16_t* data,
|
||||
|
||||
Reference in New Issue
Block a user