-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(graphics): add canvas_2d component
- Loading branch information
Showing
12 changed files
with
260 additions
and
140 deletions.
There are no files selected for viewing
14 changes: 11 additions & 3 deletions
14
examples/sfml/tic-tac-toe/assets/config/game.config.maker.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,15 @@ | ||
{ | ||
"native_desktop_mode": false, | ||
"canvas_height": 1080.0, | ||
"canvas_width": 1920.0, | ||
"custom_canvas_height": true, | ||
"custom_canvas_width": true, | ||
"scale_mode": "crop" | ||
"scale_mode": "fit", | ||
"window_width": 1921, | ||
"window_height": 1081, | ||
"window_title": "tic-tac-toe", | ||
"background_color": [ | ||
0, | ||
0, | ||
0, | ||
255 | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
127 changes: 127 additions & 0 deletions
127
modules/graphics/antara/gaming/graphics/component.canvas.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,127 @@ | ||
/****************************************************************************** | ||
* Copyright © 2013-2019 The Komodo Platform Developers. * | ||
* * | ||
* See the AUTHORS, DEVELOPER-AGREEMENT and LICENSE files at * | ||
* the top-level directory of this distribution for the individual copyright * | ||
* holder information and the developer policies on copyright and licensing. * | ||
* * | ||
* Unless otherwise agreed in a custom licensing agreement, no part of the * | ||
* Komodo Platform software, including this file may be copied, modified, * | ||
* propagated or distributed except according to the terms contained in the * | ||
* LICENSE file * | ||
* * | ||
* Removal or modification of this copyright notice is prohibited. * | ||
* * | ||
******************************************************************************/ | ||
|
||
#pragma once | ||
|
||
#include "antara/gaming/core/safe.refl.hpp" | ||
#include "antara/gaming/math/vector.hpp" | ||
#include "antara/gaming/graphics/component.color.hpp" | ||
|
||
namespace antara::gaming::graphics | ||
{ | ||
struct rectangle | ||
{ | ||
math::vec2f size; //! width/height | ||
math::vec2f position; | ||
|
||
bool operator==(const rectangle &rhs) const | ||
{ | ||
return size == rhs.size && | ||
position == rhs.position; | ||
} | ||
|
||
bool operator!=(const rectangle &rhs) const | ||
{ | ||
return !(rhs == *this); | ||
} | ||
//! pos of the rectangle | ||
}; | ||
|
||
struct canvas_2d | ||
{ | ||
enum scale_mode | ||
{ | ||
none, | ||
stretch, | ||
crop, | ||
fit | ||
}; | ||
|
||
rectangle window{{0.f, 0.f}, {1921.f, 1080.f}}; | ||
rectangle canvas{{0.f, 0.f}, {1920.f, 1080.f}}; | ||
rectangle canvas_texture; | ||
bool custom_canvas_width{true}; | ||
bool custom_canvas_height{true}; | ||
bool native_desktop_mode{false}; | ||
bool is_fullscreen{false}; | ||
scale_mode current_scaling_mode{crop}; | ||
rectangle view_port; | ||
std::string window_title{"game title"}; | ||
fill_color background_color{graphics::black}; | ||
math::vec2f canvas_texture_scaling{1.0f, 1.0f}; | ||
|
||
bool operator==(const canvas_2d &rhs) const | ||
{ | ||
return window == rhs.window && | ||
canvas == rhs.canvas && | ||
current_scaling_mode == rhs.current_scaling_mode && | ||
view_port == rhs.view_port && | ||
window_title == rhs.window_title && | ||
background_color == rhs.background_color; | ||
} | ||
|
||
bool operator!=(const canvas_2d &rhs) const | ||
{ | ||
return !(rhs == *this); | ||
} | ||
|
||
void reset_canvas() noexcept | ||
{ | ||
auto&&[window_width, window_height] = window.size; | ||
auto&&[canvas_width, canvas_height] = canvas.size; | ||
auto&&[canvas_texture_width, canvas_texture_height] = canvas_texture.size; | ||
if (custom_canvas_width && custom_canvas_height) { | ||
canvas_texture_width = canvas_width; | ||
canvas_texture_height = canvas_height; | ||
} else if (custom_canvas_width) { | ||
canvas_texture_width = canvas_width; | ||
canvas_texture_height = canvas_width * window_height / window_width; | ||
} else if (custom_canvas_height) { | ||
canvas_texture_width = canvas_height * window_width / window_height; | ||
canvas_texture_height = canvas_height; | ||
} else { | ||
canvas_texture_width = window_width; | ||
canvas_texture_height = window_height; | ||
} | ||
|
||
view_port.position = math::vec2f::scalar(0.f); | ||
view_port.size = math::vec2f{window_width, window_height}; | ||
|
||
switch (current_scaling_mode) { | ||
case none: | ||
break; | ||
case stretch: | ||
canvas_texture_scaling = math::vec2f{window_width / canvas_texture_width, window_height / canvas_texture_height}; | ||
break; | ||
case crop: | ||
canvas_texture_scaling = math::vec2f::scalar(std::max(window_width / canvas_texture_width, window_height / canvas_texture_height)); | ||
break; | ||
case fit: | ||
canvas_texture_scaling = math::vec2f::scalar(std::min(window_width / canvas_texture_width, window_height / canvas_texture_height)); | ||
break; | ||
} | ||
canvas_texture.position = math::vec2f{window_width * 0.5f, window_height * 0.5f}; | ||
} | ||
|
||
canvas_2d() = default; | ||
canvas_2d(const canvas_2d& other) = default; | ||
canvas_2d& operator=(const canvas_2d& other) = default; | ||
}; | ||
} | ||
|
||
REFL_AUTO(type(antara::gaming::graphics::rectangle), field(size), field(position)) | ||
REFL_AUTO(type(antara::gaming::graphics::canvas_2d), field(window), field(canvas), field(current_scaling_mode), | ||
field(view_port), field(window_title), field(background_color)) |
Oops, something went wrong.