Compare commits
3 Commits
rawalpha
...
logicalsca
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e3a07c3309 | ||
|
|
2e40285244 | ||
|
|
eca99d5af7 |
@@ -70,7 +70,7 @@ static enum android_metastate convert_meta_state(SDL_Keymod mod) {
|
||||
return autocomplete_metastate(metastate);
|
||||
}
|
||||
|
||||
static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to, Uint16 mod) {
|
||||
static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to) {
|
||||
switch (from) {
|
||||
MAP(SDLK_RETURN, AKEYCODE_ENTER);
|
||||
MAP(SDLK_KP_ENTER, AKEYCODE_NUMPAD_ENTER);
|
||||
@@ -86,39 +86,6 @@ static SDL_bool convert_keycode(SDL_Keycode from, enum android_keycode *to, Uint
|
||||
MAP(SDLK_LEFT, AKEYCODE_DPAD_LEFT);
|
||||
MAP(SDLK_DOWN, AKEYCODE_DPAD_DOWN);
|
||||
MAP(SDLK_UP, AKEYCODE_DPAD_UP);
|
||||
}
|
||||
if (mod & (KMOD_LALT | KMOD_RALT | KMOD_LGUI | KMOD_RGUI)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
// if ALT and META are not pressed, also handle letters and space
|
||||
switch (from) {
|
||||
MAP(SDLK_a, AKEYCODE_A);
|
||||
MAP(SDLK_b, AKEYCODE_B);
|
||||
MAP(SDLK_c, AKEYCODE_C);
|
||||
MAP(SDLK_d, AKEYCODE_D);
|
||||
MAP(SDLK_e, AKEYCODE_E);
|
||||
MAP(SDLK_f, AKEYCODE_F);
|
||||
MAP(SDLK_g, AKEYCODE_G);
|
||||
MAP(SDLK_h, AKEYCODE_H);
|
||||
MAP(SDLK_i, AKEYCODE_I);
|
||||
MAP(SDLK_j, AKEYCODE_J);
|
||||
MAP(SDLK_k, AKEYCODE_K);
|
||||
MAP(SDLK_l, AKEYCODE_L);
|
||||
MAP(SDLK_m, AKEYCODE_M);
|
||||
MAP(SDLK_n, AKEYCODE_N);
|
||||
MAP(SDLK_o, AKEYCODE_O);
|
||||
MAP(SDLK_p, AKEYCODE_P);
|
||||
MAP(SDLK_q, AKEYCODE_Q);
|
||||
MAP(SDLK_r, AKEYCODE_R);
|
||||
MAP(SDLK_s, AKEYCODE_S);
|
||||
MAP(SDLK_t, AKEYCODE_T);
|
||||
MAP(SDLK_u, AKEYCODE_U);
|
||||
MAP(SDLK_v, AKEYCODE_V);
|
||||
MAP(SDLK_w, AKEYCODE_W);
|
||||
MAP(SDLK_x, AKEYCODE_X);
|
||||
MAP(SDLK_y, AKEYCODE_Y);
|
||||
MAP(SDLK_z, AKEYCODE_Z);
|
||||
MAP(SDLK_SPACE, AKEYCODE_SPACE);
|
||||
FAIL;
|
||||
}
|
||||
}
|
||||
@@ -159,12 +126,11 @@ SDL_bool input_key_from_sdl_to_android(const SDL_KeyboardEvent *from,
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
Uint16 mod = from->keysym.mod;
|
||||
if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode, mod)) {
|
||||
if (!convert_keycode(from->keysym.sym, &to->keycode_event.keycode)) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
to->keycode_event.metastate = convert_meta_state(mod);
|
||||
to->keycode_event.metastate = convert_meta_state(from->keysym.mod);
|
||||
|
||||
return SDL_TRUE;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#ifndef FILE_HANDLER_H
|
||||
#define FILE_HADNELR_H
|
||||
#define FILE_HANDLER_H
|
||||
|
||||
#include <SDL2/SDL_mutex.h>
|
||||
#include <SDL2/SDL_stdinc.h>
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "input_manager.h"
|
||||
|
||||
#include <SDL2/SDL_assert.h>
|
||||
#include "convert.h"
|
||||
#include "lock_util.h"
|
||||
#include "log.h"
|
||||
@@ -130,12 +129,6 @@ static void clipboard_paste(struct controller *controller) {
|
||||
|
||||
void input_manager_process_text_input(struct input_manager *input_manager,
|
||||
const SDL_TextInputEvent *event) {
|
||||
char c = event->text[0];
|
||||
if (isalpha(c) || c == ' ') {
|
||||
SDL_assert(event->text[1] == '\0');
|
||||
// letters and space are handled as raw key event
|
||||
return;
|
||||
}
|
||||
struct control_event control_event;
|
||||
control_event.type = CONTROL_EVENT_TYPE_TEXT;
|
||||
control_event.text_event.text = SDL_strdup(event->text);
|
||||
|
||||
@@ -88,6 +88,7 @@ static SDL_bool event_loop(void) {
|
||||
switch (event.window.event) {
|
||||
case SDL_WINDOWEVENT_EXPOSED:
|
||||
case SDL_WINDOWEVENT_SIZE_CHANGED:
|
||||
screen_update_scale(&screen);
|
||||
screen_render(&screen);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -132,6 +132,17 @@ static inline struct size get_initial_optimal_size(struct size frame_size) {
|
||||
return get_optimal_size(frame_size, frame_size);
|
||||
}
|
||||
|
||||
// apply hidpi scaling and call SDL_RenderSetLogicalSize
|
||||
static inline SDL_bool render_set_scaled_logical_size(struct screen *screen, struct size size) {
|
||||
int w, h, dw, dh;
|
||||
SDL_GL_GetDrawableSize(screen->window, &w, &h);
|
||||
SDL_GetWindowSize(screen->window, &dw, &dh);
|
||||
// use 32 bits unsigned not to lose precision (width and height fit in 16 bits)
|
||||
int scaled_x = (Uint32) size.width * (Uint32) w / (Uint32) dw;
|
||||
int scaled_y = (Uint32) size.height * (Uint32) h / (Uint32) dh;
|
||||
return SDL_RenderSetLogicalSize(screen->renderer, scaled_x, scaled_y);
|
||||
}
|
||||
|
||||
void screen_init(struct screen *screen) {
|
||||
*screen = (struct screen) SCREEN_INITIALIZER;
|
||||
}
|
||||
@@ -163,7 +174,7 @@ SDL_bool screen_init_rendering(struct screen *screen, const char *device_name, s
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, frame_size.width, frame_size.height)) {
|
||||
if (render_set_scaled_logical_size(screen, frame_size)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
screen_destroy(screen);
|
||||
return SDL_FALSE;
|
||||
@@ -208,7 +219,7 @@ void screen_destroy(struct screen *screen) {
|
||||
// recreate the texture and resize the window if the frame size has changed
|
||||
static SDL_bool prepare_for_frame(struct screen *screen, struct size new_frame_size) {
|
||||
if (screen->frame_size.width != new_frame_size.width || screen->frame_size.height != new_frame_size.height) {
|
||||
if (SDL_RenderSetLogicalSize(screen->renderer, new_frame_size.width, new_frame_size.height)) {
|
||||
if (render_set_scaled_logical_size(screen, new_frame_size)) {
|
||||
LOGE("Could not set renderer logical size: %s", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
}
|
||||
@@ -302,3 +313,7 @@ void screen_resize_to_pixel_perfect(struct screen *screen) {
|
||||
LOGD("Resized to pixel-perfect");
|
||||
}
|
||||
}
|
||||
|
||||
void screen_update_scale(struct screen *screen) {
|
||||
render_set_scaled_logical_size(screen, screen->frame_size);
|
||||
}
|
||||
|
||||
@@ -66,4 +66,8 @@ void screen_resize_to_fit(struct screen *screen);
|
||||
// resize window to 1:1 (pixel-perfect)
|
||||
void screen_resize_to_pixel_perfect(struct screen *screen);
|
||||
|
||||
// recompute the scale in case the window moved from/to another screen with a
|
||||
// different HiDPI
|
||||
void screen_update_scale(struct screen *screen);
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user