Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Dealt with some suggestions. re-astyled some files
Browse files Browse the repository at this point in the history
katemonster33 committed Jan 1, 2024

Verified

This commit was signed with the committer’s verified signature.
Exirel Florian Strzelecki
1 parent d4c37f3 commit 78ddbed
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
@@ -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 ) );
@@ -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++ ) {
@@ -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;
}
}
@@ -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() );
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 )
@@ -633,14 +633,14 @@ void cataimgui::popup::draw()
{
ImGui::PushOverrideID( popup_id );
auto bounds = get_bounds();
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 ) ) {
206 changes: 103 additions & 103 deletions src/cata_imgui.h
Original file line number Diff line number Diff line change
@@ -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))
@@ -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

2 changes: 1 addition & 1 deletion src/color.cpp
Original file line number Diff line number Diff line change
@@ -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()
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
@@ -60,7 +60,7 @@
# include <unistd.h> // getpid()
#endif

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

#if defined(PREFIX)
# undef PREFIX
@@ -166,7 +166,7 @@ void exit_handler( int s )
} else
#endif
{
delete imclient;
imclient.reset();
exit( exit_status );
}
}
4 changes: 2 additions & 2 deletions src/ncurses_def.cpp
Original file line number Diff line number Diff line change
@@ -36,7 +36,7 @@
#include "output.h"
#include "ui_manager.h"

cataimgui::client *imclient = nullptr;
std::unique_ptr<cataimgui::client> imclient;

static void curses_check_result( const int result, const int expected, const char *const /*name*/ )
{
@@ -336,7 +336,7 @@ void catacurses::init_interface()
set_escdelay( 10 ); // Make Escape actually responsive
// TODO: error checking
start_color();
imclient = new cataimgui::client();
imclient = std::make_unique<cataimgui::client>();
init_colors();
#if !defined(__CYGWIN__)
// ncurses mouse registration
6 changes: 3 additions & 3 deletions src/sdltiles.cpp
Original file line number Diff line number Diff line change
@@ -74,7 +74,7 @@
#include "wcwidth.h"
#include "cata_imgui.h"

cataimgui::client *imclient = nullptr;
std::unique_ptr<cataimgui::client> imclient;

#if defined(__linux__)
# include <cstdlib> // getenv()/setenv()
@@ -433,7 +433,7 @@ static void WinCreate()

cataimgui::client::sdl_renderer = renderer.get();
cataimgui::client::sdl_window = window.get();
imclient = new cataimgui::client();
imclient = std::make_unique<cataimgui::client>();

//io.Fonts->AddFontDefault();
//io.Fonts->Build();
@@ -444,7 +444,7 @@ static void WinDestroy()
#if defined(__ANDROID__)
touch_joystick.reset();
#endif
delete imclient;
imclient.reset();
shutdown_sound();
tilecontext.reset();
gamepad::quit();
4 changes: 2 additions & 2 deletions src/ui_manager.cpp
Original file line number Diff line number Diff line change
@@ -335,7 +335,7 @@ void ui_adaptor::redraw()
redraw_invalidated();
}

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

void ui_adaptor::redraw_invalidated( bool draw_imgui )
{
@@ -440,7 +440,7 @@ void ui_adaptor::redraw_invalidated( bool draw_imgui )
ui.invalidated = false;
}
}
if( ui.is_imgui && draw_imgui && ( !ui.is_imgui || imgui_is_on_top ) ) {
if( ui.is_imgui && draw_imgui && imgui_is_on_top ) {
if( ui.redraw_cb ) {
ui.redraw_cb( ui );
}
2 changes: 1 addition & 1 deletion src/ui_manager.h
Original file line number Diff line number Diff line change
@@ -98,7 +98,7 @@ class ui_adaptor
explicit ui_adaptor( debug_message_ui );
ui_adaptor( const ui_adaptor &rhs ) = delete;
ui_adaptor( ui_adaptor &&rhs ) = delete;
virtual ~ui_adaptor();
~ui_adaptor();

ui_adaptor &operator=( const ui_adaptor &rhs ) = delete;
ui_adaptor &operator=( ui_adaptor &&rhs ) = delete;

0 comments on commit 78ddbed

Please sign in to comment.