Skip to content

Commit

Permalink
Various fixes
Browse files Browse the repository at this point in the history
- Fix UI rotation regression
- Separate UI transform from layout transform
- [macOS] try to fix crashes on Apple Silicon
  • Loading branch information
oomek committed Jul 5, 2023
1 parent 8a842e7 commit 4744d55
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 45 deletions.
34 changes: 13 additions & 21 deletions src/fe_overlay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,9 @@ FeOverlay::FeOverlay( FeWindow &wnd,
m_headingBgColour( sf::Color( 10, 20, 40, 255 ) ),
m_overlay_is_on( false )
{
init_font_sizes();
}

void FeOverlay::init_font_sizes()
void FeOverlay::init()
{
m_screen_size = m_fePresent.get_screen_size();
float scale_x = m_fePresent.get_layout_scale_x();
Expand Down Expand Up @@ -271,7 +270,7 @@ void FeOverlay::splash_message( const std::string &msg,

extra.setString( aux );

const sf::Transform &t = m_fePresent.get_transform();
const sf::Transform &t = m_fePresent.get_ui_transform();

// Process tick only when Layout is fully loaded
if ( m_fePresent.is_layout_loaded() )
Expand All @@ -280,10 +279,8 @@ void FeOverlay::splash_message( const std::string &msg,
m_wnd.clear();
m_wnd.draw( m_fePresent, t );
m_wnd.draw( bg );
// m_wnd.draw( message, t );
m_wnd.draw( message );
// m_wnd.draw( extra, t );
m_wnd.draw( extra );
m_wnd.draw( message, t );
m_wnd.draw( extra, t );
m_wnd.display();
}

Expand Down Expand Up @@ -796,7 +793,7 @@ void FeOverlay::input_map_dialog(
FeInputMapEntry entry;
sf::Clock timeout;

const sf::Transform &t = m_fePresent.get_transform();
const sf::Transform &t = m_fePresent.get_ui_transform();
while ( m_wnd.isOpen() )
{
while (m_wnd.pollEvent(ev))
Expand Down Expand Up @@ -874,8 +871,7 @@ void FeOverlay::input_map_dialog(

m_wnd.clear();
m_wnd.draw( m_fePresent, t );
// m_wnd.draw( message, t );
m_wnd.draw( message );
m_wnd.draw( message, t );
m_wnd.display();
redraw = false;
}
Expand Down Expand Up @@ -1299,7 +1295,7 @@ void FeOverlay::init_event_loop( FeEventLoopCtx &ctx )
// Make sure the Back and Select buttons are NOT down, to avoid immediately
// triggering an exit/selection
//
const sf::Transform &t = m_fePresent.get_transform();
const sf::Transform &t = m_fePresent.get_ui_transform();

sf::Clock timer;
while (( timer.getElapsedTime() < sf::seconds( 6 ) )
Expand All @@ -1320,8 +1316,7 @@ void FeOverlay::init_event_loop( FeEventLoopCtx &ctx )

for ( std::vector<sf::Drawable *>::const_iterator itr=ctx.draw_list.begin();
itr < ctx.draw_list.end(); ++itr )
// m_wnd.draw( *(*itr), t );
m_wnd.draw( *(*itr) );
m_wnd.draw( *(*itr), t );

m_wnd.display();
}
Expand All @@ -1336,7 +1331,7 @@ void FeOverlay::init_event_loop( FeEventLoopCtx &ctx )
//
bool FeOverlay::event_loop( FeEventLoopCtx &ctx )
{
const sf::Transform &t = m_fePresent.get_transform();
const sf::Transform &t = m_fePresent.get_ui_transform();

bool redraw=true;

Expand Down Expand Up @@ -1409,8 +1404,7 @@ bool FeOverlay::event_loop( FeEventLoopCtx &ctx )

for ( std::vector<sf::Drawable *>::const_iterator itr=ctx.draw_list.begin();
itr < ctx.draw_list.end(); ++itr )
// m_wnd.draw( *(*itr), t );
m_wnd.draw( *(*itr));
m_wnd.draw( *(*itr), t );

m_wnd.display();
redraw = false;
Expand Down Expand Up @@ -1617,7 +1611,7 @@ bool FeOverlay::edit_loop( std::vector<sf::Drawable *> d,
std::basic_string<sf::Uint32> &str, FeTextPrimitive *tp )
{
sf::Clock cursor_timer;
const sf::Transform &t = m_fePresent.get_transform();
const sf::Transform &t = m_fePresent.get_ui_transform();

const sf::Font *font = tp->getFont();
sf::Text cursor( "|", *font, tp->getCharacterSize() / tp->getTextScale().x );
Expand Down Expand Up @@ -1878,15 +1872,13 @@ bool FeOverlay::edit_loop( std::vector<sf::Drawable *> d,

for ( std::vector<sf::Drawable *>::iterator itr=d.begin();
itr < d.end(); ++itr )
// m_wnd.draw( *(*itr), t );
m_wnd.draw( *(*itr) );
m_wnd.draw( *(*itr), t );

int cursor_fade = ( sin( cursor_timer.getElapsedTime().asMilliseconds() / 250.0 * M_PI ) + 1.0 ) * 255;

cursor.setFillColor( sf::Color( 255, 255, 255, std::max( 0, std::min( cursor_fade, 255 ))));

// m_wnd.draw( cursor, t );
m_wnd.draw( cursor );
m_wnd.draw( cursor, t );
m_wnd.display();

if ( !redraw && m_feSettings.get_info_bool( FeSettings::PowerSaving ) )
Expand Down
2 changes: 1 addition & 1 deletion src/fe_overlay.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ friend class FeConfigContextImp;
//
bool common_exit();

void init_font_sizes();
void init();
};

#endif
75 changes: 55 additions & 20 deletions src/fe_present.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ FePresent::FePresent( FeSettings *fesettings, FeWindow &wnd )
m_overlay_lb( NULL ),
m_layout_loaded( false )
{
m_baseRotation = m_feSettings->get_screen_rotation();
m_layoutFontName = "";
init_monitors();
}
Expand Down Expand Up @@ -404,7 +405,8 @@ void FePresent::clear()
// mute and toggle rotation are kept whenever the layout is changed
//
m_listBox=NULL; // listbox gets deleted with the m_mon.elements below
m_transform = sf::Transform();
m_layout_transform = sf::Transform();
m_ui_transform = sf::Transform();
m_layoutFont = NULL;
m_layoutFontName = "";
m_user_page_size = -1;
Expand Down Expand Up @@ -493,7 +495,7 @@ void FePresent::draw( sf::RenderTarget& target, sf::RenderStates states ) const
for ( unsigned int i=0; i<m_mon.size(); i++ )
{
// use m_transform on monitor 0
states.transform = i ? m_mon[i].transform : m_transform;
states.transform = i ? m_mon[i].transform : m_layout_transform;
for ( itl=m_mon[i].elements.begin(); itl != m_mon[i].elements.end(); ++itl )
{
if ( (*itl)->get_visible() )
Expand Down Expand Up @@ -1242,7 +1244,7 @@ void FePresent::redraw()
tick();

m_window.clear();
m_window.draw( *this, m_transform );
m_window.draw( *this, m_layout_transform );
m_window.display();
}

Expand Down Expand Up @@ -1382,7 +1384,12 @@ void FePresent::toggle_mute()

const sf::Transform &FePresent::get_transform() const
{
return m_transform;
return m_layout_transform;
}

const sf::Transform &FePresent::get_ui_transform() const
{
return m_ui_transform;
}

const sf::Font *FePresent::get_layout_font()
Expand Down Expand Up @@ -1425,7 +1432,7 @@ FeSettings::RotationState FePresent::get_actual_rotation()

void FePresent::set_transforms()
{
m_transform = m_mon[0].transform;
m_layout_transform = m_mon[0].transform;

FeSettings::RotationState actualRotation = get_actual_rotation();

Expand All @@ -1438,7 +1445,7 @@ void FePresent::set_transforms()
m_layoutScale.x = m_layoutScale.y = std::min( (float) m_mon[0].size.x / m_layoutSize.x, (float) m_mon[0].size.y / m_layoutSize.y );
float adjust_x = std::floor(( m_layoutSize.x * m_layoutScale.x - m_mon[0].size.x ) / 2.0 + 0.5 );
float adjust_y = std::floor(( m_layoutSize.y * m_layoutScale.y - m_mon[0].size.y ) / 2.0 + 0.5 );
m_transform.translate( -adjust_x, -adjust_y );
m_layout_transform.translate( -adjust_x, -adjust_y );
break;
}

Expand All @@ -1447,8 +1454,8 @@ void FePresent::set_transforms()
m_layoutScale.x = m_layoutScale.y = std::min( (float) m_mon[0].size.y / m_layoutSize.x, (float) m_mon[0].size.x / m_layoutSize.y );
float adjust_x = std::floor( std::abs( m_layoutSize.y * m_layoutScale.x - m_mon[0].size.x ) / 2 + 0.5 );
float adjust_y = std::floor( std::abs( m_layoutSize.x * m_layoutScale.y - m_mon[0].size.y ) / 2 + 0.5 );
m_transform.translate( m_mon[0].size.x - adjust_x, adjust_y );
m_transform.rotate(90);
m_layout_transform.translate( m_mon[0].size.x - adjust_x, adjust_y );
m_layout_transform.rotate(90);
break;
}

Expand All @@ -1457,8 +1464,8 @@ void FePresent::set_transforms()
m_layoutScale.x = m_layoutScale.y = std::min( (float) m_mon[0].size.y / m_layoutSize.x, (float) m_mon[0].size.x / m_layoutSize.y );
float adjust_x = std::floor( std::fabs( m_layoutSize.y * m_layoutScale.x - m_mon[0].size.x ) / 2 + 0.5 );
float adjust_y = std::floor( std::fabs( m_layoutSize.x * m_layoutScale.y - m_mon[0].size.y ) / 2 + 0.5 );
m_transform.translate( adjust_x, m_mon[0].size.y - adjust_y );
m_transform.rotate(270);
m_layout_transform.translate( adjust_x, m_mon[0].size.y - adjust_y );
m_layout_transform.rotate(270);
break;
}

Expand All @@ -1467,8 +1474,8 @@ void FePresent::set_transforms()
m_layoutScale.x = m_layoutScale.y = std::min( (float) m_mon[0].size.x / m_layoutSize.x, (float) m_mon[0].size.y / m_layoutSize.y );
float adjust_x = std::floor(( m_layoutSize.x * m_layoutScale.x - m_mon[0].size.x ) / 2.0 + 0.5 );
float adjust_y = std::floor(( m_layoutSize.y * m_layoutScale.y - m_mon[0].size.y ) / 2.0 + 0.5 );
m_transform.translate( m_mon[0].size.x + adjust_x, m_mon[0].size.y + adjust_y );
m_transform.rotate(180);
m_layout_transform.translate( m_mon[0].size.x + adjust_x, m_mon[0].size.y + adjust_y );
m_layout_transform.rotate(180);
break;
}
}
Expand All @@ -1483,33 +1490,58 @@ void FePresent::set_transforms()
break;

case FeSettings::RotateRight:
m_transform.translate( m_mon[0].size.x, 0 );
m_layout_transform.translate( m_mon[0].size.x, 0 );
m_layoutScale.x = (float) m_mon[0].size.y / m_layoutSize.x;
m_layoutScale.y = (float) m_mon[0].size.x / m_layoutSize.y;
m_transform.rotate(90);
m_layout_transform.rotate(90);
break;

case FeSettings::RotateLeft:
m_transform.translate( 0, m_mon[0].size.y );
m_layout_transform.translate( 0, m_mon[0].size.y );
m_layoutScale.x = (float) m_mon[0].size.y / m_layoutSize.x;
m_layoutScale.y = (float) m_mon[0].size.x / m_layoutSize.y;
m_transform.rotate(270);
m_layout_transform.rotate(270);
break;

case FeSettings::RotateFlip:
m_transform.translate( m_mon[0].size.x, m_mon[0].size.y );
m_layout_transform.translate( m_mon[0].size.x, m_mon[0].size.y );
m_layoutScale.x = (float) m_mon[0].size.x / m_layoutSize.x;
m_layoutScale.y = (float) m_mon[0].size.y / m_layoutSize.y;
m_transform.rotate(180);
m_layout_transform.rotate(180);
break;
}
}

m_transform.scale( m_layoutScale.x, m_layoutScale.y );
m_layout_transform.scale( m_layoutScale.x, m_layoutScale.y );

for ( std::vector<FeBasePresentable *>::iterator itr=m_mon[0].elements.begin();
itr!=m_mon[0].elements.end(); ++itr )
(*itr)->set_scale_factor( m_layoutScale.x, m_layoutScale.y );


// UI transform
m_ui_transform = m_mon[0].transform;

switch ( actualRotation )
{
case FeSettings::RotateNone:
break;

case FeSettings::RotateRight:
m_ui_transform.translate( m_mon[0].size.x, 0 );
m_ui_transform.rotate(90);
break;

case FeSettings::RotateLeft:
m_ui_transform.translate( 0, m_mon[0].size.y );
m_ui_transform.rotate(270);
break;

case FeSettings::RotateFlip:
m_ui_transform.translate( m_mon[0].size.x, m_mon[0].size.y );
m_ui_transform.rotate(180);
break;
}
}

FeShader *FePresent::get_empty_shader()
Expand Down Expand Up @@ -1642,5 +1674,8 @@ std::string FePresent::script_get_base_path()

const sf::Vector2i FePresent::get_screen_size()
{
return m_mon[0].size;
if ( get_actual_rotation() == FeSettings::RotateLeft || get_actual_rotation() == FeSettings::RotateRight )
return sf::Vector2i( m_mon[0].size.y, m_mon[0].size.x);
else
return m_mon[0].size;
}
4 changes: 3 additions & 1 deletion src/fe_present.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ class FePresent

FeSettings::RotationState m_baseRotation;
FeSettings::RotationState m_toggleRotation;
sf::Transform m_transform;
sf::Transform m_layout_transform;
sf::Transform m_ui_transform;

std::vector<FeBaseTextureContainer *> m_texturePool;
std::vector<FeSound *> m_sounds;
Expand Down Expand Up @@ -245,6 +246,7 @@ class FePresent
void set_page_size( int );

const sf::Transform &get_transform() const;
const sf::Transform &get_ui_transform() const;
const sf::Font *get_layout_font();
const sf::Font *get_default_font();
const FeFontContainer *get_default_font_container();
Expand Down
2 changes: 1 addition & 1 deletion src/fe_vm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ bool FeVM::poll_command( FeInputMap::Command &c, sf::Event &ev, bool &from_ui )
void FeVM::clear()
{
FePresent::clear();

m_overlay->init();
m_last_ui_cmd = sf::Time();
m_ticks.clear();
m_trans.clear();
Expand Down
1 change: 0 additions & 1 deletion src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -385,7 +385,6 @@ int main(int argc, char *argv[])
window.get_win().setView( sf::View( sf::FloatRect( 0, 0, ev.size.width, ev.size.height )));
feVM.init_monitors();
feVM.load_layout();
feOverlay.init_font_sizes();
redraw = true;
break;

Expand Down

0 comments on commit 4744d55

Please sign in to comment.