Skip to content

Commit

Permalink
Document text effect active push/pop/peek
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Jun 30, 2024
1 parent a89b4b8 commit 6c47fc1
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -1454,18 +1454,21 @@ This is a list of all functions in Cute Framework organized by categories. This
- [cf_peek_font_blur](/text/cf_peek_font_blur.md)
- [cf_peek_font_size](/text/cf_peek_font_size.md)
- [cf_peek_text_clip_box](/text/cf_peek_text_clip_box.md)
- [cf_peek_text_effect_active](/text/cf_peek_text_effect_active.md)
- [cf_peek_text_vertical_layout](/text/cf_peek_text_vertical_layout.md)
- [cf_peek_text_wrap_width](/text/cf_peek_text_wrap_width.md)
- [cf_pop_font](/text/cf_pop_font.md)
- [cf_pop_font_blur](/text/cf_pop_font_blur.md)
- [cf_pop_font_size](/text/cf_pop_font_size.md)
- [cf_pop_text_clip_box](/text/cf_pop_text_clip_box.md)
- [cf_pop_text_effect_active](/text/cf_pop_text_effect_active.md)
- [cf_pop_text_vertical_layout](/text/cf_pop_text_vertical_layout.md)
- [cf_pop_text_wrap_width](/text/cf_pop_text_wrap_width.md)
- [cf_push_font](/text/cf_push_font.md)
- [cf_push_font_blur](/text/cf_push_font_blur.md)
- [cf_push_font_size](/text/cf_push_font_size.md)
- [cf_push_text_clip_box](/text/cf_push_text_clip_box.md)
- [cf_push_text_effect_active](/text/cf_push_text_effect_active.md)
- [cf_push_text_vertical_layout](/text/cf_push_text_vertical_layout.md)
- [cf_push_text_wrap_width](/text/cf_push_text_wrap_width.md)
- [cf_text_effect_get_color](/text/cf_text_effect_get_color.md)
Expand Down
18 changes: 18 additions & 0 deletions docs/text/cf_peek_text_effect_active.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[](../header.md ':include')

# cf_peek_text_effect_active

Category: [text](/api_reference?id=text)
GitHub: [cute_draw.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_draw.h)
---

Returns the last text active state.

```cpp
bool cf_peek_text_effect_active();
```

## Related Pages

[cf_push_text_effect_active](/text/cf_push_text_effect_active.md)
[cf_pop_text_effect_active](/text/cf_pop_text_effect_active.md)
18 changes: 18 additions & 0 deletions docs/text/cf_pop_text_effect_active.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
[](../header.md ':include')

# cf_pop_text_effect_active

Category: [text](/api_reference?id=text)
GitHub: [cute_draw.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_draw.h)
---

Pops the previously pushed activated state for text effects. See [cf_push_text_effect_active](/text/cf_push_text_effect_active.md).

```cpp
bool cf_pop_text_effect_active();
```

## Related Pages

[cf_push_text_effect_active](/text/cf_push_text_effect_active.md)
[cf_peek_text_effect_active](/text/cf_peek_text_effect_active.md)
22 changes: 22 additions & 0 deletions docs/text/cf_push_text_effect_active.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[](../header.md ':include')

# cf_push_text_effect_active

Category: [text](/api_reference?id=text)
GitHub: [cute_draw.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_draw.h)
---

Turns on/off text effects.

```cpp
void cf_push_text_effect_active(bool effects_on);
```
## Remarks
Text effects are on by default.
## Related Pages
[cf_peek_text_effect_active](/text/cf_peek_text_effect_active.md)
[cf_pop_text_effect_active](/text/cf_pop_text_effect_active.md)
27 changes: 24 additions & 3 deletions include/cute_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,9 +783,30 @@ CF_API bool CF_CALL cf_pop_text_vertical_layout();
*/
CF_API bool CF_CALL cf_peek_text_vertical_layout();

CF_API void CF_CALL cf_push_text_effect(bool effects_on);
CF_API bool CF_CALL cf_pop_text_effect();
CF_API bool CF_CALL cf_peek_text_effect();
/**
* @function cf_push_text_effect_active
* @category text
* @brief Turns on/off text effects.
* @remarks Text effects are on by default.
* @related cf_push_text_effect_active cf_pop_text_effect_active cf_peek_text_effect_active
*/
CF_API void CF_CALL cf_push_text_effect_active(bool effects_on);

/**
* @function cf_pop_text_effect_active
* @category text
* @brief Pops the previously pushed activated state for text effects. See `cf_push_text_effect_active`.
* @related cf_push_text_effect_active cf_pop_text_effect_active cf_peek_text_effect_active
*/
CF_API bool CF_CALL cf_pop_text_effect_active();

/**
* @function cf_peek_text_effect_active
* @category text
* @brief Returns the last text active state.
* @related cf_push_text_effect_active cf_pop_text_effect_active cf_peek_text_effect_active
*/
CF_API bool CF_CALL cf_peek_text_effect_active();

/**
* @function cf_text_width
Expand Down
9 changes: 5 additions & 4 deletions src/cute_draw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1407,12 +1407,12 @@ bool cf_peek_text_vertical_layout()
return draw->vertical.last();
}

void cf_push_text_effect(bool text_effects_on)
void cf_push_text_effect_active(bool text_effects_on)
{
draw->text_effects.add(text_effects_on);
}

bool cf_pop_text_effect()
bool cf_pop_text_effect_active()
{
if (draw->text_effects.count() > 1) {
return draw->text_effects.pop();
Expand All @@ -1421,7 +1421,7 @@ bool cf_pop_text_effect()
}
}

bool cf_peek_text_effect()
bool cf_peek_text_effect_active()
{
return draw->text_effects.last();
}
Expand Down Expand Up @@ -1799,7 +1799,6 @@ static v2 s_draw_text(const char* text, CF_V2 position, int text_length, bool re
CF_ASSERT(font);
if (!font) return V2(0,0);

bool do_effects = draw->text_effects.last();
// Cache effect state key'd by input text pointer.
CF_TextEffectState* effect_state = app->text_effect_states.try_find(text);
if (!effect_state) {
Expand All @@ -1822,6 +1821,7 @@ static v2 s_draw_text(const char* text, CF_V2 position, int text_length, bool re
}

// Use the sanitized string for rendering. This excludes all text codes.
bool do_effects = draw->text_effects.last();
if (do_effects) {
text = effect_state->sanitized.c_str();
}
Expand Down Expand Up @@ -1913,6 +1913,7 @@ static v2 s_draw_text(const char* text, CF_V2 position, int text_length, bool re
if (!text) {
text_length = 0;
}

// Render the string glyph-by-glyph.
while (text_length-- && *text) {
cp_prev = cp;
Expand Down

0 comments on commit 6c47fc1

Please sign in to comment.