commit
319f32cdaa
|
@ -128,7 +128,7 @@ void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWal
|
||||||
dest -= datType->getDisplacement() * scaleFactor;
|
dest -= datType->getDisplacement() * scaleFactor;
|
||||||
datType->draw(dest, scaleFactor, 0, xPattern, 0, 0, animationPhase, lightView);
|
datType->draw(dest, scaleFactor, 0, xPattern, 0, 0, animationPhase, lightView);
|
||||||
dest += getDisplacement() * scaleFactor;
|
dest += getDisplacement() * scaleFactor;
|
||||||
zPattern = std::min(1, getNumPatternZ() - 1);
|
zPattern = std::min<int>(1, getNumPatternZ() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
PointF jumpOffset = m_jumpOffset * scaleFactor;
|
PointF jumpOffset = m_jumpOffset * scaleFactor;
|
||||||
|
@ -183,7 +183,7 @@ void Creature::internalDrawOutfit(Point dest, float scaleFactor, bool animateWal
|
||||||
}
|
}
|
||||||
|
|
||||||
if(m_outfit.getCategory() == ThingCategoryEffect)
|
if(m_outfit.getCategory() == ThingCategoryEffect)
|
||||||
animationPhase = std::min(animationPhase+1, animationPhases);
|
animationPhase = std::min<int>(animationPhase+1, animationPhases);
|
||||||
|
|
||||||
type->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase, lightView);
|
type->draw(dest - (getDisplacement() * scaleFactor), scaleFactor, 0, 0, 0, 0, animationPhase, lightView);
|
||||||
}
|
}
|
||||||
|
@ -480,7 +480,7 @@ void Creature::updateWalkAnimation(int totalPixelsWalked)
|
||||||
if(!self->m_walking || self->m_walkTimer.ticksElapsed() >= self->getStepDuration(true))
|
if(!self->m_walking || self->m_walkTimer.ticksElapsed() >= self->getStepDuration(true))
|
||||||
self->m_walkAnimationPhase = 0;
|
self->m_walkAnimationPhase = 0;
|
||||||
self->m_walkFinishAnimEvent = nullptr;
|
self->m_walkFinishAnimEvent = nullptr;
|
||||||
}, std::min(footDelay, 200));
|
}, std::min<int>(footDelay, 200));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -553,7 +553,7 @@ void Creature::nextWalkUpdate()
|
||||||
void Creature::updateWalk()
|
void Creature::updateWalk()
|
||||||
{
|
{
|
||||||
float walkTicksPerPixel = getStepDuration(true) / 32;
|
float walkTicksPerPixel = getStepDuration(true) / 32;
|
||||||
int totalPixelsWalked = std::min(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
|
int totalPixelsWalked = std::min<int>(m_walkTimer.ticksElapsed() / walkTicksPerPixel, 32.0f);
|
||||||
|
|
||||||
// needed for paralyze effect
|
// needed for paralyze effect
|
||||||
m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked);
|
m_walkedPixels = std::max<int>(m_walkedPixels, totalPixelsWalked);
|
||||||
|
|
|
@ -50,7 +50,7 @@ TexturePtr LightView::generateLightBubble(float centerFactor)
|
||||||
for(int x = 0; x < bubbleDiameter; x++) {
|
for(int x = 0; x < bubbleDiameter; x++) {
|
||||||
for(int y = 0; y < bubbleDiameter; y++) {
|
for(int y = 0; y < bubbleDiameter; y++) {
|
||||||
float radius = std::sqrt((bubbleRadius - x)*(bubbleRadius - x) + (bubbleRadius - y)*(bubbleRadius - y));
|
float radius = std::sqrt((bubbleRadius - x)*(bubbleRadius - x) + (bubbleRadius - y)*(bubbleRadius - y));
|
||||||
float intensity = std::max<float>(std::min<float>((bubbleRadius-radius)/(float)(bubbleRadius-centerRadius), 1.0f), 0.0f);
|
float intensity = stdext::clamp<float>((bubbleRadius - radius) / (float)(bubbleRadius - centerRadius), 0.0f, 1.0f);
|
||||||
|
|
||||||
// light intensity varies inversely with the square of the distance
|
// light intensity varies inversely with the square of the distance
|
||||||
intensity = intensity * intensity;
|
intensity = intensity * intensity;
|
||||||
|
|
|
@ -644,7 +644,7 @@ int MapView::calcFirstVisibleFloor()
|
||||||
}
|
}
|
||||||
|
|
||||||
// just ensure the that the floor is in the valid range
|
// just ensure the that the floor is in the valid range
|
||||||
z = std::min<int>(std::max<int>(z, 0), (int)Otc::MAX_Z);
|
z = stdext::clamp<int>(z, 0, (int)Otc::MAX_Z);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -669,7 +669,7 @@ int MapView::calcLastVisibleFloor()
|
||||||
z = std::max<int>(m_lockedFirstVisibleFloor, z);
|
z = std::max<int>(m_lockedFirstVisibleFloor, z);
|
||||||
|
|
||||||
// just ensure the that the floor is in the valid range
|
// just ensure the that the floor is in the valid range
|
||||||
z = std::min<int>(std::max<int>(z, 0), (int)Otc::MAX_Z);
|
z = stdext::clamp<int>(z, 0, (int)Otc::MAX_Z);
|
||||||
return z;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -77,7 +77,7 @@ void UIMap::movePixels(int x, int y)
|
||||||
|
|
||||||
bool UIMap::setZoom(int zoom)
|
bool UIMap::setZoom(int zoom)
|
||||||
{
|
{
|
||||||
m_zoom = std::min<int>(std::max<int>(zoom, m_maxZoomIn), m_maxZoomOut);
|
m_zoom = stdext::clamp<int>(zoom, m_maxZoomIn, m_maxZoomOut);
|
||||||
updateVisibleDimension();
|
updateVisibleDimension();
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -84,7 +84,7 @@ void UIProgressRect::drawSelf(Fw::DrawPane drawPane)
|
||||||
|
|
||||||
void UIProgressRect::setPercent(float percent)
|
void UIProgressRect::setPercent(float percent)
|
||||||
{
|
{
|
||||||
m_percent = std::max<float>(std::min<float>((double)percent, 100.0), 0.0);
|
m_percent = stdext::clamp<float>((double)percent, 0.0, 100.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
void UIProgressRect::onStyleApply(const std::string& styleName, const OTMLNodePtr& styleNode)
|
||||||
|
|
|
@ -89,7 +89,7 @@ bool AdaptativeFrameCounter::update()
|
||||||
|
|
||||||
void AdaptativeFrameCounter::setMaxFps(int maxFps)
|
void AdaptativeFrameCounter::setMaxFps(int maxFps)
|
||||||
{
|
{
|
||||||
maxFps = std::max<int>(std::min<int>(maxFps, 1000), 0);
|
maxFps = stdext::clamp<int>(maxFps, 0, 1000);
|
||||||
|
|
||||||
if(maxFps != 0) {
|
if(maxFps != 0) {
|
||||||
m_bestFrameDelay = 1000000 / maxFps;
|
m_bestFrameDelay = 1000000 / maxFps;
|
||||||
|
|
|
@ -170,7 +170,7 @@ bool Texture::setupSize(const Size& size, bool forcePowerOfTwo)
|
||||||
glSize = size;
|
glSize = size;
|
||||||
|
|
||||||
// checks texture max size
|
// checks texture max size
|
||||||
if(std::max(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) {
|
if(std::max<int>(glSize.width(), glSize.height()) > g_graphics.getMaxTextureSize()) {
|
||||||
g_logger.error(stdext::format("loading texture with size %dx%d failed, "
|
g_logger.error(stdext::format("loading texture with size %dx%d failed, "
|
||||||
"the maximum size allowed by the graphics card is %dx%d,"
|
"the maximum size allowed by the graphics card is %dx%d,"
|
||||||
"to prevent crashes the texture will be displayed as a blank texture",
|
"to prevent crashes the texture will be displayed as a blank texture",
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
#ifndef STDEXT_MATH_H
|
#ifndef STDEXT_MATH_H
|
||||||
#define STDEXT_MATH_H
|
#define STDEXT_MATH_H
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
#include "types.h"
|
#include "types.h"
|
||||||
|
|
||||||
namespace stdext {
|
namespace stdext {
|
||||||
|
@ -45,6 +46,9 @@ float random_range(float min, float max);
|
||||||
|
|
||||||
double round(double r);
|
double round(double r);
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
T clamp(T x, T min, T max) { return std::max<T>(min, std::min<T>(x, max)); }
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -66,10 +66,10 @@ bool UIHorizontalLayout::internalUpdate()
|
||||||
pos.y = paddingRect.top() + widget->getMarginTop();
|
pos.y = paddingRect.top() + widget->getMarginTop();
|
||||||
} else if(widget->getTextAlign() & Fw::AlignBottom) {
|
} else if(widget->getTextAlign() & Fw::AlignBottom) {
|
||||||
pos.y = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
|
pos.y = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
|
||||||
pos.y = std::max(pos.y, paddingRect.top());
|
pos.y = std::max<int>(pos.y, paddingRect.top());
|
||||||
} else { // center it
|
} else { // center it
|
||||||
pos.y = paddingRect.top() + (paddingRect.height() - (widget->getMarginTop() + widget->getHeight() + widget->getMarginBottom()))/2;
|
pos.y = paddingRect.top() + (paddingRect.height() - (widget->getMarginTop() + widget->getHeight() + widget->getMarginBottom()))/2;
|
||||||
pos.y = std::max(pos.y, paddingRect.top());
|
pos.y = std::max<int>(pos.y, paddingRect.top());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// expand height
|
// expand height
|
||||||
|
|
|
@ -40,7 +40,7 @@ public:
|
||||||
virtual void addWidget(const UIWidgetPtr& widget) { }
|
virtual void addWidget(const UIWidgetPtr& widget) { }
|
||||||
virtual void removeWidget(const UIWidgetPtr& widget) { }
|
virtual void removeWidget(const UIWidgetPtr& widget) { }
|
||||||
void disableUpdates() { m_updateDisabled++; }
|
void disableUpdates() { m_updateDisabled++; }
|
||||||
void enableUpdates() { m_updateDisabled = std::max(m_updateDisabled-1,0); }
|
void enableUpdates() { m_updateDisabled = std::max<int>(m_updateDisabled-1,0); }
|
||||||
|
|
||||||
void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; }
|
void setParent(UIWidgetPtr parentWidget) { m_parentWidget = parentWidget; }
|
||||||
UIWidgetPtr getParentWidget() { return m_parentWidget; }
|
UIWidgetPtr getParentWidget() { return m_parentWidget; }
|
||||||
|
|
|
@ -181,15 +181,15 @@ void UITextEdit::update(bool focusCursor)
|
||||||
if(!virtualRect.contains(glyphRect.topLeft()) || !virtualRect.contains(glyphRect.bottomRight())) {
|
if(!virtualRect.contains(glyphRect.topLeft()) || !virtualRect.contains(glyphRect.bottomRight())) {
|
||||||
// calculate where is the first glyph visible
|
// calculate where is the first glyph visible
|
||||||
Point startGlyphPos;
|
Point startGlyphPos;
|
||||||
startGlyphPos.y = std::max(glyphRect.bottom() - virtualRect.height(), 0);
|
startGlyphPos.y = std::max<int>(glyphRect.bottom() - virtualRect.height(), 0);
|
||||||
startGlyphPos.x = std::max(glyphRect.right() - virtualRect.width(), 0);
|
startGlyphPos.x = std::max<int>(glyphRect.right() - virtualRect.width(), 0);
|
||||||
|
|
||||||
// find that glyph
|
// find that glyph
|
||||||
for(pos = 0; pos < textLength; ++pos) {
|
for(pos = 0; pos < textLength; ++pos) {
|
||||||
glyph = (uchar)text[pos];
|
glyph = (uchar)text[pos];
|
||||||
glyphRect = Rect(glyphsPositions[pos], glyphsSize[glyph]);
|
glyphRect = Rect(glyphsPositions[pos], glyphsSize[glyph]);
|
||||||
glyphRect.setTop(std::max(glyphRect.top() - m_font->getYOffset() - m_font->getGlyphSpacing().height(), 0));
|
glyphRect.setTop(std::max<int>(glyphRect.top() - m_font->getYOffset() - m_font->getGlyphSpacing().height(), 0));
|
||||||
glyphRect.setLeft(std::max(glyphRect.left() - m_font->getGlyphSpacing().width(), 0));
|
glyphRect.setLeft(std::max<int>(glyphRect.left() - m_font->getGlyphSpacing().width(), 0));
|
||||||
|
|
||||||
// first glyph entirely visible found
|
// first glyph entirely visible found
|
||||||
if(glyphRect.topLeft() >= startGlyphPos) {
|
if(glyphRect.topLeft() >= startGlyphPos) {
|
||||||
|
@ -358,8 +358,8 @@ void UITextEdit::setSelection(int start, int end)
|
||||||
if(end == -1)
|
if(end == -1)
|
||||||
end = m_text.length();
|
end = m_text.length();
|
||||||
|
|
||||||
m_selectionStart = std::min(std::max(start, 0), (int)m_text.length());
|
m_selectionStart = stdext::clamp<int>(start, 0, (int)m_text.length());
|
||||||
m_selectionEnd = std::min(std::max(end, 0), (int)m_text.length());
|
m_selectionEnd = stdext::clamp<int>(end, 0, (int)m_text.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
void UITextEdit::setTextHidden(bool hidden)
|
void UITextEdit::setTextHidden(bool hidden)
|
||||||
|
|
|
@ -68,10 +68,10 @@ bool UIVerticalLayout::internalUpdate()
|
||||||
pos.x = paddingRect.left() + widget->getMarginLeft();
|
pos.x = paddingRect.left() + widget->getMarginLeft();
|
||||||
} else if(widget->getTextAlign() & Fw::AlignLeft) {
|
} else if(widget->getTextAlign() & Fw::AlignLeft) {
|
||||||
pos.x = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
|
pos.x = paddingRect.bottom() - widget->getHeight() - widget->getMarginBottom();
|
||||||
pos.x = std::max(pos.x, paddingRect.left());
|
pos.x = std::max<int>(pos.x, paddingRect.left());
|
||||||
} else {
|
} else {
|
||||||
pos.x = paddingRect.left() + (paddingRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
pos.x = paddingRect.left() + (paddingRect.width() - (widget->getMarginLeft() + widget->getWidth() + widget->getMarginRight()))/2;
|
||||||
pos.x = std::max(pos.x, paddingRect.left());
|
pos.x = std::max<int>(pos.x, paddingRect.left());
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// expand width
|
// expand width
|
||||||
|
|
|
@ -192,7 +192,7 @@ void UIWidget::insertChild(int index, const UIWidgetPtr& child)
|
||||||
|
|
||||||
if(!(index >= 0 && (uint)index <= m_children.size())) {
|
if(!(index >= 0 && (uint)index <= m_children.size())) {
|
||||||
//g_logger.traceWarning("attempt to insert a child UIWidget into an invalid index, using nearest index...");
|
//g_logger.traceWarning("attempt to insert a child UIWidget into an invalid index, using nearest index...");
|
||||||
index = std::min(std::max(index, 0), (int)m_children.size());
|
index = stdext::clamp<int>(index, 0, (int)m_children.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
// retrieve child by index
|
// retrieve child by index
|
||||||
|
|
|
@ -346,7 +346,7 @@ public:
|
||||||
void setPaddingRight(int padding) { m_padding.right = padding; updateLayout(); }
|
void setPaddingRight(int padding) { m_padding.right = padding; updateLayout(); }
|
||||||
void setPaddingBottom(int padding) { m_padding.bottom = padding; updateLayout(); }
|
void setPaddingBottom(int padding) { m_padding.bottom = padding; updateLayout(); }
|
||||||
void setPaddingLeft(int padding) { m_padding.left = padding; updateLayout(); }
|
void setPaddingLeft(int padding) { m_padding.left = padding; updateLayout(); }
|
||||||
void setOpacity(float opacity) { m_opacity = std::min(std::max(opacity, 0.0f), 1.0f); }
|
void setOpacity(float opacity) { m_opacity = stdext::clamp<float>(opacity, 0.0f, 1.0f); }
|
||||||
void setRotation(float degrees) { m_rotation = degrees; }
|
void setRotation(float degrees) { m_rotation = degrees; }
|
||||||
|
|
||||||
int getX() { return m_rect.x(); }
|
int getX() { return m_rect.x(); }
|
||||||
|
|
|
@ -221,10 +221,10 @@ public:
|
||||||
|
|
||||||
TRect<T> united(const TRect<T> &r) const {
|
TRect<T> united(const TRect<T> &r) const {
|
||||||
TRect<T> tmp;
|
TRect<T> tmp;
|
||||||
tmp.x1 = std::min(x1, r.x1);
|
tmp.x1 = std::min<T>(x1, r.x1);
|
||||||
tmp.x2 = std::max(x2, r.x2);
|
tmp.x2 = std::max<T>(x2, r.x2);
|
||||||
tmp.y1 = std::min(y1, r.y1);
|
tmp.y1 = std::min<T>(y1, r.y1);
|
||||||
tmp.y2 = std::max(y2, r.y2);
|
tmp.y2 = std::max<T>(y2, r.y2);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -263,10 +263,10 @@ public:
|
||||||
b2 = r.y2;
|
b2 = r.y2;
|
||||||
|
|
||||||
TRect<T> tmp;
|
TRect<T> tmp;
|
||||||
tmp.x1 = std::max(l1, l2);
|
tmp.x1 = std::max<int>(l1, l2);
|
||||||
tmp.x2 = std::min(r1, r2);
|
tmp.x2 = std::min<int>(r1, r2);
|
||||||
tmp.y1 = std::max(t1, t2);
|
tmp.y1 = std::max<int>(t1, t2);
|
||||||
tmp.y2 = std::min(b1, b2);
|
tmp.y2 = std::min<int>(b1, b2);
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -70,8 +70,8 @@ public:
|
||||||
bool operator==(const TSize<T>& other) const { return other.wd==wd && other.ht==ht; }
|
bool operator==(const TSize<T>& other) const { return other.wd==wd && other.ht==ht; }
|
||||||
bool operator!=(const TSize<T>& other) const { return other.wd!=wd || other.ht!=ht; }
|
bool operator!=(const TSize<T>& other) const { return other.wd!=wd || other.ht!=ht; }
|
||||||
|
|
||||||
TSize<T> expandedTo(const TSize<T>& other) const { return TSize<T>(std::max(wd,other.wd), std::max(ht,other.ht)); }
|
TSize<T> expandedTo(const TSize<T>& other) const { return TSize<T>(std::max<T>(wd, other.wd), std::max<T>(ht, other.ht)); }
|
||||||
TSize<T> boundedTo(const TSize<T>& other) const { return TSize<T>(std::min(wd,other.wd), std::min(ht,other.ht)); }
|
TSize<T> boundedTo(const TSize<T>& other) const { return TSize<T>(std::min<T>(wd, other.wd), std::min<T>(ht, other.ht)); }
|
||||||
|
|
||||||
void scale(const TSize<T>& s, Fw::AspectRatioMode mode) {
|
void scale(const TSize<T>& s, Fw::AspectRatioMode mode) {
|
||||||
if(mode == Fw::IgnoreAspectRatio || wd == 0 || ht == 0) {
|
if(mode == Fw::IgnoreAspectRatio || wd == 0 || ht == 0) {
|
||||||
|
|
Loading…
Reference in New Issue