diff options
-rw-r--r-- | src/crepe/api/Button.h | 6 | ||||
-rw-r--r-- | src/crepe/api/Text.h | 18 | ||||
-rw-r--r-- | src/crepe/api/UIObject.h | 2 | ||||
-rw-r--r-- | src/crepe/facade/SDLContext.cpp | 17 | ||||
-rw-r--r-- | src/example/rendering_particle.cpp | 25 |
5 files changed, 33 insertions, 35 deletions
diff --git a/src/crepe/api/Button.h b/src/crepe/api/Button.h index d42527e..25709a4 100644 --- a/src/crepe/api/Button.h +++ b/src/crepe/api/Button.h @@ -1,8 +1,5 @@ #pragma once -#include <functional> - -#include "Event.h" #include "UIObject.h" namespace crepe { @@ -43,6 +40,9 @@ private: friend class InputSystem; //! Indicates whether the mouse is currently hovering over the button bool hover = false; + + //! variable indicating if transform is relative to camera(false) or world(true) + bool world_space = false; }; } // namespace crepe diff --git a/src/crepe/api/Text.h b/src/crepe/api/Text.h index 0289b85..0163bbb 100644 --- a/src/crepe/api/Text.h +++ b/src/crepe/api/Text.h @@ -17,22 +17,8 @@ class Text : public UIObject { public: //! Text data that does not have to be set in the constructor struct Data { - /** - * \brief fontsize for text rendering - * - * \note this is not the actual font size that is loaded in. - * - * Since SDL_TTF requires the font size when loading in the font it is not possible to switch the font size. - * The default font size that is loaded is set in the Config. - * Instead this value is used to upscale the font texture which can cause blurring or distorted text when upscaling or downscaling too much. - */ - unsigned int font_size = 16; - - //! Layer sorting level of the text - const int sorting_in_layer = 0; - - //! Order within the sorting text - const int order_in_layer = 0; + //! variable indicating if transform is relative to camera(false) or world(true) + bool world_space = false; //! Label text color. Color text_color = Color::BLACK; diff --git a/src/crepe/api/UIObject.h b/src/crepe/api/UIObject.h index f1318ab..f7f4fba 100644 --- a/src/crepe/api/UIObject.h +++ b/src/crepe/api/UIObject.h @@ -20,8 +20,6 @@ public: vec2 dimensions; //! Position offset relative to this GameObjects Transform vec2 offset; - //! variable indicating if transform is relative to camera(false) or world(true) - bool world_space = false; }; } // namespace crepe diff --git a/src/crepe/facade/SDLContext.cpp b/src/crepe/facade/SDLContext.cpp index 859f966..6c93fb2 100644 --- a/src/crepe/facade/SDLContext.cpp +++ b/src/crepe/facade/SDLContext.cpp @@ -69,8 +69,6 @@ SDLContext::SDLContext(Mediator & mediator) { throw runtime_error(format("SDL_ttf initialization failed: {}", TTF_GetError())); } - SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "1"); - mediator.sdl_context = *this; } @@ -174,6 +172,7 @@ SDL_FRect SDLContext::get_dst_rect(const DestinationRectangleData & ctx) const { } void SDLContext::draw(const RenderContext & ctx) { + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "2"); const Sprite::Data & data = ctx.sprite.data; SDL_RendererFlip render_flip = (SDL_RendererFlip) ((SDL_FLIP_HORIZONTAL * data.flip.flip_x) @@ -206,6 +205,7 @@ void SDLContext::draw(const RenderContext & ctx) { } void SDLContext::draw_text(const RenderText & data) { + SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0"); const Text & text = data.text; const Font & font = data.font; @@ -235,9 +235,16 @@ void SDLContext::draw_text(const RenderText & data) { = {tmp_font_texture, [](SDL_Texture * texture) { SDL_DestroyTexture(texture); }}; vec2 size = text.dimensions * cam_aux_data.render_scale * data.transform.scale; - vec2 screen_pos = (absoluut_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2 - ) * cam_aux_data.render_scale - - size / 2 + cam_aux_data.bar_size; + vec2 screen_pos = absoluut_pos; + if (text.data.world_space) { + screen_pos = (screen_pos - cam_aux_data.cam_pos + (cam_aux_data.zoomed_viewport) / 2) + * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; + } else { + screen_pos + = (screen_pos + (cam_aux_data.zoomed_viewport) / 2) * cam_aux_data.render_scale + - size / 2 + cam_aux_data.bar_size; + } SDL_FRect dstrect { .x = screen_pos.x, diff --git a/src/example/rendering_particle.cpp b/src/example/rendering_particle.cpp index 7942fce..9093fd5 100644 --- a/src/example/rendering_particle.cpp +++ b/src/example/rendering_particle.cpp @@ -7,8 +7,8 @@ #include <crepe/api/Button.h> #include <crepe/api/Camera.h> #include <crepe/api/Color.h> +#include <crepe/api/Engine.h> #include <crepe/api/GameObject.h> -#include <crepe/api/LoopManager.hpp> #include <crepe/api/ParticleEmitter.h> #include <crepe/api/Rigidbody.h> #include <crepe/api/Sprite.h> @@ -62,21 +62,28 @@ public: } ); - /* - game_object.add_component<Text>(vec2{1, 1}, vec2{0, -0.5}, "ComicSansMS", - Text::Data{.text_color = Color::RED}, "test TEST"); + game_object.add_component<Text>(vec2{1, 1}, vec2{0, -1}, "ComicSansMS", + Text::Data{ + .text_color = Color::RED, + }, + "test TEST"); - game_object.add_component<Text>(vec2{1, 1}, vec2{0, 0.5}, "ComicSansMS", - Text::Data{.text_color = Color::BLACK}, "TEST test"); - */ + game_object + .add_component<Text>(vec2{1, 1}, vec2{0, 1}, "Ariel", + Text::Data{ + .text_color = Color::BLACK, + }, + "TEST test") + .world_space + = true; } string get_name() const { return "TestScene"; }; }; int main(int argc, char * argv[]) { - LoopManager engine; + Engine engine; engine.add_scene<TestScene>(); - engine.start(); + engine.main(); return 0; } |