demotool/utilities.hh

89 lines
2 KiB
C++
Raw Normal View History

2017-09-30 10:37:45 +02:00
#pragma once
#ifndef REAL_BUILD
# include "externals.hh"
#endif
/*= Utilities ================================================================*/
// Disable next ImGui button(s)
void disableButton( );
// Re-enable ImGui buttons
inline void reenableButtons( )
{
ImGui::PopStyleColor( 3 );
}
/*----------------------------------------------------------------------------*/
2017-10-02 13:51:08 +02:00
#define GL_CHECK( FAIL ) \
2017-10-01 18:51:02 +02:00
do { \
auto err_( glGetError( ) ); \
2017-10-02 13:51:08 +02:00
if ( err_ != GL_NO_ERROR ) FAIL; \
2017-10-01 18:51:02 +02:00
} while ( 0 )
2017-10-02 13:51:08 +02:00
#define GL_ASSERT( ) \
GL_CHECK({ \
fprintf( stderr , "GL error %x in %s:%d\n" , \
err_ , __FILE__ , __LINE__ ); \
abort( ); \
})
2017-10-01 18:51:02 +02:00
/*----------------------------------------------------------------------------*/
2017-09-30 10:37:45 +02:00
// Add some value to an angle, keeping it in [-180;180]
void updateAngle(
2017-11-03 09:08:19 +01:00
float& initial ,
const float delta
2017-09-30 10:37:45 +02:00
);
// Make a rotation matrix from three YPR angles (in degrees)
void anglesToMatrix(
2017-11-03 09:08:19 +01:00
float const* angles ,
float* matrix );
2017-09-30 10:37:45 +02:00
/*----------------------------------------------------------------------------*/
// Helpers for finding entries in collections
template< typename T , typename I >
inline auto find(
2017-11-03 09:08:19 +01:00
T const& collection ,
I const& item )
2017-09-30 10:37:45 +02:00
{
return std::find( collection.begin( ) , collection.end( ) , item );
}
template< typename T , typename I >
inline auto find(
2017-11-03 09:08:19 +01:00
T& collection ,
I const& item )
2017-09-30 10:37:45 +02:00
{
return std::find( collection.begin( ) , collection.end( ) , item );
}
2017-10-31 09:22:38 +01:00
template< typename T , typename I >
inline bool Contains(
2017-11-03 09:08:19 +01:00
T const& collection ,
I const& item )
{
return std::find( collection.begin( ) , collection.end( ) , item ) != collection.end( );
}
/*----------------------------------------------------------------------------*/
// Get the absolute path
std::string GetAbsolutePath(
2017-11-03 09:08:19 +01:00
std::string const& path );
// Get the absolute parent path for a (possibly relative) path
std::string GetParentPath(
2017-11-03 09:08:19 +01:00
std::string const& path );
/*----------------------------------------------------------------------------*/
namespace ImGui {
bool MenuItemCheckbox(
char const* name ,
bool* checked );
} // namespace ImGui