aboutsummaryrefslogtreecommitdiffstats
path: root/examples/pugl_embed_demo.c
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2022-05-20 19:44:20 -0400
committerDavid Robillard <d@drobilla.net>2022-05-21 16:49:47 -0400
commita136586a339032126540ceb24f7c3f15eaba68c8 (patch)
treecd3e35e2cab5c71517c691cfad6dbeac8664b945 /examples/pugl_embed_demo.c
parent1cd37cad0a06fbb15c44fd59dd6b2c12a0812a76 (diff)
downloadpugl-a136586a339032126540ceb24f7c3f15eaba68c8.tar.gz
pugl-a136586a339032126540ceb24f7c3f15eaba68c8.tar.bz2
pugl-a136586a339032126540ceb24f7c3f15eaba68c8.zip
Use consistent integer types for view positions and sizes
Actual window sizes and positions fit easily in a 16-bit integer. So, we use that in "representation contexts" like events. This makes structures smaller, and allows the values to be converted to float, double, or integer without casting (since any int16_t or uint16_t value can fit in them without loss). Setter APIs use native integers for convenience, to avoid casting hassles when doing arithmetic. Ranges are checked at runtime.
Diffstat (limited to 'examples/pugl_embed_demo.c')
-rw-r--r--examples/pugl_embed_demo.c27
1 files changed, 14 insertions, 13 deletions
diff --git a/examples/pugl_embed_demo.c b/examples/pugl_embed_demo.c
index 66605b7..ae3956a 100644
--- a/examples/pugl_embed_demo.c
+++ b/examples/pugl_embed_demo.c
@@ -14,7 +14,7 @@
#include <stdio.h>
#include <string.h>
-static const int borderWidth = 64;
+static const uint8_t borderWidth = 64u;
static const uintptr_t reverseTimerId = 1u;
typedef struct {
@@ -55,10 +55,11 @@ static const float backgroundColorVertices[] = {
static PuglRect
getChildFrame(const PuglRect parentFrame)
{
- const PuglRect childFrame = {borderWidth,
- borderWidth,
- parentFrame.width - 2 * borderWidth,
- parentFrame.height - 2 * borderWidth};
+ const PuglRect childFrame = {
+ borderWidth,
+ borderWidth,
+ (PuglSpan)(parentFrame.width - 2 * borderWidth),
+ (PuglSpan)(parentFrame.height - 2 * borderWidth)};
return childFrame;
}
@@ -118,26 +119,26 @@ onKeyPress(PuglView* view, const PuglKeyEvent* event, const char* prefix)
fprintf(stderr, "%sPaste \"%s\"\n", prefix, text);
} else if (event->state & PUGL_MOD_SHIFT) {
if (event->key == PUGL_KEY_UP) {
- frame.height += 10;
+ frame.height = (PuglSpan)(frame.height + 10u);
} else if (event->key == PUGL_KEY_DOWN) {
- frame.height -= 10;
+ frame.height = (PuglSpan)(frame.height - 10u);
} else if (event->key == PUGL_KEY_LEFT) {
- frame.width -= 10;
+ frame.width = (PuglSpan)(frame.width - 10u);
} else if (event->key == PUGL_KEY_RIGHT) {
- frame.width += 10;
+ frame.width = (PuglSpan)(frame.width + 10u);
} else {
return;
}
puglSetFrame(view, frame);
} else {
if (event->key == PUGL_KEY_UP) {
- frame.y -= 10;
+ frame.y = (PuglCoord)(frame.y - 10);
} else if (event->key == PUGL_KEY_DOWN) {
- frame.y += 10;
+ frame.y = (PuglCoord)(frame.y + 10);
} else if (event->key == PUGL_KEY_LEFT) {
- frame.x -= 10;
+ frame.x = (PuglCoord)(frame.x - 10);
} else if (event->key == PUGL_KEY_RIGHT) {
- frame.x += 10;
+ frame.x = (PuglCoord)(frame.x + 10);
} else {
return;
}