Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions engine/includes/components/textrender.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,6 @@ class ENGINE_EXPORT TextRender : public Renderable {
bool kerning() const;
void setKerning(const bool kerning);

static Vector2 cursorPosition(Font *font, int size, const TString &text, bool kerning, const Vector2 &boundaries);

private:
Mesh *meshToDraw(int instance) override;

Expand Down
2 changes: 2 additions & 0 deletions engine/includes/pipelinecontext.h
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ class ENGINE_EXPORT PipelineContext : public Object {
static Mesh *defaultPlane();
static Mesh *defaultCube();

static Texture *whiteTexture();

private:
void analizeGraph();

Expand Down
3 changes: 1 addition & 2 deletions engine/includes/resources/font.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class ENGINE_EXPORT Font : public Sprite {

float lineHeight() const;

float cursorWidth() const;
float textWidth(const TString &text, int size, bool kerning);

void composeMesh(Mesh *mesh, const TString &text, int size, int alignment, bool kerning, bool wrap, const Vector2 &boundaries);

Expand All @@ -69,7 +69,6 @@ class ENGINE_EXPORT Font : public Sprite {

float m_spaceWidth;
float m_lineHeight;
float m_cursorWidth;

bool m_useKerning;

Expand Down
3 changes: 3 additions & 0 deletions engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ Actor *Component::actor() const {
Scene *Component::scene() const {
return actor()->scene();
}
/*!
Returns a World which the Component is attached to.
*/
World *Component::world() const {
Scene *scene = Component::scene();
if(scene) {
Expand Down
63 changes: 0 additions & 63 deletions engine/src/components/textrender.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -240,69 +240,6 @@ AABBox TextRender::localBound() const {

return Renderable::localBound();
}
/*!
\fn Vector2 TextRender::cursorPosition(Font *font, int size, const std::string &text, bool kerning, const Vector2 &boundaries)

Returns the cursor position for rendering \a text with specified \a font and \a size.
Developer can also enable \a kerning and specify a \a boundaries for the text.
*/
Vector2 TextRender::cursorPosition(Font *font, int size, const TString &text, bool kerning, const Vector2 &boundaries) {
if(font) {
float spaceWidth = font->spaceWidth() * size;
float spaceLine = font->lineHeight() * size;
float cursorMid = font->cursorWidth() * 0.5f * size;

TString data = Engine::translate(text);
font->requestCharacters(data);

Vector2 pos(0.0, boundaries.y - size);

uint32_t length = font->length(data);
if(length) {
std::u32string u32 = data.toUtf32();

uint32_t previous = 0;
uint32_t it = 0;

for(uint32_t i = 0; i < length; i++) {
uint32_t ch = u32[i];
switch(ch) {
case ' ': {
pos += Vector2(spaceWidth, 0.0f);
} break;
case '\t': {
pos += Vector2(spaceWidth * 4, 0.0f);
} break;
case '\r': break;
case '\n': {
pos = Vector2(0.0f, pos.y - spaceLine);
} break;
default: {
if(kerning) {
pos.x += font->requestKerning(ch, previous);
}
uint32_t index = font->atlasIndex(ch);

Mesh *glyph = font->shape(index);
if(glyph == nullptr) {
continue;
}
Vector3Vector &shape = glyph->vertices();

pos += Vector2(shape[2].x * size, 0.0f);
it++;
} break;
}
previous = ch;
}
}
pos.x -= cursorMid;

return pos;
}

return Vector2();
}
/*!
\internal
*/
Expand Down
2 changes: 0 additions & 2 deletions engine/src/editor/editorplatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,8 +146,6 @@ EditorPlatform &EditorPlatform::instance() {
static EditorPlatform *instance = nullptr;
if(instance == nullptr) {
instance = new EditorPlatform;

Engine::setPlatformAdaptor(instance);
}

return *instance;
Expand Down
17 changes: 17 additions & 0 deletions engine/src/pipelinecontext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,23 @@ Mesh *PipelineContext::defaultCube() {
}
return cube;
}
/*!
Return the white texture used in rendering.
*/
Texture *PipelineContext::whiteTexture() {
static Texture *white = nullptr;
if(white == nullptr) {
white = Engine::objectCreate<Texture>("white");
white->setFormat(Texture::RGBA8);

Texture::Surface surface;
surface.push_back({255, 255, 255, 255});

white->addSurface(surface);
white->setDirty();
}
return white;
}
/*!
Sets the rendering \a pipeline for the context, creating and linking associated rendering tasks.
*/
Expand Down
59 changes: 45 additions & 14 deletions engine/src/resources/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,6 @@ Font::Font() :
m_scale(DF_GLYPH_SIZE),
m_spaceWidth(0.0f),
m_lineHeight(0.0f),
m_cursorWidth(0.0f),
m_useKerning(false) {

FT_Init_FreeType( &library );
Expand Down Expand Up @@ -203,8 +202,7 @@ int Font::requestKerning(int glyph, int previous) const {
Returns the number of \a characters in the string.
*/
int Font::length(const TString &characters) const {
std::u32string u32 = characters.toUtf32();
return u32.length();
return characters.toUtf32().length();
}
/*!
Returns visual width of space character for the font in world units.
Expand All @@ -218,11 +216,50 @@ float Font::spaceWidth() const {
float Font::lineHeight() const {
return m_lineHeight;
}
/*!
Returns visual width of the cursor for the font in world units.
*/
float Font::cursorWidth() const {
return m_cursorWidth;

float Font::textWidth(const TString &text, int size, bool kerning) {
TString data = Engine::translate(text);
requestCharacters(data);

float pos = 0;

uint32_t length = Font::length(data);
if(length) {
std::u32string u32 = data.toUtf32();

uint32_t previous = 0;
uint32_t it = 0;

for(uint32_t i = 0; i < length; i++) {
uint32_t ch = u32[i];
switch(ch) {
case ' ': {
pos += m_spaceWidth * size;
} break;
case '\t': {
pos += m_spaceWidth * size * 4;
} break;
default: {
if(kerning) {
pos += requestKerning(ch, previous);
}
uint32_t index = atlasIndex(ch);

Mesh *glyph = shape(index);
if(glyph == nullptr) {
continue;
}
Vector3Vector &shape = glyph->vertices();

pos += shape[2].x * size;
it++;
} break;
}
previous = ch;
}
}

return pos;
}

void Font::composeMesh(Mesh *mesh, const TString &text, int size, int alignment, bool kerning, bool wrap, const Vector2 &boundaries) {
Expand Down Expand Up @@ -391,12 +428,6 @@ void Font::loadUserData(const VariantMap &data) {
if(!error) {
m_lineHeight = static_cast<float>(face->glyph->metrics.height) / m_scale / 32.0f;
}

error = FT_Load_Glyph( face, FT_Get_Char_Index( face, '|' ), FT_LOAD_DEFAULT );
if(!error) {
m_cursorWidth = static_cast<float>(face->glyph->advance.x) / m_scale / 64.0f;
}

}
}
}
Expand Down
8 changes: 5 additions & 3 deletions modules/editor/grapheditor/editor/graph/graphcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void GraphController::update() {
Qt::CursorShape shape = Qt::ArrowCursor;
for(auto node : m_graph->nodes()) {
NodeWidget *widget = static_cast<NodeWidget *>(node->widget());
RectTransform *rect = widget->rectTransform();
RectTransform *rect = widget->title()->rectTransform();
if(rect->isHovered(mousePosition.x, mousePosition.y)) {
hovered = widget;
}
Expand Down Expand Up @@ -365,8 +365,10 @@ void GraphController::update() {
}
}

beginDrag();
m_dragWidget = hovered;
if(Widget::focusWidget() == hovered) {
beginDrag();
m_dragWidget = hovered;
}
} else {
m_view->rubberBand()->setEnabled(true);
m_view->rubberBand()->raise();
Expand Down
21 changes: 8 additions & 13 deletions modules/uikit/includes/components/abstractbutton.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,10 @@ class UIKIT_EXPORT AbstractButton : public Widget {
A_PROPERTY(bool, checkable, AbstractButton::isCheckable, AbstractButton::setCheckable),
A_PROPERTY(bool, checked, AbstractButton::isChecked, AbstractButton::setChecked),
A_PROPERTY(bool, exclusive, AbstractButton::isExclusive, AbstractButton::setExclusive),
A_PROPERTYEX(Vector4, color, AbstractButton::color, AbstractButton::setColor, "editor=Color"),
A_PROPERTYEX(Frame *, background, AbstractButton::background, AbstractButton::setBackground, "editor=Component"),
A_PROPERTYEX(Label *, label, AbstractButton::label, AbstractButton::setLabel, "editor=Component"),
A_PROPERTYEX(Image *, icon, AbstractButton::icon, AbstractButton::setIcon, "editor=Component"),
A_PROPERTY(float, fadeDuration, AbstractButton::fadeDuration, AbstractButton::setFadeDuration),
A_PROPERTYEX(Vector4, highlightedColor, AbstractButton::highlightedColor, AbstractButton::setHighlightedColor, "editor=Color"),
A_PROPERTYEX(Vector4, normalColor, AbstractButton::normalColor, AbstractButton::setNormalColor, "editor=Color"),
A_PROPERTYEX(Vector4, pressedColor, AbstractButton::pressedColor, AbstractButton::setPressedColor, "editor=Color")
A_PROPERTYEX(Image *, icon, AbstractButton::icon, AbstractButton::setIcon, "editor=Component")
)
A_METHODS(
A_SIGNAL(AbstractButton::pressed),
Expand All @@ -45,19 +42,16 @@ class UIKIT_EXPORT AbstractButton : public Widget {
void setIcon(Image *image);

Vector2 iconSize() const;
void setIconSize(Vector2 size);
void setIconSize(const Vector2 &size);

float fadeDuration() const;
void setFadeDuration(float duration);
Vector4 color() const;
void setColor(const Vector4 &color);

Vector4 highlightedColor() const;
void setHighlightedColor(const Vector4 color);

Vector4 normalColor() const;
void setNormalColor(const Vector4 color);
void setHighlightedColor(const Vector4 &color);

Vector4 pressedColor() const;
void setPressedColor(const Vector4 color);
void setPressedColor(const Vector4 &color);

bool isCheckable() const;
void setCheckable(bool checkable);
Expand All @@ -71,6 +65,7 @@ class UIKIT_EXPORT AbstractButton : public Widget {
bool isMirrored() const;
virtual void setMirrored(bool mirrored);

public: // signals
void pressed();
void clicked();

Expand Down
74 changes: 74 additions & 0 deletions modules/uikit/includes/components/abstractslider.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#ifndef ABSTRACTSLIDER_H
#define ABSTRACTSLIDER_H

#include "widget.h"

class Frame;

class UIKIT_EXPORT AbstractSlider : public Widget {
A_OBJECT(AbstractSlider, Widget, General)

A_PROPERTIES(
A_PROPERTYEX(int, orientation, AbstractSlider::orientation, AbstractSlider::setOrientation, "enum=Orientation"),
A_PROPERTY(int, value, AbstractSlider::value, AbstractSlider::setValue),
A_PROPERTY(int, minimum, AbstractSlider::minimum, AbstractSlider::setMinimum),
A_PROPERTY(int, maximum, AbstractSlider::maximum, AbstractSlider::setMaximum),
A_PROPERTYEX(Widget *, knob, AbstractSlider::knob, AbstractSlider::setKnob, "editor=Component")
)
A_METHODS(
A_SIGNAL(AbstractSlider::pressed),
A_SIGNAL(AbstractSlider::valueChanged)
)
A_ENUMS(
A_ENUM(Orientation,
A_VALUE(Horizontal),
A_VALUE(Vertical)
)
)

public:
enum Orientation {
Horizontal,
Vertical
};

public:
AbstractSlider();

int orientation() const;
virtual void setOrientation(int orientation);

int value() const;
virtual void setValue(int value);

int minimum() const;
virtual void setMinimum(int minimum);

int maximum() const;
virtual void setMaximum(int maximum);

Widget *knob() const;
void setKnob(Widget *handle);

public: // signals
void pressed();

void valueChanged(int value);

protected:
void update() override;

protected:
int m_value;
int m_minimum;
int m_maximum;

float m_currentFade;

int m_orientation;

bool m_hovered;

};

#endif // ABSTRACTSLIDER_H
Loading
Loading