2019-02-25 16:52:53 +00:00
/*
Copyright 2019 flyinghead
2021-04-08 08:38:26 +00:00
This file is part of Flycast .
2019-02-25 16:52:53 +00:00
2021-04-08 08:38:26 +00:00
Flycast is free software : you can redistribute it and / or modify
2019-02-25 16:52:53 +00:00
it under the terms of the GNU General Public License as published by
the Free Software Foundation , either version 2 of the License , or
( at your option ) any later version .
2021-04-08 08:38:26 +00:00
Flycast is distributed in the hope that it will be useful ,
2019-02-25 16:52:53 +00:00
but WITHOUT ANY WARRANTY ; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
GNU General Public License for more details .
You should have received a copy of the GNU General Public License
2021-04-08 08:38:26 +00:00
along with Flycast . If not , see < https : //www.gnu.org/licenses/>.
2019-02-25 16:52:53 +00:00
*/
2020-03-28 16:58:01 +00:00
# pragma once
2019-02-25 16:52:53 +00:00
# include <string>
2019-10-05 09:50:14 +00:00
# include "types.h"
# include "imgui/imgui.h"
2021-03-01 09:13:40 +00:00
# include "imgui/imgui_internal.h"
2019-12-25 12:09:54 +00:00
# include "gui.h"
2021-10-02 09:30:40 +00:00
# include "emulator.h"
2021-11-28 15:19:03 +00:00
# include "stdclass.h"
2019-10-05 09:50:14 +00:00
2021-10-14 09:39:27 +00:00
typedef bool ( * StringCallback ) ( bool cancelled , std : : string selection ) ;
2019-02-25 16:52:53 +00:00
2021-04-06 09:41:04 +00:00
void select_file_popup ( const char * prompt , StringCallback callback ,
bool selectFile = false , const std : : string & extension = " " ) ;
2019-10-05 09:50:14 +00:00
2021-06-07 10:18:05 +00:00
void scrollWhenDraggingOnVoid ( ImGuiMouseButton mouse_button = ImGuiMouseButton_Left ) ;
2021-02-01 11:38:29 +00:00
IMGUI_API const ImWchar * GetGlyphRangesChineseSimplifiedOfficial ( ) ; // Default + Half-Width + Japanese Hiragana/Katakana + set of 7800 CJK Unified Ideographs from General Standard Chinese Characters
2021-02-01 14:56:12 +00:00
IMGUI_API const ImWchar * GetGlyphRangesChineseTraditionalOfficial ( ) ; // Default + Half-Width + Japanese Hiragana/Katakana + set of 4700 CJK Unified Ideographs from Hong Kong's List of Graphemes of Commonly-Used Chinese Characters
2021-03-01 09:13:40 +00:00
// Helper to display a little (?) mark which shows a tooltip when hovered.
void ShowHelpMarker ( const char * desc ) ;
template < bool PerGameOption >
bool OptionCheckbox ( const char * name , config : : Option < bool , PerGameOption > & option , const char * help = nullptr ) ;
bool OptionSlider ( const char * name , config : : Option < int > & option , int min , int max , const char * help = nullptr ) ;
template < typename T >
bool OptionRadioButton ( const char * name , config : : Option < T > & option , T value , const char * help = nullptr ) ;
void OptionComboBox ( const char * name , config : : Option < int > & option , const char * values [ ] , int count ,
const char * help = nullptr ) ;
2021-06-07 10:18:05 +00:00
bool OptionArrowButtons ( const char * name , config : : Option < int > & option , int min , int max , const char * help = nullptr ) ;
2021-04-06 09:41:04 +00:00
static inline void centerNextWindow ( )
{
2021-05-20 08:45:12 +00:00
ImGui : : SetNextWindowPos ( ImVec2 ( ImGui : : GetIO ( ) . DisplaySize . x / 2.f , ImGui : : GetIO ( ) . DisplaySize . y / 2.f ) ,
ImGuiCond_Always , ImVec2 ( 0.5f , 0.5f ) ) ;
2021-04-06 09:41:04 +00:00
}
2021-06-07 10:18:05 +00:00
static inline bool operator = = ( const ImVec2 & l , const ImVec2 & r )
{
return l . x = = r . x & & l . y = = r . y ;
}
static inline bool operator ! = ( const ImVec2 & l , const ImVec2 & r )
{
return ! ( l = = r ) ;
}
void fullScreenWindow ( bool modal ) ;
void windowDragScroll ( ) ;
2021-10-02 09:30:40 +00:00
class BackgroundGameLoader
{
public :
void load ( const std : : string & path )
{
progress . reset ( ) ;
future = std : : async ( std : : launch : : async , [ this , path ] {
emu . loadGame ( path . c_str ( ) , & progress ) ;
} ) ;
}
void cancel ( )
{
2021-12-06 16:43:22 +00:00
if ( progress . cancelled )
return ;
2021-10-02 09:30:40 +00:00
progress . cancelled = true ;
2021-12-06 16:43:22 +00:00
if ( future . valid ( ) )
try {
future . get ( ) ;
2021-12-11 17:53:35 +00:00
} catch ( const FlycastException & ) {
2021-12-06 16:43:22 +00:00
}
2021-10-02 09:30:40 +00:00
emu . unloadGame ( ) ;
2021-11-20 15:18:27 +00:00
gui_state = GuiState : : Main ;
2021-10-02 09:30:40 +00:00
}
bool ready ( )
{
if ( ! future . valid ( ) )
return true ;
if ( future . wait_for ( std : : chrono : : seconds ( 0 ) ) = = std : : future_status : : ready )
{
2021-12-06 16:43:22 +00:00
future . get ( ) ;
2021-10-02 09:30:40 +00:00
return true ;
}
return false ;
}
const LoadProgress & getProgress ( ) const {
return progress ;
}
private :
LoadProgress progress ;
std : : future < void > future ;
} ;
2022-04-13 16:06:19 +00:00
struct ScaledVec2 : public ImVec2
{
ScaledVec2 ( )
: ImVec2 ( ) { }
ScaledVec2 ( float x , float y )
: ImVec2 ( x * settings . display . uiScale , y * settings . display . uiScale ) { }
} ;
inline static ImVec2 min ( const ImVec2 & l , const ImVec2 & r ) {
return ImVec2 ( std : : min ( l . x , r . x ) , std : : min ( l . y , r . y ) ) ;
}
inline static ImVec2 operator + ( const ImVec2 & l , const ImVec2 & r ) {
return ImVec2 ( l . x + r . x , l . y + r . y ) ;
}
inline static ImVec2 operator - ( const ImVec2 & l , const ImVec2 & r ) {
return ImVec2 ( l . x - r . x , l . y - r . y ) ;
}
2022-06-15 19:22:12 +00:00
inline static ImVec2 operator * ( const ImVec2 & v , float f ) {
return ImVec2 ( v . x * f , v . y * f ) ;
}
inline static ImVec2 operator / ( const ImVec2 & v , float f ) {
return ImVec2 ( v . x / f , v . y / f ) ;
}
u8 * loadImage ( const std : : string & path , int & width , int & height ) ;