Add correct hit-test information and menu icon
This commit is contained in:
parent
7531a0ddc8
commit
8ad87d77da
|
@ -400,9 +400,11 @@ function core.init()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
core.window_borderless = false
|
||||||
|
core.hit_test_title_height = 0
|
||||||
if config.borderless then
|
if config.borderless then
|
||||||
system.set_window_bordered(false)
|
system.set_window_bordered(false)
|
||||||
system.set_window_hit_test()
|
core.window_borderless = true
|
||||||
end
|
end
|
||||||
|
|
||||||
core.frame_start = 0
|
core.frame_start = 0
|
||||||
|
|
|
@ -16,11 +16,25 @@ function TitleView:on_mouse_pressed()
|
||||||
core.set_active_view(core.last_active_view)
|
core.set_active_view(core.last_active_view)
|
||||||
end
|
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()
|
function TitleView:get_items()
|
||||||
local title = core.compose_window_title(core.window_title)
|
local title = core.compose_window_title(core.window_title)
|
||||||
return {
|
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",
|
style.text, style.icon_font, "_", TitleView.separator, "w", TitleView.separator, "W",
|
||||||
}
|
}
|
||||||
|
|
Binary file not shown.
|
@ -101,6 +101,12 @@
|
||||||
"css": "window-close",
|
"css": "window-close",
|
||||||
"code": 87,
|
"code": 87,
|
||||||
"src": "fontawesome"
|
"src": "fontawesome"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"uid": "559647a6f430b3aeadbecd67194451dd",
|
||||||
|
"css": "menu-1",
|
||||||
|
"code": 77,
|
||||||
|
"src": "fontawesome"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
|
@ -35,17 +35,22 @@ static char* key_name(char *dst, int sym) {
|
||||||
return dst;
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: shouldn't be hard-coded but should depend on TitleView's height
|
struct HitTestInfo {
|
||||||
#define TITLE_BAR_WIDTH 100
|
int title_height;
|
||||||
#define RESIZE_BORDER 40
|
int resize_border;
|
||||||
|
};
|
||||||
|
typedef struct HitTestInfo HitTestInfo;
|
||||||
|
|
||||||
static SDL_HitTestResult SDLCALL
|
static HitTestInfo window_hit_info[1] = {{0, 0}};
|
||||||
hit_test(SDL_Window *window, const SDL_Point *pt, void *data) {
|
|
||||||
|
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;
|
int w, h;
|
||||||
|
|
||||||
SDL_GetWindowSize(window, &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;
|
return SDL_HITTEST_DRAGGABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -53,21 +58,21 @@ hit_test(SDL_Window *window, const SDL_Point *pt, void *data) {
|
||||||
return SDL_HITTEST_RESIZE_##name; \
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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);
|
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) {
|
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);
|
lua_pushboolean(L, 0);
|
||||||
} else {
|
} else {
|
||||||
lua_pushboolean(L, 1);
|
lua_pushboolean(L, 1);
|
||||||
|
|
Loading…
Reference in New Issue