Skip to content

Commit

Permalink
HTTPS C++ API
Browse files Browse the repository at this point in the history
  • Loading branch information
RandyGaul committed Jul 4, 2024
1 parent d76049e commit 8366c5f
Show file tree
Hide file tree
Showing 9 changed files with 76 additions and 37 deletions.
2 changes: 1 addition & 1 deletion docs/api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -867,9 +867,9 @@ This is a list of all functions in Cute Framework organized by categories. This
- [cf_bottom](/math/cf_bottom.md)
- [cf_bottom_left](/math/cf_bottom_left.md)
- [cf_bottom_right](/math/cf_bottom_right.md)
- [cf_ceil](/math/cf_ceil.md)
- [cf_center](/math/cf_center.md)
- [cf_centroid](/math/cf_centroid.md)
- [cf_ciel](/math/cf_ciel.md)
- [cf_circle_in](/math/cf_circle_in.md)
- [cf_circle_in_out](/math/cf_circle_in_out.md)
- [cf_circle_out](/math/cf_circle_out.md)
Expand Down
4 changes: 2 additions & 2 deletions docs/math/cf_ciel.md → docs/math/cf_ceil.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[](../header.md ':include')

# cf_ciel
# cf_ceil

Category: [math](/api_reference?id=math)
GitHub: [cute_math.h](https://github.com/RandyGaul/cute_framework/blob/master/include/cute_math.h)
Expand All @@ -9,7 +9,7 @@ GitHub: [cute_math.h](https://github.com/RandyGaul/cute_framework/blob/master/in
Returns the component-wise ceil of a vector.

```cpp
CF_V2 cf_ciel(CF_V2 a)
CF_V2 cf_ceil(CF_V2 a)
```
## Remarks
Expand Down
2 changes: 1 addition & 1 deletion docs/math/cf_floor.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ Floor means the decimal-point part is zero'd out.
[cf_lesser_equal_v2](/math/cf_lesser_equal_v2.md)
[cf_greater_equal_v2](/math/cf_greater_equal_v2.md)
[cf_parallel](/math/cf_parallel.md)
[cf_ciel](/math/cf_ciel.md)
[cf_ceil](/math/cf_ceil.md)
2 changes: 1 addition & 1 deletion docs/text/cf_texteffect.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Struct Members | Description
`int index_into_effect` | Starts at 0 and increments for each character affected.
`int glyph_count` | The number of glyphs spanning the entire effect.
`float elapsed` | How long this effect has persisted for.
`CF_V2 center` | Center of this glyp's space -- not the same as the center of the glyph quad.
`CF_V2 center` | Center of this glyph's space -- not the same as the center of the glyph quad.
`CF_V2 q0, q1` | User-modifiable. This glyph's renderable quad. q0 is the min vertex, while q1 is the max vertex.
`int w, h` | Width and height of the glyph.
`CF_Color color` | User-modifiable. The color to render this glyph with.
Expand Down
4 changes: 3 additions & 1 deletion docs/web/cf_https_response_headers.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ htbl const CF_HttpsHeader* cf_https_response_headers(CF_HttpsResponse response);
## Remarks
Intended to be used with [cf_https_response_headers_count](/web/cf_https_response_headers_count.md).
Intended to be used with [cf_https_response_headers_count](/web/cf_https_response_headers_count.md). Do not free this array, it will
get cleaned up when the originating [CF_HttpsRequest](/web/cf_httpsrequest.md) is destroyed via [cf_https_destroy](/web/cf_https_destroy.md).
If you're familiar with [htbl](/hash/htbl.md) you may treat this pointer as a hashtable key'd by strings.
## Related Pages
Expand Down
52 changes: 26 additions & 26 deletions include/cute_draw.h
Original file line number Diff line number Diff line change
Expand Up @@ -783,31 +783,6 @@ CF_API bool CF_CALL cf_pop_text_vertical_layout();
*/
CF_API bool CF_CALL cf_peek_text_vertical_layout();

/**
* @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
* @category text
Expand Down Expand Up @@ -885,7 +860,7 @@ typedef struct CF_TextEffect
/* @member How long this effect has persisted for. */
float elapsed;

/* @member Center of this glyp's space -- not the same as the center of the glyph quad. */
/* @member Center of this glyph's space -- not the same as the center of the glyph quad. */
CF_V2 center;

/* @member User-modifiable. This glyph's renderable quad. q0 is the min vertex, while q1 is the max vertex. */
Expand Down Expand Up @@ -1056,6 +1031,31 @@ CF_API CF_Color CF_CALL cf_text_effect_get_color(CF_TextEffect* fx, const char*
*/
CF_API const char* CF_CALL cf_text_effect_get_string(CF_TextEffect* fx, const char* key, const char* default_val);

/**
* @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_render_settings_filter
* @category draw
Expand Down
37 changes: 36 additions & 1 deletion include/cute_https.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,9 @@ CF_API int CF_CALL cf_https_response_headers_count(CF_HttpsResponse response);
* @function cf_https_response_headers
* @category web
* @brief Returns an array of response headers.
* @remarks Intended to be used with `cf_https_response_headers_count`.
* @remarks Intended to be used with `cf_https_response_headers_count`. Do not free this array, it will
* get cleaned up when the originating `CF_HttpsRequest` is destroyed via `cf_https_destroy`.
* If you're familiar with `htbl` you may treat this pointer as a hashtable key'd by strings.
* @related CF_HttpsHeader CF_HttpsResponse cf_https_response_find_header cf_https_response_headers
*/
CF_API htbl const CF_HttpsHeader* CF_CALL cf_https_response_headers(CF_HttpsResponse response);
Expand All @@ -280,6 +282,39 @@ CF_API htbl const CF_HttpsHeader* CF_CALL cf_https_response_headers(CF_HttpsResp
namespace Cute
{

using HttpsRequest = CF_HttpsRequest;
using HttpsResponse = CF_HttpsResponse;
using HttpsHeader = CF_HttpsHeader;

CF_INLINE HttpsRequest https_get(const char* host, int port, const char* uri, bool verify_cert = true) { return cf_https_get(host, port, uri, verify_cert); }
CF_INLINE HttpsRequest https_post(const char* host, int port, const char* uri, const void* content, int content_length, bool verify_cert = true) { return cf_https_post(host, port, uri, content, content_length, verify_cert); }
CF_INLINE void https_add_header(HttpsRequest request, const char* name, const char* value) { cf_https_add_header(request, name, value); }
CF_INLINE void https_destroy(HttpsRequest request) { cf_https_destroy(request); }

using HttpsResult = CF_HttpsResult;
#define CF_ENUM(K, V) CF_INLINE constexpr HttpsResult K = CF_##K;
CF_HTTPS_RESULT_DEFS
#undef CF_ENUM

CF_INLINE const char* to_string(HttpsResult result)
{
switch (result) {
#define CF_ENUM(K, V) case CF_##K: return #K;
CF_HTTPS_RESULT_DEFS
#undef CF_ENUM
default: return NULL;
}
}

CF_INLINE HttpsResult https_process(HttpsRequest request) { return cf_https_process(request); }
CF_INLINE HttpsResponse https_response(HttpsRequest request) { return cf_https_response(request); }
CF_INLINE int https_response_code(HttpsResponse response) { return cf_https_response_code(response); }
CF_INLINE int https_response_content_length(HttpsResponse response) { return cf_https_response_content_length(response); }
CF_INLINE char* https_response_content(HttpsResponse response) { return cf_https_response_content(response); }
CF_INLINE HttpsHeader https_response_find_header(HttpsResponse response, const char* header_name) { return cf_https_response_find_header(response, header_name); }
CF_INLINE int https_response_headers_count(HttpsResponse response) { return cf_https_response_headers_count(response); }
CF_INLINE htbl const HttpsHeader* https_response_headers(HttpsResponse response) { return cf_https_response_headers(response); }

}

#endif // CF_CPP
Expand Down
2 changes: 2 additions & 0 deletions src/cute_https.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ extern "C" {
}
#endif

// Credit to Mattias Gustavsson for the original API design of cute_https.h

using namespace Cute;

#ifndef CF_EMSCRIPTEN
Expand Down
8 changes: 4 additions & 4 deletions todo.txt
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
investigate https://discord.com/channels/432009046833233930/432009046833233932/1256474663085805618
DPI handling
doc page on transforms
text fx init
text fx word iterator
note text effect onstart/finish helpers in the topic page
text effect word/line iterator, aabb calcs
docs pass on all pages
https C++ API
knock out github issues
resync all cute_headers
set cute_version.h
update cute_user_config with all the math overrides recent PR
ECS docs
draw docs
document circular buffer
Document cute_image.h
contributor list

punted
- transparent windows - Can't find an easy way to do this through SDL, might be a cross-platform nightmare
Expand Down

0 comments on commit 8366c5f

Please sign in to comment.