MexUI stuff

This commit is contained in:
Vortrex
2022-05-15 22:26:31 -05:00
parent c81f511448
commit 4b7f05a482
42 changed files with 423 additions and 398 deletions

View File

@@ -2,12 +2,12 @@ mexui.Component.Control = function(window, x, y, w, h, styles, callback)
{ {
mexui.Entity.Component.call(this, false); mexui.Entity.Component.call(this, false);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Control', styles)); mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Control', styles));
this.window = window; this.window = window;
this.position = new Vec2(x, y); this.position = new Vec2(x, y);
this.size = new Vec2(w, h); this.size = new Vec2(w, h);
this.callback = callback; this.callback = callback;
this.boundTo = null; this.boundTo = null;
}; };
mexui.util.extend(mexui.Component.Control, mexui.Entity.Component); mexui.util.extend(mexui.Component.Control, mexui.Entity.Component);
@@ -131,3 +131,4 @@ mexui.Component.Control.prototype.unbind = function()
{ {
this.boundTo = null; this.boundTo = null;
}; };

View File

@@ -2,7 +2,7 @@ mexui.Component.Entry = function(control, axisIndex, text, styles)
{ {
mexui.Entity.Component.call(this, false); mexui.Entity.Component.call(this, false);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Entry', styles)); mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Entry', styles));
this.control = control; this.control = control;
this.axisIndex = axisIndex; this.axisIndex = axisIndex;
this.text = text; this.text = text;
@@ -29,3 +29,4 @@ mexui.Component.Entry.prototype.remove = function()
this.control.axis[this.getAxisKey()].entries.splice(this.getEntryIndex(), 1); this.control.axis[this.getAxisKey()].entries.splice(this.getEntryIndex(), 1);
this.control.checkToShowScrollBars(); this.control.checkToShowScrollBars();
}; };

View File

@@ -3,3 +3,4 @@ mexui.Component.Event = function()
this.used = false; this.used = false;
this.clickedAControl = false; this.clickedAControl = false;
}; };

View File

@@ -2,11 +2,11 @@ mexui.Component.Window = function(x, y, w, h, title, styles)
{ {
mexui.Entity.Component.call(this, true); mexui.Entity.Component.call(this, true);
mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Window', styles)); mexui.Entity.StyleableEntity.call(this, this.linkComponentStyles('Window', styles));
this.position = new Vec2(x, y); this.position = new Vec2(x, y);
this.size = new Vec2(w, h); this.size = new Vec2(w, h);
this.title = title || ''; this.title = title || '';
this.controls = []; this.controls = [];
this.titleBarShown = true; this.titleBarShown = true;
this.titleBarHeight = 30; this.titleBarHeight = 30;
@@ -21,7 +21,7 @@ mexui.Component.Window.defaultStyles = mexui.util.linkStyles(mexui.Entity.Stylea
{ {
backgroundColour: toColour(0, 0, 0, 190), backgroundColour: toColour(0, 0, 0, 190),
textColour: toColour(255, 255, 255, 255), textColour: toColour(255, 255, 255, 255),
hover: hover:
{ {
backgroundColour: toColour(0, 0, 0, 170) backgroundColour: toColour(0, 0, 0, 170)
@@ -52,12 +52,12 @@ mexui.Component.Window.prototype.onMouseDown = function(e)
e.used = true; e.used = true;
return; return;
} }
if(this.isCursorOverWindow()) if(this.isCursorOverWindow())
{ {
this.setTop(); this.setTop();
} }
this.triggerEvent('onMouseDown', e); this.triggerEvent('onMouseDown', e);
}; };
@@ -70,15 +70,15 @@ mexui.Component.Window.prototype.onMouseMove = function(e, offset)
{ {
//var wasHovered = this.isHovered(); //var wasHovered = this.isHovered();
//e.wasHovered = wasHovered; //e.wasHovered = wasHovered;
if(mexui.hoveredComponent && !mexui.hoveredComponent.isCursorOverItem()) if(mexui.hoveredComponent && !mexui.hoveredComponent.isCursorOverItem())
{ {
mexui.hoveredComponent.onMouseExit(); mexui.hoveredComponent.onMouseExit();
mexui.clearHoveredComponent(); mexui.clearHoveredComponent();
} }
this.triggerEvent('onMouseMove', e, offset); this.triggerEvent('onMouseMove', e, offset);
if(e.used) if(e.used)
{ {
/* /*
@@ -90,7 +90,7 @@ mexui.Component.Window.prototype.onMouseMove = function(e, offset)
*/ */
return; return;
} }
if(this.isCursorOverWindow()) if(this.isCursorOverWindow())
{ {
if(!this.isHovered()) if(!this.isHovered())
@@ -129,13 +129,13 @@ mexui.Component.Window.prototype.render = function()
{ {
// window background // window background
mexui.native.drawRectangleBackground(this.position, this.size, this.getStyles('main')); mexui.native.drawRectangleBackground(this.position, this.size, this.getStyles('main'));
if(this.titleBarShown) if(this.titleBarShown)
{ {
// window title bar // window title bar
mexui.native.drawRectangle(this.position, new Vec2(this.size.x, this.titleBarHeight), this.getStyles('title')); 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')); mexui.native.drawText(this.position, new Vec2(this.size.x, this.titleBarHeight), this.title, this.getStyles('title'));
if(this.titleBarIconShown) if(this.titleBarIconShown)
{ {
// window title bar icons // window title bar icons
@@ -144,17 +144,17 @@ mexui.Component.Window.prototype.render = function()
mexui.native.drawText(iconPos, this.titleBarIconSize, 'X', this.getStyles('icon')); mexui.native.drawText(iconPos, this.titleBarIconSize, 'X', this.getStyles('icon'));
} }
} }
// window border // window border
mexui.native.drawRectangleBorder(this.position, this.size, this.getStyles('main')); mexui.native.drawRectangleBorder(this.position, this.size, this.getStyles('main'));
// window controls // window controls
var show, control; var show, control;
for(var i in this.controls) for(var i in this.controls)
{ {
control = this.controls[i]; control = this.controls[i];
show = false; show = false;
if(control.shown) if(control.shown)
{ {
show = true; show = true;
@@ -164,7 +164,7 @@ mexui.Component.Window.prototype.render = function()
show = false; show = false;
} }
} }
if(show) if(show)
control.render.call(control); control.render.call(control);
} }
@@ -177,7 +177,7 @@ mexui.Component.Window.prototype.renderAfter = function()
if(this.controls[i].shown) if(this.controls[i].shown)
{ {
this.controls[i].renderAfter.call(this.controls[i]); this.controls[i].renderAfter.call(this.controls[i]);
for(var i2 in this.controls[i].scrollBars) for(var i2 in this.controls[i].scrollBars)
{ {
if(this.controls[i].scrollBars[i2].shown) if(this.controls[i].scrollBars[i2].shown)
@@ -219,10 +219,10 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
for(var i in this.controls) for(var i in this.controls)
{ {
var control = this.controls[i]; var control = this.controls[i];
if(!control.shown) if(!control.shown)
continue; continue;
if(callBaseMethodFirst) if(callBaseMethodFirst)
{ {
if(mexui.Entity.Component.prototype[eventName]) if(mexui.Entity.Component.prototype[eventName])
@@ -231,7 +231,7 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
if(e.used) if(e.used)
break; break;
} }
this.controls[i][eventName].call(control, e, data); this.controls[i][eventName].call(control, e, data);
if(e.used) if(e.used)
break; break;
@@ -248,7 +248,7 @@ mexui.Component.Window.prototype.triggerEvent = function(eventName, e, data, cal
} }
break; break;
} }
if(mexui.Entity.Component.prototype[eventName]) if(mexui.Entity.Component.prototype[eventName])
{ {
mexui.Entity.Component.prototype[eventName].call(control, e, data); mexui.Entity.Component.prototype[eventName].call(control, e, data);
@@ -268,9 +268,9 @@ mexui.Component.Window.prototype.addControl = function(control)
mexui.Component.Window.prototype.setShown = function(shown) mexui.Component.Window.prototype.setShown = function(shown)
{ {
//var anyWindowShownBefore = mexui.isAnyWindowShown(); //var anyWindowShownBefore = mexui.isAnyWindowShown();
this.shown = shown; this.shown = shown;
if(mexui.focusedControl && this.isControlInWindow(mexui.focusedControl)) if(mexui.focusedControl && this.isControlInWindow(mexui.focusedControl))
{ {
if(!shown) if(!shown)
@@ -278,7 +278,7 @@ mexui.Component.Window.prototype.setShown = function(shown)
mexui.focusedControl = null; mexui.focusedControl = null;
} }
} }
/* /*
if(shown) if(shown)
{ {
@@ -336,7 +336,7 @@ mexui.Component.Window.prototype.getFirstShownControl = function()
mexui.Component.Window.prototype.getNextShownControl = function(afterControl) mexui.Component.Window.prototype.getNextShownControl = function(afterControl)
{ {
var controlIndex = this.controls.indexOf(afterControl); var controlIndex = this.controls.indexOf(afterControl);
if(this.controls[controlIndex + 1]) if(this.controls[controlIndex + 1])
return this.controls[controlIndex + 1]; return this.controls[controlIndex + 1];
else else
@@ -355,7 +355,7 @@ mexui.Component.Window.prototype.digits = function(x, y, w, h, text, styles, c
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.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.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.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.image = function(x, y, w, h, filePath, styles, callback) { return this.addControl(new mexui.Control.Image(this, x, y, w, h, filePath, styles, callback)); };
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.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.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.letters = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.Letters(this, x, y, w, h, text, styles, callback)); };
@@ -386,3 +386,4 @@ mexui.Component.Window.prototype.tree = function(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.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.weekDay = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.WeekDay(this, x, y, w, h, text, styles, callback)); }; mexui.Component.Window.prototype.weekDay = function(x, y, w, h, text, styles, callback) { return this.addControl(new mexui.Control.WeekDay(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)); }; 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)); };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Button', false, function(window, x, y, w, h, text, styles, callback) 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); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Button', styles), callback);
this.text = text; this.text = text;
}); });
@@ -31,10 +31,10 @@ mexui.Control.Button.prototype.onKeyDown = function(e, key, mods)
mexui.Control.Button.prototype.render = function() mexui.Control.Button.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main')); mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };

View File

@@ -1,15 +1,15 @@
mexui.util.createControlConstructor('Date', false, function(window, x, y, w, h, text, styles, callback) 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); mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Date', styles), callback, false, false);
this.day = 1; this.day = 1;
this.month = 1; this.month = 1;
this.year = 2019; this.year = 2019;
this.inputShown = false; this.inputShown = false;
this.valueBoxSize = new Vec2(50, 30); this.valueBoxSize = new Vec2(50, 30);
this.arrowBoxSize = new Vec2(25, 22); this.arrowBoxSize = new Vec2(25, 22);
this.maxYearOffset = 10; this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; }; this.minYearCallback = ()=>{ return 1900; };
this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; } this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; }
@@ -40,42 +40,42 @@ mexui.Control.Date.prototype.onMouseDown = function(e)
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1; var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
var propName = mexui.Control.Date.units[propIndex]; var propName = mexui.Control.Date.units[propIndex];
var isIncrease = (arrowIndex % 2) == 1; var isIncrease = (arrowIndex % 2) == 1;
if(isIncrease) if(isIncrease)
this[propName]++; this[propName]++;
else else
this[propName]--; this[propName]--;
if(this.day == 0) if(this.day == 0)
this.day = 31; this.day = 31;
else if(this.day == 32) else if(this.day == 32)
this.day = 1; this.day = 1;
if(this.month == 0) if(this.month == 0)
this.month = 12; this.month = 12;
else if(this.month == 13) else if(this.month == 13)
this.month = 1; this.month = 1;
var minYear = this.minYearCallback(); var minYear = this.minYearCallback();
var maxYear = this.maxYearCallback(); var maxYear = this.maxYearCallback();
if(this.year < minYear) if(this.year < minYear)
this.year = minYear; this.year = minYear;
else if(this.year > maxYear) else if(this.year > maxYear)
this.year = maxYear; this.year = maxYear;
this.generateText(); this.generateText();
return; return;
} }
} }
if(this.isCursorOverControl()) if(this.isCursorOverControl())
{ {
this.inputShown = !this.inputShown; this.inputShown = !this.inputShown;
e.used = true; e.used = true;
return; return;
} }
if(this.inputShown) if(this.inputShown)
{ {
this.inputShown = false; this.inputShown = false;
@@ -89,18 +89,18 @@ mexui.Control.Date.prototype.renderAfter = function()
{ {
if(!this.inputShown) if(!this.inputShown)
return; return;
var screenPos = this.getScreenPosition(); var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y); var pos = new Vec2(screenPos.x, screenPos.y);
for(var i=0; i<3; i++) for(var i=0; i<3; i++)
{ {
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main')); mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Date.units[i]], this.getStyles('main')); mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Date.units[i]], this.getStyles('main'));
pos.x += this.valueBoxSize.x; pos.x += this.valueBoxSize.x;
} }
pos = new Vec2(screenPos.x, screenPos.y); pos = new Vec2(screenPos.x, screenPos.y);
pos.y += this.valueBoxSize.y; pos.y += this.valueBoxSize.y;
for(var i=0; i<3; i++) for(var i=0; i<3; i++)
@@ -108,10 +108,10 @@ mexui.Control.Date.prototype.renderAfter = function()
for(var i2=0; i2<2; i2++) for(var i2=0; i2<2; i2++)
{ {
var text = (i2 % 2) == 0 ? '<' : '>'; var text = (i2 % 2) == 0 ? '<' : '>';
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main')); mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main')); mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
pos.x += this.arrowBoxSize.x; pos.x += this.arrowBoxSize.x;
} }
} }
@@ -133,16 +133,16 @@ mexui.Control.Date.prototype.validateInputCallback = function(e, character)
mexui.Control.Date.prototype.validateValueCallback = function(e) mexui.Control.Date.prototype.validateValueCallback = function(e)
{ {
var parts = this.getText().split('/'); var parts = this.getText().split('/');
if(parts.length != 3) if(parts.length != 3)
return false; return false;
for(var i in parts) for(var i in parts)
{ {
var partAsStr = parts[i]; var partAsStr = parts[i];
if(partAsStr === '') if(partAsStr === '')
return false; return false;
if(i == 0) if(i == 0)
{ {
if(!mexui.util.isDayIdWithOptionalSuffix(partAsStr)) if(!mexui.util.isDayIdWithOptionalSuffix(partAsStr))
@@ -159,18 +159,18 @@ mexui.Control.Date.prototype.validateValueCallback = function(e)
return false; return false;
} }
} }
return true; return true;
}; };
mexui.Control.Date.prototype.getArrowIndexByCursor = function() mexui.Control.Date.prototype.getArrowIndexByCursor = function()
{ {
var cursorPos = gui.cursorPosition; var cursorPos = gui.cursorPosition;
var screenPos = this.getScreenPosition(); var screenPos = this.getScreenPosition();
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y); 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); 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) 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); return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);

View File

@@ -2,11 +2,11 @@ mexui.util.createControlConstructor('DropDown', true, function(window, x, y, w,
{ {
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('DropDown', 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)); mexui.Entity.ControlWithEntries.call(this, true, true, new Vec2(0, h), new Vec2(w + 120, 25));
this.axis.y.entriesShown = false; this.axis.y.entriesShown = false;
this.text = text; this.text = text;
this.arrowShown = true; this.arrowShown = true;
this.selectedEntryIndex = -1; this.selectedEntryIndex = -1;
this.hoveredEntryIndex = -1; this.hoveredEntryIndex = -1;
@@ -18,7 +18,7 @@ mexui.util.linkBaseControlStyles('DropDown', {
{ {
backgroundColour: toColour(255, 255, 255, 255), backgroundColour: toColour(255, 255, 255, 255),
textColour: toColour(0, 0, 0, 255), textColour: toColour(0, 0, 0, 255),
hover: hover:
{ {
backgroundColour: toColour(80, 80, 80, 255), backgroundColour: toColour(80, 80, 80, 255),
@@ -34,7 +34,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
{ {
if(this.axis.y.entries.length == 0) if(this.axis.y.entries.length == 0)
return; return;
var hitButton = this.isCursorOverControl(); var hitButton = this.isCursorOverControl();
if(hitButton) if(hitButton)
{ {
@@ -51,7 +51,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
} }
} }
} }
if(!e.used) if(!e.used)
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e); mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
}; };
@@ -81,20 +81,20 @@ mexui.Control.DropDown.prototype.onKeyDown = function(e, key, mods)
mexui.Control.DropDown.prototype.render = function() mexui.Control.DropDown.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var text = this.selectedEntryIndex == -1 ? this.text : this.axis.y.entries[this.selectedEntryIndex].text; var text = this.selectedEntryIndex == -1 ? this.text : this.axis.y.entries[this.selectedEntryIndex].text;
mexui.native.drawText(pos, this.size, text, this.getStyles('main')); mexui.native.drawText(pos, this.size, text, this.getStyles('main'));
if(this.arrowShown) if(this.arrowShown)
{ {
var pos2 = new Vec2(pos.x + this.size.x - (25 + 3), pos.y + 0); 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.native.drawImage(pos2, new Vec2(25, 25), mexui.images.downArrow, this.getStyles('main'));
} }
mexui.Entity.ControlWithEntries.prototype.render.call(this); mexui.Entity.ControlWithEntries.prototype.render.call(this);
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -105,31 +105,31 @@ mexui.Control.DropDown.prototype.renderAfter = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y); var pos2 = new Vec2(pos.x, pos.y);
pos.x += this.entriesPositionOffset.x; pos.x += this.entriesPositionOffset.x;
pos.y += this.entriesPositionOffset.y; pos.y += this.entriesPositionOffset.y;
pos2.x += this.entriesPositionOffset.x; pos2.x += this.entriesPositionOffset.x;
pos2.y += this.entriesPositionOffset.y; pos2.y += this.entriesPositionOffset.y;
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++) for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
{ {
var item = this.axis.y.entries[i]; var item = this.axis.y.entries[i];
if(!item) if(!item)
break; break;
//this.hovered = i == this.axis.y.hoveredEntryIndex; //this.hovered = i == this.axis.y.hoveredEntryIndex;
mexui.native.drawRectangle(pos, this.entrySize, this.getStyles('item')); mexui.native.drawRectangle(pos, this.entrySize, this.getStyles('item'));
mexui.native.drawText(pos, this.entrySize, item.text, this.getStyles('item')); mexui.native.drawText(pos, this.entrySize, item.text, this.getStyles('item'));
pos.y += this.entrySize.y; pos.y += this.entrySize.y;
} }
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(new Vec2(this.entrySize.x,this.axis.y.getDisplayedEntriesLength()),new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(new Vec2(this.entrySize.x,this.axis.y.getDisplayedEntriesLength()),new Vec2(3,3)), this.getStyles('focused'));
} }
mexui.Entity.ControlWithEntries.prototype.renderAfter.call(this); mexui.Entity.ControlWithEntries.prototype.renderAfter.call(this);
}; };

View File

@@ -30,54 +30,54 @@ mexui.util.linkBaseControlStyles('Grid', {
mexui.Control.Grid.prototype.render = function() mexui.Control.Grid.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var startX = pos.x; var startX = pos.x;
var maxColumnHeight = 0; var maxColumnHeight = 0;
for(var i in this.axis.x.entries) for(var i in this.axis.x.entries)
{ {
var column = this.axis.x.entries[i]; 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')); mexui.native.drawText(new Vec2(startX, pos.y), new Vec2(column.width, column.height), column.text, this.getStyles('header'));
startX += column.width; startX += column.width;
mexui.native.drawAALine(new Vec2(startX, pos.y), new Vec2(startX, pos.y + this.size.y), this.getStyles('column')); mexui.native.drawAALine(new Vec2(startX, pos.y), new Vec2(startX, pos.y + this.size.y), this.getStyles('column'));
if(column.height > maxColumnHeight) if(column.height > maxColumnHeight)
{ {
maxColumnHeight = column.height; maxColumnHeight = column.height;
} }
} }
var startY = pos.y + maxColumnHeight; var startY = pos.y + maxColumnHeight;
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row')); 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++) for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
{ {
var row = this.axis.y.entries[i]; var row = this.axis.y.entries[i];
if(!row) if(!row)
break; break;
startX = pos.x; startX = pos.x;
for(var i2 in row.cells) for(var i2 in row.cells)
{ {
var column = this.axis.x.entries[i2]; var column = this.axis.x.entries[i2];
var cell = row.cells[i2]; var cell = row.cells[i2];
var cellText = cell.text; var cellText = cell.text;
var styles = this.getEntryStyles([[cell,'main'], [row,'main'], [this,'row'], [this,'cell']]); 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.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); mexui.native.drawText(new Vec2(startX, startY), new Vec2(column.width, column.height), cellText, styles);
startX += column.width; startX += column.width;
} }
startY += row.rowHeight; startY += row.rowHeight;
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row')); mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
} }
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -104,7 +104,7 @@ mexui.Control.Grid.prototype.row = function(cellsData, styles)
cells[i] = new mexui.Component.Entry(this, 1, cellsData[i] + ''); cells[i] = new mexui.Component.Entry(this, 1, cellsData[i] + '');
} }
} }
var entry = new mexui.Entry.GridRow(this, cells, styles); var entry = new mexui.Entry.GridRow(this, cells, styles);
this.axis.y.addEntry(entry); this.axis.y.addEntry(entry);
return entry; return entry;
@@ -127,3 +127,4 @@ mexui.Control.Grid.prototype.getAllEntriesLength = function(axisIndex)
return this.axis.y.getAllEntriesLength2(); return this.axis.y.getAllEntriesLength2();
} }
}; };

View File

@@ -13,9 +13,9 @@ mexui.Control.Hour.prototype.validateInputCallback = function(e, character)
mexui.Control.Hour.prototype.validateValueCallback = function(e) mexui.Control.Hour.prototype.validateValueCallback = function(e)
{ {
var _int = parseInt(this.getText()); var _int = parseInt(this.getText());
if(_int < 1 || _int > 23) if(_int < 1 || _int > 23)
return false; return false;
return true; return true;
}; };

View File

@@ -1,24 +1,13 @@
mexui.util.createControlConstructor('Image', false, function(window, x, y, w, h, filePath, styles) mexui.util.createControlConstructor('Image', false, function(window, x, y, w, h, filePath, styles, callback)
{ {
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Image', styles)); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Image', styles), callback);
this.image = mexui.native.loadImage(filePath); this.image = mexui.native.loadImage(filePath);
}); });
// default styles // default styles
mexui.util.linkBaseControlStyles('Image', {}); 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'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
};
// input // input
mexui.Control.Image.prototype.onMouseDown = function(e) mexui.Control.Image.prototype.onMouseDown = function(e)
{ {
@@ -27,4 +16,24 @@ mexui.Control.Image.prototype.onMouseDown = function(e)
e.used = true; e.used = true;
this.checkToCallCallback(); this.checkToCallCallback();
} }
};
mexui.Control.Image.prototype.onKeyDown = function(e, key, mods)
{
if(this.isFocused() && (key == SDLK_RETURN || key == SDLK_RETURN2 || key == SDLK_KP_ENTER || key == SDLK_SPACE))
{
e.used = true;
this.checkToCallCallback();
}
};
// render
mexui.Control.Image.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawImage(pos, this.size, this.image, this.getStyles('main'));
if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('List', true, function(window, x, y, w, h, s
{ {
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('List', styles), callback); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('List', styles), callback);
mexui.Entity.ControlWithEntries.call(this, false, false); mexui.Entity.ControlWithEntries.call(this, false, false);
this.activeRow = null; this.activeRow = null;
this.rowHeight = 25; this.rowHeight = 25;
}); });
@@ -35,19 +35,19 @@ mexui.Control.List.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y); var pos2 = new Vec2(pos.x, pos.y);
for(var i in this.axis.y.entries) for(var i in this.axis.y.entries)
{ {
var row = this.axis.y.entries[i]; var row = this.axis.y.entries[i];
var rowText = row.text; var rowText = row.text;
mexui.native.drawRectangle(pos, new Vec2(this.size.x, this.rowHeight), this.getStyles('row')); 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')); mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), rowText, this.getStyles('row'));
pos.y += this.rowHeight; pos.y += this.rowHeight;
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine')); mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
} }
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -59,3 +59,4 @@ mexui.Control.List.prototype.row = function(text)
this.axis.y.addEntry(entry); this.axis.y.addEntry(entry);
return entry; return entry;
}; };

View File

@@ -13,9 +13,9 @@ mexui.Control.Minute.prototype.validateInputCallback = function(e, character)
mexui.Control.Minute.prototype.validateValueCallback = function(e) mexui.Control.Minute.prototype.validateValueCallback = function(e)
{ {
var _int = parseInt(this.getText()); var _int = parseInt(this.getText());
if(_int < 1 || _int > 59) if(_int < 1 || _int > 59)
return false; return false;
return true; return true;
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Password', false, function(window, x, y, w, h, text, styles, callback) 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); mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Password', styles), callback, false, true);
this.masked = true; this.masked = true;
}); });
mexui.util.extend(mexui.Control.Password, mexui.Control.TextInput); mexui.util.extend(mexui.Control.Password, mexui.Control.TextInput);

View File

@@ -1,9 +1,9 @@
mexui.util.createControlConstructor('ProgressBar', false, function(window, x, y, w, h, text, styles) 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)); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ProgressBar', styles));
this.text = text; this.text = text;
this.progress = 0.0; this.progress = 0.0;
}); });
@@ -12,7 +12,7 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
innerBar: innerBar:
{ {
backgroundColour: toColour(0, 255, 0, 255), backgroundColour: toColour(0, 255, 0, 255),
hover: hover:
{ {
backgroundColour: toColour(80, 255, 0, 255) backgroundColour: toColour(80, 255, 0, 255)
@@ -24,12 +24,12 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
mexui.Control.ProgressBar.prototype.render = function() mexui.Control.ProgressBar.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var innerBarSize = new Vec2(this.size.x * this.progress, this.size.y); var innerBarSize = new Vec2(this.size.x * this.progress, this.size.y);
mexui.native.drawRectangle(pos, innerBarSize, this.getStyles('innerBar')); mexui.native.drawRectangle(pos, innerBarSize, this.getStyles('innerBar'));
if(this.text != '') if(this.text != '')
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main')); mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
}; };

View File

@@ -1,10 +1,10 @@
mexui.util.createControlConstructor('RadioButton', false, function(window, x, y, w, h, groupId, text, styles, callback) 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); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('RadioButton', styles), callback);
this.groupId = groupId; this.groupId = groupId;
this.text = text; this.text = text;
this.checked = this.isFirstRadioInGroup(); this.checked = this.isFirstRadioInGroup();
this.textMarginLeft = 5; this.textMarginLeft = 5;
}); });
@@ -42,14 +42,14 @@ mexui.Control.RadioButton.prototype.onKeyDown = function(e, key, mods)
mexui.Control.RadioButton.prototype.render = function() mexui.Control.RadioButton.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
if(this.checked) 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.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')); mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -68,11 +68,11 @@ mexui.Control.RadioButton.prototype.getGroupRadios = function()
for(var i in windows) for(var i in windows)
{ {
var window = mexui.windows[i]; var window = mexui.windows[i];
for(var i2 in window.controls) for(var i2 in window.controls)
{ {
var control = window.controls[i2]; var control = window.controls[i2];
if((control instanceof mexui.Control.RadioButton) && this.groupId == control.groupId) if((control instanceof mexui.Control.RadioButton) && this.groupId == control.groupId)
{ {
radios.push(control); radios.push(control);
@@ -103,7 +103,7 @@ mexui.Control.RadioButton.prototype.setChecked = function()
var checkedRadio = this.getCheckedRadio(); var checkedRadio = this.getCheckedRadio();
if(checkedRadio != this.checked) if(checkedRadio != this.checked)
checkedRadio.checked = false; checkedRadio.checked = false;
this.checked = !this.checked; this.checked = !this.checked;
this.checkToCallCallback(); this.checkToCallCallback();
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('RangedInteger', false, function(window, x, y, w, h, min, max, text, styles, callback) 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); 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.min = min === undefined ? 0 : min;
this.max = max === undefined ? 100 : max; this.max = max === undefined ? 100 : max;
}); });
@@ -18,7 +18,7 @@ mexui.Control.RangedInteger.prototype.validateValueCallback = function(e)
var text = this.getText(); var text = this.getText();
if(!mexui.util.isInt(text)) if(!mexui.util.isInt(text))
return false; return false;
var _int = parseInt(text); var _int = parseInt(text);
return _int >= this.min && _int <= this.max; return _int >= this.min && _int <= this.max;
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('RangedNumber', false, function(window, x, y, w, h, min, max, text, styles, callback) 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); 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.min = min === undefined ? 0.0 : min;
this.max = max === undefined ? 100.0 : max; this.max = max === undefined ? 100.0 : max;
}); });
@@ -18,7 +18,7 @@ mexui.Control.RangedNumber.prototype.validateValueCallback = function(e)
var text = this.getText(); var text = this.getText();
if(!mexui.util.isFloat(text)) if(!mexui.util.isFloat(text))
return false; return false;
var number = parseFloat(text); var number = parseFloat(text);
return number >= this.min && number <= this.max; return number >= this.min && number <= this.max;
}; };

View File

@@ -1,11 +1,11 @@
mexui.util.createControlConstructor('ScrollBar', false, function(window, x, y, w, h, isVertical, styles, callback) 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); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ScrollBar', styles), callback);
this.isVertical = isVertical; this.isVertical = isVertical;
this.axisIndex = isVertical ? 1 : 0; this.axisIndex = isVertical ? 1 : 0;
this.otherAxisIndex = isVertical ? 0 : 1; this.otherAxisIndex = isVertical ? 0 : 1;
this.barHigherLength = 50; this.barHigherLength = 50;
this.scrolledRatio = 0.0; this.scrolledRatio = 0.0;
this.isScrolling = false; this.isScrolling = false;
@@ -16,7 +16,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
main: main:
{ {
backgroundColour: toColour(0, 0, 0, 190), backgroundColour: toColour(0, 0, 0, 190),
hover: hover:
{ {
backgroundColour: toColour(0, 0, 0, 150) backgroundColour: toColour(0, 0, 0, 150)
@@ -25,7 +25,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
innerBar: innerBar:
{ {
backgroundColour: toColour(79, 161, 246, 190), backgroundColour: toColour(79, 161, 246, 190),
hover: hover:
{ {
backgroundColour: toColour(79, 161, 246, 150) backgroundColour: toColour(79, 161, 246, 150)
@@ -69,7 +69,7 @@ mexui.Control.ScrollBar.prototype.onMouseMove = function(e, offset)
this.clampScrolledRatio(); this.clampScrolledRatio();
e.used = true; e.used = true;
} }
if(!e.used) if(!e.used)
mexui.Component.Control.prototype.onMouseMove.call(this, e, offset); mexui.Component.Control.prototype.onMouseMove.call(this, e, offset);
}; };
@@ -100,7 +100,7 @@ mexui.Control.ScrollBar.prototype.getInnerBarPosition = function()
{ {
var screenPos = this.getScreenPosition(); var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y); var pos = new Vec2(screenPos.x, screenPos.y);
var minPos = pos[this.axisIndex] + 1; var minPos = pos[this.axisIndex] + 1;
var maxPos = pos[this.axisIndex] + this.size[this.axisIndex] - 2; var maxPos = pos[this.axisIndex] + this.size[this.axisIndex] - 2;
pos[this.axisIndex] = minPos + (this.scrolledRatio * (maxPos - minPos - this.barHigherLength)); pos[this.axisIndex] = minPos + (this.scrolledRatio * (maxPos - minPos - this.barHigherLength));

View File

@@ -13,9 +13,9 @@ mexui.Control.Second.prototype.validateInputCallback = function(e, character)
mexui.Control.Second.prototype.validateValueCallback = function(e) mexui.Control.Second.prototype.validateValueCallback = function(e)
{ {
var _int = parseInt(this.getText()); var _int = parseInt(this.getText());
if(_int < 1 || _int > 59) if(_int < 1 || _int > 59)
return false; return false;
return true; return true;
}; };

View File

@@ -4,14 +4,14 @@ mexui.util.createControlConstructor('Slider', false, function(window, x, y, w, h
text = text === undefined ? '' : text; text = text === undefined ? '' : text;
minText = minText === undefined ? '' : minText; minText = minText === undefined ? '' : minText;
maxText = maxText === undefined ? '' : maxText; maxText = maxText === undefined ? '' : maxText;
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Slider', styles), callback); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Slider', styles), callback);
this.isVertical = isVertical; this.isVertical = isVertical;
this.text = text; this.text = text;
this.minText = minText; this.minText = minText;
this.maxText = maxText; this.maxText = maxText;
this.progress = 0.0; this.progress = 0.0;
this.axisIndex = isVertical ? 1 : 0; this.axisIndex = isVertical ? 1 : 0;
this.innerBarSize = new Vec2(30, 25); this.innerBarSize = new Vec2(30, 25);
@@ -57,7 +57,7 @@ mexui.Control.Slider.prototype.onMouseMove = function(e, offset)
{ {
if(!this.sliding) if(!this.sliding)
return false; return false;
this.progress += this.getProgressIncreaseByPixels(offset); this.progress += this.getProgressIncreaseByPixels(offset);
this.clampProgress(); this.clampProgress();
e.used = true; e.used = true;
@@ -68,21 +68,21 @@ mexui.Control.Slider.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y); var pos2 = new Vec2(pos.x, pos.y);
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
mexui.native.drawRectangle(this.getInnerBarPosition(), this.innerBarSize, this.getStyles('innerBar')); mexui.native.drawRectangle(this.getInnerBarPosition(), this.innerBarSize, this.getStyles('innerBar'));
pos.y += this.size.y; pos.y += this.size.y;
mexui.native.drawText(pos, this.size, this.minText, this.getStyles('minText')); 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; var offset = (this.size.x - mexui.native.getTextWidth(this.text, this.getStyles('main'))) / 2;
pos.x += offset; pos.x += offset;
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main')); mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
pos.x -= offset; pos.x -= offset;
pos.x += this.size.x - mexui.native.getTextWidth(this.maxText, this.getStyles('maxText')); pos.x += this.size.x - mexui.native.getTextWidth(this.maxText, this.getStyles('maxText'));
mexui.native.drawText(pos, this.size, this.maxText, this.getStyles('maxText')); mexui.native.drawText(pos, this.size, this.maxText, this.getStyles('maxText'));
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -113,3 +113,4 @@ mexui.Control.Slider.prototype.clampProgress = function()
else if(this.progress > 1.0) else if(this.progress > 1.0)
this.progress = 1.0; this.progress = 1.0;
}; };

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('TabPanel', true, function(window, x, y, w,
{ {
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TabPanel', styles)); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TabPanel', styles));
mexui.Entity.ControlWithEntries.call(this, false, false); mexui.Entity.ControlWithEntries.call(this, false, false);
this.activeTabIndex = 0; this.activeTabIndex = 0;
}); });
@@ -13,7 +13,7 @@ mexui.util.linkBaseControlStyles('TabPanel', {
backgroundColour: toColour(240, 20, 20, 200), backgroundColour: toColour(240, 20, 20, 200),
borderColour: toColour(120, 20, 20, 225), borderColour: toColour(120, 20, 20, 225),
textColour: toColour(0, 0, 0, 255), textColour: toColour(0, 0, 0, 255),
hover: hover:
{ {
backgroundColour: toColour(240, 20, 20, 150), backgroundColour: toColour(240, 20, 20, 150),
@@ -29,24 +29,24 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
if(e.button == 0) if(e.button == 0)
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
var tabX = pos.x; var tabX = pos.x;
for(var i in this.axis.x.entries) for(var i in this.axis.x.entries)
{ {
var tab = this.axis.x.entries[i]; var tab = this.axis.x.entries[i];
var tabPos = new Vec2(tabX, pos.y); var tabPos = new Vec2(tabX, pos.y);
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25); var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
if(mexui.util.isCursorInRectangle(tabPos, tabSize)) if(mexui.util.isCursorInRectangle(tabPos, tabSize))
{ {
tab.setActive(); tab.setActive();
break; break;
} }
tabX += tabSize.x; tabX += tabSize.x;
} }
/* /*
var tab = this.axis.x.getEntryByCursor(); var tab = this.axis.x.getEntryByCursor();
if(tab) if(tab)
@@ -59,22 +59,22 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
mexui.Control.TabPanel.prototype.render = function() mexui.Control.TabPanel.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
var tabX = pos.x; var tabX = pos.x;
for(var i in this.axis.x.entries) for(var i in this.axis.x.entries)
{ {
var tab = this.axis.x.entries[i]; var tab = this.axis.x.entries[i];
var tabPos = new Vec2(tabX, pos.y); var tabPos = new Vec2(tabX, pos.y);
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25); var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
mexui.native.drawRectangle(tabPos, tabSize, this.getStyles('tab')); mexui.native.drawRectangle(tabPos, tabSize, this.getStyles('tab'));
mexui.native.drawText(tabPos, tabSize, tab.text, this.getStyles('tab')); mexui.native.drawText(tabPos, tabSize, tab.text, this.getStyles('tab'));
tabX += tabSize.x; tabX += tabSize.x;
} }
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Text', false, function(window, x, y, w, h, text, styles) 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)); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Text', styles));
this.text = text; this.text = text;
}); });
@@ -12,9 +12,9 @@ mexui.util.linkBaseControlStyles('Text', {});
mexui.Control.Text.prototype.render = function() mexui.Control.Text.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main')); mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('TextArea', false, function(window, x, y, w, h, text, styles, callback) 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); mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('TextArea', styles), callback, false, true);
this.multiLine = true; this.multiLine = true;
}); });
mexui.util.extend(mexui.Control.TextArea, mexui.Control.TextInput); mexui.util.extend(mexui.Control.TextArea, mexui.Control.TextInput);

View File

@@ -3,11 +3,11 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
text = text || ''; text = text || '';
if(singleCharacter) if(singleCharacter)
multiLineSupported = false; multiLineSupported = false;
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TextInput', styles), callback); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TextInput', styles), callback);
this.lines = text ? mexui.util.splitLines(text) : ['']; this.lines = text ? mexui.util.splitLines(text) : [''];
this.caretPosition = new Vec2(0, 0); this.caretPosition = new Vec2(0, 0);
this.multiLineSupported = multiLineSupported === undefined ? true : multiLineSupported; this.multiLineSupported = multiLineSupported === undefined ? true : multiLineSupported;
this.multiLine = this.multiLineSupported ? mexui.util.doesContainEOLChar(text) : false; this.multiLine = this.multiLineSupported ? mexui.util.doesContainEOLChar(text) : false;
@@ -17,7 +17,7 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
this.caretShownForBlink = true; this.caretShownForBlink = true;
this.lineHeight = 25; this.lineHeight = 25;
this.maxLength = this.singleCharacter ? 1 : false; this.maxLength = this.singleCharacter ? 1 : false;
this.validValue = true; this.validValue = true;
}); });
@@ -44,7 +44,7 @@ mexui.Control.TextInput.prototype.onMouseDown = function(e)
this.caretPosition = this.getCaretPositionByCursor(); this.caretPosition = this.getCaretPositionByCursor();
} }
} }
mexui.Component.Control.prototype.onMouseDown.call(this, e); mexui.Component.Control.prototype.onMouseDown.call(this, e);
}; };
@@ -57,11 +57,11 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
if(!isValid1 && isValid1 !== undefined) if(!isValid1 && isValid1 !== undefined)
return; return;
*/ */
var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true; var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true;
if(!isValid2) if(!isValid2)
return; return;
if(this.singleCharacter) if(this.singleCharacter)
{ {
this.resetText(); this.resetText();
@@ -73,7 +73,7 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character); this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character);
this.caretPosition.x++; this.caretPosition.x++;
} }
this.checkToCallCallback(); this.checkToCallCallback();
this.validateValue(e); this.validateValue(e);
} }
@@ -83,9 +83,9 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
{ {
if(mexui.focusedControl != this) if(mexui.focusedControl != this)
return; return;
var controlIsDown = (mods & KMOD_CTRL) == KMOD_CTRL; var controlIsDown = (mods & KMOD_CTRL) == KMOD_CTRL;
switch(key) switch(key)
{ {
case SDLK_LEFT: case SDLK_LEFT:
@@ -156,7 +156,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
} }
break; break;
} }
if(this.multiLine) if(this.multiLine)
{ {
switch(key) switch(key)
@@ -199,7 +199,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
break; break;
} }
} }
this.validateValue(e); this.validateValue(e);
}; };
@@ -208,9 +208,9 @@ mexui.Control.TextInput.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y); var pos2 = new Vec2(pos.x, pos.y);
mexui.native.drawRectangle(pos, this.size, this.getStyles('main')); mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
if(this.isEmpty()) if(this.isEmpty())
{ {
mexui.native.drawText(pos, this.size, this.placeholder, this.getStyles('placeholder')); mexui.native.drawText(pos, this.size, this.placeholder, this.getStyles('placeholder'));
@@ -222,18 +222,18 @@ mexui.Control.TextInput.prototype.render = function()
{ {
var displayedText = this.masked ? '*'.repeat(this.lines[i].length) : this.lines[i]; var displayedText = this.masked ? '*'.repeat(this.lines[i].length) : this.lines[i];
mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main')); mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main'));
pos.y += this.lineHeight; pos.y += this.lineHeight;
} }
} }
var valueIsInvalid = !this.isEmpty() && !this.validValue; var valueIsInvalid = !this.isEmpty() && !this.validValue;
if(this.isFocused()) if(this.isFocused())
{ {
if(!valueIsInvalid) if(!valueIsInvalid)
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
if(this.caretShownForBlink) if(this.caretShownForBlink)
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
@@ -246,7 +246,7 @@ mexui.Control.TextInput.prototype.render = function()
mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret')); mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret'));
} }
} }
if(valueIsInvalid) if(valueIsInvalid)
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('invalidValue')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos2,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('invalidValue'));
}; };
@@ -269,7 +269,7 @@ mexui.Control.TextInput.prototype.clampCaretPosition = function()
this.caretPosition.y = 0; this.caretPosition.y = 0;
else if(this.caretPosition.y > (this.lines.length - 1)) else if(this.caretPosition.y > (this.lines.length - 1))
this.caretPosition.y = this.lines.length - 1; this.caretPosition.y = this.lines.length - 1;
if(this.caretPosition.x < 0) if(this.caretPosition.x < 0)
this.caretPosition.x = 0; this.caretPosition.x = 0;
else if(this.caretPosition.x > this.lines[this.caretPosition.y].length) else if(this.caretPosition.x > this.lines[this.caretPosition.y].length)
@@ -287,7 +287,7 @@ mexui.Control.TextInput.prototype.getCaretLineIndexByCursor = function()
{ {
var yPos = gui.cursorPosition.y - this.getScreenPosition().y; var yPos = gui.cursorPosition.y - this.getScreenPosition().y;
var lineIndex = Math.floor(yPos / this.lineHeight); var lineIndex = Math.floor(yPos / this.lineHeight);
if(lineIndex < 0) if(lineIndex < 0)
return 0; return 0;
else if(lineIndex > (this.lines.length - 1)) else if(lineIndex > (this.lines.length - 1))
@@ -301,12 +301,12 @@ mexui.Control.TextInput.prototype.getCharIndexByCursor = function(lineIndex)
var xPos = gui.cursorPosition.x - this.getScreenPosition().x; var xPos = gui.cursorPosition.x - this.getScreenPosition().x;
var line = this.lines[lineIndex]; var line = this.lines[lineIndex];
var lineStyles = this.getStyles('caret'); var lineStyles = this.getStyles('caret');
for(var i=0,j=line.length; i<j; i++) for(var i=0,j=line.length; i<j; i++)
{ {
var text = line.substr(0, i + 1); var text = line.substr(0, i + 1);
var textWidth = mexui.native.getTextWidth(text, lineStyles); var textWidth = mexui.native.getTextWidth(text, lineStyles);
if(xPos < textWidth) if(xPos < textWidth)
return i; return i;
} }

View File

@@ -1,11 +1,11 @@
mexui.util.createControlConstructor('Time', false, function(window, x, y, w, h, text, styles, callback) 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); mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Time', styles), callback, false, false);
this.hour = 0; this.hour = 0;
this.minute = 0; this.minute = 0;
this.second = 0; this.second = 0;
this.inputShown = false; this.inputShown = false;
this.valueBoxSize = new Vec2(50, 30); this.valueBoxSize = new Vec2(50, 30);
this.arrowBoxSize = new Vec2(25, 22); this.arrowBoxSize = new Vec2(25, 22);
@@ -35,29 +35,29 @@ mexui.Control.Time.prototype.onMouseDown = function(e)
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1; var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
var propName = mexui.Control.Time.units[propIndex]; var propName = mexui.Control.Time.units[propIndex];
var isIncrease = (arrowIndex % 2) == 1; var isIncrease = (arrowIndex % 2) == 1;
if(isIncrease) if(isIncrease)
this[propName]++; this[propName]++;
else else
this[propName]--; this[propName]--;
this[propName] %= propIndex == 0 ? 24 : 60; this[propName] %= propIndex == 0 ? 24 : 60;
if(this[propName] == -1) if(this[propName] == -1)
this[propName] = propIndex == 0 ? 23 : 59; this[propName] = propIndex == 0 ? 23 : 59;
this.generateText(); this.generateText();
return; return;
} }
} }
if(this.isCursorOverControl()) if(this.isCursorOverControl())
{ {
this.inputShown = !this.inputShown; this.inputShown = !this.inputShown;
e.used = true; e.used = true;
return; return;
} }
if(this.inputShown) if(this.inputShown)
{ {
this.inputShown = false; this.inputShown = false;
@@ -71,18 +71,18 @@ mexui.Control.Time.prototype.renderAfter = function()
{ {
if(!this.inputShown) if(!this.inputShown)
return; return;
var screenPos = this.getScreenPosition(); var screenPos = this.getScreenPosition();
var pos = new Vec2(screenPos.x, screenPos.y); var pos = new Vec2(screenPos.x, screenPos.y);
for(var i=0; i<3; i++) for(var i=0; i<3; i++)
{ {
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main')); mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Time.units[i]], this.getStyles('main')); mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Time.units[i]], this.getStyles('main'));
pos.x += this.valueBoxSize.x; pos.x += this.valueBoxSize.x;
} }
pos = new Vec2(screenPos.x, screenPos.y); pos = new Vec2(screenPos.x, screenPos.y);
pos.y += this.valueBoxSize.y; pos.y += this.valueBoxSize.y;
for(var i=0; i<3; i++) for(var i=0; i<3; i++)
@@ -90,10 +90,10 @@ mexui.Control.Time.prototype.renderAfter = function()
for(var i2=0; i2<2; i2++) for(var i2=0; i2<2; i2++)
{ {
var text = (i2 % 2) == 0 ? '<' : '>'; var text = (i2 % 2) == 0 ? '<' : '>';
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main')); mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main')); mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
pos.x += this.arrowBoxSize.x; pos.x += this.arrowBoxSize.x;
} }
} }
@@ -115,42 +115,42 @@ mexui.Control.Time.prototype.validateInputCallback = function(e, character)
mexui.Control.Time.prototype.validateValueCallback = function(e) mexui.Control.Time.prototype.validateValueCallback = function(e)
{ {
var parts = this.getText().split(':'); var parts = this.getText().split(':');
if(parts.length != 3) if(parts.length != 3)
return false; return false;
for(var i in parts) for(var i in parts)
{ {
var partAsStr = parts[i]; var partAsStr = parts[i];
if(partAsStr === '') if(partAsStr === '')
return false; return false;
var part = parseInt(partAsStr); var part = parseInt(partAsStr);
if(partAsStr.length == 2 && partAsStr.substr(0, 1) == '0') if(partAsStr.length == 2 && partAsStr.substr(0, 1) == '0')
partAsStr = partAsStr.substr(1); partAsStr = partAsStr.substr(1);
if(!mexui.util.isPositiveInt(partAsStr)) if(!mexui.util.isPositiveInt(partAsStr))
return false; return false;
if(part < 0) if(part < 0)
return false; return false;
if(part > (i == 0 ? 23 : 59)) if(part > (i == 0 ? 23 : 59))
return false; return false;
} }
return true; return true;
}; };
mexui.Control.Time.prototype.getArrowIndexByCursor = function() mexui.Control.Time.prototype.getArrowIndexByCursor = function()
{ {
var cursorPos = gui.cursorPosition; var cursorPos = gui.cursorPosition;
var screenPos = this.getScreenPosition(); var screenPos = this.getScreenPosition();
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y); 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); 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) 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); return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);

View File

@@ -2,7 +2,7 @@ mexui.util.createControlConstructor('Tree', true, function(window, x, y, w, h, s
{ {
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Tree', styles)); mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Tree', styles));
mexui.Entity.ControlWithEntries.call(this, false, false); mexui.Entity.ControlWithEntries.call(this, false, false);
this.rowHeight = 25; this.rowHeight = 25;
this.rowLevelIndentation = 10; this.rowLevelIndentation = 10;
this.scrollMultiplier = 10.0; this.scrollMultiplier = 10.0;
@@ -32,10 +32,10 @@ mexui.Control.Tree.prototype.onMouseDown = function(e)
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
pos.y -= this.axis.y.getScrolledOffset(); pos.y -= this.axis.y.getScrolledOffset();
this.testRowClick(e, this.axis.y.entries, pos); this.testRowClick(e, this.axis.y.entries, pos);
} }
if(!e.used) if(!e.used)
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e); mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
}; };
@@ -45,9 +45,9 @@ mexui.Control.Tree.prototype.render = function()
{ {
var pos = this.getScreenPosition(); var pos = this.getScreenPosition();
pos.y -= this.axis.y.getScrolledOffset(); pos.y -= this.axis.y.getScrolledOffset();
this.renderRows(this.axis.y.entries, 0, pos); this.renderRows(this.axis.y.entries, 0, pos);
if(this.isFocused()) if(this.isFocused())
mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused')); mexui.native.drawRectangleBorder(mexui.util.subtractVec2(pos,new Vec2(2,2)), mexui.util.addVec2(this.size,new Vec2(3,3)), this.getStyles('focused'));
}; };
@@ -58,23 +58,23 @@ mexui.Control.Tree.prototype.renderRows = function(rows, level, pos)
{ {
var row = rows[i]; var row = rows[i];
var shouldDraw = pos.y >= this.getScreenPosition().y && pos.y <= (this.getScreenPosition().y + this.size.y); var shouldDraw = pos.y >= this.getScreenPosition().y && pos.y <= (this.getScreenPosition().y + this.size.y);
if(shouldDraw) if(shouldDraw)
{ {
if(row.rows.length > 0) 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.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.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')); mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), row.text, this.getStyles('row'));
} }
pos.y += this.rowHeight; pos.y += this.rowHeight;
if(shouldDraw) if(shouldDraw)
{ {
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine')); mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
} }
if(row.rows.length > 0 && row.open) if(row.rows.length > 0 && row.open)
{ {
pos.x += this.rowLevelIndentation; pos.x += this.rowLevelIndentation;
@@ -106,7 +106,7 @@ mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
for(var i in rows) for(var i in rows)
{ {
var row = rows[i]; var row = rows[i];
var rowPos = new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y); var rowPos = new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y);
var rowSize = new Vec2(this.size.x + (this.rowLevelIndentation * 2), this.rowHeight); var rowSize = new Vec2(this.size.x + (this.rowLevelIndentation * 2), this.rowHeight);
if(mexui.util.isCursorInRectangle(rowPos, rowSize)) if(mexui.util.isCursorInRectangle(rowPos, rowSize))
@@ -115,9 +115,9 @@ mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
e.used = true; e.used = true;
return; return;
} }
pos.y += this.rowHeight; pos.y += this.rowHeight;
if(row.rows.length > 0 && row.open) if(row.rows.length > 0 && row.open)
{ {
this.testRowClick(e, row.rows, pos); this.testRowClick(e, row.rows, pos);
@@ -132,10 +132,10 @@ mexui.Control.Tree.prototype.onClickRow = function(row)
if(row.rows.length > 0) if(row.rows.length > 0)
{ {
//var scrollableLengthBefore = this.axis.y.getScrollableLength(); //var scrollableLengthBefore = this.axis.y.getScrollableLength();
row.open = !row.open; row.open = !row.open;
this.checkToShowScrollBars(); this.checkToShowScrollBars();
/* /*
if(this.scrollBars[1].shown) if(this.scrollBars[1].shown)
{ {
@@ -153,3 +153,4 @@ mexui.Control.Tree.prototype.row = function(text)
this.axis.y.addEntry(entry); this.axis.y.addEntry(entry);
return entry; return entry;
}; };

View File

@@ -13,9 +13,9 @@ mexui.Control.Week.prototype.validateInputCallback = function(e, character)
mexui.Control.Week.prototype.validateValueCallback = function(e) mexui.Control.Week.prototype.validateValueCallback = function(e)
{ {
var _int = parseInt(this.getText()); var _int = parseInt(this.getText());
if(_int < 1 || _int > 52) if(_int < 1 || _int > 52)
return false; return false;
return true; return true;
}; };

View File

@@ -1,7 +1,7 @@
mexui.util.createControlConstructor('Year', false, function(window, x, y, w, h, text, styles, callback) 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.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Year', styles), callback, false, false);
this.maxYearOffset = 10; this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; }; this.minYearCallback = ()=>{ return 1900; };
this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; } this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; }

View File

@@ -1,7 +1,7 @@
mexui.Entity.Component = function(moveable) mexui.Entity.Component = function(moveable)
{ {
this.moveable = moveable; this.moveable = moveable;
this.moving = false; this.moving = false;
}; };
mexui.util.extend(mexui.Entity.Component, mexui.Entity.StyleableEntity); mexui.util.extend(mexui.Entity.Component, mexui.Entity.StyleableEntity);

View File

@@ -3,7 +3,7 @@ mexui.Entity.ControlAxis = function(control, isVertical, manualScrollBar, entrie
this.control = control; this.control = control;
this.isVertical = isVertical; this.isVertical = isVertical;
this.manualScrollBar = manualScrollBar; this.manualScrollBar = manualScrollBar;
this.axisIndex = isVertical ? 1 : 0; this.axisIndex = isVertical ? 1 : 0;
this.entriesShown = true; this.entriesShown = true;
this.entryCountShown = 15; this.entryCountShown = 15;
@@ -27,7 +27,7 @@ mexui.Entity.ControlAxis.prototype.initScrollBar = function()
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entriesPositionOffset.x, this.control.size.y)); 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); this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, this.getDisplayedEntriesLength(), 25, false, this.control.styles.scrollBar);
} }
if(this.manualScrollBar) if(this.manualScrollBar)
this.scrollBar.shown = false; this.scrollBar.shown = false;
}; };
@@ -73,19 +73,19 @@ mexui.Entity.ControlAxis.prototype.getEntryIndexByPoint = function(point)
{ {
return null; return null;
} }
var pos = new Vec2(screenPos.x + this.control.entriesPositionOffset.x, screenPos.y + this.control.entriesPositionOffset.y); 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]); var index = Math.floor((point.y - pos.y) / this.control.entrySize[this.axisIndex]);
index += this.getEntryStartIndex(); index += this.getEntryStartIndex();
if(index < 0 || index >= this.entries.length) if(index < 0 || index >= this.entries.length)
return null; return null;
return index; return index;
} }
else else
{ {
} }
}; };
@@ -121,7 +121,7 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntriesLength = function()
mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual) mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual)
{ {
this.manualScrollBar = manual; this.manualScrollBar = manual;
if(manual) if(manual)
{ {
this.setScrollBarShown(false); this.setScrollBarShown(false);
@@ -150,7 +150,7 @@ mexui.Entity.ControlAxis.prototype.checkToShowScrollBar = function()
{ {
if(this.manualScrollBar) if(this.manualScrollBar)
return; return;
this.setScrollBarShown(this.shouldDisplayScrollBar(), true); this.setScrollBarShown(this.shouldDisplayScrollBar(), true);
}; };
@@ -160,7 +160,7 @@ mexui.Entity.ControlAxis.prototype.getScrolledOffset = function()
{ {
if(!this.scrollBar.shown) if(!this.scrollBar.shown)
return 0; return 0;
return this.scrollBar.scrolledRatio * this.getScrollableLength(); return this.scrollBar.scrolledRatio * this.getScrollableLength();
} }
else else
@@ -197,3 +197,4 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntryCount = function()
var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]); var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]);
return this.entries.length < displayedEntryCount ? this.entries.length : displayedEntryCount; return this.entries.length < displayedEntryCount ? this.entries.length : displayedEntryCount;
}; };

View File

@@ -4,14 +4,14 @@ mexui.Entity.ControlWithEntries = function(entriesOutsideControl, manualScrollBa
this.entriesPositionOffset = entriesPositionOffset || new Vec2(0, 0); this.entriesPositionOffset = entriesPositionOffset || new Vec2(0, 0);
this.entrySize = entrySize || new Vec2(this.size.x, 25); this.entrySize = entrySize || new Vec2(this.size.x, 25);
this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0); this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0);
this.axis = {}; this.axis = {};
this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset); this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset);
this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset); this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset);
this.axis.x.initScrollBar(); this.axis.x.initScrollBar();
this.axis.y.initScrollBar(); this.axis.y.initScrollBar();
this.checkToShowScrollBars(); this.checkToShowScrollBars();
}; };
mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control); mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control);
@@ -46,7 +46,7 @@ mexui.Entity.ControlWithEntries.prototype.onMouseMove = function(e, offset)
} }
} }
} }
if(!e.used) if(!e.used)
this.triggerEvent('onMouseMove', e, offset); this.triggerEvent('onMouseMove', e, offset);
}; };
@@ -74,7 +74,7 @@ mexui.Entity.ControlWithEntries.prototype.triggerEvent = function(eventName, e,
return; return;
} }
} }
mexui.Component.Control.prototype[eventName].call(this, e, data); mexui.Component.Control.prototype[eventName].call(this, e, data);
}; };
@@ -95,3 +95,4 @@ mexui.Entity.ControlWithEntries.prototype.removeAllEntries = function()
this.axis.x.removeAllEntries(); this.axis.x.removeAllEntries();
this.axis.y.removeAllEntries(); this.axis.y.removeAllEntries();
}; };

View File

@@ -1,12 +1,12 @@
mexui.Entity.StyleableEntity = function(styles) mexui.Entity.StyleableEntity = function(styles)
{ {
this.styles = styles; this.styles = styles;
this.shown = true; this.shown = true;
//this.hovered = false; //this.hovered = false;
this.transitions = {}; // string controlPartName => Transition transition this.transitions = {}; // string controlPartName => Transition transition
/* /*
this.transitionDelayTimer = null; this.transitionDelayTimer = null;
this.transitionStartTime = 0; this.transitionStartTime = 0;
@@ -26,9 +26,9 @@ mexui.Entity.StyleableEntity.globalDefaultStyles = {
textAlign: 0.0, textAlign: 0.0,
textIndent: 5, textIndent: 5,
textColour: toColour(0, 0, 0, 255), textColour: toColour(0, 0, 0, 255),
backgroundColour: toColour(255, 255, 255, 255), backgroundColour: toColour(255, 255, 255, 255),
lineWeight: 1 lineWeight: 1
} }
}; };
@@ -39,14 +39,14 @@ mexui.Entity.StyleableEntity.defaultStyles = mexui.util.linkGlobalStyles(mexui.E
backgroundColour: toColour(255, 255, 255, 255), backgroundColour: toColour(255, 255, 255, 255),
borderColour: 'none', borderColour: 'none',
textColour: toColour(0, 0, 0, 255), textColour: toColour(0, 0, 0, 255),
hover: hover:
{ {
backgroundColour: toColour(220, 220, 220, 255), backgroundColour: toColour(220, 220, 220, 255),
borderColour: 'none', borderColour: 'none',
textColour: toColour(0, 0, 0, 255) textColour: toColour(0, 0, 0, 255)
}/*, }/*,
focus: focus:
{ {
borderColour: toColour(255, 128, 0, 230), borderColour: toColour(255, 128, 0, 230),
@@ -96,30 +96,30 @@ mexui.Entity.StyleableEntity.prototype.getStyles = function(controlPartName)
var isFocused = this.isFocused(); var isFocused = this.isFocused();
var isHovered = this.isHovered(); var isHovered = this.isHovered();
var styles = this.styles[controlPartName]; var styles = this.styles[controlPartName];
var transition = this.getTransition(controlPartName); var transition = this.getTransition(controlPartName);
if(transition.isProcessing()) if(transition.isProcessing())
{ {
return mexui.util.getTransitionStyles(styles, ['hover'], transition.getMainToPseudoProgress()); return mexui.util.getTransitionStyles(styles, ['hover'], transition.getMainToPseudoProgress());
} }
if(isHovered) if(isHovered)
{ {
return mexui.util.mergeStyles(styles, ['hover']); return mexui.util.mergeStyles(styles, ['hover']);
} }
return styles; return styles;
}; };
mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data) mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
{ {
var styles = {}; var styles = {};
for(var i in data) for(var i in data)
{ {
var baseStyles = data[i][0].getStyles(data[i][1]); var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles) for(var k in baseStyles)
{ {
if(baseStyles.hasOwnProperty(k) && styles[k] === undefined) if(baseStyles.hasOwnProperty(k) && styles[k] === undefined)
@@ -128,11 +128,11 @@ mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
} }
} }
} }
for(var i in data) for(var i in data)
{ {
var baseStyles = data[i][0].getStyles(data[i][1]); var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles) for(var k in baseStyles)
{ {
if(styles[k] === undefined) if(styles[k] === undefined)
@@ -141,7 +141,7 @@ mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
} }
} }
} }
return styles; return styles;
}; };
@@ -152,10 +152,10 @@ mexui.Entity.StyleableEntity.prototype.onMouseEnter = function()
for(var i in controlParts) for(var i in controlParts)
{ {
var transition = this.getTransition(controlParts[i]); var transition = this.getTransition(controlParts[i]);
var delay = this.getTransitionDelayStyle(controlParts[i]); var delay = this.getTransitionDelayStyle(controlParts[i]);
var time = this.getTransitionTimeStyle(controlParts[i]); var time = this.getTransitionTimeStyle(controlParts[i]);
transition.onMouseEnter(delay, time); transition.onMouseEnter(delay, time);
} }
}; };
@@ -166,7 +166,7 @@ mexui.Entity.StyleableEntity.prototype.onMouseExit = function()
for(var i in controlParts) for(var i in controlParts)
{ {
var transition = this.getTransition(controlParts[i]); var transition = this.getTransition(controlParts[i]);
transition.onMouseExit(); transition.onMouseExit();
} }
}; };
@@ -207,3 +207,4 @@ mexui.Entity.StyleableEntity.prototype.getTransitionTimeStyle = function(control
else else
return mexui.Entity.Transition.defaultTransitionTime; return mexui.Entity.Transition.defaultTransitionTime;
}; };

View File

@@ -21,10 +21,10 @@ mexui.Entity.Transition.prototype.onMouseEnter = function(transitionDelay, trans
if(this.isMouseEntered()) if(this.isMouseEntered())
return; return;
this.setMouseEntered(true); this.setMouseEntered(true);
this.transitionDelay = transitionDelay; this.transitionDelay = transitionDelay;
this.transitionTime = transitionTime; this.transitionTime = transitionTime;
if(transitionDelay > 0) if(transitionDelay > 0)
{ {
this.startDelay(); this.startDelay();
@@ -44,7 +44,7 @@ mexui.Entity.Transition.prototype.onMouseExit = function()
if(!this.isMouseEntered()) if(!this.isMouseEntered())
return; return;
this.setMouseEntered(false); this.setMouseEntered(false);
if(this.isDelayActive()) if(this.isDelayActive())
{ {
this.clearDelayTimer(); this.clearDelayTimer();
@@ -82,7 +82,7 @@ mexui.Entity.Transition.prototype.stopProcessing = function()
{ {
this.stopInterpolation(); this.stopInterpolation();
} }
this.delayTimer = null; this.delayTimer = null;
this.processing = false; this.processing = false;
}; };
@@ -129,12 +129,12 @@ mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
var timeDiff = mexui.util.time() - this.lastUpdateTime; var timeDiff = mexui.util.time() - this.lastUpdateTime;
this.lastUpdateTime = mexui.util.time(); this.lastUpdateTime = mexui.util.time();
var progressDiff = timeDiff / this.transitionTime; var progressDiff = timeDiff / this.transitionTime;
if(this.direction) if(this.direction)
this.mainToPseudoProgress += progressDiff; this.mainToPseudoProgress += progressDiff;
else else
this.mainToPseudoProgress -= progressDiff; this.mainToPseudoProgress -= progressDiff;
if(this.mainToPseudoProgress < 0.0) if(this.mainToPseudoProgress < 0.0)
{ {
this.mainToPseudoProgress = 0.0; this.mainToPseudoProgress = 0.0;
@@ -149,7 +149,7 @@ mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
mexui.Entity.Transition.prototype.getMainToPseudoProgress = function() mexui.Entity.Transition.prototype.getMainToPseudoProgress = function()
{ {
this.increaseMainToPseudoProgress(); this.increaseMainToPseudoProgress();
return this.mainToPseudoProgress; return this.mainToPseudoProgress;
}; };
@@ -181,3 +181,4 @@ mexui.Entity.Transition.prototype.clearDelayTimer = function()
clearTimeout(this.delayTimer); clearTimeout(this.delayTimer);
this.delayTimer = null; this.delayTimer = null;
}; };

View File

@@ -1,7 +1,7 @@
mexui.Entry.DropDownItem = function(dropDown, text) mexui.Entry.DropDownItem = function(dropDown, text)
{ {
mexui.Component.Entry.call(this, dropDown, 1); mexui.Component.Entry.call(this, dropDown, 1);
this.text = text; this.text = text;
}; };
mexui.util.extend(mexui.Entry.DropDownItem, mexui.Component.Entry); mexui.util.extend(mexui.Entry.DropDownItem, mexui.Component.Entry);

View File

@@ -1,7 +1,7 @@
mexui.Entry.GridColumn = function(grid, text, width, height) mexui.Entry.GridColumn = function(grid, text, width, height)
{ {
mexui.Component.Entry.call(this, grid, 0); mexui.Component.Entry.call(this, grid, 0);
this.text = text || 'Column'; this.text = text || 'Column';
this.width = width || 100; this.width = width || 100;
this.height = height || 25; this.height = height || 25;

View File

@@ -2,7 +2,7 @@ mexui.Entry.GridRow = function(grid, cells, styles)
{ {
mexui.Component.Entry.call(this, grid, 1); mexui.Component.Entry.call(this, grid, 1);
mexui.Entity.StyleableEntity.call(this, this.linkEntryStyles('GridRow', styles)); mexui.Entity.StyleableEntity.call(this, this.linkEntryStyles('GridRow', styles));
this.cells = cells; this.cells = cells;
this.rowHeight = 25; this.rowHeight = 25;
}; };
@@ -10,3 +10,4 @@ mexui.util.extend(mexui.Entry.GridRow, mexui.Component.Entry);
// default styles // default styles
mexui.Entry.GridRow.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {}); mexui.Entry.GridRow.defaultStyles = mexui.util.linkStyles(mexui.Entity.StyleableEntity.defaultStyles, {});

View File

@@ -1,7 +1,7 @@
mexui.Entry.ListRow = function(list, text) mexui.Entry.ListRow = function(list, text)
{ {
mexui.Component.Entry.call(this, list, 1); mexui.Component.Entry.call(this, list, 1);
this.text = text; this.text = text;
}; };
mexui.util.extend(mexui.Entry.ListRow, mexui.Component.Entry); mexui.util.extend(mexui.Entry.ListRow, mexui.Component.Entry);

View File

@@ -1,7 +1,7 @@
mexui.Entry.Tab = function(tabPanel, text) mexui.Entry.Tab = function(tabPanel, text)
{ {
mexui.Component.Entry.call(this, tabPanel, 0); mexui.Component.Entry.call(this, tabPanel, 0);
this.text = text; this.text = text;
this.controls = []; this.controls = [];
}; };
@@ -18,9 +18,9 @@ mexui.Entry.Tab.prototype.setActive = function()
{ {
for(var i in this.control.entries[this.control.activeTabIndex].controls) for(var i in this.control.entries[this.control.activeTabIndex].controls)
this.control.entries[this.control.activeTabIndex].controls[i].shown = false; this.control.entries[this.control.activeTabIndex].controls[i].shown = false;
this.control.activeTabIndex = this.getEntryIndex(); this.control.activeTabIndex = this.getEntryIndex();
for(var i in this.control.entries[this.control.activeTabIndex].controls) for(var i in this.control.entries[this.control.activeTabIndex].controls)
this.control.entries[this.control.activeTabIndex].controls[i].shown = true; this.control.entries[this.control.activeTabIndex].controls[i].shown = true;
}; };

View File

@@ -1,7 +1,7 @@
mexui.Entry.TreeRow = function(tree, text) mexui.Entry.TreeRow = function(tree, text)
{ {
mexui.Component.Entry.call(this, tree, 1); mexui.Component.Entry.call(this, tree, 1);
this.open = true; this.open = true;
this.text = text; this.text = text;
this.rows = []; this.rows = [];

View File

@@ -6,35 +6,35 @@ mexui.native.loadImage = function(imageFilePath, imageName)
var file = openFile(imageFilePath); var file = openFile(imageFilePath);
if(!file) if(!file)
{ {
logToConsole(LOG_DEBUG|LOG_ERROR, 'ERROR [IMAGE LOAD] - Opening File: '+imageFilePath); console.log('ERROR [IMAGE LOAD] - Opening File: '+imageFilePath);
return false; return false;
} }
var image = null; var image = null;
var parts = imageFilePath.split('.'); var parts = imageFilePath.split('.');
var ext = parts[parts.length - 1].toLowerCase(); var ext = parts[parts.length - 1].toLowerCase();
if(ext == 'png') if(ext == 'png')
image = drawing.loadPNG(file); image = graphics.loadPNG(file);
else if(ext == 'bmp') else if(ext == 'bmp')
image = drawing.loadBMP(file); image = graphics.loadBMP(file);
else else
{ {
logToConsole(LOG_DEBUG|LOG_ERROR, 'ERROR [IMAGE LOAD] - Unsupported image file path extension. Currently only supports PNG or BMP.'); console.log('ERROR [IMAGE LOAD] - Unsupported image file path extension. Currently only supports PNG or BMP.');
return false; return false;
} }
if(!image) if(!image)
{ {
file.close(); file.close();
logToConsole(LOG_DEBUG|LOG_ERROR, 'ERROR [IMAGE LOAD] - Reading File: '+imageFilePath); console.log('ERROR [IMAGE LOAD] - Reading File: '+imageFilePath);
return false; return false;
} }
file.close(); file.close();
if(imageName) if(imageName)
mexui.images[imageName] = image; mexui.images[imageName] = image;
return image; return image;
}; };
@@ -42,17 +42,17 @@ mexui.native.loadImage = function(imageFilePath, imageName)
mexui.native.getFont = function(textSize, textFont) mexui.native.getFont = function(textSize, textFont)
{ {
var textSizeStr = textSize + ''; var textSizeStr = textSize + '';
if(!mexui.fonts[textSizeStr]) if(!mexui.fonts[textSizeStr])
{ {
mexui.fonts[textSizeStr] = {}; mexui.fonts[textSizeStr] = {};
} }
if(!mexui.fonts[textSizeStr][textFont]) if(!mexui.fonts[textSizeStr][textFont])
{ {
mexui.fonts[textSizeStr][textFont] = lucasFont.createDefaultFont(textSize, textFont); mexui.fonts[textSizeStr][textFont] = lucasFont.createDefaultFont(textSize, textFont);
} }
return mexui.fonts[textSizeStr][textFont]; return mexui.fonts[textSizeStr][textFont];
}; };
@@ -61,12 +61,12 @@ mexui.native.getTextSize = function(text, styles, font)
{ {
if(!font) if(!font)
font = mexui.native.getFont(styles.textSize, styles.textFont); font = mexui.native.getFont(styles.textSize, styles.textFont);
var size = font.measure(text + '', 10000, styles.textAlign, 0.0, styles.textSize, false, false); var size = font.measure(text + '', 10000, styles.textAlign, 0.0, styles.textSize, false, false);
//if(text[text.length - 1] == ' ') //if(text[text.length - 1] == ' ')
// width += mexui.util.getStringCount(text, ' ') * spaceWidth; // width += mexui.util.getStringCount(text, ' ') * spaceWidth;
return size; return size;
}; };
@@ -92,8 +92,8 @@ mexui.native.drawRectangleBackground = function(position, size, styles)
var backgroundColour = styles.backgroundColour != null ? styles.backgroundColour : styles.backgroundColor; var backgroundColour = styles.backgroundColour != null ? styles.backgroundColour : styles.backgroundColor;
if(backgroundColour == null || backgroundColour == 'none') if(backgroundColour == null || backgroundColour == 'none')
return; return;
drawing.drawRectangle(null, position, size, backgroundColour, backgroundColour, backgroundColour, backgroundColour); graphics.drawRectangle(null, position, size, backgroundColour, backgroundColour, backgroundColour, backgroundColour);
}; };
mexui.native.drawRectangleBorder = function(position, size, styles) mexui.native.drawRectangleBorder = function(position, size, styles)
@@ -101,29 +101,29 @@ mexui.native.drawRectangleBorder = function(position, size, styles)
var borderColour = styles.borderColour || styles.borderColor; var borderColour = styles.borderColour || styles.borderColor;
if(borderColour == null || borderColour == 'none') if(borderColour == null || borderColour == 'none')
return; return;
var rightXPosition = position.x + size.x; var rightXPosition = position.x + size.x;
var bottomYPosition = position.y + size.y; var bottomYPosition = position.y + size.y;
var topLeftPosition = new Vec2(position.x, position.y); var topLeftPosition = new Vec2(position.x, position.y);
var topRightPosition = new Vec2(rightXPosition, position.y); var topRightPosition = new Vec2(rightXPosition, position.y);
var bottomLeftPosition = new Vec2(position.x, bottomYPosition); var bottomLeftPosition = new Vec2(position.x, bottomYPosition);
var bottomRightPosition = new Vec2(rightXPosition, bottomYPosition); var bottomRightPosition = new Vec2(rightXPosition, bottomYPosition);
var original = styles.lineColour; var original = styles.lineColour;
styles.lineColour = styles.topBorderColour != null ? styles.topBorderColour : (styles.topBorderColor != null ? styles.topBorderColor : borderColour); styles.lineColour = styles.topBorderColour != null ? styles.topBorderColour : (styles.topBorderColor != null ? styles.topBorderColor : borderColour);
mexui.native.drawAALine(topLeftPosition, topRightPosition, styles); mexui.native.drawAALine(topLeftPosition, topRightPosition, styles);
styles.lineColour = styles.leftBorderColour != null ? styles.leftBorderColour : (styles.leftBorderColor != null ? styles.leftBorderColor : borderColour); styles.lineColour = styles.leftBorderColour != null ? styles.leftBorderColour : (styles.leftBorderColor != null ? styles.leftBorderColor : borderColour);
mexui.native.drawAALine(topLeftPosition, bottomLeftPosition, styles); mexui.native.drawAALine(topLeftPosition, bottomLeftPosition, styles);
styles.lineColour = styles.bottomBorderColour != null ? styles.bottomBorderColour : (styles.bottomBorderColor != null ? styles.bottomBorderColor : borderColour); styles.lineColour = styles.bottomBorderColour != null ? styles.bottomBorderColour : (styles.bottomBorderColor != null ? styles.bottomBorderColor : borderColour);
mexui.native.drawAALine(bottomLeftPosition, bottomRightPosition, styles); mexui.native.drawAALine(bottomLeftPosition, bottomRightPosition, styles);
styles.lineColour = styles.rightBorderColour != null ? styles.rightBorderColour : (styles.rightBorderColor != null ? styles.rightBorderColor : borderColour); styles.lineColour = styles.rightBorderColour != null ? styles.rightBorderColour : (styles.rightBorderColor != null ? styles.rightBorderColor : borderColour);
mexui.native.drawAALine(topRightPosition, bottomRightPosition, styles); mexui.native.drawAALine(topRightPosition, bottomRightPosition, styles);
styles.lineColour = original; styles.lineColour = original;
}; };
@@ -132,22 +132,23 @@ mexui.native.drawAALine = function(point1, point2, styles)
var lineColour = styles.lineColour != null ? styles.lineColour : styles.lineColor; var lineColour = styles.lineColour != null ? styles.lineColour : styles.lineColor;
if(lineColour == null || lineColour == 'none') if(lineColour == null || lineColour == 'none')
return; return;
drawing.drawRectangle(null, point1, new Vec2((point2.x - point1.x) + styles.lineWeight, (point2.y - point1.y) + styles.lineWeight), lineColour, lineColour, lineColour, lineColour); graphics.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) mexui.native.drawText = function(position, size, text, styles)
{ {
var font = mexui.native.getFont(styles.textSize, styles.textFont); var font = mexui.native.getFont(styles.textSize, styles.textFont);
var textHeight = mexui.native.getTextHeight(text, styles, font); var textHeight = mexui.native.getTextHeight(text, styles, font);
var textIndent = styles.textAlign == 0.0 || styles.textAlign == 1.0 ? styles.textIndent : 0; 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)); 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); 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) mexui.native.drawImage = function(position, size, image, styles)
{ {
drawing.drawRectangle(image, position, size); graphics.drawRectangle(image, position, size);
}; };

View File

@@ -15,7 +15,7 @@ mexui.util.isPointInRectangle = function(point, position, size)
{ {
if(!point) if(!point)
return false; // temp bug fix 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); return point.x >= position.x && point.y >= position.y && point.x <= (position.x + size.x) && point.y <= (position.y + size.y);
}; };
@@ -53,7 +53,7 @@ mexui.util.linkBaseControlStyles = function(controlName, derivedStyles)
mexui.util.linkStyles = function(baseStyles, derivedStyles) mexui.util.linkStyles = function(baseStyles, derivedStyles)
{ {
derivedStyles = derivedStyles || {}; derivedStyles = derivedStyles || {};
for(var k in baseStyles) for(var k in baseStyles)
{ {
switch(k) switch(k)
@@ -62,12 +62,12 @@ mexui.util.linkStyles = function(baseStyles, derivedStyles)
case 'hover': case 'hover':
continue; continue;
} }
if(!derivedStyles[k]) if(!derivedStyles[k])
derivedStyles[k] = {}; derivedStyles[k] = {};
if(!(derivedStyles[k].__proto__ instanceof Object)) if(!(derivedStyles[k].__proto__ instanceof Object))
derivedStyles[k].__proto__ = baseStyles[k]; derivedStyles[k].__proto__ = baseStyles[k];
/* /*
var hoverBaseStyles = JSON.parse(JSON.stringify(baseStyles[k])); var hoverBaseStyles = JSON.parse(JSON.stringify(baseStyles[k]));
if(!derivedStyles[k].hover) if(!derivedStyles[k].hover)
@@ -76,7 +76,7 @@ mexui.util.linkStyles = function(baseStyles, derivedStyles)
derivedStyles[k].hover.__proto__ = hoverBaseStyles; derivedStyles[k].hover.__proto__ = hoverBaseStyles;
*/ */
} }
return mexui.util.linkGlobalStyles(mexui.Entity.StyleableEntity.globalDefaultStyles, derivedStyles); return mexui.util.linkGlobalStyles(mexui.Entity.StyleableEntity.globalDefaultStyles, derivedStyles);
//return derivedStyles; //return derivedStyles;
}; };
@@ -84,7 +84,7 @@ mexui.util.linkStyles = function(baseStyles, derivedStyles)
mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles) mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
{ {
derivedStyles = derivedStyles || {}; derivedStyles = derivedStyles || {};
for(var k in derivedStyles) for(var k in derivedStyles)
{ {
switch(k) switch(k)
@@ -93,13 +93,13 @@ mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
case 'hover': case 'hover':
continue; continue;
} }
if(!(derivedStyles[k].__proto__ instanceof Object)) if(!(derivedStyles[k].__proto__ instanceof Object))
{ {
derivedStyles[k].__proto__ = baseStyles.all; derivedStyles[k].__proto__ = baseStyles.all;
} }
} }
for(var k in derivedStyles) for(var k in derivedStyles)
{ {
switch(k) switch(k)
@@ -108,7 +108,7 @@ mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
case 'hover': case 'hover':
continue; continue;
} }
/* /*
if(!derivedStyles[k].hasOwnProperty('hover')) if(!derivedStyles[k].hasOwnProperty('hover'))
{ {
@@ -116,14 +116,14 @@ mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
derivedStyles[k].hover.__proto__ = derivedStyles[k]; derivedStyles[k].hover.__proto__ = derivedStyles[k];
} }
*/ */
if(derivedStyles[k].focus) if(derivedStyles[k].focus)
{ {
if(!(derivedStyles[k].focus.__proto__ instanceof Object)) if(!(derivedStyles[k].focus.__proto__ instanceof Object))
{ {
derivedStyles[k].focus.__proto__ = baseStyles.all; derivedStyles[k].focus.__proto__ = baseStyles.all;
} }
if(derivedStyles[k].focus.hover) if(derivedStyles[k].focus.hover)
{ {
if(!(derivedStyles[k].focus.hover.__proto__ instanceof Object)) if(!(derivedStyles[k].focus.hover.__proto__ instanceof Object))
@@ -132,7 +132,7 @@ mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
} }
} }
} }
if(derivedStyles[k].hover) if(derivedStyles[k].hover)
{ {
if(!(derivedStyles[k].hover.__proto__ instanceof Object)) if(!(derivedStyles[k].hover.__proto__ instanceof Object))
@@ -141,7 +141,7 @@ mexui.util.linkGlobalStyles = function(baseStyles, derivedStyles)
} }
} }
} }
return derivedStyles; return derivedStyles;
}; };
@@ -236,15 +236,15 @@ mexui.util.getCenterPosition = function(largerSize, smallerSize)
mexui.util.getWindowSize = function() mexui.util.getWindowSize = function()
{ {
return new Vec2(game.width, game.height); return new Vec2(gta.width, gta.height);
}; };
mexui.util.isRectangleInsideRectangle = function(pos1, size1, pos2, size2) mexui.util.isRectangleInsideRectangle = function(pos1, size1, pos2, size2)
{ {
return !(pos2.x > (pos1.x + size1.x) || return !(pos2.x > (pos1.x + size1.x) ||
(pos2.x + size2.x) < pos1.x || (pos2.x + size2.x) < pos1.x ||
pos2.y > (pos1.y + size1.y) || pos2.y > (pos1.y + size1.y) ||
(pos2.y + size2.y) < pos1.y); (pos2.y + size2.y) < pos1.y);
}; };
mexui.util.mergeStyles = function(styles, pseudoPartNames) mexui.util.mergeStyles = function(styles, pseudoPartNames)
@@ -257,38 +257,38 @@ mexui.util.mergeStyles = function(styles, pseudoPartNames)
for(var i in pseudoPartNames) for(var i in pseudoPartNames)
{ {
var pseudoPartName = pseudoPartNames[i]; var pseudoPartName = pseudoPartNames[i];
if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName)) if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName))
styles2.push(styles2[0][pseudoPartName]); styles2.push(styles2[0][pseudoPartName]);
} }
for(var i=styles2.length-1; i>=0; i--) for(var i=styles2.length-1; i>=0; i--)
{ {
if(styles2[i] == null) if(styles2[i] == null)
continue; continue;
for(var k in styles2[i]) for(var k in styles2[i])
{ {
switch(k) switch(k)
{ {
case 'focus': case 'focus':
case 'hover': case 'hover':
case 'transitionTime': case 'transitionTime':
case 'transitionDelay': case 'transitionDelay':
case 'transitionDelayStartTime': case 'transitionDelayStartTime':
case 'transitionStartTime': case 'transitionStartTime':
case 'transitionStarted': case 'transitionStarted':
case 'transitionEnded': case 'transitionEnded':
case 'transitionReverting': case 'transitionReverting':
continue; continue;
} }
if(styles2[i].hasOwnProperty(k) && styles3[k] == null) if(styles2[i].hasOwnProperty(k) && styles3[k] == null)
{ {
var styleValue = styles2[i][k]; var styleValue = styles2[i][k];
/* /*
if(i > 0 && (styles2[i].transitionTime != null || styles2[i].transitionDelay != null)) if(i > 0 && (styles2[i].transitionTime != null || styles2[i].transitionDelay != null))
{ {
@@ -301,7 +301,7 @@ mexui.util.mergeStyles = function(styles, pseudoPartNames)
{ {
styles2[i].transitionEnded = true; styles2[i].transitionEnded = true;
styleValue = styles2[0][k]; styleValue = styles2[0][k];
delete styles2[i].transitionDelayStartTime; delete styles2[i].transitionDelayStartTime;
delete styles2[i].transitionStartTime; delete styles2[i].transitionStartTime;
delete styles2[i].transitionStarted; delete styles2[i].transitionStarted;
@@ -348,19 +348,19 @@ mexui.util.mergeStyles = function(styles, pseudoPartNames)
} }
} }
*/ */
styles3[k] = styleValue; styles3[k] = styleValue;
} }
} }
} }
for(var i in styles2) for(var i in styles2)
{ {
if(styles2[i]) if(styles2[i])
styles2[i] = styles2[i].__proto__; styles2[i] = styles2[i].__proto__;
} }
} }
return styles3; return styles3;
}; };
@@ -374,54 +374,54 @@ mexui.util.getTransitionStyles = function(styles, pseudoPartNames, progress)
for(var i in pseudoPartNames) for(var i in pseudoPartNames)
{ {
var pseudoPartName = pseudoPartNames[i]; var pseudoPartName = pseudoPartNames[i];
if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName)) if(styles2[0] && styles2[0].hasOwnProperty(pseudoPartName))
styles2.push(styles2[0][pseudoPartName]); styles2.push(styles2[0][pseudoPartName]);
} }
for(var i=styles2.length-1; i>=0; i--) for(var i=styles2.length-1; i>=0; i--)
{ {
if(styles2[i] == null) if(styles2[i] == null)
continue; continue;
for(var k in styles2[i]) for(var k in styles2[i])
{ {
switch(k) switch(k)
{ {
case 'focus': case 'focus':
case 'hover': case 'hover':
case 'transitionTime': case 'transitionTime':
case 'transitionDelay': case 'transitionDelay':
continue; continue;
} }
if(styles2[i].hasOwnProperty(k) && styles3[k] == null) if(styles2[i].hasOwnProperty(k) && styles3[k] == null)
{ {
var styleValue = styles2[i][k]; var styleValue = styles2[i][k];
if(i > 0) if(i > 0)
{ {
var mainStyleValue = styles2[0][k]; var mainStyleValue = styles2[0][k];
var pseudoStyleValue = styles2[i][k]; var pseudoStyleValue = styles2[i][k];
//console.log(mainStyleValue+' '+pseudoStyleValue); //console.log(mainStyleValue+' '+pseudoStyleValue);
styleValue = mexui.util.interpolateStyle(k, progress, mainStyleValue, pseudoStyleValue); styleValue = mexui.util.interpolateStyle(k, progress, mainStyleValue, pseudoStyleValue);
} }
styles3[k] = styleValue; styles3[k] = styleValue;
} }
} }
} }
for(var i in styles2) for(var i in styles2)
{ {
if(styles2[i]) if(styles2[i])
styles2[i] = styles2[i].__proto__; styles2[i] = styles2[i].__proto__;
} }
} }
return styles3; return styles3;
}; };
@@ -476,7 +476,7 @@ mexui.util.fromColour = function(colour)
mexui.util.time = function() mexui.util.time = function()
{ {
return sdl.tickCount; return gta.tickCount;
}; };
mexui.util.isIntChar = function(character) mexui.util.isIntChar = function(character)
@@ -570,14 +570,14 @@ mexui.util.isDayId = function(text)
{ {
if(text.length == 2 && text.substr(0, 1) == '0') if(text.length == 2 && text.substr(0, 1) == '0')
text = text.substr(1); text = text.substr(1);
if(mexui.util.isPositiveInt(text)) if(mexui.util.isPositiveInt(text))
{ {
var _int = parseInt(text); var _int = parseInt(text);
if(_int >= 1 && _int <= 31) if(_int >= 1 && _int <= 31)
return true; return true;
} }
return false; return false;
}; };
@@ -585,7 +585,7 @@ mexui.util.isDayIdWithOptionalSuffix = function(text)
{ {
if(mexui.util.isDayId(text)) if(mexui.util.isDayId(text))
return true; return true;
if(text.length > 2) if(text.length > 2)
{ {
var last2Chars = text.substr(text.length - 2, 2); var last2Chars = text.substr(text.length - 2, 2);
@@ -598,14 +598,14 @@ mexui.util.isDayIdWithOptionalSuffix = function(text)
} }
} }
} }
return false; return false;
}; };
mexui.util.inArrayOrStartsWithInArray = function(text, arr, startsWithCharCount) mexui.util.inArrayOrStartsWithInArray = function(text, arr, startsWithCharCount)
{ {
text = text.toLowerCase(); text = text.toLowerCase();
for(var i in arr) for(var i in arr)
{ {
if(text === arr[i]) if(text === arr[i])
@@ -613,7 +613,7 @@ mexui.util.inArrayOrStartsWithInArray = function(text, arr, startsWithCharCount)
return true; return true;
} }
} }
if(text.length == startsWithCharCount) if(text.length == startsWithCharCount)
{ {
for(var i in arr) for(var i in arr)
@@ -624,7 +624,7 @@ mexui.util.inArrayOrStartsWithInArray = function(text, arr, startsWithCharCount)
} }
} }
} }
return false; return false;
}; };
@@ -633,14 +633,14 @@ mexui.util.isMonthIdOrName = function(text)
var text2 = text; var text2 = text;
if(text2.length == 2 && text2.substr(0, 1) == '0') if(text2.length == 2 && text2.substr(0, 1) == '0')
text2 = text2.substr(1); text2 = text2.substr(1);
if(mexui.util.isPositiveInt(text2)) if(mexui.util.isPositiveInt(text2))
{ {
var _int = parseInt(text2); var _int = parseInt(text2);
if(_int >= 1 && _int <= 12) if(_int >= 1 && _int <= 12)
return true; return true;
} }
return mexui.util.isMonthName(text); return mexui.util.isMonthName(text);
}; };
@@ -649,14 +649,14 @@ mexui.util.isWeekDayId = function(text)
var text2 = text; var text2 = text;
if(text2.length == 2 && text2.substr(0, 1) == '0') if(text2.length == 2 && text2.substr(0, 1) == '0')
text2 = text2.substr(1); text2 = text2.substr(1);
if(mexui.util.isPositiveInt(text2)) if(mexui.util.isPositiveInt(text2))
{ {
var _int = parseInt(text2); var _int = parseInt(text2);
if(_int >= 1 && _int <= 7) if(_int >= 1 && _int <= 7)
return true; return true;
} }
return false; return false;
}; };
@@ -665,14 +665,14 @@ mexui.util.isWeekDayIdOrName = function(text)
var text2 = text; var text2 = text;
if(text2.length == 2 && text2.substr(0, 1) == '0') if(text2.length == 2 && text2.substr(0, 1) == '0')
text2 = text2.substr(1); text2 = text2.substr(1);
if(mexui.util.isPositiveInt(text2)) if(mexui.util.isPositiveInt(text2))
{ {
var _int = parseInt(text2); var _int = parseInt(text2);
if(_int >= 1 && _int <= 7) if(_int >= 1 && _int <= 7)
return true; return true;
} }
return mexui.util.isWeekDayName(text); return mexui.util.isWeekDayName(text);
}; };
@@ -690,15 +690,15 @@ mexui.util.expand2DigitYear = function(year, twoDigitYearCapOffset)
mexui.util.isYear = function(text, minYear, maxYear, twoDigitYearCapOffset) mexui.util.isYear = function(text, minYear, maxYear, twoDigitYearCapOffset)
{ {
var _int = parseInt(text); var _int = parseInt(text);
if(isNaN(_int)) if(isNaN(_int))
return false; return false;
if(_int >= 0 && _int <= 99) if(_int >= 0 && _int <= 99)
_int = mexui.util.expand2DigitYear(_int, twoDigitYearCapOffset); _int = mexui.util.expand2DigitYear(_int, twoDigitYearCapOffset);
if(_int < minYear || _int > maxYear) if(_int < minYear || _int > maxYear)
return false; return false;
return true; return true;
}; };

View File

@@ -17,7 +17,7 @@ mexui.hoveredComponent = null;
// initialization // initialization
mexui.init = function() mexui.init = function()
{ {
mexui.native.loadImage('third-party/mexui/Images/down-arrow.png', 'downArrow'); mexui.native.loadImage('mexui/Images/down-arrow.png', 'downArrow');
mexui.bindEvents(); mexui.bindEvents();
mexui.startTimers(); mexui.startTimers();
}; };
@@ -43,7 +43,7 @@ mexui.bindEvents = function()
{ {
if(isAbsolute) if(isAbsolute)
return; return;
mexui.triggerEvent('onMouseMove', new Vec2(position.x, position.y), true); mexui.triggerEvent('onMouseMove', new Vec2(position.x, position.y), true);
}); });
@@ -55,7 +55,7 @@ mexui.bindEvents = function()
addEventHandler('onKeyDown', function(event, key, pkey, mods) addEventHandler('onKeyDown', function(event, key, pkey, mods)
{ {
mexui.triggerEvent('onKeyDown', key, mods); mexui.triggerEvent('onKeyDown', key, mods);
if(key == SDLK_TAB) if(key == SDLK_TAB)
{ {
mexui.cycleFocusedControl(); mexui.cycleFocusedControl();
@@ -65,7 +65,7 @@ mexui.bindEvents = function()
addEventHandler('onCharacter', function(event, character) addEventHandler('onCharacter', function(event, character)
{ {
mexui.triggerEvent('onCharacter', character); mexui.triggerEvent('onCharacter', character);
if(character == 't' || character == 'T') if(character == 't' || character == 'T')
{ {
var textInput = mexui.getFocusedTextInput(); var textInput = mexui.getFocusedTextInput();
@@ -75,11 +75,14 @@ mexui.bindEvents = function()
} }
} }
}); });
addEventHandler('onDrawnHUD', function(event)
{ {
mexui.render(); var eventName = gta.game == GAME_GTA_SA ? 'onDrawnHUD' : 'onBeforeDrawHUD';
}); addEventHandler(eventName, function(event)
{
mexui.render();
});
}
}; };
mexui.unbindEvents = function() mexui.unbindEvents = function()
@@ -90,7 +93,7 @@ mexui.unbindEvents = function()
removeEventHandler('onMouseWheel'); removeEventHandler('onMouseWheel');
removeEventHandler('onKeyDown'); removeEventHandler('onKeyDown');
removeEventHandler('onCharacter'); removeEventHandler('onCharacter');
removeEventHandler('onDrawnHUD'); removeEventHandler('onBeforeDrawHUD');
}; };
// timers // timers
@@ -118,10 +121,10 @@ mexui.render = function()
mexui.triggerEvent = function(eventName, data, callBaseMethodFirst) mexui.triggerEvent = function(eventName, data, callBaseMethodFirst)
{ {
var e = new mexui.Component.Event(); var e = new mexui.Component.Event();
if(data.button !== undefined) if(data.button !== undefined)
e.button = data.button; e.button = data.button;
var windows = mexui.windows.slice(0, mexui.windows.length).reverse(); var windows = mexui.windows.slice(0, mexui.windows.length).reverse();
for(var i in windows) for(var i in windows)
{ {
@@ -135,7 +138,7 @@ mexui.triggerEvent = function(eventName, data, callBaseMethodFirst)
if(e.used) if(e.used)
break; break;
} }
windows[i][eventName].call(windows[i], e, data); windows[i][eventName].call(windows[i], e, data);
if(e.used) if(e.used)
break; break;
@@ -145,7 +148,7 @@ mexui.triggerEvent = function(eventName, data, callBaseMethodFirst)
windows[i][eventName].call(windows[i], e, data); windows[i][eventName].call(windows[i], e, data);
if(e.used) if(e.used)
break; break;
if(mexui.Entity.Component.prototype[eventName]) if(mexui.Entity.Component.prototype[eventName])
{ {
mexui.Entity.Component.prototype[eventName].call(windows[i], e, data); mexui.Entity.Component.prototype[eventName].call(windows[i], e, data);
@@ -182,15 +185,15 @@ mexui.getShownWindows = function()
mexui.getNextShownWindows = function(afterWindow) mexui.getNextShownWindows = function(afterWindow)
{ {
var shownWindows = mexui.getShownWindows(); var shownWindows = mexui.getShownWindows();
var windowIndex = shownWindows.indexOf(afterWindow); var windowIndex = shownWindows.indexOf(afterWindow);
var windows2 = shownWindows.splice(0, windowIndex + 1); var windows2 = shownWindows.splice(0, windowIndex + 1);
var args = windows2; var args = windows2;
args.unshift(0); args.unshift(0);
args.unshift(shownWindows.length); args.unshift(shownWindows.length);
shownWindows.splice.apply(shownWindows, args); shownWindows.splice.apply(shownWindows, args);
return shownWindows; return shownWindows;
}; };
@@ -199,18 +202,18 @@ mexui.cycleFocusedControl = function()
// no windows are created // no windows are created
if(mexui.windows.length == 0) if(mexui.windows.length == 0)
return; return;
// no control is focused // no control is focused
if(!mexui.focusedControl) if(!mexui.focusedControl)
{ {
var topWindow = mexui.getTopWindow(); var topWindow = mexui.getTopWindow();
if(!topWindow) if(!topWindow)
return; return;
mexui.focusedControl = topWindow.getFirstShownControl(); mexui.focusedControl = topWindow.getFirstShownControl();
return; return;
} }
// a control is focused // a control is focused
var focusedControlWindow = mexui.focusedControl.window; var focusedControlWindow = mexui.focusedControl.window;
var nextControl = focusedControlWindow.getNextShownControl(mexui.focusedControl); var nextControl = focusedControlWindow.getNextShownControl(mexui.focusedControl);
@@ -219,7 +222,7 @@ mexui.cycleFocusedControl = function()
mexui.focusedControl = nextControl; mexui.focusedControl = nextControl;
return; return;
} }
// set focus to first control on next window that has a control shown // set focus to first control on next window that has a control shown
var shownWindows = mexui.getNextShownWindows(focusedControlWindow); var shownWindows = mexui.getNextShownWindows(focusedControlWindow);
for(var i in shownWindows) for(var i in shownWindows)
@@ -238,10 +241,10 @@ mexui.getFocusedTextInput = function()
{ {
if(!mexui.focusedControl) if(!mexui.focusedControl)
return null; return null;
if(!(mexui.focusedControl instanceof mexui.Control.TextInput)) if(!(mexui.focusedControl instanceof mexui.Control.TextInput))
return null; return null;
return mexui.focusedControl; return mexui.focusedControl;
}; };
@@ -250,7 +253,7 @@ mexui.toggleTextInputCaretShownForBlink = function()
var textInput = mexui.getFocusedTextInput(); var textInput = mexui.getFocusedTextInput();
if(!textInput) if(!textInput)
return; return;
textInput.caretShownForBlink = !textInput.caretShownForBlink; textInput.caretShownForBlink = !textInput.caretShownForBlink;
}; };
@@ -287,13 +290,12 @@ mexui.isAnyWindowShown = function()
mexui.setInput = function(showInput) mexui.setInput = function(showInput)
{ {
gui.showCursor(showInput, !showInput); gui.showCursor(showInput, !showInput);
//if(game.game != VRR_GAME_GTA_IV) { if(localClient.player && gta.game != GAME_GTA_IV)
// if(localPlayer) {
// { if(showInput)
// if(showInput) gta.setCameraLookAtEntity(new Vec3(gta.cameraMatrix.m41, gta.cameraMatrix.m42, gta.cameraMatrix.m43), localPlayer, false);
// game.setCameraLookAt(new Vec3(game.cameraMatrix.m41, game.cameraMatrix.m42, game.cameraMatrix.m43), localPlayer.position, false); else
// else gta.restoreCamera(false);
// game.restoreCamera(false); }
// }
//}
}; };