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