Add correct hit-test information and menu icon

This commit is contained in:
Francesco Abbate 2021-04-11 15:08:25 +02:00
parent 7531a0ddc8
commit 8ad87d77da
6 changed files with 47 additions and 18 deletions

View File

@ -400,9 +400,11 @@ function core.init()
end
end
core.window_borderless = false
core.hit_test_title_height = 0
if config.borderless then
system.set_window_bordered(false)
system.set_window_hit_test()
core.window_borderless = true
end
core.frame_start = 0

View File

@ -16,11 +16,25 @@ function TitleView:on_mouse_pressed()
core.set_active_view(core.last_active_view)
end
function TitleView:on_mouse_moved(px, py, ...)
end
function TitleView:update()
TitleView.super.update(self)
local title_height = self.size.y
if core.window_borderless and title_height ~= core.hit_test_title_height then
local resize_border = title_height / 2
system.set_window_hit_test(title_height, resize_border)
core.hit_test_title_height = title_height
end
end
function TitleView:get_items()
local title = core.compose_window_title(core.window_title)
return {
style.text, style.icon_font, "g ", style.font, title,
style.text, style.icon_font, "M ", style.font, title,
}, {
style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W",
}

Binary file not shown.

View File

@ -101,6 +101,12 @@
"css": "window-close",
"code": 87,
"src": "fontawesome"
},
{
"uid": "559647a6f430b3aeadbecd67194451dd",
"css": "menu-1",
"code": 77,
"src": "fontawesome"
}
]
}
}

View File

@ -35,17 +35,22 @@ static char* key_name(char *dst, int sym) {
return dst;
}
// FIXME: shouldn't be hard-coded but should depend on TitleView's height
#define TITLE_BAR_WIDTH 100
#define RESIZE_BORDER 40
struct HitTestInfo {
int title_height;
int resize_border;
};
typedef struct HitTestInfo HitTestInfo;
static SDL_HitTestResult SDLCALL
hit_test(SDL_Window *window, const SDL_Point *pt, void *data) {
static HitTestInfo window_hit_info[1] = {{0, 0}};
static SDL_HitTestResult SDLCALL hit_test(SDL_Window *window, const SDL_Point *pt, void *data) {
const HitTestInfo *hit_info = (HitTestInfo *) data;
const int resize_border = hit_info->resize_border;
int w, h;
SDL_GetWindowSize(window, &w, &h);
if (pt->y < TITLE_BAR_WIDTH && pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER) {
if (pt->y < hit_info->title_height && pt->x > resize_border && pt->x < w - resize_border) {
return SDL_HITTEST_DRAGGABLE;
}
@ -53,21 +58,21 @@ hit_test(SDL_Window *window, const SDL_Point *pt, void *data) {
return SDL_HITTEST_RESIZE_##name; \
}
if (pt->x < RESIZE_BORDER && pt->y < RESIZE_BORDER) {
if (pt->x < resize_border && pt->y < resize_border) {
REPORT_RESIZE_HIT(TOPLEFT);
} else if (pt->x > RESIZE_BORDER && pt->x < w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
} else if (pt->x > resize_border && pt->x < w - resize_border && pt->y < resize_border) {
REPORT_RESIZE_HIT(TOP);
} else if (pt->x > w - RESIZE_BORDER && pt->y < RESIZE_BORDER) {
} else if (pt->x > w - resize_border && pt->y < resize_border) {
REPORT_RESIZE_HIT(TOPRIGHT);
} else if (pt->x > w - RESIZE_BORDER && pt->y > RESIZE_BORDER && pt->y < h - RESIZE_BORDER) {
} else if (pt->x > w - resize_border && pt->y > resize_border && pt->y < h - resize_border) {
REPORT_RESIZE_HIT(RIGHT);
} else if (pt->x > w - RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
} else if (pt->x > w - resize_border && pt->y > h - resize_border) {
REPORT_RESIZE_HIT(BOTTOMRIGHT);
} else if (pt->x < w - RESIZE_BORDER && pt->x > RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
} else if (pt->x < w - resize_border && pt->x > resize_border && pt->y > h - resize_border) {
REPORT_RESIZE_HIT(BOTTOM);
} else if (pt->x < RESIZE_BORDER && pt->y > h - RESIZE_BORDER) {
} else if (pt->x < resize_border && pt->y > h - resize_border) {
REPORT_RESIZE_HIT(BOTTOMLEFT);
} else if (pt->x < RESIZE_BORDER && pt->y < h - RESIZE_BORDER && pt->y > RESIZE_BORDER) {
} else if (pt->x < resize_border && pt->y < h - resize_border && pt->y > resize_border) {
REPORT_RESIZE_HIT(LEFT);
}
@ -247,7 +252,9 @@ static int f_set_window_bordered(lua_State *L) {
static int f_set_window_hit_test(lua_State *L) {
if (SDL_SetWindowHitTest(window, hit_test, NULL) == -1) {
window_hit_info->title_height = luaL_checknumber(L, 1);
window_hit_info->resize_border = luaL_checknumber(L, 2);
if (SDL_SetWindowHitTest(window, hit_test, window_hit_info) == -1) {
lua_pushboolean(L, 0);
} else {
lua_pushboolean(L, 1);