2019-01-12 22:03:39 +00:00
|
|
|
#
|
|
|
|
# FlightGear canvas gui
|
|
|
|
# Namespace: canvas
|
|
|
|
#
|
|
|
|
# Classes:
|
|
|
|
# WindowButton
|
|
|
|
# Window
|
|
|
|
#
|
|
|
|
# see also api.nas
|
|
|
|
|
|
|
|
|
2013-07-27 09:54:41 +00:00
|
|
|
var gui = {
|
|
|
|
widgets: {},
|
2013-07-26 22:34:30 +00:00
|
|
|
focused_window: nil,
|
2014-06-24 13:34:03 +00:00
|
|
|
region_highlight: nil,
|
|
|
|
|
|
|
|
# Window/dialog stacking order
|
|
|
|
STACK_INDEX: {
|
|
|
|
"default": 0,
|
|
|
|
"always-on-top": 1,
|
|
|
|
"tooltip": 2
|
|
|
|
}
|
2013-07-27 09:54:41 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
var gui_dir = getprop("/sim/fg-root") ~ "/Nasal/canvas/gui/";
|
|
|
|
var loadGUIFile = func(file) io.load_nasal(gui_dir ~ file, "canvas");
|
|
|
|
var loadWidget = func(name) loadGUIFile("widgets/" ~ name ~ ".nas");
|
2014-06-10 16:47:13 +00:00
|
|
|
var loadDialog = func(name) loadGUIFile("dialogs/" ~ name ~ ".nas");
|
2013-07-27 09:54:41 +00:00
|
|
|
|
2014-03-19 22:20:09 +00:00
|
|
|
loadGUIFile("Config.nas");
|
2013-07-27 09:54:41 +00:00
|
|
|
loadGUIFile("Style.nas");
|
|
|
|
loadGUIFile("Widget.nas");
|
|
|
|
loadGUIFile("styles/DefaultStyle.nas");
|
|
|
|
loadWidget("Button");
|
2014-06-17 19:02:59 +00:00
|
|
|
loadWidget("CheckBox");
|
2014-06-08 22:37:14 +00:00
|
|
|
loadWidget("Label");
|
2014-08-31 16:08:00 +00:00
|
|
|
loadWidget("LineEdit");
|
2014-03-19 22:20:09 +00:00
|
|
|
loadWidget("ScrollArea");
|
2014-09-01 17:31:25 +00:00
|
|
|
loadDialog("InputDialog");
|
2014-06-17 15:13:13 +00:00
|
|
|
loadDialog("MessageBox");
|
2013-07-27 09:54:41 +00:00
|
|
|
|
2014-06-17 15:13:13 +00:00
|
|
|
var style = DefaultStyle.new("AmbianceClassic", "Humanity");
|
2013-07-27 09:54:41 +00:00
|
|
|
var WindowButton = {
|
|
|
|
new: func(parent, name)
|
|
|
|
{
|
|
|
|
var m = {
|
|
|
|
parents: [WindowButton, gui.widgets.Button.new(parent, nil, {"flat": 1})],
|
|
|
|
_name: name
|
|
|
|
};
|
|
|
|
m._focus_policy = m.NoFocus;
|
2014-06-08 22:37:14 +00:00
|
|
|
m._setView({_root: parent.createChild("image", "WindowButton-" ~ name)});
|
2013-07-27 09:54:41 +00:00
|
|
|
return m;
|
|
|
|
},
|
|
|
|
# protected:
|
|
|
|
_onStateChange: func
|
|
|
|
{
|
|
|
|
var file = style._dir_decoration ~ "/" ~ me._name;
|
2014-06-01 10:25:34 +00:00
|
|
|
var window_focus = me._windowFocus();
|
|
|
|
file ~= window_focus ? "_focused" : "_unfocused";
|
2013-07-27 09:54:41 +00:00
|
|
|
|
2014-06-10 16:46:52 +00:00
|
|
|
if( me._down )
|
2013-07-27 09:54:41 +00:00
|
|
|
file ~= "_pressed";
|
|
|
|
else if( me._hover )
|
|
|
|
file ~= "_prelight";
|
2014-06-01 10:25:34 +00:00
|
|
|
else if( window_focus )
|
2013-07-27 09:54:41 +00:00
|
|
|
file ~= "_normal";
|
|
|
|
|
2014-06-08 22:37:14 +00:00
|
|
|
me._view._root.set("src", file ~ ".png");
|
2013-07-27 09:54:41 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-01-22 16:47:51 +00:00
|
|
|
var Window = {
|
2012-08-01 23:14:18 +00:00
|
|
|
# Constructor
|
|
|
|
#
|
2013-01-22 16:47:51 +00:00
|
|
|
# @param size ([width, height])
|
2013-06-06 20:46:37 +00:00
|
|
|
new: func(size, type = nil, id = nil)
|
2012-08-01 23:14:18 +00:00
|
|
|
{
|
2013-06-06 20:46:37 +00:00
|
|
|
var ghost = _newWindowGhost(id);
|
2012-08-01 23:14:18 +00:00
|
|
|
var m = {
|
2013-06-06 20:46:37 +00:00
|
|
|
parents: [Window, PropertyElement, ghost],
|
2014-06-01 10:25:34 +00:00
|
|
|
_ghost: ghost,
|
2013-07-27 09:54:41 +00:00
|
|
|
_node: props.wrapNode(ghost._node_ghost),
|
|
|
|
_focused: 0,
|
2017-05-29 07:24:22 +00:00
|
|
|
_widgets: [],
|
|
|
|
_frame_width: 4,
|
|
|
|
_title_bar_height: 25,
|
2020-07-05 08:01:01 +00:00
|
|
|
_title: nil,
|
2012-08-01 23:14:18 +00:00
|
|
|
};
|
2013-06-06 20:46:37 +00:00
|
|
|
|
2013-07-26 22:32:26 +00:00
|
|
|
m.setInt("content-size[0]", size[0]);
|
|
|
|
m.setInt("content-size[1]", size[1]);
|
2019-11-06 21:59:08 +00:00
|
|
|
m.setDouble("aspect-ratio", size[0]/size[1]);
|
|
|
|
m.setBool("lock-aspect-ratio", 0);
|
|
|
|
|
2013-06-06 20:46:37 +00:00
|
|
|
# TODO better default position
|
|
|
|
m.move(0,0);
|
2013-07-27 09:54:41 +00:00
|
|
|
m.setFocus();
|
2013-06-06 20:46:37 +00:00
|
|
|
|
2012-12-14 16:25:04 +00:00
|
|
|
# arg = [child, listener_node, mode, is_child_event]
|
|
|
|
setlistener(m._node, func m._propCallback(arg[0], arg[2]), 0, 2);
|
2013-06-06 20:46:37 +00:00
|
|
|
if( type )
|
|
|
|
m.set("type", type);
|
2012-12-14 16:25:04 +00:00
|
|
|
|
2012-08-01 23:14:18 +00:00
|
|
|
return m;
|
|
|
|
},
|
2013-01-01 12:16:19 +00:00
|
|
|
# Destructor
|
|
|
|
del: func
|
|
|
|
{
|
2020-07-05 08:01:01 +00:00
|
|
|
if (me["_title"] != nil)
|
|
|
|
me._title.del();
|
2013-07-27 09:54:41 +00:00
|
|
|
me.clearFocus();
|
|
|
|
|
2013-01-01 12:16:19 +00:00
|
|
|
if( me["_canvas"] != nil )
|
2013-06-08 11:07:16 +00:00
|
|
|
{
|
2014-06-01 10:25:34 +00:00
|
|
|
var placements = me._canvas._node.getChildren("placement");
|
2013-07-21 09:31:41 +00:00
|
|
|
# Do not remove canvas if other placements exist
|
2019-01-12 22:03:39 +00:00
|
|
|
if( size(placements) > 1 ) {
|
2013-07-21 09:31:41 +00:00
|
|
|
foreach(var p; placements)
|
|
|
|
{
|
|
|
|
if( p.getValue("type") == "window"
|
|
|
|
and p.getValue("id") == me.get("id") )
|
|
|
|
p.remove();
|
|
|
|
}
|
2019-01-12 22:03:39 +00:00
|
|
|
}
|
|
|
|
else {
|
2013-07-21 09:31:41 +00:00
|
|
|
me._canvas.del();
|
2019-01-12 22:03:39 +00:00
|
|
|
}
|
2013-06-08 11:07:16 +00:00
|
|
|
me._canvas = nil;
|
|
|
|
}
|
2018-12-04 13:47:20 +00:00
|
|
|
if (me._node != nil) {
|
|
|
|
me._node.remove();
|
|
|
|
me._node = nil;
|
|
|
|
}
|
2013-01-01 12:16:19 +00:00
|
|
|
},
|
2014-06-17 15:13:13 +00:00
|
|
|
setTitle: func(title)
|
|
|
|
{
|
|
|
|
return me.set("title", title);
|
|
|
|
},
|
2013-01-22 16:47:51 +00:00
|
|
|
# Create the canvas to be used for this Window
|
2012-08-01 23:14:18 +00:00
|
|
|
#
|
|
|
|
# @return The new canvas
|
|
|
|
createCanvas: func()
|
|
|
|
{
|
2013-01-22 16:47:51 +00:00
|
|
|
var size = [
|
2013-07-26 22:32:26 +00:00
|
|
|
me.get("content-size[0]"),
|
|
|
|
me.get("content-size[1]")
|
2012-08-01 23:14:18 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
me._canvas = new({
|
2014-06-08 22:37:14 +00:00
|
|
|
size: [size[0], size[1]],
|
2013-01-22 16:47:51 +00:00
|
|
|
view: size,
|
2012-08-01 23:14:18 +00:00
|
|
|
placement: {
|
|
|
|
type: "window",
|
2013-06-14 18:29:39 +00:00
|
|
|
id: me.get("id")
|
2013-07-13 10:52:46 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
# Standard alpha blending
|
|
|
|
"blend-source-rgb": "src-alpha",
|
|
|
|
"blend-destination-rgb": "one-minus-src-alpha",
|
|
|
|
|
|
|
|
# Just keep current alpha (TODO allow using rgb textures instead of rgba?)
|
|
|
|
"blend-source-alpha": "zero",
|
|
|
|
"blend-destination-alpha": "one"
|
2012-08-01 23:14:18 +00:00
|
|
|
});
|
2013-01-22 16:47:51 +00:00
|
|
|
|
2014-06-01 10:25:34 +00:00
|
|
|
me._canvas._focused_widget = nil;
|
|
|
|
me._canvas.data("focused", me._focused);
|
2013-01-22 16:47:51 +00:00
|
|
|
me._canvas.addEventListener("mousedown", func me.raise());
|
2014-06-01 10:25:34 +00:00
|
|
|
|
2013-01-22 16:47:51 +00:00
|
|
|
return me._canvas;
|
2012-08-01 23:14:18 +00:00
|
|
|
},
|
2013-01-22 16:47:51 +00:00
|
|
|
# Set an existing canvas to be used for this Window
|
2012-08-01 23:14:18 +00:00
|
|
|
setCanvas: func(canvas_)
|
|
|
|
{
|
2014-06-19 19:25:45 +00:00
|
|
|
if( ghosttype(canvas_) != "Canvas" )
|
|
|
|
return debug.warn("Not a Canvas");
|
2012-08-01 23:14:18 +00:00
|
|
|
|
2013-07-20 16:03:18 +00:00
|
|
|
canvas_.addPlacement({type: "window", "id": me.get("id")});
|
2012-08-01 23:14:18 +00:00
|
|
|
me['_canvas'] = canvas_;
|
2014-06-29 10:03:47 +00:00
|
|
|
|
|
|
|
canvas_._focused_widget = nil;
|
2014-06-01 10:25:34 +00:00
|
|
|
canvas_.data("focused", me._focused);
|
2013-07-26 22:34:30 +00:00
|
|
|
|
|
|
|
# prevent resizing if canvas is placed from somewhere else
|
|
|
|
me.onResize = nil;
|
2020-07-02 08:00:43 +00:00
|
|
|
return me;
|
2012-08-01 23:14:18 +00:00
|
|
|
},
|
|
|
|
# Get the displayed canvas
|
2014-06-04 15:52:48 +00:00
|
|
|
getCanvas: func(create = 0)
|
2012-08-01 23:14:18 +00:00
|
|
|
{
|
2014-06-04 15:52:48 +00:00
|
|
|
if( me['_canvas'] == nil and create )
|
|
|
|
me.createCanvas();
|
|
|
|
|
2012-08-01 23:14:18 +00:00
|
|
|
return me['_canvas'];
|
|
|
|
},
|
2013-06-06 20:46:37 +00:00
|
|
|
getCanvasDecoration: func()
|
|
|
|
{
|
|
|
|
return wrapCanvas(me._getCanvasDecoration());
|
|
|
|
},
|
2014-06-01 10:25:34 +00:00
|
|
|
setLayout: func(l)
|
2013-07-27 09:54:41 +00:00
|
|
|
{
|
2014-06-01 10:25:34 +00:00
|
|
|
if( me['_canvas'] == nil )
|
|
|
|
me.createCanvas();
|
|
|
|
|
|
|
|
me._canvas.update(); # Ensure placement is applied
|
|
|
|
me._ghost.setLayout(l);
|
2013-07-27 09:54:41 +00:00
|
|
|
return me;
|
|
|
|
},
|
|
|
|
#
|
|
|
|
setFocus: func
|
|
|
|
{
|
|
|
|
if( me._focused )
|
|
|
|
return me;
|
|
|
|
|
|
|
|
if( gui.focused_window != nil )
|
|
|
|
gui.focused_window.clearFocus();
|
|
|
|
|
|
|
|
me._focused = 1;
|
|
|
|
# me.onFocusIn();
|
|
|
|
me._onStateChange();
|
|
|
|
gui.focused_window = me;
|
2014-08-04 21:48:29 +00:00
|
|
|
setInputFocus(me);
|
2013-07-27 09:54:41 +00:00
|
|
|
return me;
|
|
|
|
},
|
|
|
|
#
|
|
|
|
clearFocus: func
|
|
|
|
{
|
|
|
|
if( !me._focused )
|
|
|
|
return me;
|
|
|
|
|
|
|
|
me._focused = 0;
|
|
|
|
# me.onFocusOut();
|
|
|
|
me._onStateChange();
|
|
|
|
gui.focused_window = nil;
|
2014-08-04 21:48:29 +00:00
|
|
|
setInputFocus(nil);
|
2013-07-27 09:54:41 +00:00
|
|
|
return me;
|
|
|
|
},
|
2014-06-30 21:18:48 +00:00
|
|
|
setPosition: func
|
2012-08-01 23:14:18 +00:00
|
|
|
{
|
2014-06-30 21:18:48 +00:00
|
|
|
if( size(arg) == 1 )
|
|
|
|
var arg = arg[0];
|
|
|
|
var (x, y) = arg;
|
|
|
|
|
2013-06-06 20:46:37 +00:00
|
|
|
me.setInt("tf/t[0]", x);
|
|
|
|
me.setInt("tf/t[1]", y);
|
2020-07-02 08:00:43 +00:00
|
|
|
return me;
|
2012-08-01 23:14:18 +00:00
|
|
|
},
|
2014-06-30 21:18:48 +00:00
|
|
|
setSize: func
|
2013-07-26 22:32:26 +00:00
|
|
|
{
|
2014-06-30 21:18:48 +00:00
|
|
|
if( size(arg) == 1 )
|
|
|
|
var arg = arg[0];
|
|
|
|
var (w, h) = arg;
|
|
|
|
|
2013-07-26 22:32:26 +00:00
|
|
|
me.set("content-size[0]", w);
|
|
|
|
me.set("content-size[1]", h);
|
2014-06-19 19:25:45 +00:00
|
|
|
|
|
|
|
if( me.onResize != nil )
|
|
|
|
me.onResize();
|
|
|
|
|
|
|
|
return me;
|
2013-07-26 22:32:26 +00:00
|
|
|
},
|
2018-12-05 16:00:30 +00:00
|
|
|
getSize: func
|
|
|
|
{
|
|
|
|
var w = me.get("content-size[0]");
|
|
|
|
var h = me.get("content-size[1]");
|
|
|
|
return [w,h];
|
|
|
|
},
|
2014-06-30 21:18:48 +00:00
|
|
|
move: func
|
2012-08-01 23:14:18 +00:00
|
|
|
{
|
2014-06-30 21:18:48 +00:00
|
|
|
if( size(arg) == 1 )
|
|
|
|
var arg = arg[0];
|
|
|
|
var (x, y) = arg;
|
|
|
|
|
2013-06-06 20:46:37 +00:00
|
|
|
me.setInt("tf/t[0]", me.get("tf/t[0]", 10) + x);
|
|
|
|
me.setInt("tf/t[1]", me.get("tf/t[1]", 30) + y);
|
2020-07-02 08:00:43 +00:00
|
|
|
return me;
|
2012-08-01 23:14:18 +00:00
|
|
|
},
|
|
|
|
# Raise to top of window stack
|
|
|
|
raise: func()
|
|
|
|
{
|
2013-06-14 18:29:39 +00:00
|
|
|
# on writing the z-index the window always is moved to the top of all other
|
|
|
|
# windows with the same z-index.
|
2014-06-24 13:34:03 +00:00
|
|
|
me.setInt("z-index", me.get("z-index", gui.STACK_INDEX["default"]));
|
2013-07-27 09:54:41 +00:00
|
|
|
|
|
|
|
me.setFocus();
|
|
|
|
},
|
2013-07-26 22:34:30 +00:00
|
|
|
onResize: func()
|
|
|
|
{
|
2013-07-27 20:22:38 +00:00
|
|
|
if( me['_canvas'] == nil )
|
|
|
|
return;
|
|
|
|
|
2013-07-26 22:34:30 +00:00
|
|
|
for(var i = 0; i < 2; i += 1)
|
|
|
|
{
|
|
|
|
var size = me.get("content-size[" ~ i ~ "]");
|
|
|
|
me._canvas.set("size[" ~ i ~ "]", size);
|
|
|
|
me._canvas.set("view[" ~ i ~ "]", size);
|
|
|
|
}
|
|
|
|
},
|
2019-11-06 21:59:08 +00:00
|
|
|
lockAspectRatio: func (lock=1) {
|
|
|
|
me.setBool("lock-aspect-ratio", lock);
|
|
|
|
},
|
2013-07-27 09:54:41 +00:00
|
|
|
# protected:
|
|
|
|
_onStateChange: func
|
|
|
|
{
|
2014-06-01 10:25:34 +00:00
|
|
|
var event = canvas.CustomEvent.new("wm.focus-" ~ (me._focused ? "in" : "out"));
|
|
|
|
|
2013-07-27 09:54:41 +00:00
|
|
|
if( me._getCanvasDecoration() != nil )
|
|
|
|
{
|
|
|
|
# Stronger shadow for focused windows
|
|
|
|
me.getCanvasDecoration()
|
|
|
|
.set("image[1]/fill", me._focused ? "#000000" : "rgba(0,0,0,0.5)");
|
|
|
|
|
|
|
|
var suffix = me._focused ? "" : "-unfocused";
|
|
|
|
me._title_bar_bg.set("fill", style.getColor("title" ~ suffix));
|
2019-01-06 23:10:07 +00:00
|
|
|
me._frame.setStroke(style.getColor("title" ~ suffix));
|
|
|
|
me._title.setColor(style.getColor("title-text" ~ suffix));
|
|
|
|
me._top_line.setStroke(style.getColor("title-highlight" ~ suffix));
|
2014-06-01 10:25:34 +00:00
|
|
|
|
|
|
|
me.getCanvasDecoration()
|
|
|
|
.data("focused", me._focused)
|
|
|
|
.dispatchEvent(event);
|
2013-07-27 09:54:41 +00:00
|
|
|
}
|
|
|
|
|
2014-06-01 10:25:34 +00:00
|
|
|
if( me.getCanvas() != nil )
|
|
|
|
me.getCanvas()
|
|
|
|
.data("focused", me._focused)
|
|
|
|
.dispatchEvent(event);
|
2012-12-14 16:25:04 +00:00
|
|
|
},
|
|
|
|
# private:
|
2019-11-06 21:59:08 +00:00
|
|
|
#mode 0 = value changed, +-1 add/remove node
|
2012-12-14 16:25:04 +00:00
|
|
|
_propCallback: func(child, mode)
|
|
|
|
{
|
2013-06-06 20:46:37 +00:00
|
|
|
if( !me._node.equals(child.getParent()) )
|
|
|
|
return;
|
|
|
|
var name = child.getName();
|
|
|
|
|
2012-12-14 16:25:04 +00:00
|
|
|
# support for CSS like position: absolute; with right and/or bottom margin
|
2013-06-06 20:46:37 +00:00
|
|
|
if( name == "right" )
|
|
|
|
me._handlePositionAbsolute(child, mode, name, 0);
|
2020-07-05 08:01:01 +00:00
|
|
|
elsif( name == "bottom" )
|
2013-06-06 20:46:37 +00:00
|
|
|
me._handlePositionAbsolute(child, mode, name, 1);
|
|
|
|
|
2020-07-05 08:01:01 +00:00
|
|
|
if (mode == 0) {
|
|
|
|
if (name == "type") me._updateDecoration();
|
|
|
|
elsif (name.starts_with("resize-")) me._handleResize(child, name);
|
|
|
|
elsif (name == "size") me._resizeDecoration();
|
2013-07-26 22:34:30 +00:00
|
|
|
}
|
2012-12-14 16:25:04 +00:00
|
|
|
},
|
|
|
|
_handlePositionAbsolute: func(child, mode, name, index)
|
|
|
|
{
|
|
|
|
# mode
|
|
|
|
# -1 child removed
|
|
|
|
# 0 value changed
|
|
|
|
# 1 child added
|
|
|
|
|
|
|
|
if( mode == 0 )
|
|
|
|
me._updatePos(index, name);
|
|
|
|
else if( mode == 1 )
|
|
|
|
me["_listener_" ~ name] = [
|
|
|
|
setlistener
|
|
|
|
(
|
|
|
|
"/sim/gui/canvas/size[" ~ index ~ "]",
|
|
|
|
func me._updatePos(index, name)
|
|
|
|
),
|
|
|
|
setlistener
|
|
|
|
(
|
2013-07-26 22:32:26 +00:00
|
|
|
me._node.getNode("content-size[" ~ index ~ "]"),
|
2012-12-14 16:25:04 +00:00
|
|
|
func me._updatePos(index, name)
|
|
|
|
)
|
|
|
|
];
|
|
|
|
else if( mode == -1 )
|
|
|
|
for(var i = 0; i < 2; i += 1)
|
|
|
|
removelistener(me["_listener_" ~ name][i]);
|
|
|
|
},
|
|
|
|
_updatePos: func(index, name)
|
|
|
|
{
|
|
|
|
me.setInt
|
|
|
|
(
|
2013-06-06 20:46:37 +00:00
|
|
|
"tf/t[" ~ index ~ "]",
|
2012-12-14 16:25:04 +00:00
|
|
|
getprop("/sim/gui/canvas/size[" ~ index ~ "]")
|
|
|
|
- me.get(name)
|
2013-07-26 22:32:26 +00:00
|
|
|
- me.get("content-size[" ~ index ~ "]")
|
2012-12-14 16:25:04 +00:00
|
|
|
);
|
2013-06-06 20:46:37 +00:00
|
|
|
},
|
2013-07-26 22:34:30 +00:00
|
|
|
_handleResize: func(child, name)
|
|
|
|
{
|
|
|
|
var is_status = name == "resize-status";
|
|
|
|
if( !is_status and !me["_resize"] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var min_size = [75, 100];
|
|
|
|
|
|
|
|
var x = me.get("tf/t[0]");
|
|
|
|
var y = me.get("tf/t[1]");
|
|
|
|
var old_size = [me.get("size[0]"), me.get("size[1]")];
|
2019-11-06 21:59:08 +00:00
|
|
|
if (me.get("lock-aspect-ratio"))
|
|
|
|
{
|
|
|
|
var old_csize = [me.get("content-size[0]"), me.get("content-size[1]")];
|
|
|
|
var dx = old_size[0] - old_csize[0];
|
|
|
|
var dy = old_size[1] - old_csize[1];
|
|
|
|
var ar = me.get("aspect-ratio");
|
|
|
|
|
|
|
|
if (name == "resize-right")
|
|
|
|
me.set("resize-bottom", (me.get("resize-right") - dx) / ar + dy);
|
|
|
|
if (name == "resize-bottom")
|
|
|
|
me.set("resize-right", (me.get("resize-bottom") - dy)* ar + dx);
|
|
|
|
|
|
|
|
if (name == "resize-left")
|
|
|
|
me.set("resize-top", (me.get("resize-left"))/ ar );
|
|
|
|
if (name == "resize-top")
|
|
|
|
me.set("resize-left", (me.get("resize-top"))* ar );
|
|
|
|
}
|
2013-07-26 22:34:30 +00:00
|
|
|
|
|
|
|
var l = x + math.min(me.get("resize-left"), old_size[0] - min_size[0]);
|
|
|
|
var t = y + math.min(me.get("resize-top"), old_size[1] - min_size[1]);
|
|
|
|
var r = x + math.max(me.get("resize-right"), min_size[0]);
|
|
|
|
var b = y + math.max(me.get("resize-bottom"), min_size[1]);
|
|
|
|
if( is_status )
|
|
|
|
{
|
|
|
|
me._resize = child.getValue();
|
|
|
|
|
|
|
|
if( me._resize and gui.region_highlight == nil )
|
|
|
|
gui.region_highlight =
|
|
|
|
getDesktop().createChild("path", "highlight")
|
|
|
|
.set("stroke", "#ffa500")
|
|
|
|
.set("stroke-width", 2)
|
|
|
|
.set("fill", "rgba(255, 165, 0, 0.15)")
|
|
|
|
.set("z-index", 100);
|
|
|
|
else if( !me._resize and gui.region_highlight != nil )
|
|
|
|
{
|
|
|
|
gui.region_highlight.hide();
|
|
|
|
me.setPosition(l, t);
|
|
|
|
me.setSize
|
|
|
|
(
|
|
|
|
me.get("content-size[0]") + (r - l) - old_size[0],
|
|
|
|
me.get("content-size[1]") + (b - t) - old_size[1],
|
|
|
|
);
|
|
|
|
if( me.onResize != nil )
|
|
|
|
me.onResize();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if( !me["_resize"] )
|
|
|
|
return;
|
|
|
|
|
|
|
|
gui.region_highlight.reset()
|
|
|
|
.moveTo(l, t)
|
|
|
|
.horizTo(r)
|
|
|
|
.vertTo(b)
|
|
|
|
.horizTo(l)
|
|
|
|
.close()
|
|
|
|
.update()
|
|
|
|
.show();
|
|
|
|
},
|
2013-06-06 20:46:37 +00:00
|
|
|
_updateDecoration: func()
|
|
|
|
{
|
|
|
|
var border_radius = 9;
|
|
|
|
me.set("decoration-border", "25 1 1");
|
|
|
|
me.set("shadow-inset", int((1 - math.cos(45 * D2R)) * border_radius + 0.5));
|
|
|
|
me.set("shadow-radius", 5);
|
2013-06-08 11:07:16 +00:00
|
|
|
me.setBool("update", 1);
|
2013-06-06 20:46:37 +00:00
|
|
|
|
|
|
|
var canvas_deco = me.getCanvasDecoration();
|
|
|
|
canvas_deco.addEventListener("mousedown", func me.raise());
|
|
|
|
canvas_deco.set("blend-source-rgb", "src-alpha");
|
|
|
|
canvas_deco.set("blend-destination-rgb", "one-minus-src-alpha");
|
|
|
|
canvas_deco.set("blend-source-alpha", "one");
|
|
|
|
canvas_deco.set("blend-destination-alpha", "one");
|
|
|
|
|
|
|
|
var group_deco = canvas_deco.getGroup("decoration");
|
|
|
|
var title_bar = group_deco.createChild("group", "title_bar");
|
2013-07-26 22:34:30 +00:00
|
|
|
me._title_bar_bg = title_bar.createChild("path");
|
|
|
|
me._top_line = title_bar.createChild("path", "top-line");
|
2017-05-29 07:24:22 +00:00
|
|
|
me._frame = title_bar.createChild("path");
|
|
|
|
me._frame.set("fill", "none");
|
|
|
|
me._frame.set("stroke-width", me._frame_width);
|
2013-06-06 20:46:37 +00:00
|
|
|
|
|
|
|
# close icon
|
|
|
|
var x = 10;
|
|
|
|
var y = 3;
|
|
|
|
var w = 19;
|
|
|
|
var h = 19;
|
2013-07-27 09:54:41 +00:00
|
|
|
|
|
|
|
var button_close = WindowButton.new(title_bar, "close")
|
|
|
|
.move(x, y);
|
2014-06-10 16:46:52 +00:00
|
|
|
button_close.listen("clicked", func me.del());
|
2013-06-06 20:46:37 +00:00
|
|
|
|
|
|
|
# title
|
|
|
|
var title = me.get("title", "Canvas Dialog");
|
2019-01-06 23:10:07 +00:00
|
|
|
me._title = title_bar.createChild("text", "title")
|
|
|
|
.setText(title)
|
|
|
|
.setAlignment("left-center")
|
|
|
|
.set("character-size", 14)
|
|
|
|
.setFont("LiberationFonts/LiberationSans-Bold.ttf")
|
|
|
|
.setTranslation(int(x + 1.5 * w + 0.5), int(y + 0.5 * h + 0.5));
|
|
|
|
|
2013-06-06 20:46:37 +00:00
|
|
|
me._node.getNode("title", 1).alias(me._title._node.getPath() ~ "/text");
|
2013-07-27 09:54:41 +00:00
|
|
|
title_bar.addEventListener("drag", func(e) me.move(e.deltaX, e.deltaY));
|
2013-07-26 22:34:30 +00:00
|
|
|
|
|
|
|
me._resizeDecoration();
|
2013-07-27 09:54:41 +00:00
|
|
|
me._onStateChange();
|
2013-07-26 22:34:30 +00:00
|
|
|
},
|
|
|
|
_resizeDecoration: func()
|
|
|
|
{
|
|
|
|
if( me["_title_bar_bg"] == nil )
|
|
|
|
return;
|
|
|
|
|
|
|
|
var border_radius = 9;
|
|
|
|
me._title_bar_bg
|
2017-05-29 07:24:22 +00:00
|
|
|
.reset()
|
|
|
|
.rect( 0, 0,
|
|
|
|
me.get("size[0]"), me._title_bar_height,
|
|
|
|
{"border-top-radius": border_radius} );
|
|
|
|
me._frame
|
2013-07-26 22:34:30 +00:00
|
|
|
.reset()
|
|
|
|
.rect( 0, 0,
|
|
|
|
me.get("size[0]"), me.get("size[1]"),
|
|
|
|
{"border-top-radius": border_radius} );
|
|
|
|
|
|
|
|
me._top_line
|
|
|
|
.reset()
|
|
|
|
.moveTo(border_radius - 2, 2)
|
|
|
|
.lineTo(me.get("size[0]") - border_radius + 2, 2);
|
2012-08-01 23:14:18 +00:00
|
|
|
}
|
2019-01-06 23:10:07 +00:00
|
|
|
}; #Window
|
2013-07-20 16:03:18 +00:00
|
|
|
|
2014-08-04 21:48:29 +00:00
|
|
|
# Clear focus on click outside any window
|
|
|
|
getDesktop().addEventListener("mousedown", func {
|
|
|
|
if( gui.focused_window != nil )
|
|
|
|
gui.focused_window.clearFocus();
|
|
|
|
});
|
|
|
|
|
2013-07-20 16:03:18 +00:00
|
|
|
# Provide old 'Dialog' for backwards compatiblity (should be removed for 3.0)
|
|
|
|
var Dialog = {
|
|
|
|
new: func(size, type = nil, id = nil)
|
|
|
|
{
|
|
|
|
debug.warn("'canvas.Dialog' is deprectated! (use canvas.Window instead)");
|
|
|
|
return Window.new(size, type, id);
|
|
|
|
}
|
|
|
|
};
|