}
}
}
+
+struct u_vec2 i_cursor_pos(void) {
+ struct u_vec2 r;
+ r.x = i_input_map.cursor_x;
+ r.y = i_input_map.cursor_y;
+ return r;
+}
/* sets cursor positon
* should be called by p_poll_events
+ * this should be the position of the cursor
+ * in render space *not* window space
*/
void i_input_cursor_set(i32 x, i32 y);
/* tests if the input is delayed */
lrts_bool i_input_is_delayed(enum i_input_actions action);
+struct u_vec2 i_cursor_pos(void);
+
/* inits the default for a keybind */
void i_input_map_init_default(enum i_input_actions action,
u16 scan_code,
}
int p_poll_events() {
+ struct u_vec2 render_res = lrts_get_render_res();
+ struct u_vec2 screen_res = lrts_get_screen_res();
SDL_Event e;
float x, y;
+ float scale_x = (float)screen_res.x / (float)render_res.x;
+ float scale_y = (float)screen_res.y / (float)render_res.y;
while (SDL_PollEvent(&e)) {
switch (e.type) {
mouse_state = SDL_GetMouseState(&x, &y);
- i_input_cursor_set(x, y);
+ i_input_cursor_set((float)x / scale_x, (float)y / scale_y);
+
return 0;
}
u32 i = 0;
u32 j = 0;
r_color final_color;
+ u32 hover_color_shift = 0;
struct u_vec2 t = u_tile_to_screen(x, y);
struct u_vec2 tt = u_tile_to_screen(x+1, y+1);
struct u_vec2 tl = u_tile_to_screen(x+2, y);
struct u_vec2 tb = u_tile_to_screen(x+2, y-2);
+
+ /* get mouse cursor and move by camera */
+ struct u_vec2 cursor_pos = u_world_to_camera(&t_main_camera, i_cursor_pos());
+ if (u_point_in_rect(cursor_pos.x, cursor_pos.y,
+ t.x, t.y,
+ R_TILE_W, R_TILE_H)) {
+ hover_color_shift = 1;
+ }
/* do not draw if tile is not visible at all
* also include a few points outside the camera to avoid tiles
for (i = 0; i < R_TILE_W; i++) {
for (j = 0; j < R_TILE_H; j++) {
final_color = r_asset_fallback_tile[i + j * R_TILE_W] & color;
+ final_color <<= hover_color_shift;
r_draw_pixel(&r_framebuffer, t.x + i, t.y + j, final_color);
+
}
}
return v;
}
+
+struct u_vec2 u_world_to_camera(struct t_camera *c, struct u_vec2 v) {
+ v.x += c->x;
+ v.y += c->y;
+
+ return v;
+}
void t_camera_scroll(struct t_camera *c, i32 by_x, i32 by_y);
-/* adjusts a screen coodrinate by the camera offset */
+/* adjusts a screen coodrinate (isometric) by the camera offset */
struct u_vec2 u_screen_to_camera(struct t_camera *c, struct u_vec2 v);
+/* converts a world coordinate (not isometric) to camera */
+struct u_vec2 u_world_to_camera(struct t_camera *c, struct u_vec2 v);
+
/* tests if a point is visible in screen sapce */
lrts_bool t_camera_is_visible_screen(struct t_camera *c, i32 x, i32 y);