Skip to content

Commit

Permalink
Fixed various drawing issues. Fixed drag-drop broken after showing popup
Browse files Browse the repository at this point in the history
  • Loading branch information
katemonster33 committed Dec 14, 2023
1 parent 7056dc5 commit 954c207
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 19 deletions.
21 changes: 14 additions & 7 deletions src/cata_imgui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,8 +112,11 @@ void cataimgui::client::process_input( void *input )
}
imtui_events.push_back( std::pair<int, ImTui::mouse_event>( KEY_MOUSE, new_mouse_event ) );
} else {
imtui_events.push_back( std::pair<int, ImTui::mouse_event>( curses_input->get_first_input(),
new_mouse_event ) );
int ch = curses_input->get_first_input();
if(ch != UNKNOWN_UNICODE)
{
imtui_events.push_back( std::pair<int, ImTui::mouse_event>(ch, new_mouse_event ) );
}
}
}
}
Expand Down Expand Up @@ -256,7 +259,7 @@ void cataimgui::window::draw_colored_text( std::string const &text, nc_color &co
}
}
size_t chars_to_print = seg.length() - current_seg_index;
if( alignment != text_align::Left ) {
if( alignment == text_align::Left ) {
chars_to_print = std::min( chars_per_line - current_x, chars_to_print );
}
#if !(defined(TILES) || defined(WIN32))
Expand Down Expand Up @@ -426,6 +429,7 @@ cataimgui::window::window( int window_flags )

this->window_flags = window_flags | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize |
ImGuiWindowFlags_NoSavedSettings;
open_popup_requested = false;
parent = nullptr;
}

Expand Down Expand Up @@ -495,6 +499,7 @@ void cataimgui::window::draw()
if( active_popup ) {
if( open_popup_requested ) {
active_popup->open();
open_popup_requested = false;
}
if( active_popup->is_open ) {
active_popup->draw();
Expand All @@ -520,11 +525,13 @@ void cataimgui::window::draw()
/// <param name="next_popup">the popup to be shown</param>
void cataimgui::window::show_popup_async( const std::shared_ptr<popup> &next_popup )
{
open_popup_requested = true;
this->active_popup = next_popup;
}

void cataimgui::window::show_popup_async( popup *next_popup )
{
open_popup_requested = true;
this->active_popup.reset( next_popup );
}

Expand Down Expand Up @@ -625,6 +632,8 @@ void cataimgui::popup::draw()
#else
ImGui::SetNextWindowSize( { 50, 0 } );
#endif
ImGui::SetNextWindowPos(ImVec2(ImGui::GetIO().DisplaySize.x * 0.5f, ImGui::GetIO().DisplaySize.y * 0.5f), ImGuiCond_Always, ImVec2(0.5f,0.5f));

if( is_modal ) {
if( ImGui::BeginPopupModal( id.c_str(), &is_open, ImGuiWindowFlags_AlwaysAutoResize ) ) {
draw_controls();
Expand Down Expand Up @@ -653,7 +662,6 @@ void cataimgui::popup::open()
void cataimgui::popup::close()
{
is_open = false;
ImGui::CloseCurrentPopup();
}

cataimgui::dialog_result cataimgui::popup::get_result()
Expand All @@ -667,8 +675,7 @@ bool cataimgui::popup::is_draw_callback_set()
}

cataimgui::message_box::message_box( const std::string &title,
const std::string &prompt, cataimgui::mbox_btn buttons ) : cataimgui::popup( title,
true )
const std::string &prompt, cataimgui::mbox_btn buttons ) : cataimgui::popup( title, true )
{
this->buttons = buttons;
this->prompt = prompt;
Expand Down Expand Up @@ -698,7 +705,7 @@ void cataimgui::message_box::draw_controls()
{
ImGui::Indent( 1.0f );
nc_color tcolor = c_light_gray;
draw_colored_text( prompt, tcolor );
draw_colored_text( prompt, tcolor, cataimgui::text_align::Left, ImGui::GetContentRegionAvail().x );
ImGui::Unindent( 1.0f );
if( ImGui::IsKeyDown( ImGuiKey_Escape ) ) {
if( buttons == mbox_btn::BT_OKCancel || buttons == mbox_btn::BT_YesNoCancel ) {
Expand Down
5 changes: 3 additions & 2 deletions src/ncurses_def.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -467,8 +467,9 @@ input_event input_manager::get_input_event( const keyboard_mode /*preferred_keyb
// Other control character, etc. - no text at all, return an event
// without the text property
previously_pressed_key = key;
imclient->process_input( &rval );
return input_event( key, input_event_t::keyboard_char );
input_event tmp_event( key, input_event_t::keyboard_char );
imclient->process_input( &tmp_event );
return tmp_event;
}
// Now we have loaded an UTF-8 sequence (possibly several bytes)
// but we should only return *one* key, so return the code point of it.
Expand Down
25 changes: 15 additions & 10 deletions src/trade_ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,25 @@ trade_ui::trade_result_t trade_ui::perform_trade()
{
_exit = false;
_traded = false;
inventory_entry *last_focused_entry = nullptr;
while( !_exit ) {
#if !(defined(WIN32) || defined(TILES))
ui_adaptor::redraw_all_invalidated( true );
#endif
bool no_auto_cpane_switch = false;
_panes[_cpane]->execute();

while( !_queue.empty() ) {
no_auto_cpane_switch = true;
event const ev = _queue.front();
_queue.pop();
_process( ev );
}
for( int new_cpane = 0; new_cpane < 2;
new_cpane++ ) { // selected entry belongs to this pane? break - we've figured out the selected pane
if( _panes[new_cpane]->mouse_hovered_entry != nullptr &&
_panes[new_cpane]->mouse_hovered_entry->is_item() ) {
_cpane = new_cpane;
break;
if(!no_auto_cpane_switch)
{
for( int new_cpane = 0; new_cpane < 2;
new_cpane++ ) { // selected entry belongs to this pane? break - we've figured out the selected pane
if( _panes[new_cpane]->mouse_hovered_entry != nullptr &&
_panes[new_cpane]->mouse_hovered_entry->is_item() ) {
_cpane = new_cpane;
break;
}
}
}
}
Expand Down Expand Up @@ -347,6 +348,7 @@ trade_selector::trade_selector( trade_ui *parent, Character &u,
_ctxt_trade.register_action( "MOUSE_MOVE" );

_ctxt_trade.register_action( "ANY_INPUT" );
_ctxt_trade.set_timeout(0);
// duplicate this action in the parent ctxt so it shows up in the keybindings menu
// CANCEL and OK are already set in inventory_selector
ctxt.register_action( ACTION_SWITCH_PANES );
Expand All @@ -371,6 +373,9 @@ void trade_selector::execute()
columns[0]->on_activate();

while( !exit ) {
#if !(defined(WIN32) || defined(TILES))
ui_adaptor::redraw_all_invalidated( true );
#endif
std::string const &action = _ctxt_trade.handle_input();
if( !is_open ) {
break;
Expand Down

0 comments on commit 954c207

Please sign in to comment.