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.StyleableEntity.call(this, this.linkComponentStyles('Control', styles));
this.window = window;
this.position = new Vec2(x, y);
this.size = new Vec2(w, h);
this.callback = callback;
this.boundTo = null;
};
mexui.util.extend(mexui.Component.Control, mexui.Entity.Component);
@@ -131,3 +131,4 @@ mexui.Component.Control.prototype.unbind = function()
{
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.StyleableEntity.call(this, this.linkComponentStyles('Entry', styles));
this.control = control;
this.axisIndex = axisIndex;
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.checkToShowScrollBars();
};

View File

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

View File

@@ -1,7 +1,7 @@
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;
});
@@ -31,10 +31,10 @@ mexui.Control.Button.prototype.onKeyDown = function(e, key, mods)
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'));
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

@@ -1,15 +1,15 @@
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);
this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; };
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 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;
var minYear = this.minYearCallback();
var maxYear = this.maxYearCallback();
if(this.year < minYear)
this.year = minYear;
else if(this.year > maxYear)
this.year = maxYear;
this.generateText();
return;
}
}
if(this.isCursorOverControl())
{
this.inputShown = !this.inputShown;
e.used = true;
return;
}
if(this.inputShown)
{
this.inputShown = false;
@@ -89,18 +89,18 @@ 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++)
@@ -108,10 +108,10 @@ mexui.Control.Date.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;
}
}
@@ -133,16 +133,16 @@ mexui.Control.Date.prototype.validateInputCallback = function(e, character)
mexui.Control.Date.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;
if(i == 0)
{
if(!mexui.util.isDayIdWithOptionalSuffix(partAsStr))
@@ -159,18 +159,18 @@ mexui.Control.Date.prototype.validateValueCallback = function(e)
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);

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.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;
@@ -18,7 +18,7 @@ mexui.util.linkBaseControlStyles('DropDown', {
{
backgroundColour: toColour(255, 255, 255, 255),
textColour: toColour(0, 0, 0, 255),
hover:
{
backgroundColour: toColour(80, 80, 80, 255),
@@ -34,7 +34,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
{
if(this.axis.y.entries.length == 0)
return;
var hitButton = this.isCursorOverControl();
if(hitButton)
{
@@ -51,7 +51,7 @@ mexui.Control.DropDown.prototype.onMouseDown = function(e)
}
}
}
if(!e.used)
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()
{
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);
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'));
};
@@ -105,31 +105,31 @@ mexui.Control.DropDown.prototype.renderAfter = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
pos.x += this.entriesPositionOffset.x;
pos.y += this.entriesPositionOffset.y;
pos2.x += this.entriesPositionOffset.x;
pos2.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;
}
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.Entity.ControlWithEntries.prototype.renderAfter.call(this);
};

View File

@@ -30,54 +30,54 @@ mexui.util.linkBaseControlStyles('Grid', {
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'));
}
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'));
};
@@ -104,7 +104,7 @@ mexui.Control.Grid.prototype.row = function(cellsData, styles)
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;
@@ -127,3 +127,4 @@ mexui.Control.Grid.prototype.getAllEntriesLength = function(axisIndex)
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)
{
var _int = parseInt(this.getText());
if(_int < 1 || _int > 23)
return false;
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);
});
// 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'));
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
mexui.Control.Image.prototype.onMouseDown = function(e)
{
@@ -27,4 +16,24 @@ mexui.Control.Image.prototype.onMouseDown = function(e)
e.used = true;
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.Entity.ControlWithEntries.call(this, false, false);
this.activeRow = null;
this.rowHeight = 25;
});
@@ -35,19 +35,19 @@ mexui.Control.List.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
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'));
}
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'));
};
@@ -59,3 +59,4 @@ mexui.Control.List.prototype.row = function(text)
this.axis.y.addEntry(entry);
return entry;
};

View File

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

View File

@@ -1,7 +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);

View File

@@ -1,9 +1,9 @@
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;
});
@@ -12,7 +12,7 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
innerBar:
{
backgroundColour: toColour(0, 255, 0, 255),
hover:
{
backgroundColour: toColour(80, 255, 0, 255)
@@ -24,12 +24,12 @@ mexui.util.linkBaseControlStyles('ProgressBar', {
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'));
};

View File

@@ -1,10 +1,10 @@
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;
});
@@ -42,14 +42,14 @@ mexui.Control.RadioButton.prototype.onKeyDown = function(e, key, mods)
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'));
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'));
};
@@ -68,11 +68,11 @@ mexui.Control.RadioButton.prototype.getGroupRadios = function()
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);
@@ -103,7 +103,7 @@ mexui.Control.RadioButton.prototype.setChecked = function()
var checkedRadio = this.getCheckedRadio();
if(checkedRadio != this.checked)
checkedRadio.checked = false;
this.checked = !this.checked;
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.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;
});
@@ -18,7 +18,7 @@ mexui.Control.RangedInteger.prototype.validateValueCallback = function(e)
var text = this.getText();
if(!mexui.util.isInt(text))
return false;
var _int = parseInt(text);
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.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;
});
@@ -18,7 +18,7 @@ mexui.Control.RangedNumber.prototype.validateValueCallback = function(e)
var text = this.getText();
if(!mexui.util.isFloat(text))
return false;
var number = parseFloat(text);
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.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;
@@ -16,7 +16,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
main:
{
backgroundColour: toColour(0, 0, 0, 190),
hover:
{
backgroundColour: toColour(0, 0, 0, 150)
@@ -25,7 +25,7 @@ mexui.util.linkBaseControlStyles('ScrollBar', {
innerBar:
{
backgroundColour: toColour(79, 161, 246, 190),
hover:
{
backgroundColour: toColour(79, 161, 246, 150)
@@ -69,7 +69,7 @@ mexui.Control.ScrollBar.prototype.onMouseMove = function(e, offset)
this.clampScrolledRatio();
e.used = true;
}
if(!e.used)
mexui.Component.Control.prototype.onMouseMove.call(this, e, offset);
};
@@ -100,7 +100,7 @@ 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));

View File

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

View File

@@ -4,14 +4,14 @@ mexui.util.createControlConstructor('Slider', false, function(window, x, y, w, h
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);
@@ -57,7 +57,7 @@ mexui.Control.Slider.prototype.onMouseMove = function(e, offset)
{
if(!this.sliding)
return false;
this.progress += this.getProgressIncreaseByPixels(offset);
this.clampProgress();
e.used = true;
@@ -68,21 +68,21 @@ mexui.Control.Slider.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
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'));
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'));
};
@@ -113,3 +113,4 @@ mexui.Control.Slider.prototype.clampProgress = function()
else if(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.Entity.ControlWithEntries.call(this, false, false);
this.activeTabIndex = 0;
});
@@ -13,7 +13,7 @@ mexui.util.linkBaseControlStyles('TabPanel', {
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),
@@ -29,24 +29,24 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
if(e.button == 0)
{
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)
@@ -59,22 +59,22 @@ mexui.Control.TabPanel.prototype.onMouseDown = function(e)
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;
}
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

@@ -1,7 +1,7 @@
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;
});
@@ -12,9 +12,9 @@ mexui.util.linkBaseControlStyles('Text', {});
mexui.Control.Text.prototype.render = function()
{
var pos = this.getScreenPosition();
mexui.native.drawText(pos, this.size, this.text, 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

@@ -1,7 +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);

View File

@@ -3,11 +3,11 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
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;
@@ -17,7 +17,7 @@ mexui.util.createControlConstructor('TextInput', false, function(window, x, y, w
this.caretShownForBlink = true;
this.lineHeight = 25;
this.maxLength = this.singleCharacter ? 1 : false;
this.validValue = true;
});
@@ -44,7 +44,7 @@ mexui.Control.TextInput.prototype.onMouseDown = function(e)
this.caretPosition = this.getCaretPositionByCursor();
}
}
mexui.Component.Control.prototype.onMouseDown.call(this, e);
};
@@ -57,11 +57,11 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
if(!isValid1 && isValid1 !== undefined)
return;
*/
var isValid2 = this.validateInputCallback ? this.validateInputCallback(e, character) : true;
if(!isValid2)
return;
if(this.singleCharacter)
{
this.resetText();
@@ -73,7 +73,7 @@ mexui.Control.TextInput.prototype.onCharacter = function(e, character)
this.lines[this.caretPosition.y] = this.getTextWithNewCharacter(character);
this.caretPosition.x++;
}
this.checkToCallCallback();
this.validateValue(e);
}
@@ -83,9 +83,9 @@ 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:
@@ -156,7 +156,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
}
break;
}
if(this.multiLine)
{
switch(key)
@@ -199,7 +199,7 @@ mexui.Control.TextInput.prototype.onKeyDown = function(e, key, mods)
break;
}
}
this.validateValue(e);
};
@@ -208,9 +208,9 @@ mexui.Control.TextInput.prototype.render = function()
{
var pos = this.getScreenPosition();
var pos2 = new Vec2(pos.x, pos.y);
mexui.native.drawRectangle(pos, this.size, this.getStyles('main'));
if(this.isEmpty())
{
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];
mexui.native.drawText(pos, lineSize, displayedText, this.getStyles('main'));
pos.y += this.lineHeight;
}
}
var valueIsInvalid = !this.isEmpty() && !this.validValue;
if(this.isFocused())
{
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'));
if(this.caretShownForBlink)
{
var pos = this.getScreenPosition();
@@ -246,7 +246,7 @@ mexui.Control.TextInput.prototype.render = function()
mexui.native.drawAALine(caretPoint1, caretPoint2, this.getStyles('caret'));
}
}
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'));
};
@@ -269,7 +269,7 @@ mexui.Control.TextInput.prototype.clampCaretPosition = function()
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)
@@ -287,7 +287,7 @@ 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))
@@ -301,12 +301,12 @@ 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;
}

View File

@@ -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);

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.Entity.ControlWithEntries.call(this, false, false);
this.rowHeight = 25;
this.rowLevelIndentation = 10;
this.scrollMultiplier = 10.0;
@@ -32,10 +32,10 @@ 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);
};
@@ -45,9 +45,9 @@ mexui.Control.Tree.prototype.render = function()
{
var pos = this.getScreenPosition();
pos.y -= this.axis.y.getScrolledOffset();
this.renderRows(this.axis.y.entries, 0, pos);
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'));
};
@@ -58,23 +58,23 @@ mexui.Control.Tree.prototype.renderRows = function(rows, level, pos)
{
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;
@@ -106,7 +106,7 @@ 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))
@@ -115,9 +115,9 @@ mexui.Control.Tree.prototype.testRowClick = function(e, rows, pos)
e.used = true;
return;
}
pos.y += this.rowHeight;
if(row.rows.length > 0 && row.open)
{
this.testRowClick(e, row.rows, pos);
@@ -132,10 +132,10 @@ 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)
{
@@ -153,3 +153,4 @@ mexui.Control.Tree.prototype.row = function(text)
this.axis.y.addEntry(entry);
return entry;
};

View File

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

View File

@@ -1,7 +1,7 @@
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);
this.maxYearOffset = 10;
this.minYearCallback = ()=>{ return 1900; };
this.maxYearCallback = ()=>{ return new Date().getFullYear() + this.maxYearOffset; }

View File

@@ -1,7 +1,7 @@
mexui.Entity.Component = function(moveable)
{
this.moveable = moveable;
this.moving = false;
};
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.isVertical = isVertical;
this.manualScrollBar = manualScrollBar;
this.axisIndex = isVertical ? 1 : 0;
this.entriesShown = true;
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));
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, this.getDisplayedEntriesLength(), 25, false, this.control.styles.scrollBar);
}
if(this.manualScrollBar)
this.scrollBar.shown = false;
};
@@ -73,19 +73,19 @@ mexui.Entity.ControlAxis.prototype.getEntryIndexByPoint = function(point)
{
return null;
}
var pos = new Vec2(screenPos.x + this.control.entriesPositionOffset.x, screenPos.y + this.control.entriesPositionOffset.y);
var index = Math.floor((point.y - pos.y) / this.control.entrySize[this.axisIndex]);
index += this.getEntryStartIndex();
if(index < 0 || index >= this.entries.length)
return null;
return index;
}
else
{
}
};
@@ -121,7 +121,7 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntriesLength = function()
mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual)
{
this.manualScrollBar = manual;
if(manual)
{
this.setScrollBarShown(false);
@@ -150,7 +150,7 @@ mexui.Entity.ControlAxis.prototype.checkToShowScrollBar = function()
{
if(this.manualScrollBar)
return;
this.setScrollBarShown(this.shouldDisplayScrollBar(), true);
};
@@ -160,7 +160,7 @@ mexui.Entity.ControlAxis.prototype.getScrolledOffset = function()
{
if(!this.scrollBar.shown)
return 0;
return this.scrollBar.scrolledRatio * this.getScrollableLength();
}
else
@@ -197,3 +197,4 @@ mexui.Entity.ControlAxis.prototype.getDisplayedEntryCount = function()
var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]);
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.entrySize = entrySize || new Vec2(this.size.x, 25);
this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0);
this.axis = {};
this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset);
this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset);
this.axis.x.initScrollBar();
this.axis.y.initScrollBar();
this.checkToShowScrollBars();
};
mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control);
@@ -46,7 +46,7 @@ mexui.Entity.ControlWithEntries.prototype.onMouseMove = function(e, offset)
}
}
}
if(!e.used)
this.triggerEvent('onMouseMove', e, offset);
};
@@ -74,7 +74,7 @@ mexui.Entity.ControlWithEntries.prototype.triggerEvent = function(eventName, e,
return;
}
}
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.y.removeAllEntries();
};

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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