3
4
5
6
7
8
9
10
11
12
15#include <pu/pu_Include.hpp>
33 return "DefaultFont@" + std::to_string(font_size);
37 return DefaultFontSizes[
static_cast<u32>(kind)];
41 return MakeDefaultFontName(GetDefaultFontSize(kind));
51 constexpr Color(
const u8 r,
const u8 g,
const u8 b,
const u8 a) :
r(
r),
g(
g),
b(
b),
a(
a) {}
57 return {
this->r,
this->g,
this->b, a };
61 static inline constexpr bool TouchHitsRegion(
const i32 touch_x,
const i32 touch_y,
const i32 region_x,
const i32 region_y,
const i32 region_w,
const i32 region_h) {
62 return (touch_x >= region_x) && (touch_x < (region_x + region_w)) && (touch_y >= region_y) && (touch_y < (region_y + region_h));
75 return (
this->x < 0) && (
this->y < 0);
78 inline constexpr bool HitsRegion(
const i32 region_x,
const i32 region_y,
const i32 region_w,
const i32 region_h)
const {
83 return TouchHitsRegion(
this->x,
this->y, region_x, region_y, region_w, region_h);
94 bool inverted_for_zero;
96 inline double ComputeIncrement() {
97 return (
double)
this->target_incr * (1.0f / (1.0f + exp(-
this->f)));
105 void Start(
const u32 f_steps,
const T target_initial_val,
const T target_incr) {
106 this->target_initial_val = target_initial_val;
107 this->target_incr = target_incr;
108 this->inverted_for_zero =
false;
110 auto target_final_val = target_initial_val + target_incr;
111 if(target_final_val == 0) {
113 this->inverted_for_zero =
true;
114 this->target_initial_val = 0;
115 this->target_incr = target_initial_val;
116 target_final_val = target_initial_val;
120 this->f_incr = (2.0f * f_limit_abs) / (
double)f_steps;
121 this->f = -f_limit_abs;
125 this->Start(f_steps, 0, target_final_val);
128 inline void StartToZero(
const u32 f_steps,
const T target_initial_val) {
129 this->Start(f_steps, target_initial_val, -target_initial_val);
137 const auto target_f = (
double)
this->target_initial_val +
this->ComputeIncrement();
138 if(
this->target_incr > 0) {
139 target = (T)((i32)(target_f + 0.5f));
142 target = (T)((i32)(target_f - 0.5f));
144 this->f +=
this->f_incr;
146 const auto is_done = abs((
double)target) >= abs((
double)(
this->target_initial_val +
this->target_incr));
148 if(
this->inverted_for_zero) {
152 target =
this->target_initial_val +
this->target_incr;
154 this->target_incr = 0;
157 else if(
this->inverted_for_zero) {
158 target =
this->target_incr - target;
165 return this->target_incr == 0;
Definition ui_Types.hpp:88
bool IsDone()
Definition ui_Types.hpp:164
void StartFromZero(const u32 f_steps, const T target_final_val)
Definition ui_Types.hpp:124
void StartToZero(const u32 f_steps, const T target_initial_val)
Definition ui_Types.hpp:128
bool Increment(T &target)
Definition ui_Types.hpp:132
void Start(const u32 f_steps, const T target_initial_val, const T target_incr)
Definition ui_Types.hpp:105
constexpr SigmoidIncrementer()
Definition ui_Types.hpp:103
static constexpr double AllowedError
Definition ui_Types.hpp:101
constexpr u32 DefaultFontSizes[static_cast< u32 >(DefaultFontSize::Count)]
Definition ui_Types.hpp:30
static constexpr bool TouchHitsRegion(const i32 touch_x, const i32 touch_y, const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h)
Definition ui_Types.hpp:61
std::string MakeDefaultFontName(const u32 font_size)
Definition ui_Types.hpp:32
constexpr u64 TouchPseudoKey
Definition ui_Types.hpp:65
constexpr u32 GetDefaultFontSize(const DefaultFontSize kind)
Definition ui_Types.hpp:36
std::string GetDefaultFont(const DefaultFontSize kind)
Definition ui_Types.hpp:40
DefaultFontSize
Definition ui_Types.hpp:21
Definition ui_Types.hpp:44
static Color FromHex(const std::string &str_clr)
u8 g
Definition ui_Types.hpp:46
u8 a
Definition ui_Types.hpp:48
u8 r
Definition ui_Types.hpp:45
Color WithAlpha(const u8 a)
Definition ui_Types.hpp:56
constexpr Color()
Definition ui_Types.hpp:50
u8 b
Definition ui_Types.hpp:47
constexpr Color(const u8 r, const u8 g, const u8 b, const u8 a)
Definition ui_Types.hpp:51
Definition ui_Types.hpp:67
i32 y
Definition ui_Types.hpp:69
constexpr TouchPoint(const u32 x, const u32 y)
Definition ui_Types.hpp:72
constexpr TouchPoint()
Definition ui_Types.hpp:71
constexpr bool HitsRegion(const i32 region_x, const i32 region_y, const i32 region_w, const i32 region_h) const
Definition ui_Types.hpp:78
i32 x
Definition ui_Types.hpp:68
constexpr bool IsEmpty() const
Definition ui_Types.hpp:74