mirror of
https://github.com/hyprwm/wlroots-hyprland.git
synced 2024-11-22 21:05:58 +01:00
Spice up the example program a bit
This commit is contained in:
parent
7a25d6c50b
commit
28e3148bbc
1 changed files with 16 additions and 20 deletions
|
@ -32,8 +32,7 @@ struct output_state {
|
||||||
struct wlr_output *output;
|
struct wlr_output *output;
|
||||||
struct state *state;
|
struct state *state;
|
||||||
struct wl_listener frame;
|
struct wl_listener frame;
|
||||||
float x, y;
|
float x_offs, y_offs;
|
||||||
float vel_x, vel_y;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
struct output_config {
|
struct output_config {
|
||||||
|
@ -47,12 +46,19 @@ static void output_frame(struct wl_listener *listener, void *data) {
|
||||||
struct wlr_output *output = ostate->output;
|
struct wlr_output *output = ostate->output;
|
||||||
struct state *s = ostate->state;
|
struct state *s = ostate->state;
|
||||||
|
|
||||||
|
int32_t width, height;
|
||||||
|
wlr_output_effective_resolution(output, &width, &height);
|
||||||
|
|
||||||
wlr_renderer_begin(s->renderer, output);
|
wlr_renderer_begin(s->renderer, output);
|
||||||
|
|
||||||
float matrix[16];
|
float matrix[16];
|
||||||
|
for (int y = -128 + (int)ostate->y_offs; y < height; y += 128) {
|
||||||
|
for (int x = -128 + (int)ostate->x_offs; x < width; x += 128) {
|
||||||
wlr_surface_get_matrix(s->cat_texture, &matrix,
|
wlr_surface_get_matrix(s->cat_texture, &matrix,
|
||||||
&output->transform_matrix, ostate->x, ostate->y);
|
&output->transform_matrix, x, y);
|
||||||
wlr_render_with_matrix(s->renderer, s->cat_texture, &matrix);
|
wlr_render_with_matrix(s->renderer, s->cat_texture, &matrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
wlr_renderer_end(s->renderer);
|
wlr_renderer_end(s->renderer);
|
||||||
|
|
||||||
|
@ -62,18 +68,10 @@ static void output_frame(struct wl_listener *listener, void *data) {
|
||||||
(now.tv_nsec - ostate->last_frame.tv_nsec) / 1000000;
|
(now.tv_nsec - ostate->last_frame.tv_nsec) / 1000000;
|
||||||
float seconds = ms / 1000.0f;
|
float seconds = ms / 1000.0f;
|
||||||
|
|
||||||
int32_t width, height;
|
ostate->x_offs += 128 * seconds;
|
||||||
wlr_output_effective_resolution(output, &width, &height);
|
ostate->y_offs += 128 * seconds;
|
||||||
ostate->x += ostate->vel_x * seconds;
|
if (ostate->x_offs > 128) ostate->x_offs = 0;
|
||||||
ostate->y += ostate->vel_y * seconds;
|
if (ostate->y_offs > 128) ostate->y_offs = 0;
|
||||||
if (ostate->y > height - 128) {
|
|
||||||
ostate->vel_y = -ostate->vel_y;
|
|
||||||
} else {
|
|
||||||
ostate->vel_y += 50 * seconds;
|
|
||||||
}
|
|
||||||
if (ostate->x > width - 128 || ostate->x < 0) {
|
|
||||||
ostate->vel_x = -ostate->vel_x;
|
|
||||||
}
|
|
||||||
ostate->last_frame = now;
|
ostate->last_frame = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,9 +88,7 @@ static void output_add(struct wl_listener *listener, void *data) {
|
||||||
ostate->output = output;
|
ostate->output = output;
|
||||||
ostate->state = state;
|
ostate->state = state;
|
||||||
ostate->frame.notify = output_frame;
|
ostate->frame.notify = output_frame;
|
||||||
ostate->x = ostate->y = 0;
|
ostate->x_offs = ostate->y_offs = 0;
|
||||||
ostate->vel_x = 100;
|
|
||||||
ostate->vel_y = 0;
|
|
||||||
|
|
||||||
struct output_config *conf;
|
struct output_config *conf;
|
||||||
wl_list_for_each(conf, &state->config, link) {
|
wl_list_for_each(conf, &state->config, link) {
|
||||||
|
|
Loading…
Reference in a new issue