Revert "Update xml"

This reverts commit 9b8d1f2257.
This commit is contained in:
Vortrex
2021-01-26 04:16:05 -06:00
parent 9b8d1f2257
commit caa6b3986f
190 changed files with 5046 additions and 83 deletions

View File

@@ -0,0 +1,41 @@
mexui.Entity.Component = function(moveable)
{
this.moveable = moveable;
this.moving = false;
};
mexui.util.extend(mexui.Entity.Component, mexui.Entity.StyleableEntity);
// input
mexui.Entity.Component.prototype.onMouseDown = function(e)
{
if(e.button == 0 && this.moveable && this.isCursorOverComponent())
{
this.moving = true;
e.used = true;
}
};
mexui.Entity.Component.prototype.onMouseUp = function(e)
{
if(e.button == 0 && this.moving)
{
this.moving = false;
e.used = true;
}
};
mexui.Entity.Component.prototype.onMouseMove = function(e, offset)
{
if(this.moving)
{
this.position = new Vec2(this.position.x + offset.x, this.position.y + offset.y);
e.used = true;
}
};
// model
mexui.Entity.Component.prototype.isCursorOverComponent = function()
{
return mexui.util.isCursorInRectangle(this.getScreenPosition(), this.size);
};

View File

@@ -0,0 +1,200 @@
mexui.Entity.ControlAxis = function(control, isVertical, manualScrollBar, entriesPositionOffset)
{
this.control = control;
this.isVertical = isVertical;
this.manualScrollBar = manualScrollBar;
this.axisIndex = isVertical ? 1 : 0;
this.entriesShown = true;
this.entryCountShown = 15;
this.hoveredEntryIndex = -1;
this.entries = [];
this.scrollBar = [];
};
// model
// scroll bar initialization
mexui.Entity.ControlAxis.prototype.initScrollBar = function()
{
if(this.isVertical)
{
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entrySize.x, this.control.entriesPositionOffset.y));
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, 25, this.getDisplayedEntriesLength(), true, this.control.styles.scrollBar);
}
else
{
var pos = mexui.util.addVec2(this.control.position, new Vec2(this.control.entriesPositionOffset.x, this.control.size.y));
this.scrollBar = new mexui.Control.ScrollBar(this.control.window, pos.x, pos.y, this.getDisplayedEntriesLength(), 25, false, this.control.styles.scrollBar);
}
if(this.manualScrollBar)
this.scrollBar.shown = false;
};
// add/remove entries
mexui.Entity.ControlAxis.prototype.addEntry = function(entry)
{
this.entries.push(entry);
this.checkToShowScrollBar();
};
mexui.Entity.ControlAxis.prototype.removeAllEntries = function()
{
this.entries = [];
this.checkToShowScrollBar();
};
// fetch entry by position
mexui.Entity.ControlAxis.prototype.getEntryByCursor = function()
{
return this.getEntryByPoint(gui.cursorPosition);
};
mexui.Entity.ControlAxis.prototype.getEntryIndexByCursor = function()
{
return this.getEntryIndexByPoint(gui.cursorPosition);
};
mexui.Entity.ControlAxis.prototype.getEntryByPoint = function(point)
{
var index = this.getEntryIndexByPoint(point);
if(index == null)
return null;
return this.entries[index];
};
mexui.Entity.ControlAxis.prototype.getEntryIndexByPoint = function(point)
{
var screenPos = this.control.getScreenPosition();
if(this.axisIndex == 1)
{
if(point.x < screenPos.x || point.x > (screenPos.x + this.control.entrySize.x))
{
return null;
}
var pos = new Vec2(screenPos.x + this.control.entriesPositionOffset.x, screenPos.y + this.control.entriesPositionOffset.y);
var index = Math.floor((point.y - pos.y) / this.control.entrySize[this.axisIndex]);
index += this.getEntryStartIndex();
if(index < 0 || index >= this.entries.length)
return null;
return index;
}
else
{
}
};
// entries sizing
mexui.Entity.ControlAxis.prototype.getOutsideEntriesLength = function()
{
return this.control.entrySize[this.axisIndex] * this.entryCountShown;
};
mexui.Entity.ControlAxis.prototype.getAllEntriesLength = function()
{
if(this.control.getAllEntriesLength)
return this.control.getAllEntriesLength(this.axisIndex);
else
return this.getAllEntriesLength2();
};
mexui.Entity.ControlAxis.prototype.getAllEntriesLength2 = function()
{
return this.entries.length * this.control.entrySize[this.axisIndex];
};
mexui.Entity.ControlAxis.prototype.getDisplayedEntriesLength = function()
{
var sizeOffset = this.control.entriesSizeOffset[this.axisIndex];
if(this.control.entriesOutsideControl)
return this.getOutsideEntriesLength() + sizeOffset;
else
return this.control.size[this.axisIndex] + sizeOffset;
};
// entry scrolling
mexui.Entity.ControlAxis.prototype.setScrollBarManual = function(manual)
{
this.manualScrollBar = manual;
if(manual)
{
this.setScrollBarShown(false);
}
};
mexui.Entity.ControlAxis.prototype.setScrollBarShown = function(shown)
{
//if(axisIndex != this.axisIndex)
// shown = false;
this.scrollBar.shown = shown;
if(!shown)
this.scrollBar.scrolledRatio = 0.0;
};
mexui.Entity.ControlAxis.prototype.shouldDisplayScrollBar = function()
{
//if(axisIndex != this.axisIndex)
// return false;
return this.getAllEntriesLength() > this.scrollBar.size[this.axisIndex];
};
mexui.Entity.ControlAxis.prototype.checkToShowScrollBar = function()
{
if(this.manualScrollBar)
return;
this.setScrollBarShown(this.shouldDisplayScrollBar(), true);
};
mexui.Entity.ControlAxis.prototype.getScrolledOffset = function()
{
if(this.axisIndex == 1)
{
if(!this.scrollBar.shown)
return 0;
return this.scrollBar.scrolledRatio * this.getScrollableLength();
}
else
{
return 0;
}
};
mexui.Entity.ControlAxis.prototype.getScrolledOffsetFixedStart = function()
{
var entryLength = this.control.entrySize[this.axisIndex];
return Math.floor(this.getScrolledOffset() / entryLength) * entryLength;
};
mexui.Entity.ControlAxis.prototype.getScrollableLength = function()
{
return this.getAllEntriesLength() - this.getOutsideEntriesLength();
};
// entry iteration
mexui.Entity.ControlAxis.prototype.getEntryStartIndex = function() // inclusive
{
return Math.floor(this.getScrolledOffset() / this.control.entrySize[this.axisIndex]);
};
mexui.Entity.ControlAxis.prototype.getEntryEndIndex = function() // exclusive
{
return this.getEntryStartIndex() + this.getDisplayedEntryCount();
};
mexui.Entity.ControlAxis.prototype.getDisplayedEntryCount = function()
{
var displayedEntriesLength = this.getDisplayedEntriesLength();
var displayedEntryCount = Math.floor(displayedEntriesLength / this.control.entrySize[this.axisIndex]);
return this.entries.length < displayedEntryCount ? this.entries.length : displayedEntryCount;
};

View File

@@ -0,0 +1,98 @@
mexui.Entity.ControlWithEntries = function(entriesOutsideControl, manualScrollBar, entriesPositionOffset, entrySize, entriesSizeOffset)
{
this.entriesOutsideControl = entriesOutsideControl;
this.entriesPositionOffset = entriesPositionOffset || new Vec2(0, 0);
this.entrySize = entrySize || new Vec2(this.size.x, 25);
this.entriesSizeOffset = entriesSizeOffset || new Vec2(0, 0);
this.axis = {};
this.axis.x = new mexui.Entity.ControlAxis(this, false, manualScrollBar, entriesPositionOffset);
this.axis.y = new mexui.Entity.ControlAxis(this, true, manualScrollBar, entriesPositionOffset);
this.axis.x.initScrollBar();
this.axis.y.initScrollBar();
this.checkToShowScrollBars();
};
mexui.util.extend(mexui.Entity.ControlWithEntries, mexui.Component.Control);
// input
mexui.Entity.ControlWithEntries.prototype.onMouseDown = function(e)
{
this.triggerEvent('onMouseDown', e);
};
mexui.Entity.ControlWithEntries.prototype.onMouseUp = function(e)
{
this.triggerEvent('onMouseUp', e);
};
mexui.Entity.ControlWithEntries.prototype.onMouseMove = function(e, offset)
{
for(var k in this.axis)
{
if(this.axis[k].entriesShown)
{
var hoveredEntryIndex = this.axis[k].getEntryIndexByCursor();
if(hoveredEntryIndex == null)
{
this.axis[k].hoveredEntryIndex = -1;
}
else
{
e.used = true;
this.axis[k].hoveredEntryIndex = hoveredEntryIndex;
break;
}
}
}
if(!e.used)
this.triggerEvent('onMouseMove', e, offset);
};
mexui.Entity.ControlWithEntries.prototype.onMouseWheel = function(e, data)
{
this.triggerEvent('onMouseWheel', e, data);
};
// render
mexui.Entity.ControlWithEntries.prototype.renderAfter = function()
{
this.triggerEvent('renderAfter');
};
// model
mexui.Entity.ControlWithEntries.prototype.triggerEvent = function(eventName, e, data)
{
for(var k in this.axis)
{
if(this.axis[k].scrollBar.shown)
{
this.axis[k].scrollBar[eventName].call(this.axis[k].scrollBar, e, data);
if(e && e.used)
return;
}
}
mexui.Component.Control.prototype[eventName].call(this, e, data);
};
mexui.Entity.ControlWithEntries.prototype.checkToShowScrollBars = function()
{
this.axis.x.checkToShowScrollBar();
this.axis.y.checkToShowScrollBar();
};
mexui.Entity.ControlWithEntries.prototype.setScrollBarsManual = function(manual)
{
this.axis.x.setScrollBarManual(manual);
this.axis.y.setScrollBarManual(manual);
};
mexui.Entity.ControlWithEntries.prototype.removeAllEntries = function()
{
this.axis.x.removeAllEntries();
this.axis.y.removeAllEntries();
};

View File

@@ -0,0 +1,210 @@
mexui.Entity.StyleableEntity = function(styles)
{
this.styles = styles;
this.shown = true;
//this.hovered = false;
this.transitions = {}; // string controlPartName => Transition transition
/*
this.transitionDelayTimer = null;
this.transitionStartTime = 0;
this.transitionEndTime = 0;
this.transitionIsProcessing = false;
this.transitionIsReverting = false;
this.transitionProgressReached = 0.0;
*/
};
// default styles
mexui.Entity.StyleableEntity.globalDefaultStyles = {
all:
{
textFont: 'Arial',
textSize: 14.0,
textAlign: 0.0,
textIndent: 5,
textColour: toColour(0, 0, 0, 255),
backgroundColour: toColour(255, 255, 255, 255),
lineWeight: 1
}
};
mexui.Entity.StyleableEntity.defaultStyles = mexui.util.linkGlobalStyles(mexui.Entity.StyleableEntity.globalDefaultStyles, {
main:
{
backgroundColour: toColour(255, 255, 255, 255),
borderColour: 'none',
textColour: toColour(0, 0, 0, 255),
hover:
{
backgroundColour: toColour(220, 220, 220, 255),
borderColour: 'none',
textColour: toColour(0, 0, 0, 255)
}/*,
focus:
{
borderColour: toColour(255, 128, 0, 230),
textColour: toColour(0, 0, 0, 255)
}
*/
},
focused:
{
borderColour: toColour(28, 119, 198, 255)
},
invalidValue:
{
borderColour: toColour(250, 5, 5, 255)
}
});
// model
mexui.Entity.StyleableEntity.prototype.linkControlStyles = function(controlName, styles)
{
return mexui.util.linkStyles(mexui.Control[controlName].defaultStyles, styles);
};
mexui.Entity.StyleableEntity.prototype.linkComponentStyles = function(componentName, styles)
{
return mexui.util.linkStyles(mexui.Component[componentName].defaultStyles, styles);
};
mexui.Entity.StyleableEntity.prototype.linkEntryStyles = function(entryName, styles)
{
return mexui.util.linkStyles(mexui.Entry[entryName].defaultStyles, styles);
};
mexui.Entity.StyleableEntity.prototype.isFocused = function()
{
return this == mexui.focusedControl;
};
mexui.Entity.StyleableEntity.prototype.isHovered = function()
{
//return this.hovered;
return this == mexui.hoveredComponent;
};
mexui.Entity.StyleableEntity.prototype.getStyles = function(controlPartName)
{
var isFocused = this.isFocused();
var isHovered = this.isHovered();
var styles = this.styles[controlPartName];
var transition = this.getTransition(controlPartName);
if(transition.isProcessing())
{
return mexui.util.getTransitionStyles(styles, ['hover'], transition.getMainToPseudoProgress());
}
if(isHovered)
{
return mexui.util.mergeStyles(styles, ['hover']);
}
return styles;
};
mexui.Entity.StyleableEntity.prototype.getEntryStyles = function(data)
{
var styles = {};
for(var i in data)
{
var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles)
{
if(baseStyles.hasOwnProperty(k) && styles[k] === undefined)
{
styles[k] = baseStyles[k];
}
}
}
for(var i in data)
{
var baseStyles = data[i][0].getStyles(data[i][1]);
for(var k in baseStyles)
{
if(styles[k] === undefined)
{
styles[k] = baseStyles[k];
}
}
}
return styles;
};
// custom events
mexui.Entity.StyleableEntity.prototype.onMouseEnter = function()
{
var controlParts = this.getControlPartsWithTransition();
for(var i in controlParts)
{
var transition = this.getTransition(controlParts[i]);
var delay = this.getTransitionDelayStyle(controlParts[i]);
var time = this.getTransitionTimeStyle(controlParts[i]);
transition.onMouseEnter(delay, time);
}
};
mexui.Entity.StyleableEntity.prototype.onMouseExit = function()
{
var controlParts = this.getControlPartsWithTransition();
for(var i in controlParts)
{
var transition = this.getTransition(controlParts[i]);
transition.onMouseExit();
}
};
// transitions
mexui.Entity.StyleableEntity.prototype.getTransition = function(controlPartName)
{
if(!this.transitions[controlPartName])
this.transitions[controlPartName] = new mexui.Entity.Transition;
return this.transitions[controlPartName];
};
mexui.Entity.StyleableEntity.prototype.getControlPartsWithTransition = function()
{
var controlParts = [];
for(var k in this.styles)
{
if(this.styles[k].hover && (this.styles[k].hover.transitionTime != null || this.styles[k].hover.transitionDelay != null))
{
controlParts.push(k);
}
}
return controlParts;
};
mexui.Entity.StyleableEntity.prototype.getTransitionDelayStyle = function(controlPartName)
{
if(this.styles[controlPartName].hover.transitionDelay != null)
return this.styles[controlPartName].hover.transitionDelay;
else
return mexui.Entity.Transition.defaultTransitionDelay;
};
mexui.Entity.StyleableEntity.prototype.getTransitionTimeStyle = function(controlPartName)
{
if(this.styles[controlPartName].hover.transitionTime != null)
return this.styles[controlPartName].hover.transitionTime;
else
return mexui.Entity.Transition.defaultTransitionTime;
};

View File

@@ -0,0 +1,184 @@
mexui.Entity.Transition = function()
{
this.processing = false;
this.interpolating = false;
this.mainToPseudoProgress = 0.0;
this.delayTimer = null;
this.transitionDelay = mexui.Entity.Transition.defaultTransitionDelay;
this.transitionTime = mexui.Entity.Transition.defaultTransitionTime;
this.mouseIsEntered = false;
this.lastUpdateTime = mexui.util.time();
this.direction = true;
};
// static
mexui.Entity.Transition.defaultTransitionDelay = 0;
mexui.Entity.Transition.defaultTransitionTime = 1000;//400;
// custom events
mexui.Entity.Transition.prototype.onMouseEnter = function(transitionDelay, transitionTime)
{
if(this.isMouseEntered())
return;
this.setMouseEntered(true);
this.transitionDelay = transitionDelay;
this.transitionTime = transitionTime;
if(transitionDelay > 0)
{
this.startDelay();
}
else if(this.isInterpolating())
{
this.revertInterpolationDirection();
}
else
{
this.startEnterInterpolation();
}
};
mexui.Entity.Transition.prototype.onMouseExit = function()
{
if(!this.isMouseEntered())
return;
this.setMouseEntered(false);
if(this.isDelayActive())
{
this.clearDelayTimer();
}
else if(this.isInterpolating())
{
this.revertInterpolationDirection();
}
else
{
this.startExitInterpolation();
}
};
// model
mexui.Entity.Transition.prototype.setMouseEntered = function(status)
{
this.mouseIsEntered = status;
};
mexui.Entity.Transition.prototype.isMouseEntered = function()
{
return this.mouseIsEntered;
};
// processing
mexui.Entity.Transition.prototype.isProcessing = function()
{
return this.processing;
};
mexui.Entity.Transition.prototype.stopProcessing = function()
{
if(this.isInterpolating())
{
this.stopInterpolation();
}
this.delayTimer = null;
this.processing = false;
};
// interpolation status
mexui.Entity.Transition.prototype.startEnterInterpolation = function()
{
this.lastUpdateTime = mexui.util.time();
this.processing = true;
this.interpolating = true;
this.direction = true;
this.mainToPseudoProgress = 0.0;
};
mexui.Entity.Transition.prototype.startExitInterpolation = function()
{
this.lastUpdateTime = mexui.util.time();
this.processing = true;
this.interpolating = true;
this.direction = false;
this.mainToPseudoProgress = 1.0;
};
mexui.Entity.Transition.prototype.stopInterpolation = function()
{
this.interpolating = false;
};
mexui.Entity.Transition.prototype.isInterpolating = function()
{
return this.interpolating;
};
// interpolation direction
mexui.Entity.Transition.prototype.revertInterpolationDirection = function()
{
this.lastUpdateTime = mexui.util.time();
this.direction = !this.direction;
};
// progress
mexui.Entity.Transition.prototype.increaseMainToPseudoProgress = function()
{
var timeDiff = mexui.util.time() - this.lastUpdateTime;
this.lastUpdateTime = mexui.util.time();
var progressDiff = timeDiff / this.transitionTime;
if(this.direction)
this.mainToPseudoProgress += progressDiff;
else
this.mainToPseudoProgress -= progressDiff;
if(this.mainToPseudoProgress < 0.0)
{
this.mainToPseudoProgress = 0.0;
this.stopProcessing();
}
else if(this.mainToPseudoProgress > 1.0)
{
this.mainToPseudoProgress = 1.0;
}
};
mexui.Entity.Transition.prototype.getMainToPseudoProgress = function()
{
this.increaseMainToPseudoProgress();
return this.mainToPseudoProgress;
};
mexui.Entity.Transition.prototype.getCompletionProgress = function()
{
if(this.direction)
return this.mainToPseudoProgress;
else
return 1.0 - this.mainToPseudoProgress;
};
mexui.Entity.Transition.prototype.startDelay = function()
{
var that = this;
this.delayTimer = setTimeout(function()
{
that.delayTimer = null;
that.startEnterInterpolation.call(that);
}, this.transitionDelay);
};
mexui.Entity.Transition.prototype.isDelayActive = function()
{
return this.delayTimer != null;
};
mexui.Entity.Transition.prototype.clearDelayTimer = function()
{
clearTimeout(this.delayTimer);
this.delayTimer = null;
};