Skip to content

Commit

Permalink
Dealt with some suggestions. re-astyled some files
Browse files Browse the repository at this point in the history
  • Loading branch information
katemonster33 committed Jan 1, 2024
1 parent 2510ed8 commit c833b9a
Show file tree
Hide file tree
Showing 8 changed files with 156 additions and 156 deletions.
84 changes: 42 additions & 42 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,26 +93,26 @@ void cataimgui::client::process_input( void *input )
new_mouse_event.bstate = 0;
for( int input_raw_key : curses_input->sequence ) {
switch( static_cast<MouseInput>( input_raw_key ) ) {
case MouseInput::LeftButtonPressed:
new_mouse_event.bstate |= BUTTON1_PRESSED;
break;
case MouseInput::LeftButtonReleased:
new_mouse_event.bstate |= BUTTON1_RELEASED;
break;
case MouseInput::RightButtonPressed:
new_mouse_event.bstate |= BUTTON3_PRESSED;
break;
case MouseInput::RightButtonReleased:
new_mouse_event.bstate |= BUTTON3_RELEASED;
break;
case MouseInput::ScrollWheelUp:
new_mouse_event.bstate |= BUTTON4_PRESSED;
break;
case MouseInput::ScrollWheelDown:
new_mouse_event.bstate |= BUTTON5_PRESSED;
break;
default:
break;
case MouseInput::LeftButtonPressed:
new_mouse_event.bstate |= BUTTON1_PRESSED;
break;
case MouseInput::LeftButtonReleased:
new_mouse_event.bstate |= BUTTON1_RELEASED;
break;
case MouseInput::RightButtonPressed:
new_mouse_event.bstate |= BUTTON3_PRESSED;
break;
case MouseInput::RightButtonReleased:
new_mouse_event.bstate |= BUTTON3_RELEASED;
break;
case MouseInput::ScrollWheelUp:
new_mouse_event.bstate |= BUTTON4_PRESSED;
break;
case MouseInput::ScrollWheelDown:
new_mouse_event.bstate |= BUTTON5_PRESSED;
break;
default:
break;
}
}
imtui_events.push_back( std::pair<int, ImTui::mouse_event>( KEY_MOUSE, new_mouse_event ) );
Expand Down Expand Up @@ -316,7 +316,7 @@ int cataimgui::window::draw_item_info_data( item_info_data &data )
}
// If type name is set, and not already contained in item name, output it too
if( !data.get_type_name().empty() &&
data.get_item_name().find( data.get_type_name() ) == std::string::npos ) {
data.get_item_name().find( data.get_type_name() ) == std::string::npos ) {
buffer += data.get_type_name() + "\n";
}
for( unsigned int i = 0; i < data.padding; i++ ) {
Expand Down Expand Up @@ -373,8 +373,8 @@ int cataimgui::window::draw_item_info_data( item_info_data &data )
action = ctxt.handle_input();

if( action == "CONFIRM" || action == "QUIT" ||
( data.any_input && action == "ANY_INPUT" &&
!ctxt.get_raw_input().sequence.empty() ) ) {
( data.any_input && action == "ANY_INPUT" &&
!ctxt.get_raw_input().sequence.empty() ) ) {
break;
}
}
Expand Down Expand Up @@ -408,23 +408,23 @@ bool cataimgui::window::is_child_window_navigated()

class cataimgui::window_impl : public ui_adaptor
{
friend class cataimgui::window;
cataimgui::window *win_base;
bool is_resized;
std::unique_ptr<ui_adaptor> window_adaptor;
public:
explicit window_impl( cataimgui::window *win ) {
win_base = win;
is_resized = true;
window_adaptor.reset( new ui_adaptor() );
window_adaptor->is_imgui = true;
window_adaptor->on_redraw( [this]( ui_adaptor & ) {
win_base->draw();
} );
window_adaptor->on_screen_resize( [this]( ui_adaptor & ) {
friend class cataimgui::window;
cataimgui::window *win_base;
bool is_resized;
std::unique_ptr<ui_adaptor> window_adaptor;
public:
explicit window_impl( cataimgui::window *win ) {
win_base = win;
is_resized = true;
} );
}
window_adaptor.reset( new ui_adaptor() );

Check failure on line 419 in src/cata_imgui.cpp

View workflow job for this annotation

GitHub Actions / build (src)

use std::make_unique instead [modernize-make-unique,-warnings-as-errors]
window_adaptor->is_imgui = true;
window_adaptor->on_redraw( [this]( ui_adaptor & ) {
win_base->draw();
} );
window_adaptor->on_screen_resize( [this]( ui_adaptor & ) {
is_resized = true;
} );
}
};

cataimgui::window::window( int window_flags )
Expand Down Expand Up @@ -633,14 +633,14 @@ void cataimgui::popup::draw()
{
ImGui::PushOverrideID( popup_id );
auto bounds = get_bounds();

Check failure on line 635 in src/cata_imgui.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Avoid auto in declaration of 'bounds'. [cata-almost-never-auto,-warnings-as-errors]
if(bounds.x >=0 || bounds.y >= 0) {
if( bounds.x >= 0 || bounds.y >= 0 ) {
ImGui::SetNextWindowPos( {bounds.x, bounds.y} );
} else {
ImGui::SetNextWindowPos( ImVec2( ImGui::GetIO().DisplaySize.x * 0.5f,
ImGui::GetIO().DisplaySize.y * 0.5f ), ImGuiCond_Always, ImVec2( 0.5f, 0.5f ) );
}
if(bounds.h >= 0 || bounds.w >= 0) {
ImGui::SetNextWindowSize({bounds.h, bounds.w});
if( bounds.h >= 0 || bounds.w >= 0 ) {
ImGui::SetNextWindowSize( {bounds.h, bounds.w} );
}
if( is_modal ) {
if( ImGui::BeginPopupModal( id.c_str(), &is_open, ImGuiWindowFlags_AlwaysAutoResize ) ) {
Expand Down
206 changes: 103 additions & 103 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,65 +45,65 @@ enum class text_align {

class client
{
public:
client();
~client();
public:
client();
~client();

void new_frame();
void end_frame();
void process_input( void *input );
void new_frame();
void end_frame();
void process_input( void *input );
#if !(defined(TILES) || defined(WIN32))
void upload_color_pair( int p, int f, int b );
void set_alloced_pair_count( short count );
void upload_color_pair( int p, int f, int b );
void set_alloced_pair_count( short count );
#else
static struct SDL_Renderer *sdl_renderer;
static struct SDL_Window *sdl_window;
static struct SDL_Renderer *sdl_renderer;
static struct SDL_Window *sdl_window;
#endif
};

class window
{
friend class child_window;
class window_impl *p_impl;
std::shared_ptr<class popup> active_popup;
std::vector<window *> children;
window *parent;
bool open_popup_requested;
dialog_result last_popup_result;
bounds cached_bounds;
protected:
explicit window( int window_flags = 0 );
explicit window( window *parent, int window_flags = 0 );
public:
explicit window( const std::string &title, int window_flags = 0 );
virtual ~window();
void draw_colored_text( std::string const &text, const nc_color &color,
text_align alignment = text_align::Left, float max_width = 0.0F, bool *is_selected = nullptr,
bool *is_focused = nullptr, bool *is_hovered = nullptr );
void draw_colored_text( std::string const &text, nc_color &color,
text_align alignment = text_align::Left, float max_width = 0.0F, bool *is_selected = nullptr,
bool *is_focused = nullptr, bool *is_hovered = nullptr );
bool action_button( const std::string &action, const std::string &text );
void draw_header( std::string const &text );
bool get_is_open() const;
void set_title( const std::string &title );
bool is_child_window_navigated();
void show_popup_async( popup *next_popup );
dialog_result show_popup( popup *next_popup );
void show_popup_async( const std::shared_ptr<popup> &next_popup );
dialog_result show_popup( const std::shared_ptr<popup> &next_popup );
virtual void draw();
bool is_resized();

protected:
bool is_open;
std::string id;
int window_flags;
virtual bounds get_bounds();
virtual void draw_controls() = 0;
int draw_item_info_data( item_info_data &data );

void add_child( window *child );
friend class child_window;
class window_impl *p_impl;
std::shared_ptr<class popup> active_popup;
std::vector<window *> children;
window *parent;
bool open_popup_requested;
dialog_result last_popup_result;
bounds cached_bounds;
protected:
explicit window( int window_flags = 0 );
explicit window( window *parent, int window_flags = 0 );
public:
explicit window( const std::string &title, int window_flags = 0 );
virtual ~window();
void draw_colored_text( std::string const &text, const nc_color &color,
text_align alignment = text_align::Left, float max_width = 0.0F, bool *is_selected = nullptr,
bool *is_focused = nullptr, bool *is_hovered = nullptr );
void draw_colored_text( std::string const &text, nc_color &color,
text_align alignment = text_align::Left, float max_width = 0.0F, bool *is_selected = nullptr,
bool *is_focused = nullptr, bool *is_hovered = nullptr );
bool action_button( const std::string &action, const std::string &text );
void draw_header( std::string const &text );
bool get_is_open() const;
void set_title( const std::string &title );
bool is_child_window_navigated();
void show_popup_async( popup *next_popup );
dialog_result show_popup( popup *next_popup );
void show_popup_async( const std::shared_ptr<popup> &next_popup );
dialog_result show_popup( const std::shared_ptr<popup> &next_popup );
virtual void draw();
bool is_resized();

protected:
bool is_open;
std::string id;
int window_flags;
virtual bounds get_bounds();
virtual void draw_controls() = 0;
int draw_item_info_data( item_info_data &data );

void add_child( window *child );
};

#if !(defined(TILES) || defined(WIN32))
Expand All @@ -114,69 +114,69 @@ bool is_drag_drop_active();

class popup : public window
{
friend class window;
class popup_impl *p_impl;
bool is_modal;
std::function<bool()> on_draw_callback;
public:
popup( const std::string &id, bool is_modal );
popup( const std::string &id, bool is_modal, const std::function<bool()> &on_draw_callback );
~popup() override;

void draw() override;
void set_draw_callback( const std::function<bool()> &callback );
void close();
dialog_result get_result();
bool is_draw_callback_set();

protected:
dialog_result result;
void open();
friend class window;
class popup_impl *p_impl;
bool is_modal;
std::function<bool()> on_draw_callback;
public:
popup( const std::string &id, bool is_modal );
popup( const std::string &id, bool is_modal, const std::function<bool()> &on_draw_callback );
~popup() override;

void draw() override;
void set_draw_callback( const std::function<bool()> &callback );
void close();
dialog_result get_result();
bool is_draw_callback_set();

protected:
dialog_result result;
void open();
};
class message_box : public popup
{
mbox_btn buttons;
std::string prompt;
public:
message_box( const std::string &title, const std::string &prompt,
mbox_btn buttons = mbox_btn::BT_OK );
static dialog_result show( const std::string &title, const std::string &text );
protected:
void draw_mbox_btn( const std::string &text, dialog_result result_if_clicked );
void draw_controls() override;
bounds get_bounds() override;
mbox_btn buttons;
std::string prompt;
public:
message_box( const std::string &title, const std::string &prompt,
mbox_btn buttons = mbox_btn::BT_OK );
static dialog_result show( const std::string &title, const std::string &text );
protected:
void draw_mbox_btn( const std::string &text, dialog_result result_if_clicked );
void draw_controls() override;
bounds get_bounds() override;
};

class string_input_box : public popup
{
std::string prompt;
std::array<char, 100> input;
public:
string_input_box( const std::string &title, const std::string &prompt );
static dialog_result show( const std::string &prompt, std::string &input );
std::string get_input();
protected:
void draw_controls() override;
std::string prompt;
std::array<char, 100> input;
public:
string_input_box( const std::string &title, const std::string &prompt );
static dialog_result show( const std::string &prompt, std::string &input );
std::string get_input();
protected:
void draw_controls() override;
};

class list_selector : public popup
{
std::string prompt;
int selected_index;
public:
struct litem {
std::string text;
bool is_enabled;
bool is_selected;
};

explicit list_selector( const std::string &id );
void add( const litem &it );
void add( std::initializer_list<litem> &items );
int get_selected_index() const;
protected:
void draw_controls() override;
std::vector<litem> items;
std::string prompt;
int selected_index;
public:
struct litem {
std::string text;
bool is_enabled;
bool is_selected;
};

explicit list_selector( const std::string &id );
void add( const litem &it );
void add( std::initializer_list<litem> &items );
int get_selected_index() const;
protected:
void draw_controls() override;
std::vector<litem> items;
};
} // namespace cataimgui

Expand Down
2 changes: 1 addition & 1 deletion src/color.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ nc_color color_manager::highlight_from_names( const std::string &name,
}

#if !(defined(TILES) || defined(WIN32))
extern cataimgui::client *imclient;
extern std::unique_ptr<cataimgui::client> imclient;
#endif

void color_manager::load_default()
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
# include <unistd.h> // getpid()
#endif

extern cataimgui::client *imclient;
extern std::unique_ptr<cataimgui::client> imclient;

Check failure on line 63 in src/main.cpp

View workflow job for this annotation

GitHub Actions / build (src)

Prefer including a header to making a local extern declaration of 'imclient'. [cata-static-declarations,-warnings-as-errors]

#if defined(PREFIX)
# undef PREFIX
Expand Down Expand Up @@ -166,7 +166,7 @@ void exit_handler( int s )
} else
#endif
{
delete imclient;
imclient.reset();
exit( exit_status );
}
}
Expand Down
Loading

0 comments on commit c833b9a

Please sign in to comment.