added new method set_window_icon for macos, windows, html5 platform
parent
d7865a6b0e
commit
89e9b9ab1d
|
@ -9,3 +9,4 @@ builtins
|
|||
.internal
|
||||
.clang_complete
|
||||
.vscode/
|
||||
*.txt
|
||||
|
|
|
@ -337,6 +337,13 @@ static int on_cursor_lock_disabled(lua_State *L)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int set_window_icon(lua_State *L)
|
||||
{
|
||||
const char *icon_path = luaL_checkstring(L, 1);
|
||||
defos_set_window_icon(icon_path);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void defos_emit_event(DefosEvent event)
|
||||
{
|
||||
LuaCallbackInfo *mscb = &defos_event_handlers[event];
|
||||
|
@ -401,6 +408,7 @@ static const luaL_reg Module_methods[] =
|
|||
{"get_view_size", get_view_size},
|
||||
{"set_cursor", set_cursor},
|
||||
{"reset_cursor", reset_cursor},
|
||||
{"set_window_icon", set_window_icon},
|
||||
{0, 0}};
|
||||
|
||||
static void LuaInit(lua_State *L)
|
||||
|
|
|
@ -144,6 +144,25 @@ void defos_set_window_title(const char* title_lua) {
|
|||
EM_ASM_({document.title = UTF8ToString($0)}, title_lua);
|
||||
}
|
||||
|
||||
void defos_set_window_icon(const char *icon_path)
|
||||
{
|
||||
EM_ASM_({
|
||||
document.head || (document.head = document.getElementsByTagName('head')[0]);
|
||||
function changeFavicon(src) {
|
||||
var link = document.createElement('link');
|
||||
var oldLink = document.getElementById('dynamic-favicon');
|
||||
link.id = 'dynamic-favicon';
|
||||
link.rel = 'shortcut icon';
|
||||
link.href = src;
|
||||
if (oldLink) {
|
||||
document.head.removeChild(oldLink);
|
||||
}
|
||||
document.head.appendChild(link);
|
||||
}
|
||||
changeFavicon(UTF8ToString($0));
|
||||
}, icon_path);
|
||||
}
|
||||
|
||||
void defos_set_window_size(float x, float y, float w, float h) {
|
||||
defos_set_view_size(x, y, w, h);
|
||||
}
|
||||
|
|
|
@ -110,6 +110,16 @@ void defos_set_window_size(float x, float y, float w, float h) {
|
|||
[window setFrame:NSMakeRect(x, win_y, w , h) display:YES];
|
||||
}
|
||||
|
||||
void defos_set_window_icon(const char *icon_path)
|
||||
{
|
||||
NSString *bundlePath = [[NSBundle mainBundle] resourcePath];
|
||||
NSString *secondParentPath = [[bundlePath stringByDeletingLastPathComponent] stringByDeletingLastPathComponent];
|
||||
NSString *path = [secondParentPath stringByAppendingPathComponent:[NSString stringWithUTF8String:icon_path]];
|
||||
NSImage* image = [[NSImage alloc] initWithContentsOfFile: path];
|
||||
[window setRepresentedURL:[NSURL URLWithString:path]];
|
||||
[[window standardWindowButton:NSWindowDocumentIconButton] setImage:image];
|
||||
}
|
||||
|
||||
void defos_set_view_size(float x, float y, float w, float h) {
|
||||
if (isnan(x)) {
|
||||
NSRect frame = window.screen.frame;
|
||||
|
|
|
@ -50,6 +50,8 @@ extern bool defos_is_fullscreen();
|
|||
extern bool defos_is_maximized();
|
||||
|
||||
extern void defos_set_window_title(const char* title_lua);
|
||||
extern void defos_set_window_icon(const char *icon_path);
|
||||
extern void defos_set_window_icon_mac(dmBuffer::HBuffer buffer);
|
||||
|
||||
extern void defos_set_window_size(float x, float y, float w, float h);
|
||||
extern WinRect defos_get_window_size();
|
||||
|
@ -75,4 +77,4 @@ extern void defos_set_custom_cursor_html5(const char *url);
|
|||
extern void defos_set_custom_cursor_win(const char *filename);
|
||||
extern void defos_set_custom_cursor_mac(dmBuffer::HBuffer buffer, float hotSpotX, float hotSpotY);
|
||||
extern void defos_set_cursor(DefosCursor cursor);
|
||||
extern void defos_reset_cursor();
|
||||
extern void defos_reset_cursor();
|
|
@ -206,6 +206,16 @@ void defos_set_window_title(const char *title_lua)
|
|||
SetWindowTextW(dmGraphics::GetNativeWindowsHWND(), CA2W(title_lua));
|
||||
}
|
||||
|
||||
void defos_set_window_icon(const char *icon_path)
|
||||
{
|
||||
HANDLE icon = LoadImage(NULL, icon_path, IMAGE_ICON, 32, 32, LR_LOADFROMFILE);
|
||||
if (icon)
|
||||
{
|
||||
HWND window = dmGraphics::GetNativeWindowsHWND();
|
||||
SendMessage(window, (UINT)WM_SETICON, ICON_BIG, (LPARAM)icon);
|
||||
}
|
||||
}
|
||||
|
||||
WinRect defos_get_window_size()
|
||||
{
|
||||
HWND window = dmGraphics::GetNativeWindowsHWND();
|
||||
|
|
|
@ -2668,6 +2668,166 @@ nodes {
|
|||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 861.0
|
||||
y: 389.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 200.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEMPLATE
|
||||
id: "set_icon"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
template: "/dirtylarry/button.gui"
|
||||
template_node_child: false
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 300.0
|
||||
y: 88.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_BOX
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
texture: "button/button_normal"
|
||||
id: "set_icon/larrybutton"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
parent: "set_icon"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
slice9 {
|
||||
x: 32.0
|
||||
y: 32.0
|
||||
z: 32.0
|
||||
w: 32.0
|
||||
}
|
||||
clipping_mode: CLIPPING_MODE_NONE
|
||||
clipping_visible: true
|
||||
clipping_inverted: false
|
||||
alpha: 1.0
|
||||
template_node_child: true
|
||||
size_mode: SIZE_MODE_MANUAL
|
||||
}
|
||||
nodes {
|
||||
position {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
rotation {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
scale {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
size {
|
||||
x: 250.0
|
||||
y: 100.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
color {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
type: TYPE_TEXT
|
||||
blend_mode: BLEND_MODE_ALPHA
|
||||
text: "Set Icon"
|
||||
font: "larryfont"
|
||||
id: "set_icon/larrylabel"
|
||||
xanchor: XANCHOR_NONE
|
||||
yanchor: YANCHOR_NONE
|
||||
pivot: PIVOT_CENTER
|
||||
outline {
|
||||
x: 0.0
|
||||
y: 0.0
|
||||
z: 0.0
|
||||
w: 1.0
|
||||
}
|
||||
shadow {
|
||||
x: 1.0
|
||||
y: 1.0
|
||||
z: 1.0
|
||||
w: 1.0
|
||||
}
|
||||
adjust_mode: ADJUST_MODE_FIT
|
||||
line_break: true
|
||||
parent: "set_icon/larrybutton"
|
||||
layer: ""
|
||||
inherit_alpha: true
|
||||
alpha: 1.0
|
||||
outline_alpha: 1.0
|
||||
shadow_alpha: 1.0
|
||||
overridden_fields: 4
|
||||
overridden_fields: 8
|
||||
overridden_fields: 18
|
||||
template_node_child: true
|
||||
text_leading: 1.0
|
||||
text_tracking: 0.0
|
||||
}
|
||||
material: "/builtins/materials/gui.material"
|
||||
adjust_reference: ADJUST_REFERENCE_LEGACY
|
||||
max_nodes: 512
|
||||
|
|
|
@ -4,6 +4,13 @@ local cursor_url = require("example.html5_cursor")
|
|||
|
||||
local system_name = sys.get_sys_info().system_name
|
||||
|
||||
--pls add the files using bundle_resources parameter in game.project https://www.defold.com/manuals/project-settings/
|
||||
local ICON_NAMES = {
|
||||
["Windows"] = "win.ico",
|
||||
["HTML5"] = "html5.ico",
|
||||
["Darwin"] = "/mac.png"
|
||||
}
|
||||
|
||||
function window_callback(self, event, data)
|
||||
if event == window.WINDOW_EVENT_FOCUS_LOST then
|
||||
-- though after lost focus cursor clipping will restore, we should restore it
|
||||
|
@ -204,6 +211,10 @@ function on_input(self, action_id, action)
|
|||
end
|
||||
end)
|
||||
|
||||
dirtylarry:button("set_icon", action_id, action, function()
|
||||
defos.set_window_icon(ICON_NAMES[system_name])
|
||||
end)
|
||||
|
||||
dirtylarry:button("change_cursor", action_id, action, function()
|
||||
self.current_cursor = self.current_cursor + 1
|
||||
|
||||
|
|
|
@ -3,6 +3,8 @@ title = DefOS
|
|||
version = 1.0.1
|
||||
dependencies = https://github.com/andsve/dirtylarry/archive/master.zip
|
||||
custom_resources = resources/
|
||||
bundle_resources = /icons
|
||||
write_log = 0
|
||||
|
||||
[bootstrap]
|
||||
main_collection = /example/example.collectionc
|
||||
|
|
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Binary file not shown.
After Width: | Height: | Size: 2.0 KiB |
Binary file not shown.
After Width: | Height: | Size: 21 KiB |
Loading…
Reference in New Issue