Initial commit
This commit is contained in:
131
third-party/mexui/Core/Component/Control.js
vendored
Normal file
131
third-party/mexui/Core/Component/Control.js
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
mexui.Component.Control = function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Entity.Component.call(this, false);
|
||||
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Control', styles));
|
||||
|
||||
this.window = window;
|
||||
this.position = new Vec2(x, y);
|
||||
this.size = new Vec2(w, h);
|
||||
this.callback = callback;
|
||||
|
||||
this.boundTo = null;
|
||||
};
|
||||
mexui.util.extend(mexui.Component.Control, mexui.Entity.Component);
|
||||
|
||||
// default styles
|
||||
//mexui.Component.Control.defaultStyles = {};
|
||||
//mexui.Component.Control.defaultStyles.__proto__ = mexui.Entity.StyleableEntity.defaultStyles;
|
||||
|
||||
mexui.Component.Control.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {});
|
||||
|
||||
// input
|
||||
mexui.Component.Control.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var hit = this.isCursorOverControl();
|
||||
if(hit)
|
||||
{
|
||||
e.used = true;
|
||||
e.clickedAControl = true;
|
||||
mexui.focusedControl = this;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.onMouseUp = function(e)
|
||||
{
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
if(!this.isHovered())
|
||||
{
|
||||
mexui.setHoveredComponent(this);
|
||||
this.onMouseEnter();
|
||||
}
|
||||
e.used = true;
|
||||
}
|
||||
else if(e.wasHovered)
|
||||
{
|
||||
mexui.clearHoveredComponent();
|
||||
this.onMouseExit();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.onMouseWheel = function(e, data)
|
||||
{
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.onKeyDown = function(e, key, mods)
|
||||
{
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.onCharacter = function(e, character)
|
||||
{
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Component.Control.prototype.render = function()
|
||||
{
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.renderAfter = function()
|
||||
{
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Component.Control.prototype.checkToCallCallback = function()
|
||||
{
|
||||
if(this.callback)
|
||||
this.callback.call(this);
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.getScreenPosition = function()
|
||||
{
|
||||
var pos = mexui.util.addVec2(this.window.position, this.position);
|
||||
if(this.boundTo)
|
||||
pos = mexui.util.addVec2(pos, new Vec2(-this.boundTo.axis.x.getScrolledOffsetFixedStart(), -this.boundTo.axis.y.getScrolledOffsetFixedStart()));
|
||||
return pos;
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.isCursorOverControl = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.getScreenPosition(), this.getSizeForInput ? this.getSizeForInput() : this.size);
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.isCursorOverItem = function()
|
||||
{
|
||||
return this.isCursorOverControl();
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.isInsideBoundControl = function()
|
||||
{
|
||||
if(this.boundTo instanceof mexui.Entity.ControlWithEntries)
|
||||
return this.isInsideBoundControlEntries();
|
||||
else
|
||||
return mexui.util.isRectangleInsideRectangle(this.getScreenPosition(), this.size, this.boundTo.getScreenPosition(), this.boundTo.size);
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.isInsideBoundControlEntries = function()
|
||||
{
|
||||
var boundToControlPosition = mexui.util.addVec2(this.boundTo.getScreenPosition(), this.boundTo.entriesPositionOffset);
|
||||
var boundToControlSize = new Vec2(this.boundTo.size.x, this.boundTo.axis.y.getDisplayedEntriesLength());
|
||||
return mexui.util.isRectangleInsideRectangle(this.getScreenPosition(), this.size, boundToControlPosition, boundToControlSize);
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.Component.Control.prototype.remove = function()
|
||||
{
|
||||
this.window.controls.splice(this.window.controls.indexOf(this), 1);
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.bindTo = function(control)
|
||||
{
|
||||
this.boundTo = control;
|
||||
};
|
||||
|
||||
mexui.Component.Control.prototype.unbind = function()
|
||||
{
|
||||
this.boundTo = null;
|
||||
};
|
||||
|
||||
32
third-party/mexui/Core/Component/Entry.js
vendored
Normal file
32
third-party/mexui/Core/Component/Entry.js
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
mexui.Component.Entry = function(control, axisIndex, text, styles)
|
||||
{
|
||||
mexui.Entity.Component.call(this, false);
|
||||
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Entry', styles));
|
||||
|
||||
this.control = control;
|
||||
this.axisIndex = axisIndex;
|
||||
this.text = text;
|
||||
};
|
||||
mexui.util.extend(mexui.Component.Entry, mexui.Entity.Component);
|
||||
|
||||
// default styles
|
||||
mexui.Component.Entry.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {});
|
||||
|
||||
// model
|
||||
mexui.Component.Entry.prototype.getEntryIndex = function()
|
||||
{
|
||||
return this.control.axis[this.getAxisKey()].entries.indexOf(this);
|
||||
};
|
||||
|
||||
mexui.Component.Entry.prototype.getAxisKey = function()
|
||||
{
|
||||
return this.axisIndex == 0 ? 'x' : 'y';
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.Component.Entry.prototype.remove = function()
|
||||
{
|
||||
this.control.axis[this.getAxisKey()].entries.splice(this.getEntryIndex(), 1);
|
||||
this.control.checkToShowScrollBars();
|
||||
};
|
||||
|
||||
6
third-party/mexui/Core/Component/Event.js
vendored
Normal file
6
third-party/mexui/Core/Component/Event.js
vendored
Normal file
@@ -0,0 +1,6 @@
|
||||
mexui.Component.Event = function()
|
||||
{
|
||||
this.used = false;
|
||||
this.clickedAControl = false;
|
||||
};
|
||||
|
||||
379
third-party/mexui/Core/Component/Window.js
vendored
Normal file
379
third-party/mexui/Core/Component/Window.js
vendored
Normal file
@@ -0,0 +1,379 @@
|
||||
mexui.Component.Window = function(x, y, w, h, title, styles)
|
||||
{
|
||||
mexui.Entity.Component.call(this, true);
|
||||
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Window', styles));
|
||||
|
||||
this.position = new Vec2(x, y);
|
||||
this.size = new Vec2(w, h);
|
||||
this.title = title || '';
|
||||
|
||||
this.controls = [];
|
||||
this.titleBarShown = true;
|
||||
this.titleBarHeight = 30;
|
||||
this.titleBarIconShown = true;
|
||||
this.titleBarIconSize = new Vec2(30, 30);
|
||||
};
|
||||
mexui.util.extend(mexui.Component.Window, mexui.Entity.Component);
|
||||
|
||||
// default styles
|
||||
mexui.Component.Window.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {
|
||||
main:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 190),
|
||||
textColour: toColour(255, 255, 255, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 170)
|
||||
}
|
||||
},
|
||||
title:
|
||||
{
|
||||
backgroundColour: toColour(79, 161, 246, 190),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
icon:
|
||||
{
|
||||
backgroundColour: toColour(245, 5, 5, 190),
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
textSize: 21,
|
||||
textAlign: 0.5,
|
||||
textIndent: 0
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Component.Window.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.titleBarShown && this.titleBarIconShown && this.isCursorOverCloseIcon())
|
||||
{
|
||||
this.shown = false;
|
||||
mexui.setInput(false);
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.isCursorOverWindow())
|
||||
{
|
||||
this.setTop();
|
||||
}
|
||||
|
||||
this.triggerEvent('onMouseDown', e);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.onMouseUp = function(e)
|
||||
{
|
||||
this.triggerEvent('onMouseUp', e);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
//var wasHovered = this.isHovered();
|
||||
//e.wasHovered = wasHovered;
|
||||
|
||||
if(mexui.hoveredComponent && !mexui.hoveredComponent.isCursorOverItem())
|
||||
{
|
||||
mexui.hoveredComponent.onMouseExit();
|
||||
mexui.clearHoveredComponent();
|
||||
}
|
||||
|
||||
this.triggerEvent('onMouseMove', e, offset);
|
||||
|
||||
if(e.used)
|
||||
{
|
||||
/*
|
||||
if(wasHovered)
|
||||
{
|
||||
mexui.clearHoveredComponent();
|
||||
this.onMouseExit();
|
||||
}
|
||||
*/
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.isCursorOverWindow())
|
||||
{
|
||||
if(!this.isHovered())
|
||||
{
|
||||
mexui.setHoveredComponent(this);
|
||||
this.onMouseEnter();
|
||||
}
|
||||
e.used = true;
|
||||
}
|
||||
/*
|
||||
else if(wasHovered)
|
||||
{
|
||||
mexui.clearHoveredComponent();
|
||||
this.onMouseExit();
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.onMouseWheel = function(e, data)
|
||||
{
|
||||
this.triggerEvent('onMouseWheel', e, data);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.onKeyDown = function(e, key, mods)
|
||||
{
|
||||
this.triggerEvent('onKeyDown', e, key, mods);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.onCharacter = function(e, character)
|
||||
{
|
||||
this.triggerEvent('onCharacter', e, character);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Component.Window.prototype.render = function()
|
||||
{
|
||||
// window background
|
||||
mexui.native.drawRectangleBackground(this.position, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.titleBarShown)
|
||||
{
|
||||
// window title bar
|
||||
mexui.native.drawRectangle(this.position, new Vec2(this.size.x, this.titleBarHeight), this.getStyles('title'));
|
||||
mexui.native.drawText(this.position, new Vec2(this.size.x, this.titleBarHeight), this.title, this.getStyles('title'));
|
||||
|
||||
if(this.titleBarIconShown)
|
||||
{
|
||||
// window title bar icons
|
||||
var iconPos = this.getCloseIconPosition();
|
||||
mexui.native.drawRectangle(iconPos, this.titleBarIconSize, this.getStyles('icon'));
|
||||
mexui.native.drawText(iconPos, this.titleBarIconSize, 'X', this.getStyles('icon'));
|
||||
}
|
||||
}
|
||||
|
||||
// window border
|
||||
mexui.native.drawRectangleBorder(this.position, this.size, this.getStyles('main'));
|
||||
|
||||
// window controls
|
||||
var show, control;
|
||||
for(var i in this.controls)
|
||||
{
|
||||
control = this.controls[i];
|
||||
show = false;
|
||||
|
||||
if(control.shown)
|
||||
{
|
||||
show = true;
|
||||
if(control.boundTo)
|
||||
{
|
||||
if(!control.isInsideBoundControl())
|
||||
show = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(show)
|
||||
control.render.call(control);
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.renderAfter = function()
|
||||
{
|
||||
for(var i in this.controls)
|
||||
{
|
||||
if(this.controls[i].shown)
|
||||
{
|
||||
this.controls[i].renderAfter.call(this.controls[i]);
|
||||
|
||||
for(var i2 in this.controls[i].scrollBars)
|
||||
{
|
||||
if(this.controls[i].scrollBars[i2].shown)
|
||||
this.controls[i].scrollBars[i2].renderAfter(this.controls[i].scrollBars[i2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Component.Window.prototype.center = function()
|
||||
{
|
||||
this.position = mexui.util.getCenterPosition(mexui.util.getWindowSize(), this.size);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.setTop = function()
|
||||
{
|
||||
mexui.windows.splice(mexui.windows.indexOf(this), 1);
|
||||
mexui.windows.push(this);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.remove = function()
|
||||
{
|
||||
mexui.windows.splice(mexui.windows.indexOf(this), 1);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.isCursorOverCloseIcon = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.getCloseIconPosition(), this.titleBarIconSize);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.getCloseIconPosition = function()
|
||||
{
|
||||
return new Vec2(this.position.x + (this.size.x - this.titleBarIconSize.x), this.position.y);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, callBaseMethodFirst)
|
||||
{
|
||||
for(var i in this.controls)
|
||||
{
|
||||
var control = this.controls[i];
|
||||
|
||||
if(!control.shown)
|
||||
continue;
|
||||
|
||||
if(callBaseMethodFirst)
|
||||
{
|
||||
if(mexui.Entity.Component.prototype[eventName])
|
||||
{
|
||||
mexui.Entity.Component.prototype[eventName].call(control, e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
|
||||
this.controls[i][eventName].call(control, e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.controls[i][eventName].call(control, e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
|
||||
if(mexui.Entity.Component.prototype[eventName])
|
||||
{
|
||||
mexui.Entity.Component.prototype[eventName].call(control, e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.addControl = function(control)
|
||||
{
|
||||
this.controls.push(control);
|
||||
return control;
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.setShown = function(shown)
|
||||
{
|
||||
//var anyWindowShownBefore = mexui.isAnyWindowShown();
|
||||
|
||||
this.shown = shown;
|
||||
|
||||
if(mexui.focusedControl && this.isControlInWindow(mexui.focusedControl))
|
||||
{
|
||||
if(!shown)
|
||||
{
|
||||
mexui.focusedControl = null;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if(shown)
|
||||
{
|
||||
if(!anyWindowShownBefore)
|
||||
mexui.bindEvents();
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!mexui.isAnyWindowShown())
|
||||
mexui.unbindEvents();
|
||||
}
|
||||
*/
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.isShown = function()
|
||||
{
|
||||
return this.shown;
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.isControlInWindow = function(control)
|
||||
{
|
||||
for(var i in this.controls)
|
||||
{
|
||||
if(control == this.controls[i])
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.isCursorOverWindow = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.position, this.size);
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.isCursorOverItem = function()
|
||||
{
|
||||
return this.isCursorOverWindow();
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.getScreenPosition = function()
|
||||
{
|
||||
return this.position;
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.getFirstShownControl = function()
|
||||
{
|
||||
for(var i in this.controls)
|
||||
{
|
||||
if(this.controls[i].shown)
|
||||
return this.controls[i];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
mexui.Component.Window.prototype.getNextShownControl = function(afterControl)
|
||||
{
|
||||
var controlIndex = this.controls.indexOf(afterControl);
|
||||
|
||||
if(this.controls[controlIndex + 1])
|
||||
return this.controls[controlIndex + 1];
|
||||
else
|
||||
return null;
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.Component.Window.prototype.button = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Button(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.character = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Character(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.characters = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Characters(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.checkBox = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.CheckBox(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.day = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Day(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.date = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Date(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.digit = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Digit(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.digits = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Digits(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.dropDown = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.DropDown(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.grid = function(x, y, w, h, styles) { return this.addControl(new mexui.Control.Grid(this, x, y, w, h, styles)); };
|
||||
mexui.Component.Window.prototype.hour = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Hour(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.image = function(x, y, w, h, filePath, styles) { return this.addControl(new mexui.Control.Image(this, x, y, w, h, filePath, styles)); };
|
||||
mexui.Component.Window.prototype.integer = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Integer(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.letter = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Letter(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.letters = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Letters(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.letterDigit = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.LetterDigit(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.lettersDigits = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.LettersDigits(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.line = function(x, y, w, h, styles, callback) { return this.addControl(new mexui.Control.Line(this, x, y, w, h, styles, callback)); };
|
||||
mexui.Component.Window.prototype.list = function(x, y, w, h, styles, callback) { return this.addControl(new mexui.Control.List(this, x, y, w, h, styles, callback)); };
|
||||
mexui.Component.Window.prototype.minute = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Minute(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.month = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Month(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.number = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Number(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.password = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Password(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.progressBar = function(x, y, w, h, text, styles) { return this.addControl(new mexui.Control.ProgressBar(this, x, y, w, h, text, styles)); };
|
||||
mexui.Component.Window.prototype.radioButton = function(x, y, w, h, text, groupId, styles, callback) { return this.addControl(new mexui.Control.RadioButton(this, x, y, w, h, text, groupId, styles, callback)); };
|
||||
mexui.Component.Window.prototype.rangedInteger = function(x, y, w, h, text, min, max, styles, callback) { return this.addControl(new mexui.Control.RangedInteger(this, x, y, w, h, text, min, max, styles, callback)); };
|
||||
mexui.Component.Window.prototype.rangedNumber = function(x, y, w, h, text, min, max, styles, callback) { return this.addControl(new mexui.Control.RangedNumber(this, x, y, w, h, text, min, max, styles, callback)); };
|
||||
mexui.Component.Window.prototype.rectangle = function(x, y, w, h, styles, callback) { return this.addControl(new mexui.Control.Rectangle(this, x, y, w, h, styles, callback)); };
|
||||
mexui.Component.Window.prototype.scrollBar = function(x, y, w, h, isVertical, styles, callback) { return this.addControl(new mexui.Control.ScrollBar(this, x, y, w, h, isVertical, styles, callback)); };
|
||||
mexui.Component.Window.prototype.second = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Second(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.slider = function(x, y, w, h, isVertical, text, minText, maxText, styles, callback) { return this.addControl(new mexui.Control.Slider(this, x, y, w, h, isVertical, text, minText, maxText, styles, callback)); };
|
||||
mexui.Component.Window.prototype.tabPanel = function(x, y, w, h, styles, callback) { return this.addControl(new mexui.Control.TabPanel(this, x, y, w, h, styles, callback)); };
|
||||
mexui.Component.Window.prototype.text = function(x, y, w, h, text, styles) { return this.addControl(new mexui.Control.Text(this, x, y, w, h, text, styles)); };
|
||||
mexui.Component.Window.prototype.textArea = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.TextArea(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.textInput = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.TextInput(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.time = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Time(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.tree = function(x, y, w, h, styles, callback) { return this.addControl(new mexui.Control.Tree(this, x, y, w, h, styles, callback)); };
|
||||
mexui.Component.Window.prototype.week = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Week(this, x, y, w, h, text, styles, callback)); };
|
||||
mexui.Component.Window.prototype.year = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Year(this, x, y, w, h, text, styles, callback)); };
|
||||
|
||||
28
third-party/mexui/Core/Control/Button.js
vendored
Normal file
28
third-party/mexui/Core/Control/Button.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
mexui.util.createControlConstructor('Button', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Button', styles), callback);
|
||||
|
||||
this.text = text;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Button', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Button.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Button.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Character.js
vendored
Normal file
11
third-party/mexui/Core/Control/Character.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Character', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Character', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Character, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Character.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isCharacterInOctetRange(character, 32, 126);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Characters.js
vendored
Normal file
11
third-party/mexui/Core/Control/Characters.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Characters', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Characters', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Characters, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Characters.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isCharacterInOctetRange(character, 32, 126);
|
||||
};
|
||||
48
third-party/mexui/Core/Control/CheckBox.js
vendored
Normal file
48
third-party/mexui/Core/Control/CheckBox.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
mexui.util.createControlConstructor('CheckBox', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('CheckBox', styles), callback);
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.checked = false;
|
||||
this.textMarginLeft = 5;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('CheckBox', {
|
||||
innerBox:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.CheckBox.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.CheckBox.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.checked)
|
||||
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(1, 1)), new Vec2(this.size.x - 2, this.size.y - 2), this.getStyles('innerBox'));
|
||||
|
||||
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.CheckBox.prototype.getSizeForInput = function()
|
||||
{
|
||||
var textWidth = mexui.native.getTextWidth(this.text, this.getStyles('main'));
|
||||
return new Vec2(this.size.x + this.textMarginLeft + textWidth, this.size.y);
|
||||
};
|
||||
162
third-party/mexui/Core/Control/Date.js
vendored
Normal file
162
third-party/mexui/Core/Control/Date.js
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
mexui.util.createControlConstructor('Date', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Date', styles), callback, false, false);
|
||||
|
||||
this.day = 1;
|
||||
this.month = 1;
|
||||
this.year = 2019;
|
||||
|
||||
this.inputShown = false;
|
||||
this.valueBoxSize = new Vec2(50, 30);
|
||||
this.arrowBoxSize = new Vec2(25, 22);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Date, mexui.Control.TextInput);
|
||||
|
||||
// static
|
||||
mexui.Control.Date.units = ['day', 'month', 'year'];
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Date', {
|
||||
arrow:
|
||||
{
|
||||
backgroundColour: toColour(90, 90, 80, 230),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Date.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.inputShown)
|
||||
{
|
||||
var arrowIndex = this.getArrowIndexByCursor();
|
||||
if(arrowIndex !== false)
|
||||
{
|
||||
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
|
||||
var propName = mexui.Control.Date.units[propIndex];
|
||||
var isIncrease = (arrowIndex % 2) == 1;
|
||||
|
||||
if(isIncrease)
|
||||
this[propName]++;
|
||||
else
|
||||
this[propName]--;
|
||||
|
||||
if(this.day == 0)
|
||||
this.day = 31;
|
||||
else if(this.day == 32)
|
||||
this.day = 1;
|
||||
|
||||
if(this.month == 0)
|
||||
this.month = 12;
|
||||
else if(this.month == 13)
|
||||
this.month = 1;
|
||||
|
||||
if(this.year == 1899)
|
||||
this.year = 1900;
|
||||
else if(this.year == 2020)
|
||||
this.year = 2019;
|
||||
|
||||
this.generateText();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.inputShown = !this.inputShown;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.inputShown)
|
||||
{
|
||||
this.inputShown = false;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Date.prototype.renderAfter = function()
|
||||
{
|
||||
if(!this.inputShown)
|
||||
return;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Date.units[i]], this.getStyles('main'));
|
||||
|
||||
pos.x += this.valueBoxSize.x;
|
||||
}
|
||||
|
||||
pos = new Vec2(screenPos.x, screenPos.y);
|
||||
pos.y += this.valueBoxSize.y;
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
for(var i2=0; i2<2; i2++)
|
||||
{
|
||||
var text = (i2 % 2) == 0 ? '<' : '>';
|
||||
|
||||
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
|
||||
|
||||
pos.x += this.arrowBoxSize.x;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Date.prototype.generateText = function()
|
||||
{
|
||||
this.text = (this.day < 10 ? '0'+this.day : this.day)
|
||||
+'/'+(this.month < 10 ? '0'+this.month : this.month)
|
||||
+'/'+(this.year < 10 ? '0'+this.year : this.year);
|
||||
};
|
||||
|
||||
mexui.Control.Date.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var text = this.getTextWithNewCharacter(character);
|
||||
var parts = text.split(':');
|
||||
|
||||
for(var i in parts)
|
||||
{
|
||||
if(i == 3)
|
||||
return false;
|
||||
|
||||
var part = parseInt(parts[i]);
|
||||
|
||||
if(isNaN(part))
|
||||
return false;
|
||||
|
||||
if(part < 0)
|
||||
return false;
|
||||
|
||||
if(part > (i == 0 ? 23 : 59))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mexui.Control.Date.prototype.getArrowIndexByCursor = function()
|
||||
{
|
||||
var cursorPos = gui.cursorPosition;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
|
||||
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
|
||||
|
||||
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
|
||||
{
|
||||
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Day.js
vendored
Normal file
19
third-party/mexui/Core/Control/Day.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Day', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Day', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Day, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Day.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 31)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Digit.js
vendored
Normal file
11
third-party/mexui/Core/Control/Digit.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Digit', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Digit', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Digit, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Digit.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isDigit(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Digits.js
vendored
Normal file
11
third-party/mexui/Core/Control/Digits.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Digits', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Digits', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Digits, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Digits.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isDigit(character);
|
||||
};
|
||||
117
third-party/mexui/Core/Control/DropDown.js
vendored
Normal file
117
third-party/mexui/Core/Control/DropDown.js
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
mexui.util.createControlConstructor('DropDown', true, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('DropDown', styles), callback);
|
||||
mexui.Entity.ControlWithEntries.call(this, true, true, new Vec2(0, h), new Vec2(w + 120, 25));
|
||||
|
||||
this.axis.y.entriesShown = false;
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.arrowShown = true;
|
||||
this.selectedEntryIndex = -1;
|
||||
this.hoveredEntryIndex = -1;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('DropDown', {
|
||||
item:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(80, 80, 80, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.DropDown.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.axis.y.entries.length == 0)
|
||||
return;
|
||||
|
||||
var hitButton = this.isCursorOverControl();
|
||||
if(hitButton)
|
||||
{
|
||||
e.used = true;
|
||||
this.setListShown(!this.axis.y.entriesShown);
|
||||
}
|
||||
else if(this.axis.y.entriesShown)
|
||||
{
|
||||
var selectedEntryIndex = this.axis.y.getEntryIndexByCursor();
|
||||
if(selectedEntryIndex != null)
|
||||
{
|
||||
e.used = true;
|
||||
this.selectedEntryIndex = selectedEntryIndex;
|
||||
this.checkToCallCallback();
|
||||
this.setListShown(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(!e.used)
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.DropDown.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var text = this.selectedEntryIndex == -1 ? this.text : this.axis.y.entries[this.selectedEntryIndex].text;
|
||||
mexui.native.drawText(pos, this.size, text, this.getStyles('main'));
|
||||
|
||||
if(this.arrowShown)
|
||||
{
|
||||
var pos2 = new Vec2(pos.x + this.size.x - (25 + 3), pos.y + 0);
|
||||
mexui.native.drawImage(pos2, new Vec2(25, 25), mexui.images.downArrow, this.getStyles('main'));
|
||||
}
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.render.call(this);
|
||||
};
|
||||
|
||||
mexui.Control.DropDown.prototype.renderAfter = function()
|
||||
{
|
||||
if(this.axis.y.entriesShown)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
pos.x += this.entriesPositionOffset.x;
|
||||
pos.y += this.entriesPositionOffset.y;
|
||||
|
||||
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
|
||||
{
|
||||
var item = this.axis.y.entries[i];
|
||||
if(!item)
|
||||
break;
|
||||
|
||||
//this.hovered = i == this.axis.y.hoveredEntryIndex;
|
||||
|
||||
mexui.native.drawRectangle(pos, this.entrySize, this.getStyles('item'));
|
||||
mexui.native.drawText(pos, this.entrySize, item.text, this.getStyles('item'));
|
||||
|
||||
pos.y += this.entrySize.y;
|
||||
}
|
||||
}
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.renderAfter.call(this);
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.DropDown.prototype.item = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.DropDownItem(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.DropDown.prototype.setListShown = function(shown)
|
||||
{
|
||||
this.axis.y.entriesShown = shown;
|
||||
this.axis.y.setScrollBarShown(shown);
|
||||
};
|
||||
|
||||
127
third-party/mexui/Core/Control/Grid.js
vendored
Normal file
127
third-party/mexui/Core/Control/Grid.js
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
mexui.util.createControlConstructor('Grid', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Grid', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false, new Vec2(0, 25), new Vec2(this.size.x, 25), new Vec2(0, -25));
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Grid', {
|
||||
column:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
header:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
cell:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
row:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// render
|
||||
mexui.Control.Grid.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var startX = pos.x;
|
||||
var maxColumnHeight = 0;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var column = this.axis.x.entries[i];
|
||||
|
||||
mexui.native.drawText(new Vec2(startX, pos.y), new Vec2(column.width, column.height), column.text, this.getStyles('header'));
|
||||
|
||||
startX += column.width;
|
||||
mexui.native.drawAALine(new Vec2(startX, pos.y), new Vec2(startX, pos.y + this.size.y), this.getStyles('column'));
|
||||
|
||||
if(column.height > maxColumnHeight)
|
||||
{
|
||||
maxColumnHeight = column.height;
|
||||
}
|
||||
}
|
||||
|
||||
var startY = pos.y + maxColumnHeight;
|
||||
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
|
||||
|
||||
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
|
||||
{
|
||||
var row = this.axis.y.entries[i];
|
||||
if(!row)
|
||||
break;
|
||||
|
||||
startX = pos.x;
|
||||
for(var i2 in row.cells)
|
||||
{
|
||||
var column = this.axis.x.entries[i2];
|
||||
var cell = row.cells[i2];
|
||||
var cellText = cell.text;
|
||||
|
||||
var styles = this.getEntryStyles([[cell,'main'], [row,'main'], [this,'row'], [this,'cell']]);
|
||||
|
||||
mexui.native.drawRectangle(new Vec2(startX, startY), new Vec2(column.width, column.height), styles);
|
||||
mexui.native.drawText(new Vec2(startX, startY), new Vec2(column.width, column.height), cellText, styles);
|
||||
|
||||
startX += column.width;
|
||||
}
|
||||
|
||||
startY += row.rowHeight;
|
||||
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Grid.prototype.column = function(text, width, height)
|
||||
{
|
||||
var entry = new mexui.Entry.GridColumn(this, text, width, height);
|
||||
this.axis.x.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.row = function(cellsData, styles)
|
||||
{
|
||||
var cells = [];
|
||||
for(var i in cellsData)
|
||||
{
|
||||
if(cellsData[i] instanceof mexui.Component.Entry)
|
||||
{
|
||||
cells[i] = cellsData[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
cells[i] = new mexui.Component.Entry(this, 1, cellsData[i] + '');
|
||||
}
|
||||
}
|
||||
|
||||
var entry = new mexui.Entry.GridRow(this, cells, styles);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.cell = function(text, styles)
|
||||
{
|
||||
var entry = new mexui.Component.Entry(this, 0, text, styles);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.getAllEntriesLength = function(axisIndex)
|
||||
{
|
||||
if(axisIndex == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.axis.y.getAllEntriesLength2();
|
||||
}
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Hour.js
vendored
Normal file
19
third-party/mexui/Core/Control/Hour.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Hour', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Hour', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Hour, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Hour.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 23)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
17
third-party/mexui/Core/Control/Image.js
vendored
Normal file
17
third-party/mexui/Core/Control/Image.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
mexui.util.createControlConstructor('Image', false, function(window, x, y, w, h, filePath, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Image', styles));
|
||||
|
||||
this.image = mexui.native.loadImage(filePath);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Image', {});
|
||||
|
||||
// render
|
||||
mexui.Control.Image.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawImage(pos, this.size, this.image, this.getStyles('main'));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Integer.js
vendored
Normal file
11
third-party/mexui/Core/Control/Integer.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Integer', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Integer', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Integer, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Integer.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return !isNaN(parseInt(this.getTextWithNewCharacter(character)));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Letter.js
vendored
Normal file
11
third-party/mexui/Core/Control/Letter.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Letter', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Letter', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Letter, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Letter.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetter(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/LetterDigit.js
vendored
Normal file
11
third-party/mexui/Core/Control/LetterDigit.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('LetterDigit', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('LetterDigit', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.LetterDigit, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.LetterDigit.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetterOrDigit(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Letters.js
vendored
Normal file
11
third-party/mexui/Core/Control/Letters.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Letters', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Letters', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Letters, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Letters.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetter(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/LettersDigits.js
vendored
Normal file
11
third-party/mexui/Core/Control/LettersDigits.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('LettersDigits', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('LettersDigits', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.LettersDigits, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.LettersDigits.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetterOrDigit(character);
|
||||
};
|
||||
23
third-party/mexui/Core/Control/Line.js
vendored
Normal file
23
third-party/mexui/Core/Control/Line.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
mexui.util.createControlConstructor('Line', false, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Line', styles), callback);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Line', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Line.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Line.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawAALine(pos, this.size, this.getStyles('main'));
|
||||
};
|
||||
58
third-party/mexui/Core/Control/List.js
vendored
Normal file
58
third-party/mexui/Core/Control/List.js
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
mexui.util.createControlConstructor('List', true, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('List', styles), callback);
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.activeRow = null;
|
||||
this.rowHeight = 25;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('List', {
|
||||
row:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
rowLine:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.List.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.activeRow = this.axis.y.getEntryByCursor();
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.List.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
for(var i in this.axis.y.entries)
|
||||
{
|
||||
var row = this.axis.y.entries[i];
|
||||
var rowText = row.text;
|
||||
|
||||
mexui.native.drawRectangle(pos, new Vec2(this.size.x, this.rowHeight), this.getStyles('row'));
|
||||
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), rowText, this.getStyles('row'));
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.List.prototype.row = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.ListRow(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Minute.js
vendored
Normal file
19
third-party/mexui/Core/Control/Minute.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Minute', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Minute', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Minute, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Minute.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 59)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Month.js
vendored
Normal file
19
third-party/mexui/Core/Control/Month.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Month', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Month', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Month, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Month.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 11)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Number.js
vendored
Normal file
11
third-party/mexui/Core/Control/Number.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Number', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Number', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Number, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Number.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return !isNaN(parseFloat(this.getTextWithNewCharacter(character)));
|
||||
};
|
||||
7
third-party/mexui/Core/Control/Password.js
vendored
Normal file
7
third-party/mexui/Core/Control/Password.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.util.createControlConstructor('Password', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Password', styles), callback, false, true);
|
||||
|
||||
this.masked = true;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Password, mexui.Control.TextInput);
|
||||
35
third-party/mexui/Core/Control/ProgressBar.js
vendored
Normal file
35
third-party/mexui/Core/Control/ProgressBar.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
mexui.util.createControlConstructor('ProgressBar', false, function(window, x, y, w, h, text, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ProgressBar', styles));
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.progress = 0.0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('ProgressBar', {
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(80, 255, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// render
|
||||
mexui.Control.ProgressBar.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var innerBarSize = new Vec2(this.size.x * this.progress, this.size.y);
|
||||
mexui.native.drawRectangle(pos, innerBarSize, this.getStyles('innerBar'));
|
||||
|
||||
if(this.text != '')
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
88
third-party/mexui/Core/Control/RadioButton.js
vendored
Normal file
88
third-party/mexui/Core/Control/RadioButton.js
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
mexui.util.createControlConstructor('RadioButton', false, function(window, x, y, w, h, groupId, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('RadioButton', styles), callback);
|
||||
|
||||
this.groupId = groupId;
|
||||
this.text = text;
|
||||
|
||||
this.checked = this.isFirstRadioInGroup();
|
||||
this.textMarginLeft = 5;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('RadioButton', {
|
||||
innerBox:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.RadioButton.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
var checkedRadio = this.getCheckedRadio();
|
||||
if(checkedRadio != this.checked)
|
||||
checkedRadio.checked = false;
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.RadioButton.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.checked)
|
||||
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(2, 2)), new Vec2(this.size.x - 4, this.size.y - 4), this.getStyles('innerBox'));
|
||||
|
||||
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.RadioButton.prototype.getSizeForInput = function()
|
||||
{
|
||||
var textWidth = mexui.native.getTextWidth(this.text, this.getStyles('main'));
|
||||
return new Vec2(this.size.x + this.textMarginLeft + textWidth, this.size.y);
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.getGroupRadios = function()
|
||||
{
|
||||
var radios = [];
|
||||
var windows = mexui.windows;
|
||||
for(var i in windows)
|
||||
{
|
||||
var window = mexui.windows[i];
|
||||
|
||||
for(var i2 in window.controls)
|
||||
{
|
||||
var control = window.controls[i2];
|
||||
|
||||
if((control instanceof mexui.Control.RadioButton) && this.groupId == control.groupId)
|
||||
{
|
||||
radios.push(control);
|
||||
}
|
||||
}
|
||||
}
|
||||
return radios;
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.getCheckedRadio = function()
|
||||
{
|
||||
var radios = this.getGroupRadios();
|
||||
for(var i in radios)
|
||||
{
|
||||
if(radios[i].checked)
|
||||
return radios[i];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.isFirstRadioInGroup = function()
|
||||
{
|
||||
return this.getGroupRadios().length == 0;
|
||||
};
|
||||
22
third-party/mexui/Core/Control/RangedInteger.js
vendored
Normal file
22
third-party/mexui/Core/Control/RangedInteger.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
mexui.util.createControlConstructor('RangedInteger', false, function(window, x, y, w, h, min, max, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedInteger', styles), callback, false, false);
|
||||
|
||||
this.min = min === undefined ? 0 : min;
|
||||
this.max = max === undefined ? 100 : max;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.RangedInteger, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.RangedInteger.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var number = parseInt(this.getTextWithNewCharacter(character));
|
||||
|
||||
if(!isNaN(number))
|
||||
return false;
|
||||
|
||||
if(number < this.min || number > this.max)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
22
third-party/mexui/Core/Control/RangedNumber.js
vendored
Normal file
22
third-party/mexui/Core/Control/RangedNumber.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
mexui.util.createControlConstructor('RangedNumber', false, function(window, x, y, w, h, min, max, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedNumber', styles), callback, false, false);
|
||||
|
||||
this.min = min === undefined ? 0.0 : min;
|
||||
this.max = max === undefined ? 100.0 : max;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.RangedNumber, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.RangedNumber.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var number = parseFloat(this.getTextWithNewCharacter(character));
|
||||
|
||||
if(!isNaN(number))
|
||||
return false;
|
||||
|
||||
if(number < this.min || number > this.max)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
23
third-party/mexui/Core/Control/Rectangle.js
vendored
Normal file
23
third-party/mexui/Core/Control/Rectangle.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
mexui.util.createControlConstructor('Rectangle', false, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Rectangle', styles), callback);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Rectangle', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Rectangle.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Rectangle.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
};
|
||||
120
third-party/mexui/Core/Control/ScrollBar.js
vendored
Normal file
120
third-party/mexui/Core/Control/ScrollBar.js
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
mexui.util.createControlConstructor('ScrollBar', false, function(window, x, y, w, h, isVertical, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ScrollBar', styles), callback);
|
||||
|
||||
this.isVertical = isVertical;
|
||||
this.axisIndex = isVertical ? 1 : 0;
|
||||
this.otherAxisIndex = isVertical ? 0 : 1;
|
||||
|
||||
this.barHigherLength = 50;
|
||||
this.scrolledRatio = 0.0;
|
||||
this.isScrolling = false;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('ScrollBar', {
|
||||
main:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 190),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
},
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(79, 161, 246, 190),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(79, 161, 246, 150)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.ScrollBar.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(mexui.util.isCursorInRectangle(this.getInnerBarPosition(), this.getInnerBarSize()))
|
||||
{
|
||||
e.used = true;
|
||||
this.isScrolling = true;
|
||||
}
|
||||
else if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.scrolledRatio += this.getScrolledRatioOuterBarClickIncrease();
|
||||
this.clampScrolledRatio();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseUp = function(e)
|
||||
{
|
||||
if(this.isScrolling)
|
||||
{
|
||||
this.isScrolling = false;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(this.isScrolling)
|
||||
{
|
||||
this.scrolledRatio += offset.y * 0.002;
|
||||
this.clampScrolledRatio();
|
||||
e.used = true;
|
||||
}
|
||||
|
||||
if(!e.used)
|
||||
mexui.Component.Control.prototype.onMouseMove.call(this, e, offset);
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseWheel = function(e, offset)
|
||||
{
|
||||
this.scrolledRatio -= offset.y * 0.12;
|
||||
this.clampScrolledRatio();
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.ScrollBar.prototype.renderAfter = function()
|
||||
{
|
||||
mexui.native.drawRectangle(this.getScreenPosition(), this.size, this.getStyles('main'));
|
||||
mexui.native.drawRectangle(this.getInnerBarPosition(), this.getInnerBarSize(), this.getStyles('innerBar'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.ScrollBar.prototype.clampScrolledRatio = function()
|
||||
{
|
||||
if(this.scrolledRatio < 0.0)
|
||||
this.scrolledRatio = 0.0;
|
||||
else if(this.scrolledRatio > 1.0)
|
||||
this.scrolledRatio = 1.0;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getInnerBarPosition = function()
|
||||
{
|
||||
var screenPos = this.getScreenPosition();
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
|
||||
var minPos = pos[this.axisIndex] + 1;
|
||||
var maxPos = pos[this.axisIndex] + this.size[this.axisIndex] - 2;
|
||||
pos[this.axisIndex] = minPos + (this.scrolledRatio * (maxPos - minPos - this.barHigherLength));
|
||||
pos[this.otherAxisIndex] += 1;
|
||||
return pos;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getInnerBarSize = function()
|
||||
{
|
||||
var size = new Vec2(this.size.x, this.size.y);
|
||||
size[this.axisIndex] = this.barHigherLength;
|
||||
size[this.otherAxisIndex] -= 2;
|
||||
return size;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getScrolledRatioOuterBarClickIncrease = function()
|
||||
{
|
||||
var direction = gui.cursorPosition.y < this.getInnerBarPosition().y ? -1.0 : 1.0;
|
||||
return direction * 0.05;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Second.js
vendored
Normal file
19
third-party/mexui/Core/Control/Second.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Second', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Second', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Second, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Second.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 59)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
112
third-party/mexui/Core/Control/Slider.js
vendored
Normal file
112
third-party/mexui/Core/Control/Slider.js
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
mexui.util.createControlConstructor('Slider', false, function(window, x, y, w, h, isVertical, text, minText, maxText, styles, callback)
|
||||
{
|
||||
isVertical = isVertical === undefined ? false : isVertical;
|
||||
text = text === undefined ? '' : text;
|
||||
minText = minText === undefined ? '' : minText;
|
||||
maxText = maxText === undefined ? '' : maxText;
|
||||
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Slider', styles), callback);
|
||||
|
||||
this.isVertical = isVertical;
|
||||
this.text = text;
|
||||
this.minText = minText;
|
||||
this.maxText = maxText;
|
||||
|
||||
this.progress = 0.0;
|
||||
this.axisIndex = isVertical ? 1 : 0;
|
||||
this.innerBarSize = new Vec2(30, 25);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Slider', {
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
},
|
||||
minText:
|
||||
{
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
maxText:
|
||||
{
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Slider.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverInnerBar())
|
||||
{
|
||||
this.sliding = true;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.onMouseUp = function(e)
|
||||
{
|
||||
if(this.sliding)
|
||||
{
|
||||
this.sliding = false;
|
||||
this.checkToCallCallback();
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(!this.sliding)
|
||||
return false;
|
||||
|
||||
this.progress += this.getProgressIncreaseByPixels(offset);
|
||||
this.clampProgress();
|
||||
e.used = true;
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Slider.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
mexui.native.drawRectangle(this.getInnerBarPosition(), this.innerBarSize, this.getStyles('innerBar'));
|
||||
|
||||
pos.y += this.size.y;
|
||||
mexui.native.drawText(pos, this.size, this.minText, this.getStyles('minText'));
|
||||
|
||||
var offset = (this.size.x - mexui.native.getTextWidth(this.text, this.getStyles('main'))) / 2;
|
||||
pos.x += offset;
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
pos.x -= offset;
|
||||
|
||||
pos.x += this.size.x - mexui.native.getTextWidth(this.maxText, this.getStyles('maxText'));
|
||||
mexui.native.drawText(pos, this.size, this.maxText, this.getStyles('maxText'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Slider.prototype.isCursorOverInnerBar = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.getInnerBarPosition(), this.innerBarSize);
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.getInnerBarPosition = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos[this.axisIndex] = mexui.util.interpolateScalar(pos.x, (pos.x + this.size.x) - this.innerBarSize.x, this.progress);
|
||||
pos.y -= 3;
|
||||
return new Vec2(pos.x, pos.y);
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.getProgressIncreaseByPixels = function(offset)
|
||||
{
|
||||
return offset.x / this.size.x;
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.clampProgress = function()
|
||||
{
|
||||
if(this.progress < 0.0)
|
||||
this.progress = 0.0;
|
||||
else if(this.progress > 1.0)
|
||||
this.progress = 1.0;
|
||||
};
|
||||
|
||||
82
third-party/mexui/Core/Control/TabPanel.js
vendored
Normal file
82
third-party/mexui/Core/Control/TabPanel.js
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
mexui.util.createControlConstructor('TabPanel', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TabPanel', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.activeTabIndex = 0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('TabPanel', {
|
||||
tab:
|
||||
{
|
||||
backgroundColour: toColour(240, 20, 20, 200),
|
||||
borderColour: toColour(120, 20, 20, 225),
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(240, 20, 20, 150),
|
||||
borderColour: toColour(120, 20, 20, 120),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.TabPanel.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
var tabX = pos.x;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var tab = this.axis.x.entries[i];
|
||||
|
||||
var tabPos = new Vec2(tabX, pos.y);
|
||||
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
|
||||
|
||||
if(mexui.util.isCursorInRectangle(tabPos, tabSize))
|
||||
{
|
||||
tab.setActive();
|
||||
break;
|
||||
}
|
||||
|
||||
tabX += tabSize.x;
|
||||
}
|
||||
|
||||
/*
|
||||
var tab = this.axis.x.getEntryByCursor();
|
||||
if(tab)
|
||||
tab.setActive();
|
||||
*/
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.TabPanel.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var tabX = pos.x;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var tab = this.axis.x.entries[i];
|
||||
|
||||
var tabPos = new Vec2(tabX, pos.y);
|
||||
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
|
||||
mexui.native.drawRectangle(tabPos, tabSize, this.getStyles('tab'));
|
||||
mexui.native.drawText(tabPos, tabSize, tab.text, this.getStyles('tab'));
|
||||
|
||||
tabX += tabSize.x;
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.TabPanel.prototype.tab = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.Tab(this, text);
|
||||
this.axis.x.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
17
third-party/mexui/Core/Control/Text.js
vendored
Normal file
17
third-party/mexui/Core/Control/Text.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
mexui.util.createControlConstructor('Text', false, function(window, x, y, w, h, text, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Text', styles));
|
||||
|
||||
this.text = text;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Text', {});
|
||||
|
||||
// render
|
||||
mexui.Control.Text.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
7
third-party/mexui/Core/Control/TextArea.js
vendored
Normal file
7
third-party/mexui/Core/Control/TextArea.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.util.createControlConstructor('TextArea', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('TextArea', styles), callback, false, true);
|
||||
|
||||
this.multiLine = true;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.TextArea, mexui.Control.TextInput);
|
||||
347
third-party/mexui/Core/Control/TextInput.js
vendored
Normal file
347
third-party/mexui/Core/Control/TextInput.js
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w, h, text, styles, callback, singleCharacter, multiLineSupported)
|
||||
{
|
||||
text = text || '';
|
||||
if(singleCharacter)
|
||||
multiLineSupported = false;
|
||||
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TextInput', styles), callback);
|
||||
|
||||
this.lines = text ? mexui.util.splitLines(text) : [''];
|
||||
|
||||
this.caretPosition = new Vec2(0, 0);
|
||||
this.multiLineSupported = multiLineSupported === undefined ? true : multiLineSupported;
|
||||
this.multiLine = this.multiLineSupported ? mexui.util.doesContainEOLChar(text) : false;
|
||||
this.masked = false;
|
||||
this.singleCharacter = singleCharacter === undefined ? false : singleCharacter;
|
||||
this.placeholder = '';
|
||||
this.caretShownForBlink = true;
|
||||
this.lineHeight = 25;
|
||||
this.maxLength = this.singleCharacter ? 1 : false;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('TextInput', {
|
||||
caret:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
placeholder:
|
||||
{
|
||||
textColour: toColour(100, 100, 100, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.TextInput.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var hit = this.isCursorOverControl();
|
||||
if(hit)
|
||||
{
|
||||
this.caretPosition = this.getCaretPositionByCursor();
|
||||
}
|
||||
|
||||
mexui.Component.Control.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.onCharacter = function(e, character)
|
||||
{
|
||||
if(mexui.focusedControl == this)
|
||||
{
|
||||
/*
|
||||
var isValid1 = this.callback ? this.callback(character) : true;
|
||||
if(!isValid1 && isValid1 !== undefined)
|
||||
return;
|
||||
*/
|
||||
|
||||
var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true;
|
||||
if(!isValid2)
|
||||
return;
|
||||
|
||||
if(this.singleCharacter)
|
||||
{
|
||||
this.resetText();
|
||||
this.lines = [character];
|
||||
this.caretPosition.x = this.caretPosition.x < 2 ? this.caretPosition.x : 0;
|
||||
}
|
||||
else if(this.canAddCharacter())
|
||||
{
|
||||
this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character);
|
||||
this.caretPosition.x++;
|
||||
}
|
||||
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
|
||||
{
|
||||
if(mexui.focusedControl != this)
|
||||
return;
|
||||
|
||||
var controlIsDown = (mods & KMOD_CTRL) == KMOD_CTRL;
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case SDLK_LEFT:
|
||||
if(this.caretPosition.x != 0)
|
||||
{
|
||||
this.caretPosition.x--;
|
||||
}
|
||||
else if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if(this.caretPosition.x != this.getCaretLine().length)
|
||||
{
|
||||
this.caretPosition.x++;
|
||||
}
|
||||
else if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
}
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
if(controlIsDown)
|
||||
{
|
||||
this.caretPosition.y = 0;
|
||||
this.caretPosition.x = 0;
|
||||
}
|
||||
else
|
||||
this.caretPosition.x = 0;
|
||||
break;
|
||||
case SDLK_END:
|
||||
if(controlIsDown)
|
||||
{
|
||||
this.caretPosition.y = this.lines.length - 1;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
else
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
if(this.caretPosition.x != this.getCaretLine().length)
|
||||
{
|
||||
this.deleteCharacter(this.caretPosition);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.mergeLines(this.caretPosition.y);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
if(this.caretPosition.x != 0)
|
||||
{
|
||||
this.deleteCharacter(new Vec2(this.caretPosition.x - 1, this.caretPosition.y));
|
||||
this.caretPosition.x--;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
this.mergeLines(this.caretPosition.y);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.multiLine)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case SDLK_RETURN:
|
||||
case SDLK_KP_ENTER:
|
||||
if(this.canAddCharacter())
|
||||
{
|
||||
if(this.caretPosition.x == this.getCaretLine().length)
|
||||
{
|
||||
this.addLine(this.caretPosition.y + 1);
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.splitLine(this.caretPosition.y);
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDLK_UP:
|
||||
if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
if(this.caretPosition.x > this.getCaretLine().length)
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.caretPosition.y++;
|
||||
if(this.caretPosition.x > this.getCaretLine().length)
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.TextInput.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.isEmpty())
|
||||
{
|
||||
mexui.native.drawText(pos, this.size, this.placeholder, this.getStyles('placeholder'));
|
||||
}
|
||||
else
|
||||
{
|
||||
var lineSize = new Vec2(this.size.x, this.lineHeight);
|
||||
for(var i=0,j=this.lines.length; i<j; i++)
|
||||
{
|
||||
var displayedText = this.masked ? '*'.repeat(this.lines[i].length) : this.lines[i];
|
||||
mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main'));
|
||||
|
||||
pos.y += this.lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
if(mexui.focusedControl == this && this.caretShownForBlink)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
var text = this.lines[this.caretPosition.y].substr(0, this.caretPosition.x);
|
||||
var displayedText = this.masked ? '*'.repeat(text.length) : text;
|
||||
var textWidth = mexui.native.getTextWidth(displayedText, this.getStyles('main'));
|
||||
var caretPosOffset = new Vec2(5 + textWidth, (this.caretPosition.y * this.lineHeight) + 1);
|
||||
var caretPoint1 = mexui.util.addVec2(pos, caretPosOffset);
|
||||
var caretPoint2 = new Vec2(caretPoint1.x, caretPoint1.y + 22);
|
||||
mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
|
||||
|
||||
mexui.Control.TextInput.prototype.getTextWithNewCharacter = function(character)
|
||||
{
|
||||
return this.lines[this.caretPosition.y].substr(0, this.caretPosition.x) + character + this.lines[this.caretPosition.y].substr(this.caretPosition.x);
|
||||
};
|
||||
|
||||
// caret
|
||||
mexui.Control.TextInput.prototype.getCaretLine = function()
|
||||
{
|
||||
return this.lines[this.caretPosition.y];
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.clampCaretPosition = function()
|
||||
{
|
||||
if(this.caretPosition.y < 0)
|
||||
this.caretPosition.y = 0;
|
||||
else if(this.caretPosition.y > (this.lines.length - 1))
|
||||
this.caretPosition.y = this.lines.length - 1;
|
||||
|
||||
if(this.caretPosition.x < 0)
|
||||
this.caretPosition.x = 0;
|
||||
else if(this.caretPosition.x > this.lines[this.caretPosition.y].length)
|
||||
this.caretPosition.x = this.lines[this.caretPosition.y].length;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCaretPositionByCursor = function()
|
||||
{
|
||||
var lineIndex = this.getCaretLineIndexByCursor();
|
||||
var charIndex = this.getCharIndexByCursor(lineIndex);
|
||||
return new Vec2(charIndex, lineIndex);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCaretLineIndexByCursor = function()
|
||||
{
|
||||
var yPos = gui.cursorPosition.y - this.getScreenPosition().y;
|
||||
var lineIndex = Math.floor(yPos / this.lineHeight);
|
||||
|
||||
if(lineIndex < 0)
|
||||
return 0;
|
||||
else if(lineIndex > (this.lines.length - 1))
|
||||
return this.lines.length - 1;
|
||||
else
|
||||
return lineIndex;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCharIndexByCursor = function(lineIndex)
|
||||
{
|
||||
var xPos = gui.cursorPosition.x - this.getScreenPosition().x;
|
||||
var line = this.lines[lineIndex];
|
||||
var lineStyles = this.getStyles('caret');
|
||||
|
||||
for(var i=0,j=line.length; i<j; i++)
|
||||
{
|
||||
var text = line.substr(0, i + 1);
|
||||
var textWidth = mexui.native.getTextWidth(text, lineStyles);
|
||||
|
||||
if(xPos < textWidth)
|
||||
return i;
|
||||
}
|
||||
return line.length;
|
||||
};
|
||||
|
||||
// lines
|
||||
mexui.Control.TextInput.prototype.addLine = function(lineIndex)
|
||||
{
|
||||
this.lines.splice(lineIndex, 0, '');
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.removeLine = function(lineIndex)
|
||||
{
|
||||
this.lines.splice(lineIndex, 1);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getLineLength = function(lineIndex)
|
||||
{
|
||||
return this.lines[lineIndex].length;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.mergeLines = function(lineIndex)
|
||||
{
|
||||
this.lines[lineIndex] += this.lines[lineIndex + 1];
|
||||
this.removeLine(lineIndex + 1);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.splitLine = function(lineIndex)
|
||||
{
|
||||
this.addLine(lineIndex + 1);
|
||||
this.lines[lineIndex + 1] = this.lines[lineIndex].substr(this.caretPosition.x);
|
||||
this.lines[lineIndex] = this.lines[lineIndex].substr(0, this.caretPosition.x);
|
||||
};
|
||||
|
||||
// characters
|
||||
mexui.Control.TextInput.prototype.canAddCharacter = function()
|
||||
{
|
||||
return this.maxLength === false || this.lines.join("\r\n").length < this.maxLength;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.deleteCharacter = function(charPos)
|
||||
{
|
||||
this.lines[charPos.y] = this.lines[charPos.y].substr(0, charPos.x) + this.lines[charPos.y].substr(charPos.x + 1);
|
||||
};
|
||||
|
||||
// text overall
|
||||
mexui.Control.TextInput.prototype.resetText = function()
|
||||
{
|
||||
this.lines = [''];
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.isEmpty = function()
|
||||
{
|
||||
return this.lines.length == 1 && this.lines[0] == '';
|
||||
};
|
||||
|
||||
151
third-party/mexui/Core/Control/Time.js
vendored
Normal file
151
third-party/mexui/Core/Control/Time.js
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
mexui.util.createControlConstructor('Time', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Time', styles), callback, false, false);
|
||||
|
||||
this.hour = 0;
|
||||
this.minute = 0;
|
||||
this.second = 0;
|
||||
|
||||
this.inputShown = false;
|
||||
this.valueBoxSize = new Vec2(50, 30);
|
||||
this.arrowBoxSize = new Vec2(25, 22);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Time, mexui.Control.TextInput);
|
||||
|
||||
// static
|
||||
mexui.Control.Time.units = ['hour', 'minute', 'second'];
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Time', {
|
||||
arrow:
|
||||
{
|
||||
backgroundColour: toColour(90, 90, 80, 230),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Time.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.inputShown)
|
||||
{
|
||||
var arrowIndex = this.getArrowIndexByCursor();
|
||||
if(arrowIndex !== false)
|
||||
{
|
||||
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
|
||||
var propName = mexui.Control.Time.units[propIndex];
|
||||
var isIncrease = (arrowIndex % 2) == 1;
|
||||
|
||||
if(isIncrease)
|
||||
this[propName]++;
|
||||
else
|
||||
this[propName]--;
|
||||
|
||||
this[propName] %= propIndex == 0 ? 24 : 60;
|
||||
if(this[propName] == -1)
|
||||
this[propName] = propIndex == 0 ? 23 : 59;
|
||||
|
||||
this.generateText();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.inputShown = !this.inputShown;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.inputShown)
|
||||
{
|
||||
this.inputShown = false;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Time.prototype.renderAfter = function()
|
||||
{
|
||||
if(!this.inputShown)
|
||||
return;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Time.units[i]], this.getStyles('main'));
|
||||
|
||||
pos.x += this.valueBoxSize.x;
|
||||
}
|
||||
|
||||
pos = new Vec2(screenPos.x, screenPos.y);
|
||||
pos.y += this.valueBoxSize.y;
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
for(var i2=0; i2<2; i2++)
|
||||
{
|
||||
var text = (i2 % 2) == 0 ? '<' : '>';
|
||||
|
||||
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
|
||||
|
||||
pos.x += this.arrowBoxSize.x;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Time.prototype.generateText = function()
|
||||
{
|
||||
this.text = (this.hour < 10 ? '0'+this.hour : this.hour)
|
||||
+':'+(this.minute < 10 ? '0'+this.minute : this.minute)
|
||||
+':'+(this.second < 10 ? '0'+this.second : this.second);
|
||||
};
|
||||
|
||||
mexui.Control.Time.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var text = this.getTextWithNewCharacter(character);
|
||||
var parts = text.split(':');
|
||||
|
||||
for(var i in parts)
|
||||
{
|
||||
if(i == 3)
|
||||
return false;
|
||||
|
||||
var part = parseInt(parts[i]);
|
||||
|
||||
if(isNaN(part))
|
||||
return false;
|
||||
|
||||
if(part < 0)
|
||||
return false;
|
||||
|
||||
if(part > (i == 0 ? 23 : 59))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mexui.Control.Time.prototype.getArrowIndexByCursor = function()
|
||||
{
|
||||
var cursorPos = gui.cursorPosition;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
|
||||
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
|
||||
|
||||
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
|
||||
{
|
||||
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
150
third-party/mexui/Core/Control/Tree.js
vendored
Normal file
150
third-party/mexui/Core/Control/Tree.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
mexui.util.createControlConstructor('Tree', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Tree', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.rowHeight = 25;
|
||||
this.rowLevelIndentation = 10;
|
||||
this.scrollMultiplier = 10.0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Tree', {
|
||||
row:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
rowIcon:
|
||||
{
|
||||
textColour: toColour(230, 130, 0, 190)
|
||||
},
|
||||
rowLine:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Tree.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos.y -= this.axis.y.getScrolledOffset();
|
||||
|
||||
this.testRowClick(e, this.axis.y.entries, pos);
|
||||
|
||||
if(!e.used)
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Tree.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos.y -= this.axis.y.getScrolledOffset();
|
||||
|
||||
this.renderRows(this.axis.y.entries, 0, pos);
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.renderRows = function(rows, level, pos)
|
||||
{
|
||||
for(var i in rows)
|
||||
{
|
||||
var row = rows[i];
|
||||
var shouldDraw = pos.y >= this.getScreenPosition().y && pos.y <= (this.getScreenPosition().y + this.size.y);
|
||||
|
||||
if(shouldDraw)
|
||||
{
|
||||
if(row.rows.length > 0)
|
||||
mexui.native.drawText(new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y), new Vec2(this.size.x, this.rowHeight), row.open ? '-' : '+', this.getStyles('rowIcon'));
|
||||
|
||||
mexui.native.drawRectangle(pos, new Vec2(this.size.x - (this.rowLevelIndentation * level), this.rowHeight), this.getStyles('row'));
|
||||
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), row.text, this.getStyles('row'));
|
||||
}
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
|
||||
if(shouldDraw)
|
||||
{
|
||||
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
|
||||
}
|
||||
|
||||
if(row.rows.length > 0 && row.open)
|
||||
{
|
||||
pos.x += this.rowLevelIndentation;
|
||||
this.renderRows(row.rows, level + 1, pos);
|
||||
pos.x -= this.rowLevelIndentation;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Tree.prototype.getAllEntriesLength = function(axisIndex)
|
||||
{
|
||||
return this.getRowsLength(this.axis.y.entries);
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.getRowsLength = function(rows)
|
||||
{
|
||||
var length = rows.length * this.entrySize.y;
|
||||
for(var i in rows)
|
||||
{
|
||||
if(rows[i].open)
|
||||
length += this.getRowsLength(rows[i].rows);
|
||||
}
|
||||
return length;
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
|
||||
{
|
||||
for(var i in rows)
|
||||
{
|
||||
var row = rows[i];
|
||||
|
||||
var rowPos = new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y);
|
||||
var rowSize = new Vec2(this.size.x + (this.rowLevelIndentation * 2), this.rowHeight);
|
||||
if(mexui.util.isCursorInRectangle(rowPos, rowSize))
|
||||
{
|
||||
this.onClickRow(row);
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
|
||||
if(row.rows.length > 0 && row.open)
|
||||
{
|
||||
this.testRowClick(e, row.rows, pos);
|
||||
if(e.used)
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.onClickRow = function(row)
|
||||
{
|
||||
if(row.rows.length > 0)
|
||||
{
|
||||
//var scrollableLengthBefore = this.axis.y.getScrollableLength();
|
||||
|
||||
row.open = !row.open;
|
||||
this.checkToShowScrollBars();
|
||||
|
||||
/*
|
||||
if(this.scrollBars[1].shown)
|
||||
{
|
||||
var scrollableLengthAfter = this.axis.y.getScrollableLength();
|
||||
this.scrollBars[1].scrolledRatio += (scrollableLengthAfter - scrollableLengthBefore) / scrollableLengthAfter;
|
||||
}
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.Control.Tree.prototype.row = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.TreeRow(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Week.js
vendored
Normal file
19
third-party/mexui/Core/Control/Week.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Week', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Week', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Week, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Week.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 51)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Year.js
vendored
Normal file
19
third-party/mexui/Core/Control/Year.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Year', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Year', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Year, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Year.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 1900 || _int > 2019)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
41
third-party/mexui/Core/Entity/Component.js
vendored
Normal file
41
third-party/mexui/Core/Entity/Component.js
vendored
Normal file
@@ -0,0 +1,41 @@
|
||||
mexui.Entity.Component = function(moveable)
|
||||
{
|
||||
this.moveable = moveable;
|
||||
|
||||
this.moving = false;
|
||||
};
|
||||
mexui.util.extend(mexui.Entity.Component, mexui.Entity.StyleableEntity);
|
||||
|
||||
// input
|
||||
mexui.Entity.Component.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.moveable && this.isCursorOverComponent())
|
||||
{
|
||||
this.moving = true;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.Component.prototype.onMouseUp = function(e)
|
||||
{
|
||||
if(this.moving)
|
||||
{
|
||||
this.moving = false;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.Component.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(this.moving)
|
||||
{
|
||||
this.position = new Vec2(this.position.x + offset.x, this.position.y + offset.y);
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Entity.Component.prototype.isCursorOverComponent = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.getScreenPosition(), this.size);
|
||||
};
|
||||
200
third-party/mexui/Core/Entity/ControlAxis.js
vendored
Normal file
200
third-party/mexui/Core/Entity/ControlAxis.js
vendored
Normal file
@@ -0,0 +1,200 @@
|
||||
mexui.Entity.ControlAxis = function(control, isVertical, manualScrollBar, entriesPositionOffset)
|
||||
{
|
||||
this.control = control;
|
||||
this.isVertical = isVertical;
|
||||
this.manualScrollBar = manualScrollBar;
|
||||
|
||||
this.axisIndex = isVertical ? 1 : 0;
|
||||
this.entriesShown = true;
|
||||
this.entryCountShown = 15;
|
||||
this.hoveredEntryIndex = -1;
|
||||
this.entries = [];
|
||||
this.scrollBar = [];
|
||||
};
|
||||
|
||||
// model
|
||||
|
||||
// scroll bar initialization
|
||||
mexui.Entity.ControlAxis.prototype.initScrollBar = function()
|
||||
{
|
||||
if(this.isVertical)
|
||||
{
|
||||
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entrySize.x, this.control.entriesPositionOffset.y));
|
||||
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, 25, this.getDisplayedEntriesLength(), true, this.control.styles.scrollBar);
|
||||
}
|
||||
else
|
||||
{
|
||||
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entriesPositionOffset.x, this.control.size.y));
|
||||
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, this.getDisplayedEntriesLength(), 25, false, this.control.styles.scrollBar);
|
||||
}
|
||||
|
||||
if(this.manualScrollBar)
|
||||
this.scrollBar.shown = false;
|
||||
};
|
||||
|
||||
// add/remove entries
|
||||
mexui.Entity.ControlAxis.prototype.addEntry = function(entry)
|
||||
{
|
||||
this.entries.push(entry);
|
||||
this.checkToShowScrollBar();
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.removeAllEntries = function()
|
||||
{
|
||||
this.entries = [];
|
||||
this.checkToShowScrollBar();
|
||||
};
|
||||
|
||||
// fetch entry by position
|
||||
mexui.Entity.ControlAxis.prototype.getEntryByCursor = function()
|
||||
{
|
||||
return this.getEntryByPoint(gui.cursorPosition);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getEntryIndexByCursor = function()
|
||||
{
|
||||
return this.getEntryIndexByPoint(gui.cursorPosition);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getEntryByPoint = function(point)
|
||||
{
|
||||
var index = this.getEntryIndexByPoint(point);
|
||||
if(index == null)
|
||||
return null;
|
||||
return this.entries[index];
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getEntryIndexByPoint = function(point)
|
||||
{
|
||||
var screenPos = this.control.getScreenPosition();
|
||||
if(this.axisIndex == 1)
|
||||
{
|
||||
if(point.x < screenPos.x || point.x > (screenPos.x + this.control.entrySize.x))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var pos = new Vec2(screenPos.x + this.control.entriesPositionOffset.x, screenPos.y + this.control.entriesPositionOffset.y);
|
||||
var index = Math.floor((point.y - pos.y) / this.control.entrySize[this.axisIndex]);
|
||||
index += this.getEntryStartIndex();
|
||||
|
||||
if(index < 0 || index >= this.entries.length)
|
||||
return null;
|
||||
|
||||
return index;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// entries sizing
|
||||
mexui.Entity.ControlAxis.prototype.getOutsideEntriesLength = function()
|
||||
{
|
||||
return this.control.entrySize[this.axisIndex] * this.entryCountShown;
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getAllEntriesLength = function()
|
||||
{
|
||||
if(this.control.getAllEntriesLength)
|
||||
return this.control.getAllEntriesLength(this.axisIndex);
|
||||
else
|
||||
return this.getAllEntriesLength2();
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getAllEntriesLength2 = function()
|
||||
{
|
||||
return this.entries.length * this.control.entrySize[this.axisIndex];
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getDisplayedEntriesLength = function()
|
||||
{
|
||||
var sizeOffset = this.control.entriesSizeOffset[this.axisIndex];
|
||||
if(this.control.entriesOutsideControl)
|
||||
return this.getOutsideEntriesLength() + sizeOffset;
|
||||
else
|
||||
return this.control.size[this.axisIndex] + sizeOffset;
|
||||
};
|
||||
|
||||
// entry scrolling
|
||||
mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual)
|
||||
{
|
||||
this.manualScrollBar = manual;
|
||||
|
||||
if(manual)
|
||||
{
|
||||
this.setScrollBarShown(false);
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.setScrollBarShown = function(shown)
|
||||
{
|
||||
//if(axisIndex != this.axisIndex)
|
||||
// shown = false;
|
||||
|
||||
this.scrollBar.shown = shown;
|
||||
if(!shown)
|
||||
this.scrollBar.scrolledRatio = 0.0;
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.shouldDisplayScrollBar = function()
|
||||
{
|
||||
//if(axisIndex != this.axisIndex)
|
||||
// return false;
|
||||
|
||||
return this.getAllEntriesLength() > this.scrollBar.size[this.axisIndex];
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.checkToShowScrollBar = function()
|
||||
{
|
||||
if(this.manualScrollBar)
|
||||
return;
|
||||
|
||||
this.setScrollBarShown(this.shouldDisplayScrollBar(), true);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getScrolledOffset = function()
|
||||
{
|
||||
if(this.axisIndex == 1)
|
||||
{
|
||||
if(!this.scrollBar.shown)
|
||||
return 0;
|
||||
|
||||
return this.scrollBar.scrolledRatio * this.getScrollableLength();
|
||||
}
|
||||
else
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getScrolledOffsetFixedStart = function()
|
||||
{
|
||||
var entryLength = this.control.entrySize[this.axisIndex];
|
||||
return Math.floor(this.getScrolledOffset() / entryLength) * entryLength;
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getScrollableLength = function()
|
||||
{
|
||||
return this.getAllEntriesLength() - this.getOutsideEntriesLength();
|
||||
};
|
||||
|
||||
// entry iteration
|
||||
mexui.Entity.ControlAxis.prototype.getEntryStartIndex = function() // inclusive
|
||||
{
|
||||
return Math.floor(this.getScrolledOffset() / this.control.entrySize[this.axisIndex]);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getEntryEndIndex = function() // exclusive
|
||||
{
|
||||
return this.getEntryStartIndex() + this.getDisplayedEntryCount();
|
||||
};
|
||||
|
||||
mexui.Entity.ControlAxis.prototype.getDisplayedEntryCount = function()
|
||||
{
|
||||
var displayedEntriesLength = this.getDisplayedEntriesLength();
|
||||
var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]);
|
||||
return this.entries.length < displayedEntryCount ? this.entries.length : displayedEntryCount;
|
||||
};
|
||||
|
||||
98
third-party/mexui/Core/Entity/ControlWithEntries.js
vendored
Normal file
98
third-party/mexui/Core/Entity/ControlWithEntries.js
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
mexui.Entity.ControlWithEntries = function(entriesOutsideControl, manualScrollBar, entriesPositionOffset, entrySize, entriesSizeOffset)
|
||||
{
|
||||
this.entriesOutsideControl = entriesOutsideControl;
|
||||
this.entriesPositionOffset = entriesPositionOffset || new Vec2(0, 0);
|
||||
this.entrySize = entrySize || new Vec2(this.size.x, 25);
|
||||
this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0);
|
||||
|
||||
this.axis = {};
|
||||
this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset);
|
||||
this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset);
|
||||
|
||||
this.axis.x.initScrollBar();
|
||||
this.axis.y.initScrollBar();
|
||||
|
||||
this.checkToShowScrollBars();
|
||||
};
|
||||
mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control);
|
||||
|
||||
// input
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseDown = function(e)
|
||||
{
|
||||
this.triggerEvent('onMouseDown', e);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseUp = function(e)
|
||||
{
|
||||
this.triggerEvent('onMouseUp', e);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
for(var k in this.axis)
|
||||
{
|
||||
if(this.axis[k].entriesShown)
|
||||
{
|
||||
var hoveredEntryIndex = this.axis[k].getEntryIndexByCursor();
|
||||
if(hoveredEntryIndex == null)
|
||||
{
|
||||
this.axis[k].hoveredEntryIndex = -1;
|
||||
}
|
||||
else
|
||||
{
|
||||
e.used = true;
|
||||
this.axis[k].hoveredEntryIndex = hoveredEntryIndex;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!e.used)
|
||||
this.triggerEvent('onMouseMove', e, offset);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseWheel = function(e, data)
|
||||
{
|
||||
this.triggerEvent('onMouseWheel', e, data);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Entity.ControlWithEntries.prototype.renderAfter = function()
|
||||
{
|
||||
this.triggerEvent('renderAfter');
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Entity.ControlWithEntries.prototype.triggerEvent = function(eventName, e, data)
|
||||
{
|
||||
for(var k in this.axis)
|
||||
{
|
||||
if(this.axis[k].scrollBar.shown)
|
||||
{
|
||||
this.axis[k].scrollBar[eventName].call(this.axis[k].scrollBar, e, data);
|
||||
if(e && e.used)
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
mexui.Component.Control.prototype[eventName].call(this, e, data);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.checkToShowScrollBars = function()
|
||||
{
|
||||
this.axis.x.checkToShowScrollBar();
|
||||
this.axis.y.checkToShowScrollBar();
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.setScrollBarsManual = function(manual)
|
||||
{
|
||||
this.axis.x.setScrollBarManual(manual);
|
||||
this.axis.y.setScrollBarManual(manual);
|
||||
};
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.removeAllEntries = function()
|
||||
{
|
||||
this.axis.x.removeAllEntries();
|
||||
this.axis.y.removeAllEntries();
|
||||
};
|
||||
|
||||
202
third-party/mexui/Core/Entity/StyleableEntity.js
vendored
Normal file
202
third-party/mexui/Core/Entity/StyleableEntity.js
vendored
Normal file
@@ -0,0 +1,202 @@
|
||||
mexui.Entity.StyleableEntity = function(styles)
|
||||
{
|
||||
this.styles = styles;
|
||||
|
||||
this.shown = true;
|
||||
//this.hovered = false;
|
||||
|
||||
this.transitions = {}; // string controlPartName => Transition transition
|
||||
|
||||
/*
|
||||
this.transitionDelayTimer = null;
|
||||
this.transitionStartTime = 0;
|
||||
this.transitionEndTime = 0;
|
||||
this.transitionIsProcessing = false;
|
||||
this.transitionIsReverting = false;
|
||||
this.transitionProgressReached = 0.0;
|
||||
*/
|
||||
};
|
||||
|
||||
// default styles
|
||||
mexui.Entity.StyleableEntity.globalDefaultStyles = {
|
||||
all:
|
||||
{
|
||||
textFont: 'Arial',
|
||||
textSize: 14.0,
|
||||
textAlign: 0.0,
|
||||
textIndent: 5,
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
|
||||
lineWeight: 1
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.defaultStyles = mexui.util.linkGlobalStyles(mexui.Entity.StyleableEntity.globalDefaultStyles, {
|
||||
main:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
borderColour: 'none',
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(220, 220, 220, 255),
|
||||
borderColour: 'none',
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}/*,
|
||||
|
||||
focus:
|
||||
{
|
||||
borderColour: toColour(255, 128, 0, 230),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
*/
|
||||
}
|
||||
});
|
||||
|
||||
// model
|
||||
mexui.Entity.StyleableEntity.prototype.linkControlStyles = function(controlName, styles)
|
||||
{
|
||||
return mexui.util.linkStyles(mexui.Control[controlName].defaultStyles, styles);
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.linkComponentStyles = function(componentName, styles)
|
||||
{
|
||||
return mexui.util.linkStyles(mexui.Component[componentName].defaultStyles, styles);
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.linkEntryStyles = function(entryName, styles)
|
||||
{
|
||||
return mexui.util.linkStyles(mexui.Entry[entryName].defaultStyles, styles);
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.isFocused = function()
|
||||
{
|
||||
return this == mexui.focusedControl;
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.isHovered = function()
|
||||
{
|
||||
//return this.hovered;
|
||||
return this == mexui.hoveredComponent;
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.getStyles = function(controlPartName)
|
||||
{
|
||||
var isFocused = this.isFocused();
|
||||
var isHovered = this.isHovered();
|
||||
var styles = this.styles[controlPartName];
|
||||
|
||||
var transition = this.getTransition(controlPartName);
|
||||
|
||||
if(transition.isProcessing())
|
||||
{
|
||||
return mexui.util.getTransitionStyles(styles, ['hover'], transition.getMainToPseudoProgress());
|
||||
}
|
||||
|
||||
if(isHovered)
|
||||
{
|
||||
return mexui.util.mergeStyles(styles, ['hover']);
|
||||
}
|
||||
|
||||
return styles;
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
|
||||
{
|
||||
var styles = {};
|
||||
|
||||
for(var i in data)
|
||||
{
|
||||
var baseStyles = data[i][0].getStyles(data[i][1]);
|
||||
|
||||
for(var k in baseStyles)
|
||||
{
|
||||
if(baseStyles.hasOwnProperty(k) && styles[k] === undefined)
|
||||
{
|
||||
styles[k] = baseStyles[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(var i in data)
|
||||
{
|
||||
var baseStyles = data[i][0].getStyles(data[i][1]);
|
||||
|
||||
for(var k in baseStyles)
|
||||
{
|
||||
if(styles[k] === undefined)
|
||||
{
|
||||
styles[k] = baseStyles[k];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return styles;
|
||||
};
|
||||
|
||||
// custom events
|
||||
mexui.Entity.StyleableEntity.prototype.onMouseEnter = function()
|
||||
{
|
||||
var controlParts = this.getControlPartsWithTransition();
|
||||
for(var i in controlParts)
|
||||
{
|
||||
var transition = this.getTransition(controlParts[i]);
|
||||
|
||||
var delay = this.getTransitionDelayStyle(controlParts[i]);
|
||||
var time = this.getTransitionTimeStyle(controlParts[i]);
|
||||
|
||||
transition.onMouseEnter(delay, time);
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.onMouseExit = function()
|
||||
{
|
||||
var controlParts = this.getControlPartsWithTransition();
|
||||
for(var i in controlParts)
|
||||
{
|
||||
var transition = this.getTransition(controlParts[i]);
|
||||
|
||||
transition.onMouseExit();
|
||||
}
|
||||
};
|
||||
|
||||
// transitions
|
||||
mexui.Entity.StyleableEntity.prototype.getTransition = function(controlPartName)
|
||||
{
|
||||
if(!this.transitions[controlPartName])
|
||||
this.transitions[controlPartName] = new mexui.Entity.Transition;
|
||||
return this.transitions[controlPartName];
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.getControlPartsWithTransition = function()
|
||||
{
|
||||
var controlParts = [];
|
||||
for(var k in this.styles)
|
||||
{
|
||||
if(this.styles[k].hover && (this.styles[k].hover.transitionTime != null || this.styles[k].hover.transitionDelay != null))
|
||||
{
|
||||
controlParts.push(k);
|
||||
}
|
||||
}
|
||||
return controlParts;
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.getTransitionDelayStyle = function(controlPartName)
|
||||
{
|
||||
if(this.styles[controlPartName].hover.transitionDelay != null)
|
||||
return this.styles[controlPartName].hover.transitionDelay;
|
||||
else
|
||||
return mexui.Entity.Transition.defaultTransitionDelay;
|
||||
};
|
||||
|
||||
mexui.Entity.StyleableEntity.prototype.getTransitionTimeStyle = function(controlPartName)
|
||||
{
|
||||
if(this.styles[controlPartName].hover.transitionTime != null)
|
||||
return this.styles[controlPartName].hover.transitionTime;
|
||||
else
|
||||
return mexui.Entity.Transition.defaultTransitionTime;
|
||||
};
|
||||
|
||||
184
third-party/mexui/Core/Entity/Transition.js
vendored
Normal file
184
third-party/mexui/Core/Entity/Transition.js
vendored
Normal file
@@ -0,0 +1,184 @@
|
||||
mexui.Entity.Transition = function()
|
||||
{
|
||||
this.processing = false;
|
||||
this.interpolating = false;
|
||||
this.mainToPseudoProgress = 0.0;
|
||||
this.delayTimer = null;
|
||||
this.transitionDelay = mexui.Entity.Transition.defaultTransitionDelay;
|
||||
this.transitionTime = mexui.Entity.Transition.defaultTransitionTime;
|
||||
this.mouseIsEntered = false;
|
||||
this.lastUpdateTime = mexui.util.time();
|
||||
this.direction = true;
|
||||
};
|
||||
|
||||
// static
|
||||
mexui.Entity.Transition.defaultTransitionDelay = 0;
|
||||
mexui.Entity.Transition.defaultTransitionTime = 1000;//400;
|
||||
|
||||
// custom events
|
||||
mexui.Entity.Transition.prototype.onMouseEnter = function(transitionDelay, transitionTime)
|
||||
{
|
||||
if(this.isMouseEntered())
|
||||
return;
|
||||
this.setMouseEntered(true);
|
||||
|
||||
this.transitionDelay = transitionDelay;
|
||||
this.transitionTime = transitionTime;
|
||||
|
||||
if(transitionDelay > 0)
|
||||
{
|
||||
this.startDelay();
|
||||
}
|
||||
else if(this.isInterpolating())
|
||||
{
|
||||
this.revertInterpolationDirection();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.startEnterInterpolation();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.onMouseExit = function()
|
||||
{
|
||||
if(!this.isMouseEntered())
|
||||
return;
|
||||
this.setMouseEntered(false);
|
||||
|
||||
if(this.isDelayActive())
|
||||
{
|
||||
this.clearDelayTimer();
|
||||
}
|
||||
else if(this.isInterpolating())
|
||||
{
|
||||
this.revertInterpolationDirection();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.startExitInterpolation();
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Entity.Transition.prototype.setMouseEntered = function(status)
|
||||
{
|
||||
this.mouseIsEntered = status;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.isMouseEntered = function()
|
||||
{
|
||||
return this.mouseIsEntered;
|
||||
};
|
||||
|
||||
// processing
|
||||
mexui.Entity.Transition.prototype.isProcessing = function()
|
||||
{
|
||||
return this.processing;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.stopProcessing = function()
|
||||
{
|
||||
if(this.isInterpolating())
|
||||
{
|
||||
this.stopInterpolation();
|
||||
}
|
||||
|
||||
this.delayTimer = null;
|
||||
this.processing = false;
|
||||
};
|
||||
|
||||
// interpolation status
|
||||
mexui.Entity.Transition.prototype.startEnterInterpolation = function()
|
||||
{
|
||||
this.lastUpdateTime = mexui.util.time();
|
||||
this.processing = true;
|
||||
this.interpolating = true;
|
||||
this.direction = true;
|
||||
this.mainToPseudoProgress = 0.0;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.startExitInterpolation = function()
|
||||
{
|
||||
this.lastUpdateTime = mexui.util.time();
|
||||
this.processing = true;
|
||||
this.interpolating = true;
|
||||
this.direction = false;
|
||||
this.mainToPseudoProgress = 1.0;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.stopInterpolation = function()
|
||||
{
|
||||
this.interpolating = false;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.isInterpolating = function()
|
||||
{
|
||||
return this.interpolating;
|
||||
};
|
||||
|
||||
// interpolation direction
|
||||
mexui.Entity.Transition.prototype.revertInterpolationDirection = function()
|
||||
{
|
||||
this.lastUpdateTime = mexui.util.time();
|
||||
this.direction = !this.direction;
|
||||
};
|
||||
|
||||
// progress
|
||||
mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
|
||||
{
|
||||
var timeDiff = mexui.util.time() - this.lastUpdateTime;
|
||||
this.lastUpdateTime = mexui.util.time();
|
||||
var progressDiff = timeDiff / this.transitionTime;
|
||||
|
||||
if(this.direction)
|
||||
this.mainToPseudoProgress += progressDiff;
|
||||
else
|
||||
this.mainToPseudoProgress -= progressDiff;
|
||||
|
||||
if(this.mainToPseudoProgress < 0.0)
|
||||
{
|
||||
this.mainToPseudoProgress = 0.0;
|
||||
this.stopProcessing();
|
||||
}
|
||||
else if(this.mainToPseudoProgress > 1.0)
|
||||
{
|
||||
this.mainToPseudoProgress = 1.0;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.getMainToPseudoProgress = function()
|
||||
{
|
||||
this.increaseMainToPseudoProgress();
|
||||
|
||||
return this.mainToPseudoProgress;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.getCompletionProgress = function()
|
||||
{
|
||||
if(this.direction)
|
||||
return this.mainToPseudoProgress;
|
||||
else
|
||||
return 1.0 - this.mainToPseudoProgress;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.startDelay = function()
|
||||
{
|
||||
var that = this;
|
||||
this.delayTimer = setTimeout(function()
|
||||
{
|
||||
that.delayTimer = null;
|
||||
that.startEnterInterpolation.call(that);
|
||||
}, this.transitionDelay);
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.isDelayActive = function()
|
||||
{
|
||||
return this.delayTimer != null;
|
||||
};
|
||||
|
||||
mexui.Entity.Transition.prototype.clearDelayTimer = function()
|
||||
{
|
||||
clearTimeout(this.delayTimer);
|
||||
this.delayTimer = null;
|
||||
};
|
||||
|
||||
7
third-party/mexui/Core/Entry/DropDownItem.js
vendored
Normal file
7
third-party/mexui/Core/Entry/DropDownItem.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.Entry.DropDownItem = function(dropDown, text)
|
||||
{
|
||||
mexui.Component.Entry.call(this, dropDown, 1);
|
||||
|
||||
this.text = text;
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.DropDownItem, mexui.Component.Entry);
|
||||
9
third-party/mexui/Core/Entry/GridColumn.js
vendored
Normal file
9
third-party/mexui/Core/Entry/GridColumn.js
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
mexui.Entry.GridColumn = function(grid, text, width, height)
|
||||
{
|
||||
mexui.Component.Entry.call(this, grid, 0);
|
||||
|
||||
this.text = text || 'Column';
|
||||
this.width = width || 100;
|
||||
this.height = height || 25;
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.GridColumn, mexui.Component.Entry);
|
||||
13
third-party/mexui/Core/Entry/GridRow.js
vendored
Normal file
13
third-party/mexui/Core/Entry/GridRow.js
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
mexui.Entry.GridRow = function(grid, cells, styles)
|
||||
{
|
||||
mexui.Component.Entry.call(this, grid, 1);
|
||||
mexui.Entity.StyleableEntity.call(this, this.linkEntryStyles('GridRow', styles));
|
||||
|
||||
this.cells = cells;
|
||||
this.rowHeight = 25;
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.GridRow, mexui.Component.Entry);
|
||||
|
||||
// default styles
|
||||
mexui.Entry.GridRow.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {});
|
||||
|
||||
7
third-party/mexui/Core/Entry/ListRow.js
vendored
Normal file
7
third-party/mexui/Core/Entry/ListRow.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.Entry.ListRow = function(list, text)
|
||||
{
|
||||
mexui.Component.Entry.call(this, list, 1);
|
||||
|
||||
this.text = text;
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.ListRow, mexui.Component.Entry);
|
||||
26
third-party/mexui/Core/Entry/Tab.js
vendored
Normal file
26
third-party/mexui/Core/Entry/Tab.js
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
mexui.Entry.Tab = function(tabPanel, text)
|
||||
{
|
||||
mexui.Component.Entry.call(this, tabPanel, 0);
|
||||
|
||||
this.text = text;
|
||||
this.controls = [];
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.Tab, mexui.Component.Entry);
|
||||
|
||||
// model
|
||||
mexui.Entry.Tab.prototype._control = function(control)
|
||||
{
|
||||
control.shown = this.control.activeTabIndex == this.getEntryIndex();
|
||||
this.controls.push(control);
|
||||
};
|
||||
|
||||
mexui.Entry.Tab.prototype.setActive = function()
|
||||
{
|
||||
for(var i in this.control.entries[this.control.activeTabIndex].controls)
|
||||
this.control.entries[this.control.activeTabIndex].controls[i].shown = false;
|
||||
|
||||
this.control.activeTabIndex = this.getEntryIndex();
|
||||
|
||||
for(var i in this.control.entries[this.control.activeTabIndex].controls)
|
||||
this.control.entries[this.control.activeTabIndex].controls[i].shown = true;
|
||||
};
|
||||
17
third-party/mexui/Core/Entry/TreeRow.js
vendored
Normal file
17
third-party/mexui/Core/Entry/TreeRow.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
mexui.Entry.TreeRow = function(tree, text)
|
||||
{
|
||||
mexui.Component.Entry.call(this, tree, 1);
|
||||
|
||||
this.open = true;
|
||||
this.text = text;
|
||||
this.rows = [];
|
||||
};
|
||||
mexui.util.extend(mexui.Entry.TreeRow, mexui.Component.Entry);
|
||||
|
||||
// model
|
||||
mexui.Entry.TreeRow.prototype.row = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.TreeRow(this.control, text);
|
||||
this.rows.push(entry);
|
||||
return entry;
|
||||
};
|
||||
2
third-party/mexui/Core/Init.js
vendored
Normal file
2
third-party/mexui/Core/Init.js
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
mexui.init();
|
||||
|
||||
145
third-party/mexui/Core/Native.js
vendored
Normal file
145
third-party/mexui/Core/Native.js
vendored
Normal file
@@ -0,0 +1,145 @@
|
||||
mexui.native = {};
|
||||
|
||||
// images
|
||||
mexui.native.loadImage = function(imageFilePath, imageName)
|
||||
{
|
||||
var file = openFile(imageFilePath);
|
||||
if(!file)
|
||||
{
|
||||
console.log('ERROR [IMAGE LOAD] - Opening File: '+imageFilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
var image = drawing.loadPNG(file);
|
||||
if(!image)
|
||||
{
|
||||
file.close();
|
||||
console.log('ERROR [IMAGE LOAD] - Reading File: '+imageFilePath);
|
||||
return false;
|
||||
}
|
||||
|
||||
file.close();
|
||||
|
||||
if(imageName)
|
||||
mexui.images[imageName] = image;
|
||||
|
||||
return image;
|
||||
};
|
||||
|
||||
// fonts
|
||||
mexui.native.getFont = function(textSize, textFont)
|
||||
{
|
||||
var textSizeStr = textSize + '';
|
||||
|
||||
if(!mexui.fonts[textSizeStr])
|
||||
{
|
||||
mexui.fonts[textSizeStr] = {};
|
||||
}
|
||||
|
||||
if(!mexui.fonts[textSizeStr][textFont])
|
||||
{
|
||||
mexui.fonts[textSizeStr][textFont] = lucasFont.createDefaultFont(textSize, textFont);
|
||||
}
|
||||
|
||||
return mexui.fonts[textSizeStr][textFont];
|
||||
};
|
||||
|
||||
// text size
|
||||
mexui.native.getTextSize = function(text, styles, font)
|
||||
{
|
||||
if(!font)
|
||||
font = mexui.native.getFont(styles.textSize, styles.textFont);
|
||||
|
||||
var size = font.measure(text + '', 10000, styles.textAlign, 0.0, styles.textSize, false, false);
|
||||
|
||||
//if(text[text.length - 1] == ' ')
|
||||
// width += mexui.util.getStringCount(text, ' ') * spaceWidth;
|
||||
|
||||
return size;
|
||||
};
|
||||
|
||||
mexui.native.getTextWidth = function(text, styles, font)
|
||||
{
|
||||
return mexui.native.getTextSize(text, styles, font).x;
|
||||
};
|
||||
|
||||
mexui.native.getTextHeight = function(text, styles, font)
|
||||
{
|
||||
return mexui.native.getTextSize(text, styles, font).y;
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.native.drawRectangle = function(position, size, styles)
|
||||
{
|
||||
mexui.native.drawRectangleBackground(position, size, styles);
|
||||
mexui.native.drawRectangleBorder(position, size, styles);
|
||||
};
|
||||
|
||||
mexui.native.drawRectangleBackground = function(position, size, styles)
|
||||
{
|
||||
var backgroundColour = styles.backgroundColour != null ? styles.backgroundColour : styles.backgroundColor;
|
||||
if(backgroundColour == null || backgroundColour == 'none')
|
||||
return;
|
||||
|
||||
drawing.drawRectangle(null, position, size, backgroundColour, backgroundColour, backgroundColour, backgroundColour);
|
||||
};
|
||||
|
||||
mexui.native.drawRectangleBorder = function(position, size, styles)
|
||||
{
|
||||
var borderColour = styles.borderColour || styles.borderColor;
|
||||
if(borderColour == null || borderColour == 'none')
|
||||
return;
|
||||
|
||||
var rightXPosition = position.x + size.x;
|
||||
var bottomYPosition = position.y + size.y;
|
||||
|
||||
var topLeftPosition = new Vec2(position.x, position.y);
|
||||
var topRightPosition = new Vec2(rightXPosition, position.y);
|
||||
var bottomLeftPosition = new Vec2(position.x, bottomYPosition);
|
||||
var bottomRightPosition = new Vec2(rightXPosition, bottomYPosition);
|
||||
|
||||
var original = styles.lineColour;
|
||||
|
||||
styles.lineColour = styles.topBorderColour != null ? styles.topBorderColour : (styles.topBorderColor != null ? styles.topBorderColor : borderColour);
|
||||
mexui.native.drawAALine(topLeftPosition, topRightPosition, styles);
|
||||
|
||||
styles.lineColour = styles.leftBorderColour != null ? styles.leftBorderColour : (styles.leftBorderColor != null ? styles.leftBorderColor : borderColour);
|
||||
mexui.native.drawAALine(topLeftPosition, bottomLeftPosition, styles);
|
||||
|
||||
styles.lineColour = styles.bottomBorderColour != null ? styles.bottomBorderColour : (styles.bottomBorderColor != null ? styles.bottomBorderColor : borderColour);
|
||||
mexui.native.drawAALine(bottomLeftPosition, bottomRightPosition, styles);
|
||||
|
||||
styles.lineColour = styles.rightBorderColour != null ? styles.rightBorderColour : (styles.rightBorderColor != null ? styles.rightBorderColor : borderColour);
|
||||
mexui.native.drawAALine(topRightPosition, bottomRightPosition, styles);
|
||||
|
||||
styles.lineColour = original;
|
||||
};
|
||||
|
||||
mexui.native.drawAALine = function(point1, point2, styles)
|
||||
{
|
||||
var lineColour = styles.lineColour != null ? styles.lineColour : styles.lineColor;
|
||||
if(lineColour == null || lineColour == 'none')
|
||||
return;
|
||||
|
||||
//console.log(typeof lineColour);
|
||||
//console.log(lineColour);
|
||||
|
||||
drawing.drawRectangle(null, point1, new Vec2((point2.x - point1.x) + styles.lineWeight, (point2.y - point1.y) + styles.lineWeight), lineColour, lineColour, lineColour, lineColour);
|
||||
};
|
||||
|
||||
mexui.native.drawText = function(position, size, text, styles)
|
||||
{
|
||||
var font = mexui.native.getFont(styles.textSize, styles.textFont);
|
||||
|
||||
var textHeight = mexui.native.getTextHeight(text, styles, font);
|
||||
var textIndent = styles.textAlign == 0.0 || styles.textAlign == 1.0 ? styles.textIndent : 0;
|
||||
var textPos = new Vec2(position.x + textIndent, position.y + ((size.y - textHeight) / 2.0));
|
||||
|
||||
font.render(text + '', textPos, size.x, styles.textAlign, 0.0, styles.textSize, styles.textColour != null ? styles.textColour : styles.textColor);
|
||||
};
|
||||
|
||||
mexui.native.drawImage = function(position, size, image, styles)
|
||||
{
|
||||
drawing.drawRectangle(image, position, size);
|
||||
};
|
||||
|
||||
471
third-party/mexui/Core/Utility.js
vendored
Normal file
471
third-party/mexui/Core/Utility.js
vendored
Normal file
@@ -0,0 +1,471 @@
|
||||
mexui.util = {};
|
||||
|
||||
mexui.util.extend = function(d, b)
|
||||
{
|
||||
d.prototype = Object.create(b.prototype);
|
||||
d.prototype.constructor = b;
|
||||
};
|
||||
|
||||
mexui.util.isPointInRectangle = function(point, position, size)
|
||||
{
|
||||
if(!point)
|
||||
return false; // temp bug fix
|
||||
|
||||
return point.x >= position.x && point.y >= position.y && point.x <= (position.x + size.x) && point.y <= (position.y + size.y);
|
||||
};
|
||||
|
||||
mexui.util.isCursorInRectangle = function(position, size)
|
||||
{
|
||||
return mexui.util.isPointInRectangle(gui.cursorPosition, position, size);
|
||||
};
|
||||
|
||||
mexui.util.addVec2 = function(vec2a, vec2b)
|
||||
{
|
||||
return new Vec2(vec2a.x + vec2b.x, vec2a.y + vec2b.y);
|
||||
};
|
||||
|
||||
mexui.util.addVec3 = function(vec3a, vec3b)
|
||||
{
|
||||
return new Vec3(vec3a.x + vec3b.x, vec3a.y + vec3b.y, vec3a.z + vec3b.z);
|
||||
};
|
||||
|
||||
mexui.util.createControlConstructor = function(controlName, hasEntries, constructor)
|
||||
{
|
||||
mexui.Control[controlName] = constructor;
|
||||
mexui.util.extend(mexui.Control[controlName], hasEntries ? mexui.Entity.ControlWithEntries : mexui.Component.Control);
|
||||
};
|
||||
|
||||
mexui.util.linkBaseControlStyles = function(controlName, derivedStyles)
|
||||
{
|
||||
mexui.Control[controlName].defaultStyles = mexui.util.linkStyles(mexui.Component.Control.defaultStyles, derivedStyles);
|
||||
};
|
||||
|
||||
mexui.util.linkStyles = function(baseStyles, derivedStyles)
|
||||
{
|
||||
derivedStyles = derivedStyles || {};
|
||||
|
||||
for(var k in baseStyles)
|
||||
{
|
||||
switch(k)
|
||||
{
|
||||
case 'focus':
|
||||
case 'hover':
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!derivedStyles[k])
|
||||
derivedStyles[k] = {};
|
||||
if(!(derivedStyles[k].__proto__ instanceof Object))
|
||||
derivedStyles[k].__proto__ = baseStyles[k];
|
||||
|
||||
/*
|
||||
var hoverBaseStyles = JSON.parse(JSON.stringify(baseStyles[k]));
|
||||
if(!derivedStyles[k].hover)
|
||||
derivedStyles[k].hover = {};
|
||||
if(!(derivedStyles[k].hover.__proto__ instanceof Object))
|
||||
derivedStyles[k].hover.__proto__ = hoverBaseStyles;
|
||||
*/
|
||||
}
|
||||
|
||||
return mexui.util.linkGlobalStyles(mexui.Entity.StyleableEntity.globalDefaultStyles, derivedStyles);
|
||||
//return derivedStyles;
|
||||
};
|
||||
|
||||
mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
|
||||
{
|
||||
derivedStyles = derivedStyles || {};
|
||||
|
||||
for(var k in derivedStyles)
|
||||
{
|
||||
switch(k)
|
||||
{
|
||||
case 'focus':
|
||||
case 'hover':
|
||||
continue;
|
||||
}
|
||||
|
||||
if(!(derivedStyles[k].__proto__ instanceof Object))
|
||||
{
|
||||
derivedStyles[k].__proto__ = baseStyles.all;
|
||||
}
|
||||
}
|
||||
|
||||
for(var k in derivedStyles)
|
||||
{
|
||||
switch(k)
|
||||
{
|
||||
case 'focus':
|
||||
case 'hover':
|
||||
continue;
|
||||
}
|
||||
|
||||
/*
|
||||
if(!derivedStyles[k].hasOwnProperty('hover'))
|
||||
{
|
||||
derivedStyles[k].hover = {};
|
||||
derivedStyles[k].hover.__proto__ = derivedStyles[k];
|
||||
}
|
||||
*/
|
||||
|
||||
if(derivedStyles[k].focus)
|
||||
{
|
||||
if(!(derivedStyles[k].focus.__proto__ instanceof Object))
|
||||
{
|
||||
derivedStyles[k].focus.__proto__ = baseStyles.all;
|
||||
}
|
||||
|
||||
if(derivedStyles[k].focus.hover)
|
||||
{
|
||||
if(!(derivedStyles[k].focus.hover.__proto__ instanceof Object))
|
||||
{
|
||||
derivedStyles[k].focus.hover.__proto__ = baseStyles.all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(derivedStyles[k].hover)
|
||||
{
|
||||
if(!(derivedStyles[k].hover.__proto__ instanceof Object))
|
||||
{
|
||||
derivedStyles[k].hover.__proto__ = baseStyles.all;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return derivedStyles;
|
||||
};
|
||||
|
||||
String.prototype.repeat = function(count)
|
||||
{
|
||||
return Array(count + 1).join(this);
|
||||
};
|
||||
|
||||
mexui.util.isLetter = function(character)
|
||||
{
|
||||
var ord = character.charCodeAt(0);
|
||||
return (ord >= 65 && ord <= 90) || (ord >= 97 && ord <= 122);
|
||||
};
|
||||
|
||||
mexui.util.isDigit = function(character)
|
||||
{
|
||||
var ord = character.charCodeAt(0);
|
||||
return ord >= 48 && ord <= 57;
|
||||
};
|
||||
|
||||
mexui.util.isLetterOrDigit = function(character)
|
||||
{
|
||||
return mexui.util.isLetter(character) || mexui.util.isDigit(character);
|
||||
};
|
||||
|
||||
mexui.util.isCharacterInOctetRange = function(character, min, max)
|
||||
{
|
||||
var ord = character.charCodeAt(0);
|
||||
return ord >= min && ord <= max;
|
||||
};
|
||||
|
||||
mexui.util.interpolateScalar = function(a, b, f)
|
||||
{
|
||||
return a + ((b - a) * f);
|
||||
};
|
||||
|
||||
mexui.util.doesContainEOLChar = function(text)
|
||||
{
|
||||
return text.indexOf("\n") != -1 || text.indexOf("\r") != -1;
|
||||
};
|
||||
|
||||
mexui.util.splitLines = function(text)
|
||||
{
|
||||
text = text.replace("\r\n", "\n");
|
||||
text = text.replace("\r", "\n");
|
||||
return text.split("\n");
|
||||
};
|
||||
|
||||
mexui.util.getStringCount = function(text, find)
|
||||
{
|
||||
var count = 0;
|
||||
var index = 0;
|
||||
for(;;)
|
||||
{
|
||||
index = text.indexOf(find, index);
|
||||
if(index == -1)
|
||||
break;
|
||||
count++;
|
||||
index += find.length;
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
mexui.util.stack = function()
|
||||
{
|
||||
var err = new Error();
|
||||
console.log(err.stack);
|
||||
};
|
||||
|
||||
mexui.util.deg = function(rad)
|
||||
{
|
||||
return rad * (180 / Math.PI);
|
||||
};
|
||||
|
||||
mexui.util.rad = function(deg)
|
||||
{
|
||||
return deg * (Math.PI / 180);
|
||||
};
|
||||
|
||||
mexui.util.round = function(x, n)
|
||||
{
|
||||
return parseFloat(Math.round(x * Math.pow(10, n)) / Math.pow(10, n)).toFixed(n);
|
||||
};
|
||||
|
||||
mexui.util.getCenterPosition = function(largerSize, smallerSize)
|
||||
{
|
||||
return new Vec2(
|
||||
(largerSize.x - smallerSize.x) / 2.0,
|
||||
(largerSize.y - smallerSize.y) / 2.0
|
||||
);
|
||||
};
|
||||
|
||||
mexui.util.getWindowSize = function()
|
||||
{
|
||||
return new Vec2(gta.width, gta.height);
|
||||
};
|
||||
|
||||
mexui.util.isRectangleInsideRectangle = function(pos1, size1, pos2, size2)
|
||||
{
|
||||
return !(pos2.x > (pos1.x + size1.x) ||
|
||||
(pos2.x + size2.x) < pos1.x ||
|
||||
pos2.y > (pos1.y + size1.y) ||
|
||||
(pos2.y + size2.y) < pos1.y);
|
||||
};
|
||||
|
||||
mexui.util.mergeStyles = function(styles, pseudoPartNames)
|
||||
{
|
||||
var styles3 = {};
|
||||
var styles2 = [styles];
|
||||
while(styles2[0])
|
||||
{
|
||||
styles2 = [styles2[0]];
|
||||
for(var i in pseudoPartNames)
|
||||
{
|
||||
var pseudoPartName = pseudoPartNames[i];
|
||||
|
||||
if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName))
|
||||
styles2.push(styles2[0][pseudoPartName]);
|
||||
}
|
||||
|
||||
for(var i=styles2.length-1; i>=0; i--)
|
||||
{
|
||||
if(styles2[i] == null)
|
||||
continue;
|
||||
|
||||
for(var k in styles2[i])
|
||||
{
|
||||
switch(k)
|
||||
{
|
||||
case 'focus':
|
||||
case 'hover':
|
||||
|
||||
case 'transitionTime':
|
||||
case 'transitionDelay':
|
||||
|
||||
case 'transitionDelayStartTime':
|
||||
case 'transitionStartTime':
|
||||
case 'transitionStarted':
|
||||
case 'transitionEnded':
|
||||
case 'transitionReverting':
|
||||
|
||||
continue;
|
||||
}
|
||||
if(styles2[i].hasOwnProperty(k) && styles3[k] == null)
|
||||
{
|
||||
var styleValue = styles2[i][k];
|
||||
|
||||
/*
|
||||
if(i > 0 && (styles2[i].transitionTime != null || styles2[i].transitionDelay != null))
|
||||
{
|
||||
var timeNow = mexui.util.time();
|
||||
if(styles2[i].transitionReverting)
|
||||
{
|
||||
var transitionTime = styles2[i].transitionTime == null ? 400 : styles2[i].transitionTime;
|
||||
var progress = (timeNow - styles2[i].transitionStartTime) / transitionTime;
|
||||
if(progress > 1.0)
|
||||
{
|
||||
styles2[i].transitionEnded = true;
|
||||
styleValue = styles2[0][k];
|
||||
|
||||
delete styles2[i].transitionDelayStartTime;
|
||||
delete styles2[i].transitionStartTime;
|
||||
delete styles2[i].transitionStarted;
|
||||
delete styles2[i].transitionEnded;
|
||||
delete styles2[i].transitionReverting;
|
||||
}
|
||||
else
|
||||
{
|
||||
styleValue = mexui.util.interpolateStyle(k, progress, styles2[i][k], styles2[0][k]);
|
||||
}
|
||||
}
|
||||
else if(styles2[i].transitionEnded)
|
||||
{
|
||||
styleValue = styles2[i][k];
|
||||
}
|
||||
else if(styles2[i].transitionStarted)
|
||||
{
|
||||
var transitionTime = styles2[i].transitionTime == null ? 400 : styles2[i].transitionTime;
|
||||
var progress = (timeNow - styles2[i].transitionStartTime) / transitionTime;
|
||||
if(progress > 1.0)
|
||||
{
|
||||
styles2[i].transitionEnded = true;
|
||||
styleValue = styles2[i][k];
|
||||
}
|
||||
else
|
||||
{
|
||||
styleValue = mexui.util.interpolateStyle(k, progress, styles2[0][k], styles2[i][k]);
|
||||
}
|
||||
}
|
||||
else if(styles2[i].transitionDelayStartTime)
|
||||
{
|
||||
var transitionDelay = styles2[i].transitionDelay == null ? 0 : styles2[i].transitionDelay;
|
||||
if(timeNow >= (styles2[i].transitionDelayStartTime + transitionDelay))
|
||||
{
|
||||
styles2[i].transitionStarted = true;
|
||||
styles2[i].transitionStartTime = timeNow;
|
||||
styleValue = styles2[0][k];
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
styles2[i].transitionDelayStartTime = timeNow;
|
||||
styleValue = styles2[0][k];
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
styles3[k] = styleValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(var i in styles2)
|
||||
{
|
||||
if(styles2[i])
|
||||
styles2[i] = styles2[i].__proto__;
|
||||
}
|
||||
}
|
||||
|
||||
return styles3;
|
||||
};
|
||||
|
||||
mexui.util.getTransitionStyles = function(styles, pseudoPartNames, progress)
|
||||
{
|
||||
var styles3 = {};
|
||||
var styles2 = [styles];
|
||||
while(styles2[0])
|
||||
{
|
||||
styles2 = [styles2[0]];
|
||||
for(var i in pseudoPartNames)
|
||||
{
|
||||
var pseudoPartName = pseudoPartNames[i];
|
||||
|
||||
if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName))
|
||||
styles2.push(styles2[0][pseudoPartName]);
|
||||
}
|
||||
|
||||
for(var i=styles2.length-1; i>=0; i--)
|
||||
{
|
||||
if(styles2[i] == null)
|
||||
continue;
|
||||
|
||||
for(var k in styles2[i])
|
||||
{
|
||||
switch(k)
|
||||
{
|
||||
case 'focus':
|
||||
case 'hover':
|
||||
|
||||
case 'transitionTime':
|
||||
case 'transitionDelay':
|
||||
|
||||
continue;
|
||||
}
|
||||
if(styles2[i].hasOwnProperty(k) && styles3[k] == null)
|
||||
{
|
||||
var styleValue = styles2[i][k];
|
||||
|
||||
if(i > 0)
|
||||
{
|
||||
var mainStyleValue = styles2[0][k];
|
||||
var pseudoStyleValue = styles2[i][k];
|
||||
|
||||
//console.log(mainStyleValue+' '+pseudoStyleValue);
|
||||
|
||||
styleValue = mexui.util.interpolateStyle(k, progress, mainStyleValue, pseudoStyleValue);
|
||||
}
|
||||
|
||||
styles3[k] = styleValue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for(var i in styles2)
|
||||
{
|
||||
if(styles2[i])
|
||||
styles2[i] = styles2[i].__proto__;
|
||||
}
|
||||
}
|
||||
|
||||
return styles3;
|
||||
};
|
||||
|
||||
mexui.util.interpolateStyle = function(styleName, progress, styleValueFrom, styleValueTo)
|
||||
{
|
||||
switch(styleName)
|
||||
{
|
||||
case 'backgroundColour':
|
||||
case 'backgroundColor':
|
||||
case 'textColour':
|
||||
case 'textColor':
|
||||
case 'lineColour':
|
||||
case 'lineColor':
|
||||
case 'borderColour':
|
||||
case 'borderColor':
|
||||
if(styleValueFrom == 'none')
|
||||
styleValueFrom = toColour(255, 255, 255, 0);
|
||||
if(styleValueTo == 'none')
|
||||
styleValueTo = toColour(255, 255, 255, 0);
|
||||
return mexui.util.interpolateColour(progress, styleValueFrom, styleValueTo);
|
||||
default:
|
||||
return mexui.util.interpolateScalar(progress, styleValueFrom, styleValueTo);
|
||||
}
|
||||
};
|
||||
|
||||
mexui.util.interpolateColour = function(progress, styleValueFrom, styleValueTo)
|
||||
{
|
||||
var rgbFrom = mexui.util.fromColour(styleValueFrom);
|
||||
var rgbTo = mexui.util.fromColour(styleValueTo);
|
||||
var rgba = [];
|
||||
for(var i=0; i<4; i++)
|
||||
{
|
||||
rgba[i] = mexui.util.interpolateScalar(progress, rgbFrom[i], rgbTo[i]);
|
||||
}
|
||||
return toColour.apply(null, rgba);
|
||||
};
|
||||
|
||||
mexui.util.interpolateScalar = function(progress, valueFrom, valueTo)
|
||||
{
|
||||
return valueFrom + ((valueTo - valueFrom) * progress);
|
||||
};
|
||||
|
||||
mexui.util.fromColour = function(colour)
|
||||
{
|
||||
return [
|
||||
(colour >> 16) & 0xFF,
|
||||
(colour >> 8) & 0xFF,
|
||||
colour & 0xFF,
|
||||
(colour >> 24) & 0xFF
|
||||
];
|
||||
};
|
||||
|
||||
mexui.util.time = function()
|
||||
{
|
||||
return gta.tickCount;
|
||||
};
|
||||
|
||||
BIN
third-party/mexui/Images/down-arrow.png
vendored
Normal file
BIN
third-party/mexui/Images/down-arrow.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 273 B |
292
third-party/mexui/mexui.js
vendored
Normal file
292
third-party/mexui/mexui.js
vendored
Normal file
@@ -0,0 +1,292 @@
|
||||
var mexui = {};
|
||||
|
||||
// data initialization
|
||||
mexui.Entity = {};
|
||||
mexui.Component = {};
|
||||
mexui.Control = {};
|
||||
mexui.Entry = {};
|
||||
|
||||
mexui.windows = [];
|
||||
|
||||
mexui.fonts = {};
|
||||
mexui.images = {};
|
||||
|
||||
mexui.focusedControl = null;
|
||||
mexui.hoveredComponent = null;
|
||||
|
||||
// initialization
|
||||
mexui.init = function()
|
||||
{
|
||||
mexui.native.loadImage('third-party/mexui/Images/down-arrow.png', 'downArrow');
|
||||
mexui.bindEvents();
|
||||
mexui.startTimers();
|
||||
};
|
||||
|
||||
// events
|
||||
mexui.bindEvents = function()
|
||||
{
|
||||
addEventHandler('onMouseDown', function(event)
|
||||
{
|
||||
var e = mexui.triggerEvent('onMouseDown');
|
||||
if(!e.clickedAControl)
|
||||
{
|
||||
mexui.focusedControl = null;
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler('onMouseUp', function(event)
|
||||
{
|
||||
mexui.triggerEvent('onMouseUp');
|
||||
});
|
||||
|
||||
addEventHandler('onMouseMove', function(event, mouse, isAbsolute, position)
|
||||
{
|
||||
var mouseSpeed = gta.getMouseSpeed();
|
||||
mexui.triggerEvent('onMouseMove', new Vec2(mouseSpeed.x, -mouseSpeed.y), true);
|
||||
});
|
||||
|
||||
addEventHandler('onMouseWheel', function(event, mouse, offset, flipped)
|
||||
{
|
||||
mexui.triggerEvent('onMouseWheel', offset);
|
||||
});
|
||||
|
||||
addEventHandler('onKeyDown', function(event, key, pkey, mods)
|
||||
{
|
||||
mexui.triggerEvent('onKeyDown', key, mods);
|
||||
|
||||
if(key == SDLK_TAB)
|
||||
{
|
||||
mexui.cycleFocusedControl();
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler('onCharacter', function(event, character)
|
||||
{
|
||||
mexui.triggerEvent('onCharacter', character);
|
||||
|
||||
if(character == 't' || character == 'T')
|
||||
{
|
||||
var textInput = mexui.getFocusedTextInput();
|
||||
if(textInput)
|
||||
{
|
||||
//event.preventDefault();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
addEventHandler('onBeforeDrawHUD', function(event)
|
||||
{
|
||||
mexui.render();
|
||||
});
|
||||
};
|
||||
|
||||
mexui.unbindEvents = function()
|
||||
{
|
||||
removeEventHandler('onMouseDown');
|
||||
removeEventHandler('onMouseUp');
|
||||
removeEventHandler('onMouseMove');
|
||||
removeEventHandler('onMouseWheel');
|
||||
removeEventHandler('onKeyDown');
|
||||
removeEventHandler('onCharacter');
|
||||
removeEventHandler('onBeforeDrawHUD');
|
||||
};
|
||||
|
||||
// timers
|
||||
mexui.startTimers = function()
|
||||
{
|
||||
setInterval(mexui.toggleTextInputCaretShownForBlink, 400);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.render = function()
|
||||
{
|
||||
for(var i in mexui.windows)
|
||||
{
|
||||
if(mexui.windows[i].shown)
|
||||
mexui.windows[i].render.call(mexui.windows[i]);
|
||||
}
|
||||
for(var i in mexui.windows)
|
||||
{
|
||||
if(mexui.windows[i].shown)
|
||||
mexui.windows[i].renderAfter.call(mexui.windows[i]);
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.triggerEvent = function(eventName, data, callBaseMethodFirst)
|
||||
{
|
||||
var e = new mexui.Component.Event();
|
||||
var windows = mexui.windows.slice(0, mexui.windows.length).reverse();
|
||||
for(var i in windows)
|
||||
{
|
||||
if(windows[i].shown)
|
||||
{
|
||||
if(callBaseMethodFirst)
|
||||
{
|
||||
if(mexui.Entity.Component.prototype[eventName])
|
||||
{
|
||||
mexui.Entity.Component.prototype[eventName].call(windows[i], e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
|
||||
windows[i][eventName].call(windows[i], e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
windows[i][eventName].call(windows[i], e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
|
||||
if(mexui.Entity.Component.prototype[eventName])
|
||||
{
|
||||
mexui.Entity.Component.prototype[eventName].call(windows[i], e, data);
|
||||
if(e.used)
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return e;
|
||||
};
|
||||
|
||||
mexui.getTopWindow = function()
|
||||
{
|
||||
for(var i = mexui.windows.length - 1, j = 0; i >= j; i--)
|
||||
{
|
||||
if(mexui.windows[i].shown)
|
||||
return mexui.windows[i];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
mexui.getShownWindows = function()
|
||||
{
|
||||
var shownWindows = [];
|
||||
for(var i = mexui.windows.length - 1, j = 0; i >= j; i--)
|
||||
{
|
||||
if(mexui.windows[i].shown)
|
||||
shownWindows.push(mexui.windows[i]);
|
||||
}
|
||||
return shownWindows;
|
||||
};
|
||||
|
||||
mexui.getNextShownWindows = function(afterWindow)
|
||||
{
|
||||
var shownWindows = mexui.getShownWindows();
|
||||
|
||||
var windowIndex = shownWindows.indexOf(afterWindow);
|
||||
|
||||
var windows2 = shownWindows.splice(0, windowIndex + 1);
|
||||
var args = windows2;
|
||||
args.unshift(0);
|
||||
args.unshift(shownWindows.length);
|
||||
shownWindows.splice.apply(shownWindows, args);
|
||||
|
||||
return shownWindows;
|
||||
};
|
||||
|
||||
mexui.cycleFocusedControl = function()
|
||||
{
|
||||
// no windows are created
|
||||
if(mexui.windows.length == 0)
|
||||
return;
|
||||
|
||||
// no control is focused
|
||||
if(!mexui.focusedControl)
|
||||
{
|
||||
var topWindow = mexui.getTopWindow();
|
||||
if(!topWindow)
|
||||
return;
|
||||
|
||||
mexui.focusedControl = topWindow.getFirstShownControl();
|
||||
return;
|
||||
}
|
||||
|
||||
// a control is focused
|
||||
var focusedControlWindow = mexui.focusedControl.window;
|
||||
var nextControl = focusedControlWindow.getNextShownControl(mexui.focusedControl);
|
||||
if(nextControl)
|
||||
{
|
||||
mexui.focusedControl = nextControl;
|
||||
return;
|
||||
}
|
||||
|
||||
// set focus to first control on next window that has a control shown
|
||||
var shownWindows = mexui.getNextShownWindows(focusedControlWindow);
|
||||
for(var i in shownWindows)
|
||||
{
|
||||
var window = shownWindows[i];
|
||||
var firstControl = window.getFirstShownControl();
|
||||
if(firstControl)
|
||||
{
|
||||
mexui.focusedControl = firstControl;
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mexui.getFocusedTextInput = function()
|
||||
{
|
||||
if(!mexui.focusedControl)
|
||||
return null;
|
||||
|
||||
if(!(mexui.focusedControl instanceof mexui.Control.TextInput))
|
||||
return null;
|
||||
|
||||
return mexui.focusedControl;
|
||||
};
|
||||
|
||||
mexui.toggleTextInputCaretShownForBlink = function()
|
||||
{
|
||||
var textInput = mexui.getFocusedTextInput();
|
||||
if(!textInput)
|
||||
return;
|
||||
|
||||
textInput.caretShownForBlink = !textInput.caretShownForBlink;
|
||||
};
|
||||
|
||||
mexui.setHoveredComponent = function(component)
|
||||
{
|
||||
//component.hovered = true;
|
||||
mexui.hoveredComponent = component;
|
||||
};
|
||||
|
||||
mexui.clearHoveredComponent = function()
|
||||
{
|
||||
//mexui.hoveredComponent.hovered = false;
|
||||
mexui.hoveredComponent = null;
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.window = function(x, y, w, h, title, styles)
|
||||
{
|
||||
var window = new mexui.Component.Window(x, y, w, h, title, styles);
|
||||
mexui.windows.push(window);
|
||||
return window;
|
||||
};
|
||||
|
||||
mexui.isAnyWindowShown = function()
|
||||
{
|
||||
for(var i in mexui.windows)
|
||||
{
|
||||
if(mexui.windows[i].shown)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
mexui.setInput = function(showInput)
|
||||
{
|
||||
gui.showCursor(showInput, !showInput);
|
||||
if(localPlayer)
|
||||
{
|
||||
if(showInput)
|
||||
setCameraLookAtEntity(new Vec3(cameraMatrix.m41, cameraMatrix.m42, cameraMatrix.m43), localPlayer, false);
|
||||
else
|
||||
restoreCamera(false);
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user