Added renamed Display::getPixelDensity() to Display::getPixelDensitySize() and now Display::getPixelDensity() returns the float value of the pixel density.

Moved the global test to tests/test_all.
Added a ui_perf_test used to test specific performance issues in the UI.
Fixed the element/widget inline style (now respects the specificity).
Some optimizations in UIListBox.
This commit is contained in:
Martín Lucas Golini
2020-05-03 03:39:31 -03:00
parent 16db174e48
commit 87e3d64b63
21 changed files with 263 additions and 75 deletions

2554
src/tests/test_all/test.cpp Normal file

File diff suppressed because it is too large Load Diff

257
src/tests/test_all/test.hpp Normal file
View File

@@ -0,0 +1,257 @@
#ifndef EE_EETEST_HPP
#define EE_EETEST_HPP
#include <eepp/ee.hpp>
namespace Demo_Test {
enum CollisionTypes { BALL_TYPE, BLOCKING_SENSOR_TYPE, CATCH_SENSOR_TYPE };
struct Emitter {
int queue;
int blocked;
cVect position;
};
class EETest : private Thread {
public:
typedef std::function<void()> SceneCb;
void init();
void update();
void end();
void process();
void render();
void input();
void particlesCallback( Particle* P, ParticleSystem* Me );
void particlesThread();
void particles();
void updateParticles();
void loadTextures();
void cmdSetPartsNum( const std::vector<String>& params );
Clock cElapsed;
Time PSElapsed;
private:
Engine* EE;
EE::Window::Window* mWindow;
TextureFactory* TF;
System::Log* Log;
EE::Window::Input* KM;
bool side, aside;
Float ang, scale, alpha, Ang;
Time et;
Int32 x, y;
Uint32 lasttick;
std::vector<Uint32> TN;
std::vector<Texture*> TNP;
std::vector<TextureRegion*> Tiles;
std::vector<ParticleSystem> PS;
Vector2i Mouse;
Vector2f Mousef;
Sprite SP;
Sprite CL1, CL2;
Font* TTF;
Primitives PR;
bool iL1, iL2;
Float HWidth, HHeight;
Music* Mus;
SoundManager SndMng;
bool DrawBack;
Console Con;
virtual void run();
Vector2f Point;
std::string MyPath;
bool ShowParticles;
TileMap Map;
Uint8 Screen;
SceneCb Scenes[6];
void screen1();
void screen2();
void screen3();
void screen4();
void screen5();
Zip* PakTest;
std::vector<Uint8> tmpv;
std::vector<Uint8> MySong;
Interpolation2d WP;
Int32 PartsNum;
Uint32 Cursor[1];
Texture* CursorP[1];
std::string mInfo;
bool MultiViewportMode;
BatchRenderer Batch;
Float AnimVal;
bool AnimSide;
View Views[2];
ShaderProgram* mShaderProgram;
ShaderProgram* mBlur;
Float mBlurFactor;
bool mUseShaders;
bool mJoyEnabled;
bool mMusEnabled;
bool mDebugUI;
Uint32 mLastFPSLimit;
bool mWasMinimized;
String mBuda;
ResourceLoader mResLoad;
void onTextureLoaded( ResourceLoader* ObjLoaded );
void createUI();
void createShaders();
void loadFonts();
void onFontLoaded();
JoystickManager* JM;
Float mAxisX;
Float mAxisY;
TextureAtlasLoader* mTGL;
Sprite mBlindy;
FrameBuffer* mFBO;
VertexBuffer* mVBO;
Clock mFTE;
Translator mTranslator;
void createCommonDialog();
void onItemClick( const Event* Event );
void onMainClick( const Event* Event );
void onQuitClick( const Event* Event );
void onCloseClick( const Event* Event );
void onButtonClick( const Event* Event );
void onValueChange( const Event* Event );
void onSliderValueChange( const Event* Event );
void onWinMouseUp( const Event* Event );
void createDecoratedWindow();
void createUIThemeTextureAtlas();
UINode* C;
UIScrollBar* mScrollBar;
UITextView* mTextBoxValue;
UISlider* mSlider;
UIProgressBar* mProgressBar;
UIListBox* mListBox;
UIPopUpMenu* Menu;
UIWindow* mUIWindow;
MapEditor* mMapEditor;
TextureAtlasEditor* mETGEditor;
UIColorPicker* mColorPicker;
Text mEEText;
Text mFBOText;
Text mInfoText;
std::string mThemeName;
Space* mSpace;
#ifndef EE_PLATFORM_TOUCH
Body* mMouseBody;
cVect mMousePoint;
cVect mMousePoint_last;
Constraint* mMouseJoint;
#else
Body* mMouseBody[EE_MAX_FINGERS];
cVect mMousePoint[EE_MAX_FINGERS];
cVect mMousePoint_last[EE_MAX_FINGERS];
Constraint* mMouseJoint[EE_MAX_FINGERS];
#endif
void physicsCreate();
void physicsUpdate();
void physicsDestroy();
void setScreen( Uint32 num );
cpBool blockerBegin( Arbiter* arb, Space* space, void* unused );
void blockerSeparate( Arbiter* arb, Space* space, void* unused );
void postStepRemove( Space* space, void* tshape, void* unused );
cpBool catcherBarBegin( Arbiter* arb, Space* space, void* unused );
void demo1Create();
void demo1Update();
void demo1Destroy();
void demo2Create();
void demo2Update();
void demo2Destroy();
void showMenu();
Emitter emitterInstance;
void changeDemo( Uint32 num );
struct physicDemo {
SceneCb init;
SceneCb update;
SceneCb destroy;
};
std::vector<physicDemo> mDemo;
Uint32 mCurDemo;
Sprite* mBoxSprite;
Sprite* mCircleSprite;
UITheme* mTheme;
bool mTerrainUp;
UIPushButton* mShowMenu;
UIPushButton* mTerrainBut;
UIRelativeLayout* relLay;
DrawableGroup drawableGroup;
void createMapEditor();
void createColorPicker( Node* node );
void onMapEditorClose();
void createETGEditor();
void createJointAndBody();
void destroyBody();
void onShowMenu( const Event* Event );
void onWindowResize( EE::Window::Window* win );
void createBaseUI();
void createNewUI();
};
} // namespace Demo_Test
#endif

View File

@@ -0,0 +1,97 @@
#include <eepp/ee.hpp>
// This file is used to test some UI related stuffs.
// It's not a benchmark or a real test suite.
// It's just used to test whatever I need to test at any given moment.
EE::Window::Window* win = NULL;
void mainLoop() {
win->getInput()->update();
if ( win->getInput()->isKeyUp( KEY_ESCAPE ) ) {
win->close();
}
// Update the UI scene.
SceneManager::instance()->update();
// Check if the UI has been invalidated ( needs redraw ).
if ( SceneManager::instance()->getUISceneNode()->invalidated() ) {
win->clear();
// Redraw the UI scene.
SceneManager::instance()->draw();
win->display();
} else {
Sys::sleep( Milliseconds( 8 ) );
}
}
EE_MAIN_FUNC int main( int argc, char* argv[] ) {
win = Engine::instance()->createWindow( WindowSettings( 320, 240, "eepp - UI Hello World" ),
ContextSettings( true ) );
if ( win->isOpen() ) {
PixelDensity::setPixelDensity(
Engine::instance()->getDisplayManager()->getDisplayIndex( 0 )->getPixelDensity() );
FontTrueType* font =
FontTrueType::New( "NotoSans-Regular", "assets/fonts/NotoSans-Regular.ttf" );
UISceneNode* uiSceneNode = UISceneNode::New();
SceneManager::instance()->add( uiSceneNode );
uiSceneNode->getUIThemeManager()->setDefaultFont( font );
StyleSheetParser styleSheetParser;
styleSheetParser.loadFromFile( "assets/ui/breeze.css" );
uiSceneNode->setStyleSheet( styleSheetParser.getStyleSheet() );
std::vector<String> strings;
for ( size_t i = 0; i < 10000; i++ )
strings.emplace_back( String::format(
"This is a very long string number %ld. Cover the full width of the listbox.",
i ) );
auto* vlay = UILinearLayout::NewVertical();
vlay->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent );
Clock clock, total;
/* ListBox test *//*
auto* lbox = UIListBox::New();
std::cout << "Time New: " << clock.getElapsed().asMilliseconds() << " ms" << std::endl;
lbox->setParent( vlay );
std::cout << "Time setParent: " << clock.getElapsed().asMilliseconds() << " ms"
<< std::endl;
lbox->setLayoutMargin( Rect( 4, 4, 4, 4 ) );
std::cout << "Time setLayoutMargin: " << clock.getElapsed().asMilliseconds() << " ms"
<< std::endl;
lbox->setLayoutSizePolicy( SizePolicy::MatchParent, SizePolicy::MatchParent );
std::cout << "Time setLayoutSizePolicy: " << clock.getElapsed().asMilliseconds() << " ms"
<< std::endl;
for ( size_t i = 0; i < 10; i++ )
lbox->addListBoxItem( String::format(
"This is a very long string number %ld. Cover the full width of the listbox.",
i ) );
std::cout << "Time addListBoxItem: " << clock.getElapsed().asMilliseconds() << " ms"
<< std::endl;
lbox->addListBoxItems( strings );
std::cout << "Time addListBoxItems: " << clock.getElapsed().asMilliseconds() << " ms"
<< std::endl;
*/
/* Create Widget test */
for ( size_t i = 0; i < 5000; i++ ) {
auto* widget = UIWidget::New();
widget->setParent( vlay );
//widget->setLayoutSizePolicy( SizePolicy::WrapContent, SizePolicy::WrapContent );
}
std::cout << "Time total: " << total.getElapsedTime().asMilliseconds() << " ms"
<< std::endl;
win->close();
win->runMainLoop( &mainLoop );
}
Engine::destroySingleton();
MemoryManager::showResults();
return EXIT_SUCCESS;
}