Skip to content

Commit

Permalink
Switch ChoiceFlags to strong enum
Browse files Browse the repository at this point in the history
Drop unused flag RETURN_KEY
  • Loading branch information
LegalizeAdulthood committed Dec 31, 2024
1 parent 957eede commit 947bc69
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 74 deletions.
7 changes: 4 additions & 3 deletions libid/file_item.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,9 +733,10 @@ static long gfe_choose_entry(ItemType type, char const *title, const std::string
colwidth = 76;
}

const int i = full_screen_choice(CHOICE_INSTRUCTIONS | (dosort ? 0 : CHOICE_NOT_SORTED),
heading.c_str(), nullptr, instr, numentries, (char const **) choices, attributes, boxwidth,
boxdepth, colwidth, 0, formatitem, buf, nullptr, check_gfe_key);
const int i =
full_screen_choice(ChoiceFlags::INSTRUCTIONS | (dosort ? ChoiceFlags::NONE : ChoiceFlags::NOT_SORTED),
heading.c_str(), nullptr, instr, numentries, (char const **) choices, attributes, boxwidth,
boxdepth, colwidth, 0, formatitem, buf, nullptr, check_gfe_key);
if (i == -ID_KEY_F4)
{
std::rewind(s_gfe_file);
Expand Down
56 changes: 23 additions & 33 deletions libid/full_screen_choice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ inline int is_a_dir_name(char const *name)
return *name == '.' || ends_with_slash(name) ? 1 : 0;
}

static void footer_msg(int *i, int options, char const *speedstring)
static void footer_msg(int *i, ChoiceFlags flags, char const *speedstring)
{
put_string_center((*i)++, 0, 80, C_PROMPT_BKGRD,
(speedstring) ? "Use the cursor keys or type a value to make a selection"
speedstring ? "Use the cursor keys or type a value to make a selection"
: "Use the cursor keys to highlight your selection");
put_string_center(*(i++), 0, 80, C_PROMPT_BKGRD,
(options & CHOICE_MENU) ? "Press ENTER for highlighted choice, or F1 for help"
: ((options & CHOICE_HELP) ? "Press ENTER for highlighted choice, ESCAPE to back out, or F1 for help"
: "Press ENTER for highlighted choice, or ESCAPE to back out"));
bit_set(flags, ChoiceFlags::MENU)
? "Press ENTER for highlighted choice, or F1 for help"
: (bit_set(flags, ChoiceFlags::HELP)
? "Press ENTER for highlighted choice, ESCAPE to back out, or F1 for help"
: "Press ENTER for highlighted choice, or ESCAPE to back out"));
}

static void show_speed_string(
Expand Down Expand Up @@ -78,11 +80,11 @@ static void show_speed_string(
}

static void process_speed_string(char *speedstring, //
char const **choices, // array of choice strings
int curkey, //
int *pcurrent, //
int numchoices, //
int is_unsorted)
char const **choices, // array of choice strings
int curkey, //
int *pcurrent, //
int numchoices, //
bool is_unsorted)
{
int i = (int) std::strlen(speedstring);
if (curkey == 8 && i > 0) // backspace
Expand Down Expand Up @@ -161,33 +163,21 @@ static void process_speed_string(char *speedstring, //
k for check_key routine return value k (if not 0 nor -1)
speed_string[0] != 0 on return if string is present
*/
int full_screen_choice(
int options,
char const *hdg,
char const *hdg2,
char const *instr,
int num_choices,
char const **choices,
int *attributes,
int box_width,
int box_depth,
int col_width,
int current,
void (*format_item)(int choice, char *buf),
char *speed_string,
int full_screen_choice(ChoiceFlags flags, char const *hdg, char const *hdg2, char const *instr,
int num_choices, char const **choices, int *attributes, int box_width, int box_depth, int col_width,
int current, void (*format_item)(int choice, char *buf), char *speed_string,
int (*speed_prompt)(int row, int col, int vid, char const *speed_string, int speed_match),
int (*check_key)(int key, int choice)
)
int (*check_key)(int key, int choice))
{
const int scrunch = (options & CHOICE_CRUNCH) ? 1 : 0; // scrunch up a line
const int scrunch = bit_set(flags, ChoiceFlags::CRUNCH) ? 1 : 0; // scrunch up a line
ValueSaver saved_look_at_mouse{g_look_at_mouse, +MouseLook::IGNORE_MOUSE};
int ret = -1;
// preset current to passed string
int const speed_len = (speed_string == nullptr) ? 0 : (int) std::strlen(speed_string);
if (speed_len > 0)
{
current = 0;
if (options & CHOICE_NOT_SORTED)
if (bit_set(flags, ChoiceFlags::NOT_SORTED))
{
int k;
while (current < num_choices && (k = strncasecmp(speed_string, choices[current], speed_len)) != 0)
Expand Down Expand Up @@ -279,7 +269,7 @@ int full_screen_choice(
++reqdrows;
}
}
if ((options & CHOICE_INSTRUCTIONS)) // show std instr too
if (bit_set(flags , ChoiceFlags::INSTRUCTIONS)) // show std instr too
{
reqdrows += 2;
}
Expand Down Expand Up @@ -382,7 +372,7 @@ int full_screen_choice(
int speedrow = 0; // speed key prompt
{
int i = topleftrow + box_depth + 1;
if (instr == nullptr || (options & CHOICE_INSTRUCTIONS)) // display default instructions
if (instr == nullptr || bit_set(flags, ChoiceFlags::INSTRUCTIONS)) // display default instructions
{
if (i < 20)
{
Expand All @@ -398,7 +388,7 @@ int full_screen_choice(
}
}
i -= scrunch;
footer_msg(&i, options, speed_string);
footer_msg(&i, flags, speed_string);
}
if (instr) // display caller's instructions
{
Expand Down Expand Up @@ -735,8 +725,8 @@ int full_screen_choice(
ret = -1;
if (speed_string)
{
process_speed_string(speed_string, choices, curkey, &current,
num_choices, options & CHOICE_NOT_SORTED);
process_speed_string(speed_string, choices, curkey, &current, num_choices,
bit_set(flags, ChoiceFlags::NOT_SORTED));
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion libid/get_3d_params.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ int get_3d_params() // prompt for 3D parameters
int i;
{
ValueSaver saved_help_mode{g_help_mode, HelpLabels::HELP_3D_FILL};
i = full_screen_choice(CHOICE_HELP, "Select 3D Fill Type", nullptr, nullptr, k, choices,
i = full_screen_choice(ChoiceFlags::HELP, "Select 3D Fill Type", nullptr, nullptr, k, choices,
attributes, 0, 0, 0, +g_fill_type + 1, nullptr, nullptr, nullptr, nullptr);
}
if (i < 0)
Expand Down
6 changes: 3 additions & 3 deletions libid/get_a_filename.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,9 @@ bool get_a_file_name(char const *hdg, char const *file_template, std::string &fl
}
}

i = full_screen_choice(CHOICE_INSTRUCTIONS | (dosort ? 0 : CHOICE_NOT_SORTED),
heading.c_str(), nullptr, instr, filecount, (char const **) choices,
attributes, 0, 99, 0, i, nullptr, speedstr, filename_speed_str, check_f6_key);
i = full_screen_choice(ChoiceFlags::INSTRUCTIONS | (dosort ? ChoiceFlags::NONE : ChoiceFlags::NOT_SORTED),
heading.c_str(), nullptr, instr, filecount, (char const **) choices, attributes, 0, 99, 0, i, nullptr,
speedstr, filename_speed_str, check_f6_key);
if (i == -ID_KEY_F4)
{
dosort = !dosort;
Expand Down
6 changes: 3 additions & 3 deletions libid/get_fract_type.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -158,10 +158,10 @@ static FractalType select_fract_type(FractalType t)
}

tname[0] = 0;
const int done = full_screen_choice(CHOICE_HELP | CHOICE_INSTRUCTIONS,
const int done = full_screen_choice(ChoiceFlags::HELP | ChoiceFlags::INSTRUCTIONS,
g_julibrot ? "Select Orbit Algorithm for Julibrot" : "Select a Fractal Type", nullptr,
"Press F2 for a description of the highlighted type", numtypes, (char const **) choices,
attributes, 0, 0, 0, j, nullptr, tname, nullptr, sel_fract_type_help);
"Press F2 for a description of the highlighted type", numtypes, (char const **) choices, attributes,
0, 0, 0, j, nullptr, tname, nullptr, sel_fract_type_help);
FractalType result = FractalType::NOFRACTAL;
if (done >= 0)
{
Expand Down
6 changes: 3 additions & 3 deletions libid/get_video_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,10 @@ int get_video_mode(FractalInfo *info, ExtBlock3 *blk_3_info)
int i;
{
ValueSaver saved_help_mode{g_help_mode, HelpLabels::HELP_LOADFILE};
i = full_screen_choice(0, heading,
i = full_screen_choice(ChoiceFlags::NONE, heading,
"key...name......................err...xdot..ydot.clr.comment..................",
instructions.c_str(), g_video_table_len, nullptr, &attributes[0], 1, 13, 78, 0,
format_item, nullptr, nullptr, check_mode_key);
instructions.c_str(), g_video_table_len, nullptr, &attributes[0], 1, 13, 78, 0, format_item,
nullptr, nullptr, check_mode_key);
}
if (i == -1)
{
Expand Down
64 changes: 40 additions & 24 deletions libid/include/full_screen_choice.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,30 +7,46 @@
extern std::string const g_speed_prompt;

// fullscreen_choice options
enum ChoiceFlags
enum class ChoiceFlags
{
CHOICE_RETURN_KEY = 1,
CHOICE_MENU = 2,
CHOICE_HELP = 4,
CHOICE_INSTRUCTIONS = 8,
CHOICE_CRUNCH = 16,
CHOICE_NOT_SORTED = 32
NONE = 0,
MENU = 2,
HELP = 4,
INSTRUCTIONS = 8,
CRUNCH = 16,
NOT_SORTED = 32
};
inline int operator+(ChoiceFlags value)
{
return static_cast<int>(value);
}
inline ChoiceFlags operator&(ChoiceFlags lhs, ChoiceFlags rhs)
{
return static_cast<ChoiceFlags>(+lhs & +rhs);
}
inline ChoiceFlags &operator&=(ChoiceFlags &lhs, ChoiceFlags rhs)
{
lhs = lhs & rhs;
return lhs;
}
inline ChoiceFlags operator|(ChoiceFlags lhs, ChoiceFlags rhs)
{
return static_cast<ChoiceFlags>(+lhs | +rhs);
}
inline ChoiceFlags &operator|=(ChoiceFlags &lhs, ChoiceFlags rhs)
{
lhs = lhs | rhs;
return lhs;
}
inline bool bit_set(ChoiceFlags lhs, ChoiceFlags rhs)
{
return (lhs & rhs) == rhs;
}

int full_screen_choice(
int options,
char const *hdg,
char const *hdg2,
char const *instr,
int num_choices,
char const **choices,
int *attributes,
int box_width,
int box_depth,
int col_width,
int current,
void (*format_item)(int, char*),
char *speed_string,
int (*speed_prompt)(int row, int col, int vid, char const *speedstring, int speed_match),
int (*check_key)(int, int)
);
int full_screen_choice(ChoiceFlags flags, //
char const *hdg, char const *hdg2, char const *instr, //
int num_choices, char const **choices, int *attributes, //
int box_width, int box_depth, int col_width, //
int current, void (*format_item)(int, char *), char *speed_string,
int (*speed_prompt)(int row, int col, int vid, char const *speedstring, int speed_match), //
int (*check_key)(int, int));
2 changes: 1 addition & 1 deletion libid/main_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ int MainMenu::prompt()
{
m_next_left = m_next_right + 1;
}
i = full_screen_choice(CHOICE_MENU | CHOICE_CRUNCH, "MAIN MENU", nullptr, nullptr, m_next_left,
i = full_screen_choice(ChoiceFlags::MENU | ChoiceFlags::CRUNCH, "MAIN MENU", nullptr, nullptr, m_next_left,
m_choices, m_attributes, 2, m_next_left / 2, 29, 0, nullptr, nullptr, nullptr, menu_check_key);
if (i == -1) // escape
{
Expand Down
5 changes: 2 additions & 3 deletions libid/select_video_mode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,9 @@ int select_video_mode(int curmode)
ValueSaver saved_tab_mode{g_tab_mode, false};
ValueSaver saved_help_mode{g_help_mode, HelpLabels::HELP_VIDEO_MODE};
s_modes_changed = false;
i = full_screen_choice(CHOICE_HELP, "Select Video Mode",
i = full_screen_choice(ChoiceFlags::HELP, "Select Video Mode",
"key...name..........xdot..ydot.colr.driver......comment......", nullptr, g_video_table_len,
nullptr, attributes.data(), 1, 16, 74, i, format_vid_table, nullptr, nullptr,
check_mode_key);
nullptr, attributes.data(), 1, 16, 74, i, format_vid_table, nullptr, nullptr, check_mode_key);
}
if (i == -1)
{
Expand Down

0 comments on commit 947bc69

Please sign in to comment.