Initial commit
This commit is contained in:
28
third-party/mexui/Core/Control/Button.js
vendored
Normal file
28
third-party/mexui/Core/Control/Button.js
vendored
Normal file
@@ -0,0 +1,28 @@
|
||||
mexui.util.createControlConstructor('Button', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Button', styles), callback);
|
||||
|
||||
this.text = text;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Button', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Button.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Button.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Character.js
vendored
Normal file
11
third-party/mexui/Core/Control/Character.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Character', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Character', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Character, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Character.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isCharacterInOctetRange(character, 32, 126);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Characters.js
vendored
Normal file
11
third-party/mexui/Core/Control/Characters.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Characters', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Characters', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Characters, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Characters.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isCharacterInOctetRange(character, 32, 126);
|
||||
};
|
||||
48
third-party/mexui/Core/Control/CheckBox.js
vendored
Normal file
48
third-party/mexui/Core/Control/CheckBox.js
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
mexui.util.createControlConstructor('CheckBox', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('CheckBox', styles), callback);
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.checked = false;
|
||||
this.textMarginLeft = 5;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('CheckBox', {
|
||||
innerBox:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.CheckBox.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.CheckBox.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.checked)
|
||||
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(1, 1)), new Vec2(this.size.x - 2, this.size.y - 2), this.getStyles('innerBox'));
|
||||
|
||||
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.CheckBox.prototype.getSizeForInput = function()
|
||||
{
|
||||
var textWidth = mexui.native.getTextWidth(this.text, this.getStyles('main'));
|
||||
return new Vec2(this.size.x + this.textMarginLeft + textWidth, this.size.y);
|
||||
};
|
||||
162
third-party/mexui/Core/Control/Date.js
vendored
Normal file
162
third-party/mexui/Core/Control/Date.js
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
mexui.util.createControlConstructor('Date', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Date', styles), callback, false, false);
|
||||
|
||||
this.day = 1;
|
||||
this.month = 1;
|
||||
this.year = 2019;
|
||||
|
||||
this.inputShown = false;
|
||||
this.valueBoxSize = new Vec2(50, 30);
|
||||
this.arrowBoxSize = new Vec2(25, 22);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Date, mexui.Control.TextInput);
|
||||
|
||||
// static
|
||||
mexui.Control.Date.units = ['day', 'month', 'year'];
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Date', {
|
||||
arrow:
|
||||
{
|
||||
backgroundColour: toColour(90, 90, 80, 230),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Date.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.inputShown)
|
||||
{
|
||||
var arrowIndex = this.getArrowIndexByCursor();
|
||||
if(arrowIndex !== false)
|
||||
{
|
||||
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
|
||||
var propName = mexui.Control.Date.units[propIndex];
|
||||
var isIncrease = (arrowIndex % 2) == 1;
|
||||
|
||||
if(isIncrease)
|
||||
this[propName]++;
|
||||
else
|
||||
this[propName]--;
|
||||
|
||||
if(this.day == 0)
|
||||
this.day = 31;
|
||||
else if(this.day == 32)
|
||||
this.day = 1;
|
||||
|
||||
if(this.month == 0)
|
||||
this.month = 12;
|
||||
else if(this.month == 13)
|
||||
this.month = 1;
|
||||
|
||||
if(this.year == 1899)
|
||||
this.year = 1900;
|
||||
else if(this.year == 2020)
|
||||
this.year = 2019;
|
||||
|
||||
this.generateText();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.inputShown = !this.inputShown;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.inputShown)
|
||||
{
|
||||
this.inputShown = false;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Date.prototype.renderAfter = function()
|
||||
{
|
||||
if(!this.inputShown)
|
||||
return;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Date.units[i]], this.getStyles('main'));
|
||||
|
||||
pos.x += this.valueBoxSize.x;
|
||||
}
|
||||
|
||||
pos = new Vec2(screenPos.x, screenPos.y);
|
||||
pos.y += this.valueBoxSize.y;
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
for(var i2=0; i2<2; i2++)
|
||||
{
|
||||
var text = (i2 % 2) == 0 ? '<' : '>';
|
||||
|
||||
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
|
||||
|
||||
pos.x += this.arrowBoxSize.x;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Date.prototype.generateText = function()
|
||||
{
|
||||
this.text = (this.day < 10 ? '0'+this.day : this.day)
|
||||
+'/'+(this.month < 10 ? '0'+this.month : this.month)
|
||||
+'/'+(this.year < 10 ? '0'+this.year : this.year);
|
||||
};
|
||||
|
||||
mexui.Control.Date.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var text = this.getTextWithNewCharacter(character);
|
||||
var parts = text.split(':');
|
||||
|
||||
for(var i in parts)
|
||||
{
|
||||
if(i == 3)
|
||||
return false;
|
||||
|
||||
var part = parseInt(parts[i]);
|
||||
|
||||
if(isNaN(part))
|
||||
return false;
|
||||
|
||||
if(part < 0)
|
||||
return false;
|
||||
|
||||
if(part > (i == 0 ? 23 : 59))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mexui.Control.Date.prototype.getArrowIndexByCursor = function()
|
||||
{
|
||||
var cursorPos = gui.cursorPosition;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
|
||||
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
|
||||
|
||||
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
|
||||
{
|
||||
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Day.js
vendored
Normal file
19
third-party/mexui/Core/Control/Day.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Day', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Day', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Day, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Day.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 31)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Digit.js
vendored
Normal file
11
third-party/mexui/Core/Control/Digit.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Digit', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Digit', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Digit, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Digit.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isDigit(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Digits.js
vendored
Normal file
11
third-party/mexui/Core/Control/Digits.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Digits', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Digits', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Digits, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Digits.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isDigit(character);
|
||||
};
|
||||
117
third-party/mexui/Core/Control/DropDown.js
vendored
Normal file
117
third-party/mexui/Core/Control/DropDown.js
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
mexui.util.createControlConstructor('DropDown', true, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('DropDown', styles), callback);
|
||||
mexui.Entity.ControlWithEntries.call(this, true, true, new Vec2(0, h), new Vec2(w + 120, 25));
|
||||
|
||||
this.axis.y.entriesShown = false;
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.arrowShown = true;
|
||||
this.selectedEntryIndex = -1;
|
||||
this.hoveredEntryIndex = -1;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('DropDown', {
|
||||
item:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(80, 80, 80, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.DropDown.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.axis.y.entries.length == 0)
|
||||
return;
|
||||
|
||||
var hitButton = this.isCursorOverControl();
|
||||
if(hitButton)
|
||||
{
|
||||
e.used = true;
|
||||
this.setListShown(!this.axis.y.entriesShown);
|
||||
}
|
||||
else if(this.axis.y.entriesShown)
|
||||
{
|
||||
var selectedEntryIndex = this.axis.y.getEntryIndexByCursor();
|
||||
if(selectedEntryIndex != null)
|
||||
{
|
||||
e.used = true;
|
||||
this.selectedEntryIndex = selectedEntryIndex;
|
||||
this.checkToCallCallback();
|
||||
this.setListShown(false);
|
||||
}
|
||||
}
|
||||
|
||||
if(!e.used)
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.DropDown.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var text = this.selectedEntryIndex == -1 ? this.text : this.axis.y.entries[this.selectedEntryIndex].text;
|
||||
mexui.native.drawText(pos, this.size, text, this.getStyles('main'));
|
||||
|
||||
if(this.arrowShown)
|
||||
{
|
||||
var pos2 = new Vec2(pos.x + this.size.x - (25 + 3), pos.y + 0);
|
||||
mexui.native.drawImage(pos2, new Vec2(25, 25), mexui.images.downArrow, this.getStyles('main'));
|
||||
}
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.render.call(this);
|
||||
};
|
||||
|
||||
mexui.Control.DropDown.prototype.renderAfter = function()
|
||||
{
|
||||
if(this.axis.y.entriesShown)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
pos.x += this.entriesPositionOffset.x;
|
||||
pos.y += this.entriesPositionOffset.y;
|
||||
|
||||
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
|
||||
{
|
||||
var item = this.axis.y.entries[i];
|
||||
if(!item)
|
||||
break;
|
||||
|
||||
//this.hovered = i == this.axis.y.hoveredEntryIndex;
|
||||
|
||||
mexui.native.drawRectangle(pos, this.entrySize, this.getStyles('item'));
|
||||
mexui.native.drawText(pos, this.entrySize, item.text, this.getStyles('item'));
|
||||
|
||||
pos.y += this.entrySize.y;
|
||||
}
|
||||
}
|
||||
|
||||
mexui.Entity.ControlWithEntries.prototype.renderAfter.call(this);
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.DropDown.prototype.item = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.DropDownItem(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.DropDown.prototype.setListShown = function(shown)
|
||||
{
|
||||
this.axis.y.entriesShown = shown;
|
||||
this.axis.y.setScrollBarShown(shown);
|
||||
};
|
||||
|
||||
127
third-party/mexui/Core/Control/Grid.js
vendored
Normal file
127
third-party/mexui/Core/Control/Grid.js
vendored
Normal file
@@ -0,0 +1,127 @@
|
||||
mexui.util.createControlConstructor('Grid', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Grid', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false, new Vec2(0, 25), new Vec2(this.size.x, 25), new Vec2(0, -25));
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Grid', {
|
||||
column:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
header:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
cell:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
row:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// render
|
||||
mexui.Control.Grid.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var startX = pos.x;
|
||||
var maxColumnHeight = 0;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var column = this.axis.x.entries[i];
|
||||
|
||||
mexui.native.drawText(new Vec2(startX, pos.y), new Vec2(column.width, column.height), column.text, this.getStyles('header'));
|
||||
|
||||
startX += column.width;
|
||||
mexui.native.drawAALine(new Vec2(startX, pos.y), new Vec2(startX, pos.y + this.size.y), this.getStyles('column'));
|
||||
|
||||
if(column.height > maxColumnHeight)
|
||||
{
|
||||
maxColumnHeight = column.height;
|
||||
}
|
||||
}
|
||||
|
||||
var startY = pos.y + maxColumnHeight;
|
||||
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
|
||||
|
||||
for(var i=this.axis.y.getEntryStartIndex(),j=this.axis.y.getEntryEndIndex(); i<j; i++)
|
||||
{
|
||||
var row = this.axis.y.entries[i];
|
||||
if(!row)
|
||||
break;
|
||||
|
||||
startX = pos.x;
|
||||
for(var i2 in row.cells)
|
||||
{
|
||||
var column = this.axis.x.entries[i2];
|
||||
var cell = row.cells[i2];
|
||||
var cellText = cell.text;
|
||||
|
||||
var styles = this.getEntryStyles([[cell,'main'], [row,'main'], [this,'row'], [this,'cell']]);
|
||||
|
||||
mexui.native.drawRectangle(new Vec2(startX, startY), new Vec2(column.width, column.height), styles);
|
||||
mexui.native.drawText(new Vec2(startX, startY), new Vec2(column.width, column.height), cellText, styles);
|
||||
|
||||
startX += column.width;
|
||||
}
|
||||
|
||||
startY += row.rowHeight;
|
||||
mexui.native.drawAALine(new Vec2(pos.x, startY), new Vec2(pos.x + this.size.x, startY), this.getStyles('row'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Grid.prototype.column = function(text, width, height)
|
||||
{
|
||||
var entry = new mexui.Entry.GridColumn(this, text, width, height);
|
||||
this.axis.x.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.row = function(cellsData, styles)
|
||||
{
|
||||
var cells = [];
|
||||
for(var i in cellsData)
|
||||
{
|
||||
if(cellsData[i] instanceof mexui.Component.Entry)
|
||||
{
|
||||
cells[i] = cellsData[i];
|
||||
}
|
||||
else
|
||||
{
|
||||
cells[i] = new mexui.Component.Entry(this, 1, cellsData[i] + '');
|
||||
}
|
||||
}
|
||||
|
||||
var entry = new mexui.Entry.GridRow(this, cells, styles);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.cell = function(text, styles)
|
||||
{
|
||||
var entry = new mexui.Component.Entry(this, 0, text, styles);
|
||||
return entry;
|
||||
};
|
||||
|
||||
mexui.Control.Grid.prototype.getAllEntriesLength = function(axisIndex)
|
||||
{
|
||||
if(axisIndex == 0)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
return this.axis.y.getAllEntriesLength2();
|
||||
}
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Hour.js
vendored
Normal file
19
third-party/mexui/Core/Control/Hour.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Hour', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Hour', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Hour, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Hour.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 23)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
17
third-party/mexui/Core/Control/Image.js
vendored
Normal file
17
third-party/mexui/Core/Control/Image.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
mexui.util.createControlConstructor('Image', false, function(window, x, y, w, h, filePath, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Image', styles));
|
||||
|
||||
this.image = mexui.native.loadImage(filePath);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Image', {});
|
||||
|
||||
// render
|
||||
mexui.Control.Image.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawImage(pos, this.size, this.image, this.getStyles('main'));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Integer.js
vendored
Normal file
11
third-party/mexui/Core/Control/Integer.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Integer', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Integer', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Integer, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Integer.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return !isNaN(parseInt(this.getTextWithNewCharacter(character)));
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Letter.js
vendored
Normal file
11
third-party/mexui/Core/Control/Letter.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Letter', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Letter', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Letter, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Letter.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetter(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/LetterDigit.js
vendored
Normal file
11
third-party/mexui/Core/Control/LetterDigit.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('LetterDigit', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('LetterDigit', styles), callback, true, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.LetterDigit, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.LetterDigit.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetterOrDigit(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Letters.js
vendored
Normal file
11
third-party/mexui/Core/Control/Letters.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Letters', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Letters', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Letters, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Letters.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetter(character);
|
||||
};
|
||||
11
third-party/mexui/Core/Control/LettersDigits.js
vendored
Normal file
11
third-party/mexui/Core/Control/LettersDigits.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('LettersDigits', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('LettersDigits', styles), callback, false, true);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.LettersDigits, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.LettersDigits.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return mexui.util.isLetterOrDigit(character);
|
||||
};
|
||||
23
third-party/mexui/Core/Control/Line.js
vendored
Normal file
23
third-party/mexui/Core/Control/Line.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
mexui.util.createControlConstructor('Line', false, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Line', styles), callback);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Line', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Line.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Line.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawAALine(pos, this.size, this.getStyles('main'));
|
||||
};
|
||||
58
third-party/mexui/Core/Control/List.js
vendored
Normal file
58
third-party/mexui/Core/Control/List.js
vendored
Normal file
@@ -0,0 +1,58 @@
|
||||
mexui.util.createControlConstructor('List', true, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('List', styles), callback);
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.activeRow = null;
|
||||
this.rowHeight = 25;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('List', {
|
||||
row:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
rowLine:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.List.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.activeRow = this.axis.y.getEntryByCursor();
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.List.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
for(var i in this.axis.y.entries)
|
||||
{
|
||||
var row = this.axis.y.entries[i];
|
||||
var rowText = row.text;
|
||||
|
||||
mexui.native.drawRectangle(pos, new Vec2(this.size.x, this.rowHeight), this.getStyles('row'));
|
||||
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), rowText, this.getStyles('row'));
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.List.prototype.row = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.ListRow(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Minute.js
vendored
Normal file
19
third-party/mexui/Core/Control/Minute.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Minute', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Minute', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Minute, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Minute.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 59)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Month.js
vendored
Normal file
19
third-party/mexui/Core/Control/Month.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Month', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Month', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Month, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Month.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 11)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
11
third-party/mexui/Core/Control/Number.js
vendored
Normal file
11
third-party/mexui/Core/Control/Number.js
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
mexui.util.createControlConstructor('Number', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Number', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Number, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Number.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
return !isNaN(parseFloat(this.getTextWithNewCharacter(character)));
|
||||
};
|
||||
7
third-party/mexui/Core/Control/Password.js
vendored
Normal file
7
third-party/mexui/Core/Control/Password.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.util.createControlConstructor('Password', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Password', styles), callback, false, true);
|
||||
|
||||
this.masked = true;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Password, mexui.Control.TextInput);
|
||||
35
third-party/mexui/Core/Control/ProgressBar.js
vendored
Normal file
35
third-party/mexui/Core/Control/ProgressBar.js
vendored
Normal file
@@ -0,0 +1,35 @@
|
||||
mexui.util.createControlConstructor('ProgressBar', false, function(window, x, y, w, h, text, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ProgressBar', styles));
|
||||
|
||||
this.text = text;
|
||||
|
||||
this.progress = 0.0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('ProgressBar', {
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(80, 255, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// render
|
||||
mexui.Control.ProgressBar.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var innerBarSize = new Vec2(this.size.x * this.progress, this.size.y);
|
||||
mexui.native.drawRectangle(pos, innerBarSize, this.getStyles('innerBar'));
|
||||
|
||||
if(this.text != '')
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
88
third-party/mexui/Core/Control/RadioButton.js
vendored
Normal file
88
third-party/mexui/Core/Control/RadioButton.js
vendored
Normal file
@@ -0,0 +1,88 @@
|
||||
mexui.util.createControlConstructor('RadioButton', false, function(window, x, y, w, h, groupId, text, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('RadioButton', styles), callback);
|
||||
|
||||
this.groupId = groupId;
|
||||
this.text = text;
|
||||
|
||||
this.checked = this.isFirstRadioInGroup();
|
||||
this.textMarginLeft = 5;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('RadioButton', {
|
||||
innerBox:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.RadioButton.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
var checkedRadio = this.getCheckedRadio();
|
||||
if(checkedRadio != this.checked)
|
||||
checkedRadio.checked = false;
|
||||
this.checked = !this.checked;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.RadioButton.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.checked)
|
||||
mexui.native.drawRectangle(mexui.util.addVec2(pos, new Vec2(2, 2)), new Vec2(this.size.x - 4, this.size.y - 4), this.getStyles('innerBox'));
|
||||
|
||||
mexui.native.drawText(mexui.util.addVec2(pos, new Vec2(this.size.x + this.textMarginLeft, 2)), this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.RadioButton.prototype.getSizeForInput = function()
|
||||
{
|
||||
var textWidth = mexui.native.getTextWidth(this.text, this.getStyles('main'));
|
||||
return new Vec2(this.size.x + this.textMarginLeft + textWidth, this.size.y);
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.getGroupRadios = function()
|
||||
{
|
||||
var radios = [];
|
||||
var windows = mexui.windows;
|
||||
for(var i in windows)
|
||||
{
|
||||
var window = mexui.windows[i];
|
||||
|
||||
for(var i2 in window.controls)
|
||||
{
|
||||
var control = window.controls[i2];
|
||||
|
||||
if((control instanceof mexui.Control.RadioButton) && this.groupId == control.groupId)
|
||||
{
|
||||
radios.push(control);
|
||||
}
|
||||
}
|
||||
}
|
||||
return radios;
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.getCheckedRadio = function()
|
||||
{
|
||||
var radios = this.getGroupRadios();
|
||||
for(var i in radios)
|
||||
{
|
||||
if(radios[i].checked)
|
||||
return radios[i];
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
mexui.Control.RadioButton.prototype.isFirstRadioInGroup = function()
|
||||
{
|
||||
return this.getGroupRadios().length == 0;
|
||||
};
|
||||
22
third-party/mexui/Core/Control/RangedInteger.js
vendored
Normal file
22
third-party/mexui/Core/Control/RangedInteger.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
mexui.util.createControlConstructor('RangedInteger', false, function(window, x, y, w, h, min, max, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedInteger', styles), callback, false, false);
|
||||
|
||||
this.min = min === undefined ? 0 : min;
|
||||
this.max = max === undefined ? 100 : max;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.RangedInteger, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.RangedInteger.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var number = parseInt(this.getTextWithNewCharacter(character));
|
||||
|
||||
if(!isNaN(number))
|
||||
return false;
|
||||
|
||||
if(number < this.min || number > this.max)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
22
third-party/mexui/Core/Control/RangedNumber.js
vendored
Normal file
22
third-party/mexui/Core/Control/RangedNumber.js
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
mexui.util.createControlConstructor('RangedNumber', false, function(window, x, y, w, h, min, max, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('RangedNumber', styles), callback, false, false);
|
||||
|
||||
this.min = min === undefined ? 0.0 : min;
|
||||
this.max = max === undefined ? 100.0 : max;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.RangedNumber, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.RangedNumber.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var number = parseFloat(this.getTextWithNewCharacter(character));
|
||||
|
||||
if(!isNaN(number))
|
||||
return false;
|
||||
|
||||
if(number < this.min || number > this.max)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
23
third-party/mexui/Core/Control/Rectangle.js
vendored
Normal file
23
third-party/mexui/Core/Control/Rectangle.js
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
mexui.util.createControlConstructor('Rectangle', false, function(window, x, y, w, h, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Rectangle', styles), callback);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Rectangle', {});
|
||||
|
||||
// input
|
||||
mexui.Control.Rectangle.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Rectangle.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
};
|
||||
120
third-party/mexui/Core/Control/ScrollBar.js
vendored
Normal file
120
third-party/mexui/Core/Control/ScrollBar.js
vendored
Normal file
@@ -0,0 +1,120 @@
|
||||
mexui.util.createControlConstructor('ScrollBar', false, function(window, x, y, w, h, isVertical, styles, callback)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('ScrollBar', styles), callback);
|
||||
|
||||
this.isVertical = isVertical;
|
||||
this.axisIndex = isVertical ? 1 : 0;
|
||||
this.otherAxisIndex = isVertical ? 0 : 1;
|
||||
|
||||
this.barHigherLength = 50;
|
||||
this.scrolledRatio = 0.0;
|
||||
this.isScrolling = false;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('ScrollBar', {
|
||||
main:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 190),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
},
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(79, 161, 246, 190),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(79, 161, 246, 150)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.ScrollBar.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(mexui.util.isCursorInRectangle(this.getInnerBarPosition(), this.getInnerBarSize()))
|
||||
{
|
||||
e.used = true;
|
||||
this.isScrolling = true;
|
||||
}
|
||||
else if(this.isCursorOverControl())
|
||||
{
|
||||
e.used = true;
|
||||
this.scrolledRatio += this.getScrolledRatioOuterBarClickIncrease();
|
||||
this.clampScrolledRatio();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseUp = function(e)
|
||||
{
|
||||
if(this.isScrolling)
|
||||
{
|
||||
this.isScrolling = false;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(this.isScrolling)
|
||||
{
|
||||
this.scrolledRatio += offset.y * 0.002;
|
||||
this.clampScrolledRatio();
|
||||
e.used = true;
|
||||
}
|
||||
|
||||
if(!e.used)
|
||||
mexui.Component.Control.prototype.onMouseMove.call(this, e, offset);
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.onMouseWheel = function(e, offset)
|
||||
{
|
||||
this.scrolledRatio -= offset.y * 0.12;
|
||||
this.clampScrolledRatio();
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.ScrollBar.prototype.renderAfter = function()
|
||||
{
|
||||
mexui.native.drawRectangle(this.getScreenPosition(), this.size, this.getStyles('main'));
|
||||
mexui.native.drawRectangle(this.getInnerBarPosition(), this.getInnerBarSize(), this.getStyles('innerBar'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.ScrollBar.prototype.clampScrolledRatio = function()
|
||||
{
|
||||
if(this.scrolledRatio < 0.0)
|
||||
this.scrolledRatio = 0.0;
|
||||
else if(this.scrolledRatio > 1.0)
|
||||
this.scrolledRatio = 1.0;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getInnerBarPosition = function()
|
||||
{
|
||||
var screenPos = this.getScreenPosition();
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
|
||||
var minPos = pos[this.axisIndex] + 1;
|
||||
var maxPos = pos[this.axisIndex] + this.size[this.axisIndex] - 2;
|
||||
pos[this.axisIndex] = minPos + (this.scrolledRatio * (maxPos - minPos - this.barHigherLength));
|
||||
pos[this.otherAxisIndex] += 1;
|
||||
return pos;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getInnerBarSize = function()
|
||||
{
|
||||
var size = new Vec2(this.size.x, this.size.y);
|
||||
size[this.axisIndex] = this.barHigherLength;
|
||||
size[this.otherAxisIndex] -= 2;
|
||||
return size;
|
||||
};
|
||||
|
||||
mexui.Control.ScrollBar.prototype.getScrolledRatioOuterBarClickIncrease = function()
|
||||
{
|
||||
var direction = gui.cursorPosition.y < this.getInnerBarPosition().y ? -1.0 : 1.0;
|
||||
return direction * 0.05;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Second.js
vendored
Normal file
19
third-party/mexui/Core/Control/Second.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Second', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Second', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Second, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Second.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 59)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
112
third-party/mexui/Core/Control/Slider.js
vendored
Normal file
112
third-party/mexui/Core/Control/Slider.js
vendored
Normal file
@@ -0,0 +1,112 @@
|
||||
mexui.util.createControlConstructor('Slider', false, function(window, x, y, w, h, isVertical, text, minText, maxText, styles, callback)
|
||||
{
|
||||
isVertical = isVertical === undefined ? false : isVertical;
|
||||
text = text === undefined ? '' : text;
|
||||
minText = minText === undefined ? '' : minText;
|
||||
maxText = maxText === undefined ? '' : maxText;
|
||||
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Slider', styles), callback);
|
||||
|
||||
this.isVertical = isVertical;
|
||||
this.text = text;
|
||||
this.minText = minText;
|
||||
this.maxText = maxText;
|
||||
|
||||
this.progress = 0.0;
|
||||
this.axisIndex = isVertical ? 1 : 0;
|
||||
this.innerBarSize = new Vec2(30, 25);
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Slider', {
|
||||
innerBar:
|
||||
{
|
||||
backgroundColour: toColour(0, 255, 0, 255)
|
||||
},
|
||||
minText:
|
||||
{
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
maxText:
|
||||
{
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Slider.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.isCursorOverInnerBar())
|
||||
{
|
||||
this.sliding = true;
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.onMouseUp = function(e)
|
||||
{
|
||||
if(this.sliding)
|
||||
{
|
||||
this.sliding = false;
|
||||
this.checkToCallCallback();
|
||||
e.used = true;
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.onMouseMove = function(e, offset)
|
||||
{
|
||||
if(!this.sliding)
|
||||
return false;
|
||||
|
||||
this.progress += this.getProgressIncreaseByPixels(offset);
|
||||
this.clampProgress();
|
||||
e.used = true;
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Slider.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
mexui.native.drawRectangle(this.getInnerBarPosition(), this.innerBarSize, this.getStyles('innerBar'));
|
||||
|
||||
pos.y += this.size.y;
|
||||
mexui.native.drawText(pos, this.size, this.minText, this.getStyles('minText'));
|
||||
|
||||
var offset = (this.size.x - mexui.native.getTextWidth(this.text, this.getStyles('main'))) / 2;
|
||||
pos.x += offset;
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
pos.x -= offset;
|
||||
|
||||
pos.x += this.size.x - mexui.native.getTextWidth(this.maxText, this.getStyles('maxText'));
|
||||
mexui.native.drawText(pos, this.size, this.maxText, this.getStyles('maxText'));
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Slider.prototype.isCursorOverInnerBar = function()
|
||||
{
|
||||
return mexui.util.isCursorInRectangle(this.getInnerBarPosition(), this.innerBarSize);
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.getInnerBarPosition = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos[this.axisIndex] = mexui.util.interpolateScalar(pos.x, (pos.x + this.size.x) - this.innerBarSize.x, this.progress);
|
||||
pos.y -= 3;
|
||||
return new Vec2(pos.x, pos.y);
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.getProgressIncreaseByPixels = function(offset)
|
||||
{
|
||||
return offset.x / this.size.x;
|
||||
};
|
||||
|
||||
mexui.Control.Slider.prototype.clampProgress = function()
|
||||
{
|
||||
if(this.progress < 0.0)
|
||||
this.progress = 0.0;
|
||||
else if(this.progress > 1.0)
|
||||
this.progress = 1.0;
|
||||
};
|
||||
|
||||
82
third-party/mexui/Core/Control/TabPanel.js
vendored
Normal file
82
third-party/mexui/Core/Control/TabPanel.js
vendored
Normal file
@@ -0,0 +1,82 @@
|
||||
mexui.util.createControlConstructor('TabPanel', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TabPanel', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.activeTabIndex = 0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('TabPanel', {
|
||||
tab:
|
||||
{
|
||||
backgroundColour: toColour(240, 20, 20, 200),
|
||||
borderColour: toColour(120, 20, 20, 225),
|
||||
textColour: toColour(0, 0, 0, 255),
|
||||
|
||||
hover:
|
||||
{
|
||||
backgroundColour: toColour(240, 20, 20, 150),
|
||||
borderColour: toColour(120, 20, 20, 120),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.TabPanel.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
var tabX = pos.x;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var tab = this.axis.x.entries[i];
|
||||
|
||||
var tabPos = new Vec2(tabX, pos.y);
|
||||
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
|
||||
|
||||
if(mexui.util.isCursorInRectangle(tabPos, tabSize))
|
||||
{
|
||||
tab.setActive();
|
||||
break;
|
||||
}
|
||||
|
||||
tabX += tabSize.x;
|
||||
}
|
||||
|
||||
/*
|
||||
var tab = this.axis.x.getEntryByCursor();
|
||||
if(tab)
|
||||
tab.setActive();
|
||||
*/
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.TabPanel.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
var tabX = pos.x;
|
||||
for(var i in this.axis.x.entries)
|
||||
{
|
||||
var tab = this.axis.x.entries[i];
|
||||
|
||||
var tabPos = new Vec2(tabX, pos.y);
|
||||
var tabSize = new Vec2(mexui.native.getTextWidth(tab.text, this.getStyles('tab')) + 10, 25);
|
||||
mexui.native.drawRectangle(tabPos, tabSize, this.getStyles('tab'));
|
||||
mexui.native.drawText(tabPos, tabSize, tab.text, this.getStyles('tab'));
|
||||
|
||||
tabX += tabSize.x;
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.TabPanel.prototype.tab = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.Tab(this, text);
|
||||
this.axis.x.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
17
third-party/mexui/Core/Control/Text.js
vendored
Normal file
17
third-party/mexui/Core/Control/Text.js
vendored
Normal file
@@ -0,0 +1,17 @@
|
||||
mexui.util.createControlConstructor('Text', false, function(window, x, y, w, h, text, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Text', styles));
|
||||
|
||||
this.text = text;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Text', {});
|
||||
|
||||
// render
|
||||
mexui.Control.Text.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
|
||||
mexui.native.drawText(pos, this.size, this.text, this.getStyles('main'));
|
||||
};
|
||||
7
third-party/mexui/Core/Control/TextArea.js
vendored
Normal file
7
third-party/mexui/Core/Control/TextArea.js
vendored
Normal file
@@ -0,0 +1,7 @@
|
||||
mexui.util.createControlConstructor('TextArea', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('TextArea', styles), callback, false, true);
|
||||
|
||||
this.multiLine = true;
|
||||
});
|
||||
mexui.util.extend(mexui.Control.TextArea, mexui.Control.TextInput);
|
||||
347
third-party/mexui/Core/Control/TextInput.js
vendored
Normal file
347
third-party/mexui/Core/Control/TextInput.js
vendored
Normal file
@@ -0,0 +1,347 @@
|
||||
mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w, h, text, styles, callback, singleCharacter, multiLineSupported)
|
||||
{
|
||||
text = text || '';
|
||||
if(singleCharacter)
|
||||
multiLineSupported = false;
|
||||
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('TextInput', styles), callback);
|
||||
|
||||
this.lines = text ? mexui.util.splitLines(text) : [''];
|
||||
|
||||
this.caretPosition = new Vec2(0, 0);
|
||||
this.multiLineSupported = multiLineSupported === undefined ? true : multiLineSupported;
|
||||
this.multiLine = this.multiLineSupported ? mexui.util.doesContainEOLChar(text) : false;
|
||||
this.masked = false;
|
||||
this.singleCharacter = singleCharacter === undefined ? false : singleCharacter;
|
||||
this.placeholder = '';
|
||||
this.caretShownForBlink = true;
|
||||
this.lineHeight = 25;
|
||||
this.maxLength = this.singleCharacter ? 1 : false;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('TextInput', {
|
||||
caret:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
placeholder:
|
||||
{
|
||||
textColour: toColour(100, 100, 100, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.TextInput.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var hit = this.isCursorOverControl();
|
||||
if(hit)
|
||||
{
|
||||
this.caretPosition = this.getCaretPositionByCursor();
|
||||
}
|
||||
|
||||
mexui.Component.Control.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.onCharacter = function(e, character)
|
||||
{
|
||||
if(mexui.focusedControl == this)
|
||||
{
|
||||
/*
|
||||
var isValid1 = this.callback ? this.callback(character) : true;
|
||||
if(!isValid1 && isValid1 !== undefined)
|
||||
return;
|
||||
*/
|
||||
|
||||
var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true;
|
||||
if(!isValid2)
|
||||
return;
|
||||
|
||||
if(this.singleCharacter)
|
||||
{
|
||||
this.resetText();
|
||||
this.lines = [character];
|
||||
this.caretPosition.x = this.caretPosition.x < 2 ? this.caretPosition.x : 0;
|
||||
}
|
||||
else if(this.canAddCharacter())
|
||||
{
|
||||
this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character);
|
||||
this.caretPosition.x++;
|
||||
}
|
||||
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
|
||||
{
|
||||
if(mexui.focusedControl != this)
|
||||
return;
|
||||
|
||||
var controlIsDown = (mods & KMOD_CTRL) == KMOD_CTRL;
|
||||
|
||||
switch(key)
|
||||
{
|
||||
case SDLK_LEFT:
|
||||
if(this.caretPosition.x != 0)
|
||||
{
|
||||
this.caretPosition.x--;
|
||||
}
|
||||
else if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
case SDLK_RIGHT:
|
||||
if(this.caretPosition.x != this.getCaretLine().length)
|
||||
{
|
||||
this.caretPosition.x++;
|
||||
}
|
||||
else if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
}
|
||||
break;
|
||||
case SDLK_HOME:
|
||||
if(controlIsDown)
|
||||
{
|
||||
this.caretPosition.y = 0;
|
||||
this.caretPosition.x = 0;
|
||||
}
|
||||
else
|
||||
this.caretPosition.x = 0;
|
||||
break;
|
||||
case SDLK_END:
|
||||
if(controlIsDown)
|
||||
{
|
||||
this.caretPosition.y = this.lines.length - 1;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
else
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
break;
|
||||
case SDLK_DELETE:
|
||||
if(this.caretPosition.x != this.getCaretLine().length)
|
||||
{
|
||||
this.deleteCharacter(this.caretPosition);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.mergeLines(this.caretPosition.y);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
break;
|
||||
case SDLK_BACKSPACE:
|
||||
if(this.caretPosition.x != 0)
|
||||
{
|
||||
this.deleteCharacter(new Vec2(this.caretPosition.x - 1, this.caretPosition.y));
|
||||
this.caretPosition.x--;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
this.mergeLines(this.caretPosition.y);
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
if(this.multiLine)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
case SDLK_RETURN:
|
||||
case SDLK_KP_ENTER:
|
||||
if(this.canAddCharacter())
|
||||
{
|
||||
if(this.caretPosition.x == this.getCaretLine().length)
|
||||
{
|
||||
this.addLine(this.caretPosition.y + 1);
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.splitLine(this.caretPosition.y);
|
||||
this.caretPosition.y++;
|
||||
this.caretPosition.x = 0;
|
||||
this.checkToCallCallback();
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDLK_UP:
|
||||
if(this.caretPosition.y != 0)
|
||||
{
|
||||
this.caretPosition.y--;
|
||||
if(this.caretPosition.x > this.getCaretLine().length)
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
case SDLK_DOWN:
|
||||
if(this.caretPosition.y != (this.lines.length - 1))
|
||||
{
|
||||
this.caretPosition.y++;
|
||||
if(this.caretPosition.x > this.getCaretLine().length)
|
||||
this.caretPosition.x = this.getCaretLine().length;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.TextInput.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
|
||||
|
||||
if(this.isEmpty())
|
||||
{
|
||||
mexui.native.drawText(pos, this.size, this.placeholder, this.getStyles('placeholder'));
|
||||
}
|
||||
else
|
||||
{
|
||||
var lineSize = new Vec2(this.size.x, this.lineHeight);
|
||||
for(var i=0,j=this.lines.length; i<j; i++)
|
||||
{
|
||||
var displayedText = this.masked ? '*'.repeat(this.lines[i].length) : this.lines[i];
|
||||
mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main'));
|
||||
|
||||
pos.y += this.lineHeight;
|
||||
}
|
||||
}
|
||||
|
||||
if(mexui.focusedControl == this && this.caretShownForBlink)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
var text = this.lines[this.caretPosition.y].substr(0, this.caretPosition.x);
|
||||
var displayedText = this.masked ? '*'.repeat(text.length) : text;
|
||||
var textWidth = mexui.native.getTextWidth(displayedText, this.getStyles('main'));
|
||||
var caretPosOffset = new Vec2(5 + textWidth, (this.caretPosition.y * this.lineHeight) + 1);
|
||||
var caretPoint1 = mexui.util.addVec2(pos, caretPosOffset);
|
||||
var caretPoint2 = new Vec2(caretPoint1.x, caretPoint1.y + 22);
|
||||
mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret'));
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
|
||||
|
||||
mexui.Control.TextInput.prototype.getTextWithNewCharacter = function(character)
|
||||
{
|
||||
return this.lines[this.caretPosition.y].substr(0, this.caretPosition.x) + character + this.lines[this.caretPosition.y].substr(this.caretPosition.x);
|
||||
};
|
||||
|
||||
// caret
|
||||
mexui.Control.TextInput.prototype.getCaretLine = function()
|
||||
{
|
||||
return this.lines[this.caretPosition.y];
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.clampCaretPosition = function()
|
||||
{
|
||||
if(this.caretPosition.y < 0)
|
||||
this.caretPosition.y = 0;
|
||||
else if(this.caretPosition.y > (this.lines.length - 1))
|
||||
this.caretPosition.y = this.lines.length - 1;
|
||||
|
||||
if(this.caretPosition.x < 0)
|
||||
this.caretPosition.x = 0;
|
||||
else if(this.caretPosition.x > this.lines[this.caretPosition.y].length)
|
||||
this.caretPosition.x = this.lines[this.caretPosition.y].length;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCaretPositionByCursor = function()
|
||||
{
|
||||
var lineIndex = this.getCaretLineIndexByCursor();
|
||||
var charIndex = this.getCharIndexByCursor(lineIndex);
|
||||
return new Vec2(charIndex, lineIndex);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCaretLineIndexByCursor = function()
|
||||
{
|
||||
var yPos = gui.cursorPosition.y - this.getScreenPosition().y;
|
||||
var lineIndex = Math.floor(yPos / this.lineHeight);
|
||||
|
||||
if(lineIndex < 0)
|
||||
return 0;
|
||||
else if(lineIndex > (this.lines.length - 1))
|
||||
return this.lines.length - 1;
|
||||
else
|
||||
return lineIndex;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getCharIndexByCursor = function(lineIndex)
|
||||
{
|
||||
var xPos = gui.cursorPosition.x - this.getScreenPosition().x;
|
||||
var line = this.lines[lineIndex];
|
||||
var lineStyles = this.getStyles('caret');
|
||||
|
||||
for(var i=0,j=line.length; i<j; i++)
|
||||
{
|
||||
var text = line.substr(0, i + 1);
|
||||
var textWidth = mexui.native.getTextWidth(text, lineStyles);
|
||||
|
||||
if(xPos < textWidth)
|
||||
return i;
|
||||
}
|
||||
return line.length;
|
||||
};
|
||||
|
||||
// lines
|
||||
mexui.Control.TextInput.prototype.addLine = function(lineIndex)
|
||||
{
|
||||
this.lines.splice(lineIndex, 0, '');
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.removeLine = function(lineIndex)
|
||||
{
|
||||
this.lines.splice(lineIndex, 1);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.getLineLength = function(lineIndex)
|
||||
{
|
||||
return this.lines[lineIndex].length;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.mergeLines = function(lineIndex)
|
||||
{
|
||||
this.lines[lineIndex] += this.lines[lineIndex + 1];
|
||||
this.removeLine(lineIndex + 1);
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.splitLine = function(lineIndex)
|
||||
{
|
||||
this.addLine(lineIndex + 1);
|
||||
this.lines[lineIndex + 1] = this.lines[lineIndex].substr(this.caretPosition.x);
|
||||
this.lines[lineIndex] = this.lines[lineIndex].substr(0, this.caretPosition.x);
|
||||
};
|
||||
|
||||
// characters
|
||||
mexui.Control.TextInput.prototype.canAddCharacter = function()
|
||||
{
|
||||
return this.maxLength === false || this.lines.join("\r\n").length < this.maxLength;
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.deleteCharacter = function(charPos)
|
||||
{
|
||||
this.lines[charPos.y] = this.lines[charPos.y].substr(0, charPos.x) + this.lines[charPos.y].substr(charPos.x + 1);
|
||||
};
|
||||
|
||||
// text overall
|
||||
mexui.Control.TextInput.prototype.resetText = function()
|
||||
{
|
||||
this.lines = [''];
|
||||
};
|
||||
|
||||
mexui.Control.TextInput.prototype.isEmpty = function()
|
||||
{
|
||||
return this.lines.length == 1 && this.lines[0] == '';
|
||||
};
|
||||
|
||||
151
third-party/mexui/Core/Control/Time.js
vendored
Normal file
151
third-party/mexui/Core/Control/Time.js
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
mexui.util.createControlConstructor('Time', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Time', styles), callback, false, false);
|
||||
|
||||
this.hour = 0;
|
||||
this.minute = 0;
|
||||
this.second = 0;
|
||||
|
||||
this.inputShown = false;
|
||||
this.valueBoxSize = new Vec2(50, 30);
|
||||
this.arrowBoxSize = new Vec2(25, 22);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Time, mexui.Control.TextInput);
|
||||
|
||||
// static
|
||||
mexui.Control.Time.units = ['hour', 'minute', 'second'];
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Time', {
|
||||
arrow:
|
||||
{
|
||||
backgroundColour: toColour(90, 90, 80, 230),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Time.prototype.onMouseDown = function(e)
|
||||
{
|
||||
if(this.inputShown)
|
||||
{
|
||||
var arrowIndex = this.getArrowIndexByCursor();
|
||||
if(arrowIndex !== false)
|
||||
{
|
||||
var propIndex = (Math.ceil((arrowIndex + 1) / 2)) - 1;
|
||||
var propName = mexui.Control.Time.units[propIndex];
|
||||
var isIncrease = (arrowIndex % 2) == 1;
|
||||
|
||||
if(isIncrease)
|
||||
this[propName]++;
|
||||
else
|
||||
this[propName]--;
|
||||
|
||||
this[propName] %= propIndex == 0 ? 24 : 60;
|
||||
if(this[propName] == -1)
|
||||
this[propName] = propIndex == 0 ? 23 : 59;
|
||||
|
||||
this.generateText();
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(this.isCursorOverControl())
|
||||
{
|
||||
this.inputShown = !this.inputShown;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(this.inputShown)
|
||||
{
|
||||
this.inputShown = false;
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Time.prototype.renderAfter = function()
|
||||
{
|
||||
if(!this.inputShown)
|
||||
return;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
|
||||
var pos = new Vec2(screenPos.x, screenPos.y);
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
mexui.native.drawRectangle(pos, this.valueBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.valueBoxSize, this[mexui.Control.Time.units[i]], this.getStyles('main'));
|
||||
|
||||
pos.x += this.valueBoxSize.x;
|
||||
}
|
||||
|
||||
pos = new Vec2(screenPos.x, screenPos.y);
|
||||
pos.y += this.valueBoxSize.y;
|
||||
for(var i=0; i<3; i++)
|
||||
{
|
||||
for(var i2=0; i2<2; i2++)
|
||||
{
|
||||
var text = (i2 % 2) == 0 ? '<' : '>';
|
||||
|
||||
mexui.native.drawRectangle(pos, this.arrowBoxSize, this.getStyles('main'));
|
||||
mexui.native.drawText(pos, this.arrowBoxSize, text, this.getStyles('main'));
|
||||
|
||||
pos.x += this.arrowBoxSize.x;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Time.prototype.generateText = function()
|
||||
{
|
||||
this.text = (this.hour < 10 ? '0'+this.hour : this.hour)
|
||||
+':'+(this.minute < 10 ? '0'+this.minute : this.minute)
|
||||
+':'+(this.second < 10 ? '0'+this.second : this.second);
|
||||
};
|
||||
|
||||
mexui.Control.Time.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var text = this.getTextWithNewCharacter(character);
|
||||
var parts = text.split(':');
|
||||
|
||||
for(var i in parts)
|
||||
{
|
||||
if(i == 3)
|
||||
return false;
|
||||
|
||||
var part = parseInt(parts[i]);
|
||||
|
||||
if(isNaN(part))
|
||||
return false;
|
||||
|
||||
if(part < 0)
|
||||
return false;
|
||||
|
||||
if(part > (i == 0 ? 23 : 59))
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
mexui.Control.Time.prototype.getArrowIndexByCursor = function()
|
||||
{
|
||||
var cursorPos = gui.cursorPosition;
|
||||
|
||||
var screenPos = this.getScreenPosition();
|
||||
var firstArrowStartPos = new Vec2(screenPos.x, screenPos.y + this.valueBoxSize.y);
|
||||
var lastArrowEndPos = new Vec2(screenPos.x + (this.arrowBoxSize.x * 6), screenPos.y + this.valueBoxSize.y + this.arrowBoxSize.y);
|
||||
|
||||
if(cursorPos.x >= firstArrowStartPos.x && cursorPos.y >= firstArrowStartPos.y && cursorPos.x <= lastArrowEndPos.x && cursorPos.y <= lastArrowEndPos.y)
|
||||
{
|
||||
return Math.floor((cursorPos.x - firstArrowStartPos.x) / this.arrowBoxSize.x);
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
150
third-party/mexui/Core/Control/Tree.js
vendored
Normal file
150
third-party/mexui/Core/Control/Tree.js
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
mexui.util.createControlConstructor('Tree', true, function(window, x, y, w, h, styles)
|
||||
{
|
||||
mexui.Component.Control.call(this, window, x, y, w, h, this.linkControlStyles('Tree', styles));
|
||||
mexui.Entity.ControlWithEntries.call(this, false, false);
|
||||
|
||||
this.rowHeight = 25;
|
||||
this.rowLevelIndentation = 10;
|
||||
this.scrollMultiplier = 10.0;
|
||||
});
|
||||
|
||||
// default styles
|
||||
mexui.util.linkBaseControlStyles('Tree', {
|
||||
row:
|
||||
{
|
||||
backgroundColour: toColour(255, 255, 255, 255),
|
||||
textColour: toColour(0, 0, 0, 255)
|
||||
},
|
||||
rowIcon:
|
||||
{
|
||||
textColour: toColour(230, 130, 0, 190)
|
||||
},
|
||||
rowLine:
|
||||
{
|
||||
lineColour: toColour(0, 0, 0, 150)
|
||||
}
|
||||
});
|
||||
|
||||
// input
|
||||
mexui.Control.Tree.prototype.onMouseDown = function(e)
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos.y -= this.axis.y.getScrolledOffset();
|
||||
|
||||
this.testRowClick(e, this.axis.y.entries, pos);
|
||||
|
||||
if(!e.used)
|
||||
mexui.Entity.ControlWithEntries.prototype.onMouseDown.call(this, e);
|
||||
};
|
||||
|
||||
// render
|
||||
mexui.Control.Tree.prototype.render = function()
|
||||
{
|
||||
var pos = this.getScreenPosition();
|
||||
pos.y -= this.axis.y.getScrolledOffset();
|
||||
|
||||
this.renderRows(this.axis.y.entries, 0, pos);
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.renderRows = function(rows, level, pos)
|
||||
{
|
||||
for(var i in rows)
|
||||
{
|
||||
var row = rows[i];
|
||||
var shouldDraw = pos.y >= this.getScreenPosition().y && pos.y <= (this.getScreenPosition().y + this.size.y);
|
||||
|
||||
if(shouldDraw)
|
||||
{
|
||||
if(row.rows.length > 0)
|
||||
mexui.native.drawText(new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y), new Vec2(this.size.x, this.rowHeight), row.open ? '-' : '+', this.getStyles('rowIcon'));
|
||||
|
||||
mexui.native.drawRectangle(pos, new Vec2(this.size.x - (this.rowLevelIndentation * level), this.rowHeight), this.getStyles('row'));
|
||||
mexui.native.drawText(pos, new Vec2(this.size.x, this.rowHeight), row.text, this.getStyles('row'));
|
||||
}
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
|
||||
if(shouldDraw)
|
||||
{
|
||||
mexui.native.drawAALine(pos, new Vec2(pos.x + this.size.x, pos.y), this.getStyles('rowLine'));
|
||||
}
|
||||
|
||||
if(row.rows.length > 0 && row.open)
|
||||
{
|
||||
pos.x += this.rowLevelIndentation;
|
||||
this.renderRows(row.rows, level + 1, pos);
|
||||
pos.x -= this.rowLevelIndentation;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// model
|
||||
mexui.Control.Tree.prototype.getAllEntriesLength = function(axisIndex)
|
||||
{
|
||||
return this.getRowsLength(this.axis.y.entries);
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.getRowsLength = function(rows)
|
||||
{
|
||||
var length = rows.length * this.entrySize.y;
|
||||
for(var i in rows)
|
||||
{
|
||||
if(rows[i].open)
|
||||
length += this.getRowsLength(rows[i].rows);
|
||||
}
|
||||
return length;
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
|
||||
{
|
||||
for(var i in rows)
|
||||
{
|
||||
var row = rows[i];
|
||||
|
||||
var rowPos = new Vec2(pos.x - (this.rowLevelIndentation * 2), pos.y);
|
||||
var rowSize = new Vec2(this.size.x + (this.rowLevelIndentation * 2), this.rowHeight);
|
||||
if(mexui.util.isCursorInRectangle(rowPos, rowSize))
|
||||
{
|
||||
this.onClickRow(row);
|
||||
e.used = true;
|
||||
return;
|
||||
}
|
||||
|
||||
pos.y += this.rowHeight;
|
||||
|
||||
if(row.rows.length > 0 && row.open)
|
||||
{
|
||||
this.testRowClick(e, row.rows, pos);
|
||||
if(e.used)
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
mexui.Control.Tree.prototype.onClickRow = function(row)
|
||||
{
|
||||
if(row.rows.length > 0)
|
||||
{
|
||||
//var scrollableLengthBefore = this.axis.y.getScrollableLength();
|
||||
|
||||
row.open = !row.open;
|
||||
this.checkToShowScrollBars();
|
||||
|
||||
/*
|
||||
if(this.scrollBars[1].shown)
|
||||
{
|
||||
var scrollableLengthAfter = this.axis.y.getScrollableLength();
|
||||
this.scrollBars[1].scrolledRatio += (scrollableLengthAfter - scrollableLengthBefore) / scrollableLengthAfter;
|
||||
}
|
||||
*/
|
||||
}
|
||||
};
|
||||
|
||||
// api
|
||||
mexui.Control.Tree.prototype.row = function(text)
|
||||
{
|
||||
var entry = new mexui.Entry.TreeRow(this, text);
|
||||
this.axis.y.addEntry(entry);
|
||||
return entry;
|
||||
};
|
||||
|
||||
19
third-party/mexui/Core/Control/Week.js
vendored
Normal file
19
third-party/mexui/Core/Control/Week.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Week', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Week', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Week, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Week.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 0 || _int > 51)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
19
third-party/mexui/Core/Control/Year.js
vendored
Normal file
19
third-party/mexui/Core/Control/Year.js
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
mexui.util.createControlConstructor('Year', false, function(window, x, y, w, h, text, styles, callback)
|
||||
{
|
||||
mexui.Control.TextInput.call(this, window, x, y, w, h, text, this.linkControlStyles('Year', styles), callback, false, false);
|
||||
});
|
||||
mexui.util.extend(mexui.Control.Year, mexui.Control.TextInput);
|
||||
|
||||
// model
|
||||
mexui.Control.Year.prototype.validateInputCallback = function(e, character)
|
||||
{
|
||||
var _int = parseInt(character);
|
||||
|
||||
if(isNaN(_int))
|
||||
return false;
|
||||
|
||||
if(_int < 1900 || _int > 2019)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
};
|
||||
Reference in New Issue
Block a user