Style fixes.

This commit is contained in:
Ben Vanik
2015-08-08 16:39:57 -07:00
parent 2c5b58821f
commit 5da70a8d76
101 changed files with 511 additions and 401 deletions

View File

@@ -55,8 +55,8 @@ void AnimationManager::Update() {
// If animation_duration is 0, it should just complete immediately.
float progress = 1.0f;
if (obj->animation_duration != 0) {
progress = (float)(time_now - obj->animation_start_time) /
(float)obj->animation_duration;
progress = static_cast<float>(time_now - obj->animation_start_time) /
static_cast<float>(obj->animation_duration);
progress = std::min(progress, 1.0f);
}
@@ -78,7 +78,7 @@ void AnimationManager::Update() {
break;
default: // linear (progress is already linear)
break;
};
}
// Update animation
obj->InvokeOnAnimationUpdate(progress);

View File

@@ -27,25 +27,22 @@
#define EL_UNIT_TESTING
#endif // CHECKED
/** Enable if the focus state should automatically be set on edit fields even
when using the pointer. It is normally set only while moving focus by
keyboard. */
//#define EL_ALWAYS_SHOW_EDIT_FOCUS
// Enable if the focus state should automatically be set on edit fields even
// when using the pointer. It is normally set only while moving focus by
// keyboard.
// #define EL_ALWAYS_SHOW_EDIT_FOCUS
/** Enable to support TBBF fonts (Turbo Badger Bitmap Fonts) */
// Enable to support TBBF fonts (Turbo Badger Bitmap Fonts).
#define EL_FONT_RENDERER_TBBF
/** Enable to support truetype fonts using freetype. */
//#define EL_FONT_RENDERER_FREETYPE
// Enable to support truetype fonts using freetype.
// #define EL_FONT_RENDERER_FREETYPE
/** Enable to support truetype fonts using stb_truetype.h
(http://nothings.org/).
It's a *very unsafe* font library. Use only with fonts distributed with
your
app, that you know work! Freetype generates much prettier glyphs (using
hinting) but is a lot larger. This implementation is kept here as
alternative
as long as it compiles. */
//#define EL_FONT_RENDERER_STB
// Enable to support truetype fonts using stb_truetype.h (http://nothings.org/).
// It's a *very unsafe* font library. Use only with fonts distributed with your
// app, that you know work! Freetype generates much prettier glyphs (using
// hinting) but is a lot larger. This implementation is kept here as alternative
// as long as it compiles.
// #define EL_FONT_RENDERER_STB
#endif // EL_CONFIG_H_

View File

@@ -80,7 +80,7 @@ void DesignerForm::Show(Element* root_element) {
void DesignerForm::BindContent(Element* bind_element) {
CloseContent();
bind_element_ = bind_element;
bind_element_ = WeakElementPointer(bind_element);
// TODO(benvanik): serialize element tree.
source_text_box_->set_text("Label: text: foo");

View File

@@ -10,6 +10,8 @@
#ifndef EL_DESIGN_DESIGNER_FORM_H_
#define EL_DESIGN_DESIGNER_FORM_H_
#include <string>
#include "el/element.h"
#include "el/element_listener.h"
#include "el/elements/form.h"
@@ -49,7 +51,7 @@ class DesignerForm : public elements::Form,
void RefreshContent();
void PopulateElementListBox();
EventHandler event_handler_ = {this};
EventHandler event_handler_ = EventHandler(this);
elements::ListBox* element_list_box_ = nullptr;
ListItemSourceList<ElementItem> element_list_source_;
elements::TextBox* source_text_box_ = nullptr;

View File

@@ -13,6 +13,7 @@
#include <cassert>
#include <cstdint>
#include <string>
#include <utility>
#include <vector>
#include "el/color.h"
@@ -103,17 +104,17 @@ class Node {
};
struct Dimension {
Dimension(int32_t value) : value(std::to_string(value) + "px") {}
Dimension(const char* value) : value(value) {}
Dimension(std::string value) : value(std::move(value)) {}
Dimension(int32_t value) : value(std::to_string(value) + "px") {} // NOLINT
Dimension(const char* value) : value(value) {} // NOLINT
Dimension(std::string value) : value(std::move(value)) {} // NOLINT
operator std::string() { return value; }
std::string value;
};
struct Id {
Id(int32_t value) : is_int(true), int_value(value) {}
Id(const char* value) : str_value(value) {}
Id(std::string value) : str_value(std::move(value)) {}
Id(int32_t value) : is_int(true), int_value(value) {} // NOLINT
Id(const char* value) : str_value(value) {} // NOLINT
Id(std::string value) : str_value(std::move(value)) {} // NOLINT
void set(Node* node, const char* key) {
if (is_int) {
node->set(key, int_value);
@@ -128,7 +129,7 @@ struct Id {
struct CloneNode : public Node {
using R = CloneNode;
CloneNode(const Node& source) : Node(source.parse_node()->name()) {
explicit CloneNode(const Node& source) : Node(source.parse_node()->name()) {
parse_node_->value().Copy(source.parse_node()->value());
parse_node_->CloneChildren(source.parse_node());
}

View File

@@ -389,12 +389,11 @@ Element::State Element::computed_state() const {
}
if (this == focused_element && show_focus_state) {
state |= Element::State::kFocused;
}
} else if (this == focused_element && IsOfType<elements::TextBox>()) {
#ifdef EL_ALWAYS_SHOW_EDIT_FOCUS
else if (this == focused_element && IsOfType<TextBox>()) {
state |= Element::State::kFocused;
}
#endif // EL_ALWAYS_SHOW_EDIT_FOCUS
}
return state;
}
@@ -423,7 +422,7 @@ void Element::set_opacity(float opacity) {
}
void Element::set_visibility(Visibility vis) {
if (m_packed.visibility == int(vis)) {
if (m_packed.visibility == static_cast<int>(vis)) {
return;
}
@@ -436,7 +435,7 @@ void Element::set_visibility(Visibility vis) {
}
Visibility old_vis = visibility();
m_packed.visibility = int(vis);
m_packed.visibility = static_cast<int>(vis);
Invalidate();
if (old_vis == Visibility::kGone) {
@@ -864,8 +863,9 @@ HitStatus Element::GetHitStatus(int x, int y) {
}
Element* Element::GetElementAt(int x, int y, bool include_children) const {
int child_translation_x, child_translation_y;
GetChildTranslation(child_translation_x, child_translation_y);
int child_translation_x;
int child_translation_y;
GetChildTranslation(&child_translation_x, &child_translation_y);
x -= child_translation_x;
y -= child_translation_y;
@@ -979,8 +979,9 @@ void Element::OnPaintChildren(const PaintProps& paint_props) {
if (!m_children.GetFirst()) return;
// Translate renderer with child translation.
int child_translation_x, child_translation_y;
GetChildTranslation(child_translation_x, child_translation_y);
int child_translation_x;
int child_translation_y;
GetChildTranslation(&child_translation_x, &child_translation_y);
Renderer::get()->Translate(child_translation_x, child_translation_y);
Rect clip_rect = Renderer::get()->clip_rect();
@@ -1231,15 +1232,21 @@ PreferredSize Element::GetPreferredSize(const SizeConstraints& in_constraints) {
// Returned cached result if valid and the constraints are the same.
if (m_packed.is_cached_ps_valid) {
if (m_cached_sc == constraints ||
m_cached_ps.size_dependency == SizeDependency::kNone /*||
// FIX: These optimizations would probably be good. Keeping
// disabled for now because it needs testing.
// If *only* width depend on height, only the height matter
(m_cached_ps.size_dependency == SizeDependency::kWidthOnHeight &&
m_cached_sc.available_h == constraints.available_h) ||
// If *only* height depend on width, only the width matter
(m_cached_ps.size_dependency == SizeDependency::kHeightOnWidth &&
m_cached_sc.available_w == constraints.available_w)*/) {
m_cached_ps.size_dependency == SizeDependency::kNone) {
/*||
// FIX: These optimizations would probably be good.
Keeping
// disabled for now because it needs testing.
// If *only* width depend on height, only the height
matter
(m_cached_ps.size_dependency ==
SizeDependency::kWidthOnHeight &&
m_cached_sc.available_h == constraints.available_h) ||
// If *only* height depend on width, only the width
matter
(m_cached_ps.size_dependency ==
SizeDependency::kHeightOnWidth &&
m_cached_sc.available_w == constraints.available_w)*/
return m_cached_ps;
}
}
@@ -1253,9 +1260,10 @@ PreferredSize Element::GetPreferredSize(const SizeConstraints& in_constraints) {
// Override the calculated ps with any specified layout parameter.
if (m_layout_params) {
#define LP_OVERRIDE(param) \
if (m_layout_params->param != LayoutParams::kUnspecified) \
m_cached_ps.param = m_layout_params->param;
#define LP_OVERRIDE(param) \
if (m_layout_params->param != LayoutParams::kUnspecified) { \
m_cached_ps.param = m_layout_params->param; \
}
LP_OVERRIDE(min_w);
LP_OVERRIDE(min_h);
LP_OVERRIDE(max_w);
@@ -1469,7 +1477,7 @@ bool Element::InvokeEvent(Event& ev) {
break;
default:
break;
};
}
// Call OnEvent on this elements and travel up through its parents if not
// handled.
@@ -1648,9 +1656,10 @@ void Element::HandlePanningOnMove(int x, int y) {
return;
}
int old_translation_x = 0, old_translation_y = 0;
captured_element->scroll_root()->GetChildTranslation(old_translation_x,
old_translation_y);
int old_translation_x = 0;
int old_translation_y = 0;
captured_element->scroll_root()->GetChildTranslation(&old_translation_x,
&old_translation_y);
if (scroller->OnPan(dx + start_compensation_x, dy + start_compensation_y)) {
// Scroll delta changed, so we are now panning!
@@ -1660,9 +1669,10 @@ void Element::HandlePanningOnMove(int x, int y) {
// If the captured element (or its scroll root) has panned, we have to
// compensate the pointer down coordinates so we won't accumulate the
// difference the following pan.
int new_translation_x = 0, new_translation_y = 0;
captured_element->scroll_root()->GetChildTranslation(new_translation_x,
new_translation_y);
int new_translation_x = 0;
int new_translation_y = 0;
captured_element->scroll_root()->GetChildTranslation(&new_translation_x,
&new_translation_y);
pointer_down_element_x +=
new_translation_x - old_translation_x + start_compensation_x;
pointer_down_element_y +=
@@ -1758,8 +1768,9 @@ void Element::ConvertToRoot(int& x, int& y) const {
tmp = tmp->m_parent;
if (tmp) {
int child_translation_x, child_translation_y;
tmp->GetChildTranslation(child_translation_x, child_translation_y);
int child_translation_x;
int child_translation_y;
tmp->GetChildTranslation(&child_translation_x, &child_translation_y);
x += child_translation_x;
y += child_translation_y;
}
@@ -1774,8 +1785,9 @@ void Element::ConvertFromRoot(int& x, int& y) const {
tmp = tmp->m_parent;
if (tmp) {
int child_translation_x, child_translation_y;
tmp->GetChildTranslation(child_translation_x, child_translation_y);
int child_translation_x;
int child_translation_y;
tmp->GetChildTranslation(&child_translation_x, &child_translation_y);
x -= child_translation_x;
y -= child_translation_y;
}
@@ -1957,7 +1969,7 @@ bool ElementSkinConditionContext::GetCondition(
case SkinProperty::kState:
return !!(uint32_t(element->computed_state()) & info.value);
case SkinProperty::kValue:
return element->value() == (int)info.value;
return element->value() == static_cast<int>(info.value);
case SkinProperty::kHover:
return Element::hovered_element &&
element->IsAncestorOf(Element::hovered_element);

View File

@@ -13,6 +13,7 @@
#include <algorithm>
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "el/dsl.h"
@@ -465,7 +466,9 @@ class Element : public util::TypedObject,
ElementZ z_inflate() const { return (ElementZ)m_packed.inflate_child_z; }
// Sets the z-order in which children are added during resource loading.
void set_z_inflate(ElementZ z) { m_packed.inflate_child_z = int(z) ? 1 : 0; }
void set_z_inflate(ElementZ z) {
m_packed.inflate_child_z = static_cast<int>(z) ? 1 : 0;
}
Gravity gravity() const { return m_gravity; }
// Sets the element gravity (any combination of Gravity).
@@ -771,7 +774,7 @@ class Element : public util::TypedObject,
// NOTE: you can apply the translation on one element and implement those
// methods on a parent, by returning this element from the parents
// scroll_root().
virtual void GetChildTranslation(int& x, int& y) const { x = y = 0; }
virtual void GetChildTranslation(int* x, int* y) const { *x = *y = 0; }
// If this is a element that scroll children (see GetChildTranslation), it
// should scroll to the coordinates x, y.
@@ -846,12 +849,14 @@ class Element : public util::TypedObject,
// It only makes sense to use this instead of value() on elements that
// store the value as double.
// F.ex ScrollBar, Slider.
virtual double double_value() { return double(value()); }
virtual double double_value() { return static_cast<double>(value()); }
// Sets the value in double precision.
// It only makes sense to use this instead of set_value() on elements that
// store the value as double.
// F.ex ScrollBar, Slider.
virtual void set_double_value(double value) { set_value(int(value)); }
virtual void set_double_value(double value) {
set_value(static_cast<int>(value));
}
// Gets the text of this element. Implemented by most elements that have text.
virtual std::string text() { return ""; }
@@ -1142,7 +1147,7 @@ inline Element* Element::GetElementById<Element>(const TBID& id) {
// Check if a condition is true for a element when painting a skin.
class ElementSkinConditionContext : public SkinConditionContext {
public:
ElementSkinConditionContext(Element* element) : m_element(element) {}
explicit ElementSkinConditionContext(Element* element) : m_element(element) {}
bool GetCondition(SkinTarget target,
const SkinCondition::ConditionInfo& info) override;

View File

@@ -56,8 +56,9 @@ void OpacityElementAnimation::OnAnimationStop(bool aborted) {
WeakElementPointer the_element(m_element);
if (m_element->parent()) m_element->parent()->RemoveChild(m_element);
if (the_element.get()) delete the_element.get();
} else
} else {
m_element->set_opacity(m_dst_opacity);
}
}
RectElementAnimation::RectElementAnimation(Element* element,
@@ -107,10 +108,14 @@ void RectElementAnimation::OnAnimationUpdate(float progress) {
m_mode = Mode::kSrcToDest;
}
Rect rect;
rect.x = int(Lerp(float(m_src_rect.x), float(m_dst_rect.x), progress));
rect.y = int(Lerp(float(m_src_rect.y), float(m_dst_rect.y), progress));
rect.w = int(Lerp(float(m_src_rect.w), float(m_dst_rect.w), progress));
rect.h = int(Lerp(float(m_src_rect.h), float(m_dst_rect.h), progress));
rect.x = static_cast<int>(Lerp(static_cast<float>(m_src_rect.x),
static_cast<float>(m_dst_rect.x), progress));
rect.y = static_cast<int>(Lerp(static_cast<float>(m_src_rect.y),
static_cast<float>(m_dst_rect.y), progress));
rect.w = static_cast<int>(Lerp(static_cast<float>(m_src_rect.w),
static_cast<float>(m_dst_rect.w), progress));
rect.h = static_cast<int>(Lerp(static_cast<float>(m_src_rect.h),
static_cast<float>(m_dst_rect.h), progress));
m_element->set_rect(rect);
}

View File

@@ -30,7 +30,7 @@ class ElementAnimation : public Animation,
// think focus should not be set in that form and fail.
static const float kAlmostZeroOpacity;
ElementAnimation(Element* element);
explicit ElementAnimation(Element* element);
~ElementAnimation() override;
public:

View File

@@ -85,7 +85,7 @@ class ElementListener : public util::IntrusiveListEntry<ElementListener>,
class WeakElementPointer : private ElementListener {
public:
WeakElementPointer() = default;
WeakElementPointer(Element* element) { reset(element); }
explicit WeakElementPointer(Element* element) { reset(element); }
~WeakElementPointer() { reset(nullptr); }
// Sets the element pointer that should be nulled if deleted.

View File

@@ -62,7 +62,7 @@ void ElementValue::SetFromElement(Element* source_element) {
break;
case Value::Type::kFloat:
// FIX: Value should use double instead of float?
m_value.set_float(float(source_element->double_value()));
m_value.set_float(static_cast<float>(source_element->double_value()));
break;
default:
assert(!"Unsupported value type!");
@@ -122,7 +122,7 @@ void ElementValue::set_text(const char* text) {
void ElementValue::set_double(double value) {
// FIX: Value should use double instead of float?
m_value.set_float(float(value));
m_value.set_float(static_cast<float>(value));
SyncToElements(nullptr);
}

View File

@@ -11,6 +11,7 @@
#define EL_ELEMENT_VALUE_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "el/id.h"

View File

@@ -12,34 +12,32 @@
namespace el {
void RegisterBuiltinElementInflaters() {
using namespace el::elements;
Box::RegisterInflater();
ImageBox::RegisterInflater();
SpinBox::RegisterInflater();
LayoutBox::RegisterInflater();
ScrollContainer::RegisterInflater();
DropDownButton::RegisterInflater();
ListBox::RegisterInflater();
TabContainer::RegisterInflater();
TextBox::RegisterInflater();
GroupBox::RegisterInflater();
ToggleContainer::RegisterInflater();
Element::RegisterInflater();
Label::RegisterInflater();
Button::RegisterInflater();
LabelContainer::RegisterInflater();
IconBox::RegisterInflater();
Separator::RegisterInflater();
ProgressSpinner::RegisterInflater();
CheckBox::RegisterInflater();
RadioButton::RegisterInflater();
ScrollBar::RegisterInflater();
Slider::RegisterInflater();
Mover::RegisterInflater();
Resizer::RegisterInflater();
Dimmer::RegisterInflater();
SplitContainer::RegisterInflater();
elements::Box::RegisterInflater();
elements::Button::RegisterInflater();
elements::CheckBox::RegisterInflater();
elements::Dimmer::RegisterInflater();
elements::DropDownButton::RegisterInflater();
elements::GroupBox::RegisterInflater();
elements::IconBox::RegisterInflater();
elements::ImageBox::RegisterInflater();
elements::Label::RegisterInflater();
elements::LabelContainer::RegisterInflater();
elements::LayoutBox::RegisterInflater();
elements::ListBox::RegisterInflater();
elements::Mover::RegisterInflater();
elements::ProgressSpinner::RegisterInflater();
elements::RadioButton::RegisterInflater();
elements::Resizer::RegisterInflater();
elements::ScrollBar::RegisterInflater();
elements::ScrollContainer::RegisterInflater();
elements::Separator::RegisterInflater();
elements::Slider::RegisterInflater();
elements::SpinBox::RegisterInflater();
elements::SplitContainer::RegisterInflater();
elements::TabContainer::RegisterInflater();
elements::TextBox::RegisterInflater();
elements::ToggleContainer::RegisterInflater();
}
} // namespace el

View File

@@ -46,7 +46,7 @@
namespace el {
// TODO(benvanik): using all the elements to bring them into tb?
using namespace el::elements;
using namespace el::elements; // NOLINT(build/namespaces)
using el::elements::to_string;

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_BUTTON_H_
#define EL_ELEMENTS_BUTTON_H_
#include <string>
#include "el/element.h"
#include "el/elements/label.h"
#include "el/elements/layout_box.h"
@@ -98,12 +100,14 @@ namespace dsl {
struct ButtonNode : public ElementNode<ButtonNode> {
using R = ButtonNode;
ButtonNode(const char* text = nullptr) : ElementNode("Button") {
explicit ButtonNode(const char* text = nullptr) : ElementNode("Button") {
if (text) {
this->text(text);
}
}
ButtonNode(std::string text) : ElementNode("Button") { this->text(text); }
explicit ButtonNode(std::string text) : ElementNode("Button") {
this->text(text);
}
//
R& text(std::string value) {
set("text", value);

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_FORM_H_
#define EL_ELEMENTS_FORM_H_
#include <string>
#include "el/element_listener.h"
#include "el/elements/button.h"
#include "el/elements/label.h"

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_GROUP_BOX_H_
#define EL_ELEMENTS_GROUP_BOX_H_
#include <string>
#include "el/element.h"
#include "el/elements/button.h"
#include "el/elements/layout_box.h"
@@ -79,7 +81,7 @@ namespace dsl {
struct GroupBoxNode : public ElementNode<GroupBoxNode> {
using R = GroupBoxNode;
GroupBoxNode(const char* text = nullptr) : ElementNode("GroupBox") {
explicit GroupBoxNode(const char* text = nullptr) : ElementNode("GroupBox") {
if (text) {
this->text(text);
}

View File

@@ -24,7 +24,7 @@ class IconBox : public Element {
static void RegisterInflater();
IconBox() = default;
IconBox(const TBID& skin_bg) { set_background_skin(skin_bg); }
explicit IconBox(const TBID& skin_bg) { set_background_skin(skin_bg); }
PreferredSize OnCalculatePreferredSize(
const SizeConstraints& constraints) override;

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_IMAGE_BOX_H_
#define EL_ELEMENTS_IMAGE_BOX_H_
#include <string>
#include "el/element.h"
#include "el/graphics/image_manager.h"
@@ -54,7 +56,8 @@ namespace dsl {
struct ImageBoxNode : public ElementNode<ImageBoxNode> {
using R = ImageBoxNode;
ImageBoxNode(const char* filename = nullptr) : ElementNode("ImageBox") {
explicit ImageBoxNode(const char* filename = nullptr)
: ElementNode("ImageBox") {
if (filename) {
this->filename(filename);
}

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/label.h"
#include "el/parsing/element_inflater.h"
#include "el/text/font_face.h"
@@ -43,7 +45,6 @@ void ElementString::Paint(Element* element, const Rect& rect,
// There's not enough room for the entire string
// so cut it off and end with ellipsis (...)
// const char *end = "<22>"; // 2026 HORIZONTAL ELLIPSIS
// Some fonts seem to render ellipsis a lot uglier than three dots.
const char* end = "...";

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_LABEL_H_
#define EL_ELEMENTS_LABEL_H_
#include <string>
#include "el/element.h"
namespace el {
@@ -86,7 +88,7 @@ namespace dsl {
struct LabelNode : public ElementNode<LabelNode> {
using R = LabelNode;
LabelNode(const char* text = nullptr) : ElementNode("Label") {
explicit LabelNode(const char* text = nullptr) : ElementNode("Label") {
if (text) {
this->text(text);
}

View File

@@ -10,6 +10,9 @@
#ifndef EL_ELEMENTS_LABEL_CONTAINER_H_
#define EL_ELEMENTS_LABEL_CONTAINER_H_
#include <string>
#include <vector>
#include "el/element.h"
#include "el/elements/label.h"
#include "el/elements/layout_box.h"

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/layout_box.h"
#include "el/parsing/element_inflater.h"
#include "el/skin.h"
@@ -208,7 +210,7 @@ int LayoutBox::GetWantedHeight(Gravity gravity, const PreferredSize& ps,
case LayoutSize::kAvailable:
height = std::min(available_height, ps.max_h);
break;
};
}
height = std::min(height, ps.max_h);
return height;
}
@@ -366,8 +368,9 @@ void LayoutBox::ValidateLayout(const SizeConstraints& constraints,
int width = ps.pref_w;
if (missing_space && total_min_pref_diff_w) {
int diff_w = ps.pref_w - ps.min_w;
float factor = (float)diff_w / (float)total_min_pref_diff_w;
int removed = (int)(missing_space * factor);
float factor = static_cast<float>(diff_w) /
static_cast<float>(total_min_pref_diff_w);
int removed = static_cast<int>(missing_space * factor);
removed = std::min(removed, diff_w);
width -= removed;
@@ -377,8 +380,9 @@ void LayoutBox::ValidateLayout(const SizeConstraints& constraints,
QualifyForExpansion(gravity)) {
int capped_max_w = std::min(layout_rect.w, ps.max_w);
int diff_w = capped_max_w - ps.pref_w;
float factor = (float)diff_w / (float)total_max_pref_diff_w;
int added = (int)(extra_space * factor);
float factor = static_cast<float>(diff_w) /
static_cast<float>(total_max_pref_diff_w);
int added = static_cast<int>(extra_space * factor);
added = std::min(added, diff_w);
width += added;
@@ -408,7 +412,7 @@ void LayoutBox::ValidateLayout(const SizeConstraints& constraints,
break;
default: // LayoutPosition::kLeftTop
break;
};
}
// Done! Set rect and increase used space.
Rect rect(used_space + offset, pos, width, height);
@@ -509,13 +513,13 @@ void LayoutBox::OnInflateChild(Element* child) {
// Do nothing since we're going to layout the child soon.
}
void LayoutBox::GetChildTranslation(int& x, int& y) const {
void LayoutBox::GetChildTranslation(int* x, int* y) const {
if (m_axis == Axis::kX) {
x = -m_overflow_scroll;
y = 0;
*x = -m_overflow_scroll;
*y = 0;
} else {
x = 0;
y = -m_overflow_scroll;
*x = 0;
*y = -m_overflow_scroll;
}
}

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_LAYOUT_BOX_H_
#define EL_ELEMENTS_LAYOUT_BOX_H_
#include <vector>
#include "el/element.h"
#include "el/types.h"
@@ -96,7 +98,7 @@ class LayoutBox : public Element {
// This means the spacing should be the default, read from the skin.
static const int kSpacingFromSkin = util::kInvalidDimension;
LayoutBox(Axis axis = Axis::kX);
explicit LayoutBox(Axis axis = Axis::kX);
Axis axis() const override { return m_axis; }
// Sets along which axis the content should layout.
@@ -141,7 +143,7 @@ class LayoutBox : public Element {
void OnProcess() override;
void OnResized(int old_w, int old_h) override;
void OnInflateChild(Element* child) override;
void GetChildTranslation(int& x, int& y) const override;
void GetChildTranslation(int* x, int* y) const override;
void ScrollTo(int x, int y) override;
Element::ScrollInfo scroll_info() override;
@@ -188,7 +190,7 @@ using el::elements::LayoutOverflow;
struct LayoutBoxNode : public ElementNode<LayoutBoxNode> {
using R = LayoutBoxNode;
LayoutBoxNode(std::vector<Node> children = {})
explicit LayoutBoxNode(std::vector<Node> children = {})
: ElementNode("LayoutBox", {}, std::move(children)) {}
//
R& spacing(Dimension value) {

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <vector>
#include "el/elements/form.h"
#include "el/elements/label.h"
#include "el/elements/list_box.h"
@@ -153,7 +155,7 @@ void ListBox::ValidateList() {
int num_sorted_items = 0;
for (size_t i = 0; i < m_source->size(); ++i) {
if (m_filter.empty() || m_source->Filter(i, m_filter)) {
sorted_index[num_sorted_items++] = int(i);
sorted_index[num_sorted_items++] = static_cast<int>(i);
}
}
@@ -195,7 +197,7 @@ void ListBox::ValidateList() {
Element* ListBox::CreateAndAddItemAfter(size_t index, Element* reference) {
if (Element* element = m_source->CreateItemElement(index, this)) {
// Use item data as element to index lookup.
element->data.set_integer(int(index));
element->data.set_integer(static_cast<int>(index));
m_layout.content_root()->AddChildRelative(element, ElementZRel::kAfter,
reference);
return element;
@@ -272,7 +274,7 @@ bool ListBox::OnEvent(const Event& ev) {
WeakElementPointer this_element(this);
size_t index = ev.target->data.as_integer();
set_value(int(index));
set_value(static_cast<int>(index));
// If we're still around, invoke the click event too.
if (this_element.get()) {

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_LIST_BOX_H_
#define EL_ELEMENTS_LIST_BOX_H_
#include <string>
#include "el/element.h"
#include "el/elements/layout_box.h"
#include "el/elements/scroll_container.h"

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_MESSAGE_FORM_H_
#define EL_ELEMENTS_MESSAGE_FORM_H_
#include <string>
#include "el/element_listener.h"
#include "el/elements/form.h"

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/element.h"
#include "el/elements/parts/scroller.h"
#include "el/util/metrics.h"
@@ -17,7 +19,7 @@ namespace parts {
constexpr uint32_t kPanTargetFps = 60;
constexpr uint32_t kPanMessageDelayMillis =
uint32_t(1000.0 / double(kPanTargetFps));
static_cast<uint32_t>(1000.0 / static_cast<double>(kPanTargetFps));
constexpr uint32_t kPanStartThresholdMillis = 50;
constexpr uint32_t kPanPowerAccelerationThresholdMillis = 600;
constexpr float kPanPowerMultiplier = 1.3f;
@@ -52,7 +54,7 @@ float ScrollerFunction::GetDistanceAtTime(float start_speed,
int ScrollerFunction::GetDistanceAtTimeInt(float start_speed,
float elapsed_time_ms) {
float distance = GetDistanceAtTime(start_speed, elapsed_time_ms);
return int(distance < 0 ? distance - 0.5f : distance + 0.5f);
return static_cast<int>(distance < 0 ? distance - 0.5f : distance + 0.5f);
}
Scroller::Scroller(Element* target) : m_target(target), m_func(kScrollDecay) {
@@ -79,8 +81,8 @@ void Scroller::OnScrollBy(int dx, int dy, bool accumulative) {
Start();
}
float ppms_x = m_func.GetSpeedFromDistance((float)dx);
float ppms_y = m_func.GetSpeedFromDistance((float)dy);
float ppms_x = m_func.GetSpeedFromDistance(static_cast<float>(dx));
float ppms_y = m_func.GetSpeedFromDistance(static_cast<float>(dy));
if (accumulative && IsScrolling()) {
auto scroll_info = m_target->scroll_info();
@@ -95,7 +97,8 @@ void Scroller::OnScrollBy(int dx, int dy, bool accumulative) {
m_scroll_start_scroll_x + distance_x - scroll_info.x;
distance_remaining_x += m_func.GetDistanceAtTimeInt(
ppms_x, m_func.GetDurationFromSpeed(ppms_x));
ppms_x = m_func.GetSpeedFromDistance((float)distance_remaining_x);
ppms_x =
m_func.GetSpeedFromDistance(static_cast<float>(distance_remaining_x));
}
if ((ppms_y < 0) == (m_scroll_start_speed_ppms_y < 0)) {
int distance_y = m_func.GetDistanceAtTimeInt(
@@ -105,7 +108,8 @@ void Scroller::OnScrollBy(int dx, int dy, bool accumulative) {
m_scroll_start_scroll_y + distance_y - scroll_info.y;
distance_remaining_y += m_func.GetDistanceAtTimeInt(
ppms_y, m_func.GetDurationFromSpeed(ppms_y));
ppms_y = m_func.GetSpeedFromDistance((float)distance_remaining_y);
ppms_y =
m_func.GetSpeedFromDistance(static_cast<float>(distance_remaining_y));
}
}
@@ -123,7 +127,7 @@ bool Scroller::OnPan(int dx, int dy) {
// Calculate the pan speed. Smooth it out with the
// previous pan speed to reduce fluctuation a little.
double now_ms = double(util::GetTimeMS());
double now_ms = static_cast<double>(util::GetTimeMS());
if (m_pan_time_ms) {
if (m_pan_delta_time_ms) {
m_pan_delta_time_ms =
@@ -166,14 +170,17 @@ void Scroller::OnPanReleased() {
return;
}
float ppms_x = (float)m_pan_dx / (float)m_pan_delta_time_ms;
float ppms_y = (float)m_pan_dy / (float)m_pan_delta_time_ms;
float ppms_x =
static_cast<float>(m_pan_dx) / static_cast<float>(m_pan_delta_time_ms);
float ppms_y =
static_cast<float>(m_pan_dy) / static_cast<float>(m_pan_delta_time_ms);
ppms_x *= m_pan_power_multiplier_x;
ppms_y *= m_pan_power_multiplier_y;
AdjustToSnappingAndScroll(ppms_x, ppms_y);
} else
} else {
StopOrSnapScroll();
}
}
void Scroller::Start() {
@@ -181,7 +188,7 @@ void Scroller::Start() {
return;
}
m_is_started = true;
double now_ms = double(util::GetTimeMS());
double now_ms = static_cast<double>(util::GetTimeMS());
if (now_ms < m_scroll_start_ms + kPanPowerAccelerationThresholdMillis) {
m_pan_power_multiplier_x *= kPanPowerMultiplier;
m_pan_power_multiplier_y *= kPanPowerMultiplier;
@@ -196,9 +203,11 @@ void Scroller::Stop() {
}
bool Scroller::StopIfAlmostStill() {
double now_ms = double(util::GetTimeMS());
if (now_ms > m_scroll_start_ms + (double)m_scroll_duration_x_ms &&
now_ms > m_scroll_start_ms + (double)m_scroll_duration_y_ms) {
double now_ms = static_cast<double>(util::GetTimeMS());
if (now_ms >
m_scroll_start_ms + static_cast<double>(m_scroll_duration_x_ms) &&
now_ms >
m_scroll_start_ms + static_cast<double>(m_scroll_duration_y_ms)) {
Stop();
return true;
}
@@ -229,8 +238,8 @@ void Scroller::AdjustToSnappingAndScroll(float ppms_x, float ppms_y) {
distance_y = target_y - info.y;
// Get the start speed from the new distance.
ppms_x = m_func.GetSpeedFromDistance((float)distance_x);
ppms_y = m_func.GetSpeedFromDistance((float)distance_y);
ppms_x = m_func.GetSpeedFromDistance(static_cast<float>(distance_x));
ppms_y = m_func.GetSpeedFromDistance(static_cast<float>(distance_y));
}
Scroll(ppms_x, ppms_y);
@@ -238,7 +247,7 @@ void Scroller::AdjustToSnappingAndScroll(float ppms_x, float ppms_y) {
void Scroller::Scroll(float start_speed_ppms_x, float start_speed_ppms_y) {
// Set start values.
m_scroll_start_ms = double(util::GetTimeMS());
m_scroll_start_ms = static_cast<double>(util::GetTimeMS());
GetTargetScrollXY(m_scroll_start_scroll_x, m_scroll_start_scroll_y);
m_scroll_start_speed_ppms_x = start_speed_ppms_x;
m_scroll_start_speed_ppms_y = start_speed_ppms_y;
@@ -268,10 +277,11 @@ bool Scroller::IsScrolling() {
void Scroller::GetTargetChildTranslation(int& x, int& y) const {
int root_x = 0, root_y = 0;
int child_translation_x = 0, child_translation_y = 0;
int child_translation_x = 0;
int child_translation_y = 0;
Element* scroll_root = m_target->scroll_root();
scroll_root->ConvertToRoot(root_x, root_y);
scroll_root->GetChildTranslation(child_translation_x, child_translation_y);
scroll_root->GetChildTranslation(&child_translation_x, &child_translation_y);
x = root_x + child_translation_x;
y = root_y + child_translation_y;
}
@@ -306,8 +316,8 @@ void Scroller::OnMessageReceived(Message* msg) {
// Calculate the time elapsed from scroll start. Clip within the
// duration for each axis.
double now_ms = double(util::GetTimeMS());
float elapsed_time_x = (float)(now_ms - m_scroll_start_ms);
double now_ms = static_cast<double>(util::GetTimeMS());
float elapsed_time_x = static_cast<float>(now_ms - m_scroll_start_ms);
float elapsed_time_y = elapsed_time_x;
elapsed_time_x = std::min(elapsed_time_x, m_scroll_duration_x_ms);
elapsed_time_y = std::min(elapsed_time_y, m_scroll_duration_y_ms);

View File

@@ -26,7 +26,7 @@ namespace parts {
// distance is in pixels. Distance and speed may be negative!
class ScrollerFunction {
public:
ScrollerFunction(float decay) : m_decay(decay) {}
explicit ScrollerFunction(float decay) : m_decay(decay) {}
// Calculates the duration needed until the end distance is reached from the
// given start speed.
@@ -67,7 +67,7 @@ class ScrollerSnapListener {
// released with a flick.
class Scroller : private MessageHandler {
public:
Scroller(Element* target);
explicit Scroller(Element* target);
~Scroller() override;
// Sets the listener that may override the target scroll position.

View File

@@ -25,7 +25,7 @@ class PopupAlignment {
static const int kUnspecified = el::util::kInvalidDimension;
// Aligns relative to the target element.
PopupAlignment(Align align = Align::kBottom)
explicit PopupAlignment(Align align = Align::kBottom)
: pos_in_root(kUnspecified, kUnspecified),
align(align),
expand_to_target_width(true) {}
@@ -63,7 +63,7 @@ class PopupForm : public Form, private ElementListener {
public:
TBOBJECT_SUBCLASS(PopupForm, Form);
PopupForm(Element* target);
explicit PopupForm(Element* target);
~PopupForm() override;
void Show(const PopupAlignment& alignment);

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/resizer.h"
#include "el/parsing/element_inflater.h"

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/scroll_bar.h"
#include "el/parsing/element_inflater.h"
#include "el/util/math.h"
@@ -20,8 +22,7 @@ void ScrollBar::RegisterInflater() {
}
ScrollBar::ScrollBar()
: m_axis(Axis::kY) // Make SetAxis below always succeed and set the skin
{
: m_axis(Axis::kY) { // Make SetAxis below always succeed and set the skin
set_axis(Axis::kX);
AddChild(&m_handle);
}
@@ -123,14 +124,14 @@ void ScrollBar::UpdateHandle() {
if (m_max - m_min > 0 && m_visible > 0) {
double visible_proportion = m_visible / (m_visible + m_max - m_min);
visible_pixels = (int)(visible_proportion * available_pixels);
visible_pixels = static_cast<int>(visible_proportion * available_pixels);
// Limit the size of the indicator to the slider thickness so that it
// doesn't become too tiny when the visible proportion is very small.
visible_pixels = std::max(visible_pixels, min_thickness_pixels);
m_to_pixel_factor =
double(available_pixels - visible_pixels) / (m_max - m_min) /*+ 0.5*/;
m_to_pixel_factor = static_cast<double>(available_pixels - visible_pixels) /
(m_max - m_min) /*+ 0.5*/;
} else {
m_to_pixel_factor = 0;
@@ -138,7 +139,7 @@ void ScrollBar::UpdateHandle() {
visible_pixels = 0;
}
int pixel_pos = (int)(m_value * m_to_pixel_factor);
int pixel_pos = static_cast<int>(m_value * m_to_pixel_factor);
Rect handle_rect;
if (horizontal) {

View File

@@ -53,7 +53,7 @@ class ScrollBar : public Element {
// Same as SetValue, but with double precision.
void set_double_value(double value) override;
int value() override { return (int)double_value(); }
int value() override { return static_cast<int>(double_value()); }
void set_value(int value) override { set_double_value(value); }
void OnInflate(const parsing::InflateInfo& info) override;

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/scroll_container.h"
#include "el/parsing/element_inflater.h"
#include "el/util/debug.h"
@@ -111,11 +113,11 @@ void ScrollContainer::ScrollContainerRoot::OnPaintChildren(
graphics::Renderer::get()->set_clip_rect(old_clip_rect, false);
}
void ScrollContainer::ScrollContainerRoot::GetChildTranslation(int& x,
int& y) const {
void ScrollContainer::ScrollContainerRoot::GetChildTranslation(int* x,
int* y) const {
ScrollContainer* sc = static_cast<ScrollContainer*>(parent());
x = -sc->m_scrollbar_x.value();
y = -sc->m_scrollbar_y.value();
*x = -sc->m_scrollbar_x.value();
*y = -sc->m_scrollbar_y.value();
}
void ScrollContainer::RegisterInflater() {
@@ -273,7 +275,8 @@ bool ScrollContainer::OnEvent(const Event& ev) {
} else if (ev.special_key == SpecialKey::kHome) {
ScrollToSmooth(m_scrollbar_x.value(), 0);
} else if (ev.special_key == SpecialKey::kEnd) {
ScrollToSmooth(m_scrollbar_x.value(), (int)m_scrollbar_y.max_value());
ScrollToSmooth(m_scrollbar_x.value(),
static_cast<int>(m_scrollbar_y.max_value()));
} else {
return Element::OnEvent(ev);
}

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_SCROLL_CONTAINER_H_
#define EL_ELEMENTS_SCROLL_CONTAINER_H_
#include <vector>
#include "el/element.h"
#include "el/elements/scroll_bar.h"
@@ -68,7 +70,7 @@ class ScrollContainer : public Element {
class ScrollContainerRoot : public Element {
public:
void OnPaintChildren(const PaintProps& paint_props) override;
void GetChildTranslation(int& x, int& y) const override;
void GetChildTranslation(int* x, int* y) const override;
};
void ValidateLayout(const SizeConstraints& constraints);
@@ -89,7 +91,7 @@ using el::elements::ScrollMode;
struct ScrollContainerNode : public ElementNode<ScrollContainerNode> {
using R = ScrollContainerNode;
ScrollContainerNode(std::vector<Node> children = {})
explicit ScrollContainerNode(std::vector<Node> children = {})
: ElementNode("ScrollContainer", {}, std::move(children)) {}
//
R& adapt_content(bool value) {

View File

@@ -19,8 +19,7 @@ void Slider::RegisterInflater() {
}
Slider::Slider()
: m_axis(Axis::kY) // Make SetAxis below always succeed and set the skin
{
: m_axis(Axis::kY) { // Make SetAxis below always succeed and set the skin
set_focusable(true);
set_axis(Axis::kX);
AddChild(&m_handle);
@@ -32,8 +31,10 @@ void Slider::OnInflate(const parsing::InflateInfo& info) {
auto axis = el::from_string(info.node->GetValueString("axis", "x"), Axis::kY);
set_axis(axis);
set_gravity(axis == Axis::kX ? Gravity::kLeftRight : Gravity::kTopBottom);
double min = double(info.node->GetValueFloat("min", (float)min_value()));
double max = double(info.node->GetValueFloat("max", (float)max_value()));
double min = static_cast<double>(
info.node->GetValueFloat("min", static_cast<float>(min_value())));
double max = static_cast<double>(
info.node->GetValueFloat("max", static_cast<float>(max_value())));
set_limits(min, max);
Element::OnInflate(info);
}
@@ -119,10 +120,10 @@ void Slider::UpdateHandle() {
if (m_max - m_min > 0) {
PreferredSize ps = m_handle.GetPreferredSize();
int handle_pixels = horizontal ? ps.pref_w : ps.pref_h;
m_to_pixel_factor =
double(available_pixels - handle_pixels) / (m_max - m_min) /*+ 0.5*/;
m_to_pixel_factor = static_cast<double>(available_pixels - handle_pixels) /
(m_max - m_min) /*+ 0.5*/;
int pixel_pos = int((m_value - m_min) * m_to_pixel_factor);
int pixel_pos = static_cast<int>((m_value - m_min) * m_to_pixel_factor);
if (horizontal) {
handle_rect.reset(pixel_pos, (rect().h - ps.pref_h) / 2, ps.pref_w,

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_SLIDER_H_
#define EL_ELEMENTS_SLIDER_H_
#include <algorithm>
#include "el/element.h"
namespace el {
@@ -44,7 +46,7 @@ class Slider : public Element {
// Same as SetValue, but with double precision.
void set_double_value(double value) override;
int value() override { return (int)double_value(); }
int value() override { return static_cast<int>(double_value()); }
void set_value(int value) override { set_double_value(value); }
void OnInflate(const parsing::InflateInfo& info) override;

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_SPIN_BOX_H_
#define EL_ELEMENTS_SPIN_BOX_H_
#include <algorithm>
#include "el/element.h"
#include "el/elements/button.h"
#include "el/elements/layout_box.h"

View File

@@ -10,6 +10,9 @@
#ifndef EL_ELEMENTS_SPLIT_CONTAINER_H_
#define EL_ELEMENTS_SPLIT_CONTAINER_H_
#include <algorithm>
#include <vector>
#include "el/element.h"
#include "el/elements/box.h"
@@ -91,7 +94,7 @@ using el::elements::FixedPane;
struct SplitContainerNode : public ElementNode<SplitContainerNode> {
using R = SplitContainerNode;
SplitContainerNode(std::vector<Node> children = {})
explicit SplitContainerNode(std::vector<Node> children = {})
: ElementNode("SplitContainer", {}, std::move(children)) {}
//
R& value(int32_t value) {

View File

@@ -10,6 +10,8 @@
#ifndef EL_ELEMENTS_TAB_CONTAINER_H_
#define EL_ELEMENTS_TAB_CONTAINER_H_
#include <vector>
#include "el/element.h"
#include "el/elements/layout_box.h"
@@ -79,7 +81,7 @@ namespace dsl {
struct TabContainerNode : public ElementNode<TabContainerNode> {
using R = TabContainerNode;
TabContainerNode(std::vector<Node> children = {})
explicit TabContainerNode(std::vector<Node> children = {})
: ElementNode("TabContainer", {}, std::move(children)) {}
//
R& value(int32_t value) {

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/elements/menu_form.h"
#include "el/elements/text_box.h"
#include "el/parsing/element_inflater.h"
@@ -183,7 +185,7 @@ bool TextBox::GetCustomSkinCondition(const SkinCondition::ConditionInfo& info) {
return info.value == TBIDC("url");
case EditType::kNumber:
return info.value == TBIDC("number");
};
}
} else if (info.custom_prop == TBIDC("multiline")) {
return !((uint32_t)info.value) == !is_multiline();
} else if (info.custom_prop == TBIDC("readonly")) {
@@ -339,11 +341,13 @@ void TextBox::OnPaintChildren(const PaintProps& paint_props) {
Element::OnPaintChildren(paint_props);
// Draw fadeout skin at the needed edges.
Skin::DrawEdgeFadeout(
visible_rect(), TBIDC("TextBox.fadeout_x"), TBIDC("TextBox.fadeout_y"),
m_scrollbar_x.value(), m_scrollbar_y.value(),
int(m_scrollbar_x.max_value() - m_scrollbar_x.double_value()),
int(m_scrollbar_y.max_value() - m_scrollbar_y.double_value()));
Skin::DrawEdgeFadeout(visible_rect(), TBIDC("TextBox.fadeout_x"),
TBIDC("TextBox.fadeout_y"), m_scrollbar_x.value(),
m_scrollbar_y.value(),
static_cast<int>(m_scrollbar_x.max_value() -
m_scrollbar_x.double_value()),
static_cast<int>(m_scrollbar_y.max_value() -
m_scrollbar_y.double_value()));
}
void TextBox::OnAdded() { m_style_edit.SetFont(computed_font_description()); }
@@ -536,10 +540,10 @@ void TextBox::TextBoxScrollRoot::OnPaintChildren(
Renderer::get()->set_clip_rect(old_clip_rect, false);
}
void TextBox::TextBoxScrollRoot::GetChildTranslation(int& x, int& y) const {
void TextBox::TextBoxScrollRoot::GetChildTranslation(int* x, int* y) const {
TextBox* edit_field = static_cast<TextBox*>(parent());
x = -edit_field->text_view()->scroll_x;
y = -edit_field->text_view()->scroll_y;
*x = -edit_field->text_view()->scroll_x;
*y = -edit_field->text_view()->scroll_y;
}
HitStatus TextBox::TextBoxScrollRoot::GetHitStatus(int x, int y) {

View File

@@ -7,8 +7,10 @@
******************************************************************************
*/
#ifndef EL_EDITFIELD_H
#define EL_EDITFIELD_H
#ifndef EL_ELEMENTS_TEXT_BOX_H_
#define EL_ELEMENTS_TEXT_BOX_H_
#include <string>
#include "el/element.h"
#include "el/elements/label.h"
@@ -164,7 +166,7 @@ class TextBox : public Element,
public:
void OnPaintChildren(const PaintProps& paint_props) override;
void GetChildTranslation(int& x, int& y) const override;
void GetChildTranslation(int* x, int* y) const override;
HitStatus GetHitStatus(int x, int y) override;
};
@@ -224,7 +226,7 @@ using el::elements::EditType;
struct TextBoxNode : public ElementNode<TextBoxNode> {
using R = TextBoxNode;
TextBoxNode(const char* text = nullptr) : ElementNode("TextBox") {
explicit TextBoxNode(const char* text = nullptr) : ElementNode("TextBox") {
if (text) {
this->text(text);
}
@@ -279,4 +281,4 @@ struct TextBoxNode : public ElementNode<TextBoxNode> {
} // namespace dsl
} // namespace el
#endif // EL_EDITFIELD_H
#endif // EL_ELEMENTS_TEXT_BOX_H_

View File

@@ -70,7 +70,7 @@ void ToggleContainer::UpdateInternal() {
// Also disable when collapsed so tab focus skips the children.
set_state(Element::State::kDisabled, !on);
break;
};
}
}
} // namespace elements

View File

@@ -138,7 +138,7 @@ class Event : public util::TypedObject {
// on screen).
bool touch = false;
Event(EventType type) : type(type) {}
explicit Event(EventType type) : type(type) {}
Event(EventType type, int x, int y, bool touch,
ModifierKeys modifierkeys = ModifierKeys::kNone)

View File

@@ -22,7 +22,7 @@ namespace el {
class EventHandler : public util::IntrusiveListEntry<EventHandler> {
public:
EventHandler(Element* scope_element);
explicit EventHandler(Element* scope_element);
~EventHandler();
void Listen(EventType event_type,

View File

@@ -11,6 +11,7 @@
#define EL_GRAPHICS_BITMAP_FRAGMENT_MAP_H_
#include <memory>
#include <string>
#include <vector>
#include "el/graphics/bitmap_fragment.h"

View File

@@ -20,7 +20,6 @@ namespace graphics {
// size.
#define STB_IMAGE_STATIC
#define STB_IMAGE_IMPLEMENTATION
//#define STBI_SIMD
#define STBI_NO_STDIO
#define STBI_NO_FAILURE_STRINGS
#define STBI_NO_HDR
@@ -40,7 +39,7 @@ class StbiImageLoader : public ImageLoader {
int width() override { return width_; }
int height() override { return height_; }
uint32_t* data() override { return (uint32_t*)data_; }
uint32_t* data() override { return reinterpret_cast<uint32_t*>(data_); }
private:
int width_;
@@ -57,8 +56,8 @@ std::unique_ptr<ImageLoader> ImageLoader::CreateFromFile(
}
int w, h, comp;
auto img_data = stbi_load_from_memory(buffer->data(), int(buffer->size()), &w,
&h, &comp, 4);
auto img_data = stbi_load_from_memory(
buffer->data(), static_cast<int>(buffer->size()), &w, &h, &comp, 4);
if (!img_data) {
return nullptr;
}

View File

@@ -96,7 +96,7 @@ Image ImageManager::GetImage(const char* filename) {
uint32_t hash_key = util::hash(filename);
auto it = m_image_rep_hash.find(hash_key);
if (it != m_image_rep_hash.end()) {
return it->second;
return Image(it->second);
}
// Load a fragment. Load a destination DPI bitmap if available.

View File

@@ -47,8 +47,8 @@ class ImageRep {
class Image {
public:
Image() = default;
Image(ImageRep* rep);
Image(const Image& image);
Image(ImageRep* rep); // NOLINT(runtime/explicit)
Image(const Image& image); // NOLINT(runtime/explicit)
~Image();
// Returns true if this image is empty.

View File

@@ -178,10 +178,10 @@ void Renderer::AddQuadInternal(const Rect& dst_rect, const Rect& src_rect,
if (bitmap) {
int bitmap_w = bitmap->width();
int bitmap_h = bitmap->height();
m_u = (float)src_rect.x / bitmap_w;
m_v = (float)src_rect.y / bitmap_h;
m_uu = (float)(src_rect.x + src_rect.w) / bitmap_w;
m_vv = (float)(src_rect.y + src_rect.h) / bitmap_h;
m_u = static_cast<float>(src_rect.x) / bitmap_w;
m_v = static_cast<float>(src_rect.y) / bitmap_h;
m_uu = static_cast<float>(src_rect.x + src_rect.w) / bitmap_w;
m_vv = static_cast<float>(src_rect.y + src_rect.h) / bitmap_h;
}
batch_.fragment = fragment;
if (fragment) {
@@ -189,34 +189,34 @@ void Renderer::AddQuadInternal(const Rect& dst_rect, const Rect& src_rect,
fragment->m_batch_id = batch_.batch_id;
}
v[0].x = (float)dst_rect.x;
v[0].y = (float)(dst_rect.y + dst_rect.h);
v[0].x = static_cast<float>(dst_rect.x);
v[0].y = static_cast<float>(dst_rect.y + dst_rect.h);
v[0].u = m_u;
v[0].v = m_vv;
v[0].color = color;
v[1].x = (float)(dst_rect.x + dst_rect.w);
v[1].y = (float)(dst_rect.y + dst_rect.h);
v[1].x = static_cast<float>(dst_rect.x + dst_rect.w);
v[1].y = static_cast<float>(dst_rect.y + dst_rect.h);
v[1].u = m_uu;
v[1].v = m_vv;
v[1].color = color;
v[2].x = (float)dst_rect.x;
v[2].y = (float)dst_rect.y;
v[2].x = static_cast<float>(dst_rect.x);
v[2].y = static_cast<float>(dst_rect.y);
v[2].u = m_u;
v[2].v = m_v;
v[2].color = color;
v[3].x = (float)dst_rect.x;
v[3].y = (float)dst_rect.y;
v[3].x = static_cast<float>(dst_rect.x);
v[3].y = static_cast<float>(dst_rect.y);
v[3].u = m_u;
v[3].v = m_v;
v[3].color = color;
v[4].x = (float)(dst_rect.x + dst_rect.w);
v[4].y = (float)(dst_rect.y + dst_rect.h);
v[4].x = static_cast<float>(dst_rect.x + dst_rect.w);
v[4].y = static_cast<float>(dst_rect.y + dst_rect.h);
v[4].u = m_uu;
v[4].v = m_vv;
v[4].color = color;
v[5].x = (float)(dst_rect.x + dst_rect.w);
v[5].y = (float)dst_rect.y;
v[5].x = static_cast<float>(dst_rect.x + dst_rect.w);
v[5].y = static_cast<float>(dst_rect.y);
v[5].u = m_uu;
v[5].v = m_v;
v[5].color = color;

View File

@@ -25,10 +25,12 @@ namespace el {
// string which will be hashed into the uint32_t.
class TBID {
public:
TBID(uint32_t id = 0) { reset(id); }
TBID(const char* string) { reset(string); }
TBID(const std::string& string) { reset(string.c_str()); }
TBID(const TBID& id) { reset(id); }
TBID(uint32_t id = 0) { reset(id); } // NOLINT(runtime/explicit)
TBID(const char* string) { reset(string); } // NOLINT(runtime/explicit)
TBID(const std::string& string) { // NOLINT(runtime/explicit)
reset(string.c_str());
}
TBID(const TBID& id) { reset(id); } // NOLINT(runtime/explicit)
#ifdef EL_RUNTIME_DEBUG_INFO
void reset(uint32_t newid);

View File

@@ -13,6 +13,7 @@
#include <memory>
#include <string>
#include <unordered_map>
#include <utility>
#include "el/io/file_system.h"

View File

@@ -15,13 +15,13 @@ namespace io {
namespace {
class PosixFile : public File {
public:
PosixFile(FILE* file_handle_) : file_handle_(file_handle_) {}
explicit PosixFile(FILE* file_handle) : file_handle_(file_handle) {}
~PosixFile() override { fclose(file_handle_); }
size_t size() const override {
long oldpos = ftell(file_handle_);
int32_t oldpos = ftell(file_handle_);
fseek(file_handle_, 0, SEEK_END);
long num_bytes = ftell(file_handle_);
int32_t num_bytes = ftell(file_handle_);
fseek(file_handle_, oldpos, SEEK_SET);
return num_bytes;
}

View File

@@ -20,7 +20,7 @@ namespace io {
class PosixFileSystem : public FileSystem {
public:
PosixFileSystem(std::string root_path);
explicit PosixFileSystem(std::string root_path);
std::unique_ptr<File> OpenRead(std::string filename) override;

View File

@@ -20,7 +20,7 @@ namespace io {
class Win32ResFileSystem : public FileSystem {
public:
Win32ResFileSystem(std::string prefix);
explicit Win32ResFileSystem(std::string prefix);
std::unique_ptr<File> OpenRead(std::string filename) override;

View File

@@ -18,7 +18,13 @@
namespace el {
using namespace el::elements;
using el::elements::IconBox;
using el::elements::Label;
using el::elements::LayoutBox;
using el::elements::LayoutDistribution;
using el::elements::MenuForm;
using el::elements::PopupAlignment;
using el::elements::Separator;
// SimpleBoxItemElement is a item containing a layout with the following:
// - IconBox showing the item image.

View File

@@ -11,6 +11,8 @@
#define EL_LIST_ITEM_H_
#include <memory>
#include <string>
#include <utility>
#include <vector>
#include "el/dsl.h"
@@ -203,11 +205,11 @@ class GenericStringItem {
id(other.id),
sub_source(other.sub_source),
tag(other.tag) {}
GenericStringItem(const char* str) : str(str) {}
explicit GenericStringItem(const char* str) : str(str) {}
GenericStringItem(const char* str, TBID id) : str(str), id(id) {}
GenericStringItem(const char* str, ListItemSource* sub_source)
: str(str), sub_source(sub_source) {}
GenericStringItem(const std::string& str) : str(str) {}
explicit GenericStringItem(const std::string& str) : str(str) {}
GenericStringItem(const std::string& str, TBID id) : str(str), id(id) {}
GenericStringItem(const std::string& str, ListItemSource* sub_source)
: str(str), sub_source(sub_source) {}
@@ -249,7 +251,7 @@ struct Item {
template <typename T>
struct ItemListElementNode : public ElementNode<T> {
protected:
ItemListElementNode(const char* name) : ElementNode<T>(name) {}
explicit ItemListElementNode(const char* name) : ElementNode<T>(name) {}
public:
T& item(std::string text) {

View File

@@ -11,6 +11,7 @@
#define EL_PARSING_ELEMENT_FACTORY_H_
#include <memory>
#include <string>
#include <vector>
#include "el/parsing/parse_node.h"
@@ -50,39 +51,39 @@ class ElementInflater;
//
// Resource name: Element property: Values:
//
// id m_id TBID (string or
// id m_id TBID (string or
// int)
// group-id m_group_id TBID (string or int)
// value SetValue integer
// data m_data integer
// is-group-root SetIsGroupRoot boolean
// is-focusable SetIsFocusable boolean
// want-long-click SetWantLongClick boolean
// ignore-input SetIgnoreInput boolean
// opacity SetOpacity float (0 - 1)
// text SetText string
// connection Connect string
// axis SetAxis x or y
// gravity SetGravity string
// group-id m_group_id TBID (string or int)
// value SetValue integer
// data m_data integer
// is-group-root SetIsGroupRoot boolean
// is-focusable SetIsFocusable boolean
// want-long-click SetWantLongClick boolean
// ignore-input SetIgnoreInput boolean
// opacity SetOpacity float (0 - 1)
// text SetText string
// connection Connect string
// axis SetAxis x or y
// gravity SetGravity string
// combination of left, top, right, bottom, or all
// visibility SetVisibility string (visible, invisible,
// visibility SetVisibility string (visible, invisible,
// gone)
// state SetState string (disabled)
// skin SetSkinBg TBID (string or int)
// rect set_rect 4 integers (x, y, width,
// state SetState string (disabled)
// skin SetSkinBg TBID (string or int)
// rect set_rect 4 integers (x, y, width,
// height)
// lp>width set_layout_params dimension
// lp>min-width set_layout_params dimension
// lp>max-width set_layout_params dimension
// lp>pref-width set_layout_params dimension
// lp>height set_layout_params dimension
// lp>min-height set_layout_params dimension
// lp>max-height set_layout_params dimension
// lp>pref-height set_layout_params dimension
// autofocus The Element will be focused automatically the
// lp>width set_layout_params dimension
// lp>min-width set_layout_params dimension
// lp>max-width set_layout_params dimension
// lp>pref-width set_layout_params dimension
// lp>height set_layout_params dimension
// lp>min-height set_layout_params dimension
// lp>max-height set_layout_params dimension
// lp>pref-height set_layout_params dimension
// autofocus The Element will be focused automatically the
// first time its Form is activated.
// font>name Font name
// font>size Font size
// font>name Font name
// font>size Font size
class ElementFactory {
public:
static ElementFactory* get() { return element_reader_singleton_.get(); }

View File

@@ -37,7 +37,7 @@ ParseNode* ParseNode::Create(const char* name) {
// static
ParseNode* ParseNode::Create(const char* name, size_t name_len) {
ParseNode* n = new ParseNode();
n->m_name = (char*)malloc(name_len + 1);
n->m_name = reinterpret_cast<char*>(malloc(name_len + 1));
std::memcpy(n->m_name, name, name_len);
n->m_name[name_len] = 0;
return n;

View File

@@ -10,6 +10,8 @@
#ifndef EL_PARSING_PARSE_NODE_H_
#define EL_PARSING_PARSE_NODE_H_
#include <string>
#include "el/types.h"
#include "el/util/intrusive_list.h"
#include "el/value.h"

View File

@@ -107,11 +107,10 @@ ParseNode* ParseNodeTree::FollowNodeRef(ParseNode* node) {
}
next_node =
local_root->GetNode(name_start + 1, ParseNode::MissingPolicy::kNull);
}
// We have a "@treename>noderequest" string. Go ahead and look it up from
// the right node tree.
else if (ParseNodeTree* rt =
ParseNodeTree::GetRefTree(name_start, name_end - name_start)) {
} else if (ParseNodeTree* rt = ParseNodeTree::GetRefTree(
name_start, name_end - name_start)) {
// We have a "@treename>noderequest" string. Go ahead and look it up from
// the right node tree.
next_node =
rt->m_node.GetNode(name_end + 1, ParseNode::MissingPolicy::kNull);
} else {

View File

@@ -10,6 +10,8 @@
#ifndef EL_PARSING_PARSE_NODE_TREE_H_
#define EL_PARSING_PARSE_NODE_TREE_H_
#include <string>
#include "el/id.h"
#include "el/parsing/parse_node.h"
#include "el/util/intrusive_list.h"
@@ -28,7 +30,7 @@ class ParseNodeTreeListener;
// nodes can be included.
class ParseNodeTree : public util::IntrusiveListEntry<ParseNodeTree> {
public:
ParseNodeTree(const char* name);
explicit ParseNodeTree(const char* name);
virtual ~ParseNodeTree();
const std::string& name() const { return m_name; }

View File

@@ -191,8 +191,7 @@ TextParser::Status TextParser::Read(TextParserStream* stream,
pending_multiline = false;
multi_line_sub_level = 0;
while (size_t read_len =
stream->GetMoreData((char*)work.data(), work.capacity())) {
while (size_t read_len = stream->GetMoreData(work.data(), work.capacity())) {
char* buf = work.data();
// Skip BOM (BYTE ORDER MARK) character, often in the beginning of UTF-8

View File

@@ -7,6 +7,7 @@
******************************************************************************
*/
#include <algorithm>
#include <cassert>
#include "el/rect.h"

View File

@@ -11,6 +11,7 @@
#define EL_SKIN_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "el/graphics/bitmap_fragment.h"

View File

@@ -129,15 +129,14 @@ int TBRunTests(uint32_t settings) {
// Execute test (and call setup and cleanup if available).
int fail = 0;
if (group->setup) fail = !!CallAndOutput(group, group->setup);
if (!fail) // Only run if setup succeeded
{
if (!fail) { // Only run if setup succeeded
fail |= !!CallAndOutput(group, call);
if (group->cleanup) fail |= !!CallAndOutput(group, group->cleanup);
}
// Handle result
if (fail)
if (fail) {
num_failed++;
else {
} else {
num_passed++;
OutputPass(group, call->name());
}

View File

@@ -156,7 +156,7 @@ class TBCall : public util::IntrusiveListEntry<TBCall> {
* Cleanup calls. */
class TBTestGroup {
public:
TBTestGroup(const char* name);
explicit TBTestGroup(const char* name);
bool IsSpecialTest(TBCall* call) const { return !call->linklist; }
public:

View File

@@ -158,7 +158,7 @@ void Caret::AvoidLineBreak() {
}
void Caret::Paint(int32_t translate_x, int32_t translate_y) {
// if (on && !(style_edit->select_state &&
// if (on && !(style_edit->select_state &&
// style_edit->selection.IsSelected()))
if (on || style_edit->select_state) {
style_edit->listener->DrawCaret(

View File

@@ -30,7 +30,7 @@ enum class CaretPosition {
// The caret in a TextView.
class Caret {
public:
Caret(TextView* style_edit);
explicit Caret(TextView* style_edit);
void Invalidate();
void UpdatePos();
bool Move(bool forward, bool word);

View File

@@ -60,12 +60,12 @@ void FontEffect::SetBlurRadius(int blur_radius) {
if (m_blur_radius > 0) {
delete[] m_kernel;
m_kernel = new float[m_blur_radius * 2 + 1];
float stdDevSq2 = (float)m_blur_radius / 2.f;
float stdDevSq2 = static_cast<float>(m_blur_radius) / 2.f;
stdDevSq2 = 2.f * stdDevSq2 * stdDevSq2;
float scale = 1.f / sqrt(3.1415f * stdDevSq2);
float sum = 0;
for (int k = 0; k < 2 * m_blur_radius + 1; k++) {
float x = (float)(k - m_blur_radius);
float x = static_cast<float>(k - m_blur_radius);
float kval = scale * exp(-(x * x / stdDevSq2));
m_kernel[k] = kval;
sum += kval;
@@ -98,7 +98,8 @@ FontGlyphData* FontEffect::Render(GlyphMetrics* metrics,
// Blur!
BlurGlyph(src->data8, src->w, src->h, src->stride, effect_glyph_data->data8,
effect_glyph_data->w, effect_glyph_data->h, effect_glyph_data->w,
(float*)m_blur_temp.data(), m_kernel, m_blur_radius);
reinterpret_cast<float*>(m_blur_temp.data()), m_kernel,
m_blur_radius);
// Adjust glyph position to compensate for larger size.
metrics->x -= m_blur_radius;

View File

@@ -20,6 +20,7 @@ namespace el {
namespace text {
using graphics::Renderer;
using UCS4 = el::text::utf8::UCS4;
FontGlyph::FontGlyph(const TBID& hash_id, UCS4 cp) : hash_id(hash_id), cp(cp) {}
@@ -103,7 +104,7 @@ void FontFace::RenderGlyph(FontGlyph* glyph) {
if (!glyph_dsta_src && result_glyph_data->data8) {
m_temp_buffer.Reserve(result_glyph_data->w * result_glyph_data->h *
sizeof(uint32_t));
glyph_dsta_src = (uint32_t*)m_temp_buffer.data();
glyph_dsta_src = reinterpret_cast<uint32_t*>(m_temp_buffer.data());
for (int y = 0; y < result_glyph_data->h; y++) {
for (int x = 0; x < result_glyph_data->w; x++) {
glyph_dsta_src[x + y * result_glyph_data->w] = Color(

View File

@@ -11,6 +11,7 @@
#define EL_TEXT_FONT_FACE_H_
#include <memory>
#include <string>
#include "el/color.h"
#include "el/font_description.h"
@@ -30,9 +31,6 @@ namespace text {
class FontGlyphCache;
class FontRenderer;
namespace {
using UCS4 = el::text::utf8::UCS4;
} // namespace
// Rendering info used during glyph rendering by FontRenderer.
// It does not own the data pointers.
@@ -67,9 +65,9 @@ class FontMetrics {
// FontFace.
class FontGlyph : public util::IntrusiveListEntry<FontGlyph> {
public:
FontGlyph(const TBID& hash_id, UCS4 cp);
FontGlyph(const TBID& hash_id, utf8::UCS4 cp);
TBID hash_id;
UCS4 cp;
utf8::UCS4 cp;
GlyphMetrics metrics; // The glyph metrics.
graphics::BitmapFragment* frag =
nullptr; // The bitmap fragment, or nullptr if missing.
@@ -130,9 +128,9 @@ class FontFace {
void SetBackgroundFont(FontFace* font, const Color& col, int xofs, int yofs);
private:
TBID GetHashId(UCS4 cp) const;
FontGlyph* GetGlyph(UCS4 cp, bool render_if_needed);
FontGlyph* CreateAndCacheGlyph(UCS4 cp);
TBID GetHashId(utf8::UCS4 cp) const;
FontGlyph* GetGlyph(utf8::UCS4 cp, bool render_if_needed);
FontGlyph* CreateAndCacheGlyph(utf8::UCS4 cp);
void RenderGlyph(FontGlyph* glyph);
FontGlyphCache* m_glyph_cache = nullptr;

View File

@@ -16,6 +16,7 @@ namespace el {
namespace text {
using graphics::Renderer;
using UCS4 = el::text::utf8::UCS4;
// The dimensions of the font glyph cache bitmap. Must be a power of two.
constexpr int kDefaultGlyphCacheMapWidth = 512;

View File

@@ -26,10 +26,6 @@
namespace el {
namespace text {
namespace {
using UCS4 = el::text::utf8::UCS4;
} // namespace
// Provides information about a font file associated with a font id.
class FontInfo {
public:
@@ -57,11 +53,11 @@ class FontGlyphCache : private graphics::RendererListener {
~FontGlyphCache();
// Gets the glyph or nullptr if it is not in the cache.
FontGlyph* GetGlyph(const TBID& hash_id, UCS4 cp);
FontGlyph* GetGlyph(const TBID& hash_id, utf8::UCS4 cp);
// Creates the glyph and put it in the cache.
// Returns the glyph, or nullptr on fail.
FontGlyph* CreateAndCacheGlyph(const TBID& hash_id, UCS4 cp);
FontGlyph* CreateAndCacheGlyph(const TBID& hash_id, utf8::UCS4 cp);
// Creates a bitmap fragment for the given glyph and render data. This may
// drop other rendered glyphs from the fragment map.

View File

@@ -25,9 +25,6 @@ class FontGlyphData;
class FontManager;
class FontMetrics;
class GlyphMetrics;
namespace {
using UCS4 = el::text::utf8::UCS4;
} // namespace
// Renders glyphs from a font file.
class FontRenderer {
@@ -41,8 +38,8 @@ class FontRenderer {
FontManager* font_manager, const std::string& filename,
const FontDescription& font_desc) = 0;
virtual bool RenderGlyph(FontGlyphData* data, UCS4 cp) = 0;
virtual void GetGlyphMetrics(GlyphMetrics* metrics, UCS4 cp) = 0;
virtual bool RenderGlyph(FontGlyphData* data, utf8::UCS4 cp) = 0;
virtual void GetGlyphMetrics(GlyphMetrics* metrics, utf8::UCS4 cp) = 0;
virtual FontMetrics GetMetrics() = 0;
};

View File

@@ -22,6 +22,7 @@ static FT_Library g_freetype = nullptr;
using namespace el;
using namespace el::resources;
using UCS4 = el::text::utf8::UCS4;
/** Cache of truetype file data, so it isn't loaded multiple times for each font
* size */
@@ -153,11 +154,11 @@ FontFace* FreetypeFontRenderer::Create(FontManager* font_manager,
FreetypeFace* f = ft_face_cache.Get(face_cache_id);
if (f) {
++f->refCount;
if (fr->Load(f, (int)font_desc.size()))
if (fr->Load(f, static_cast<int>(font_desc.size())))
if (FontFace* font =
new FontFace(font_manager->glyph_cache(), fr, font_desc))
return font;
} else if (fr->Load(filename, (int)font_desc.size())) {
} else if (fr->Load(filename, static_cast<int>(font_desc.size()))) {
if (ft_face_cache.Add(face_cache_id, fr->m_face))
fr->m_face->hashID = face_cache_id;
if (FontFace* font =

View File

@@ -21,7 +21,9 @@ namespace text {
// implementation
#include "third_party/stb/stb_truetype.h"
/** SFontRenderer renders fonts using stb_truetype.h (http://nothings.org/) */
// SFontRenderer renders fonts using stb_truetype.h (http://nothings.org/).
using UCS4 = el::text::utf8::UCS4;
class SFontRenderer : public FontRenderer {
public:
@@ -66,7 +68,7 @@ bool SFontRenderer::RenderGlyph(FontGlyphData* data, UCS4 cp) {
void SFontRenderer::GetGlyphMetrics(GlyphMetrics* metrics, UCS4 cp) {
int advanceWidth, leftSideBearing;
stbtt_GetCodepointHMetrics(&font, cp, &advanceWidth, &leftSideBearing);
metrics->advance = (int)(advanceWidth * scale + 0.5f);
metrics->advance = static_cast<int>(advanceWidth * scale + 0.5f);
int ix0, iy0, ix1, iy1;
stbtt_GetCodepointBitmapBox(&font, cp, 0, scale, &ix0, &iy0, &ix1, &iy1);
metrics->x = ix0;
@@ -77,9 +79,10 @@ FontMetrics SFontRenderer::GetMetrics() {
FontMetrics metrics;
int ascent, descent, lineGap;
stbtt_GetFontVMetrics(&font, &ascent, &descent, &lineGap);
metrics.ascent = (int)(ascent * scale + 0.5f);
metrics.descent = (int)((-descent) * scale + 0.5f);
metrics.height = (int)((ascent - descent + lineGap) * scale + 0.5f);
metrics.ascent = static_cast<int>(ascent * scale + 0.5f);
metrics.descent = static_cast<int>((-descent) * scale + 0.5f);
metrics.height =
static_cast<int>((ascent - descent + lineGap) * scale + 0.5f);
return metrics;
}
@@ -93,9 +96,10 @@ bool SFontRenderer::Load(const char* filename, int size) {
stbtt_InitFont(&font, ttf_buffer, stbtt_GetFontOffsetForIndex(ttf_buffer, 0));
font_size = (int)(size * 1.3f); // FIX: Constant taken out of thin air
// because fonts get too small.
scale = stbtt_ScaleForPixelHeight(&font, (float)font_size);
font_size =
static_cast<int>(size * 1.3f); // FIX: Constant taken out of thin air
// because fonts get too small.
scale = stbtt_ScaleForPixelHeight(&font, static_cast<float>(font_size));
return true;
}
@@ -103,7 +107,8 @@ std::unique_ptr<FontFace> SFontRenderer::Create(
FontManager* font_manager, const std::string& filename,
const FontDescription& font_desc) {
auto font_renderer = std::make_unique<SFontRenderer>();
if (font_renderer->Load(filename.c_str(), (int)font_desc.size())) {
if (font_renderer->Load(filename.c_str(),
static_cast<int>(font_desc.size()))) {
return std::make_unique<FontFace>(font_manager->glyph_cache(),
std::move(font_renderer), font_desc);
}

View File

@@ -25,6 +25,7 @@ namespace el {
namespace text {
using namespace el::parsing;
using UCS4 = el::text::utf8::UCS4;
namespace {
struct GLYPH {
@@ -284,7 +285,7 @@ std::unique_ptr<FontFace> TBBFRenderer::Create(
const FontDescription& font_desc) {
if (!strstr(filename.c_str(), ".tb.txt")) return nullptr;
auto fr = std::make_unique<TBBFRenderer>();
if (!fr->Load(filename, (int)font_desc.size())) {
if (!fr->Load(filename, static_cast<int>(font_desc.size()))) {
return nullptr;
}
return std::make_unique<FontFace>(font_manager->glyph_cache(), std::move(fr),

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/text/font_manager.h"
#include "el/text/text_fragment.h"
#include "el/text/text_fragment_content.h"
@@ -264,7 +266,7 @@ void TextBlock::Merge() {
int32_t TextBlock::CalculateTabWidth(el::text::FontFace* font,
int32_t xpos) const {
int tabsize = font->GetStringWidth("x", 1) * TAB_SPACE;
int p2 = int(xpos / tabsize) * tabsize + tabsize;
int p2 = static_cast<int>(xpos / tabsize) * tabsize + tabsize;
return p2 - xpos;
}
@@ -274,7 +276,7 @@ int32_t TextBlock::CalculateStringWidth(el::text::FontFace* font,
// Convert the length in number or characters, since that's what matters for
// password width.
len = utf8::count_characters(str, len);
return font->GetStringWidth(special_char_password) * int(len);
return font->GetStringWidth(special_char_password) * static_cast<int>(len);
}
return font->GetStringWidth(str, len);
}
@@ -308,7 +310,7 @@ int TextBlock::GetStartIndentation(el::text::FontFace* font,
case 0x2022: // BULLET
indentation += CalculateStringWidth(font, current_str, 3);
continue;
};
}
break;
}
return indentation;
@@ -661,7 +663,7 @@ void TextFragment::Paint(int32_t translate_x, int32_t translate_y,
int cw = block->CalculateStringWidth(font, special_char_password);
size_t num_char = utf8::count_characters(Str(), len);
for (size_t i = 0; i < num_char; ++i) {
listener->DrawString(int(x + i * cw), y, font, color,
listener->DrawString(static_cast<int>(x + i * cw), y, font, color,
special_char_password);
}
} else if (block->style_edit->packed.show_whitespace) {

View File

@@ -53,7 +53,7 @@ class TextProps {
// A block of text (a line, that might be wrapped).
class TextBlock : public el::util::IntrusiveListEntry<TextBlock> {
public:
TextBlock(TextView* style_edit);
explicit TextBlock(TextView* style_edit);
~TextBlock();
void Clear();
@@ -118,12 +118,12 @@ class TextBlock : public el::util::IntrusiveListEntry<TextBlock> {
// The text fragment base class for TextView.
class TextFragment : public el::util::IntrusiveListEntry<TextFragment> {
// TODO: This object is allocated on vast amounts and need
// to shrink in size.Remove all cached positioning
// and implement a fragment traverser(for TextBlock).
// Also allocate fragments in chunks.
// TODO(benvanik): This object is allocated on vast amounts and need to shrink
// in size. Remove all cached positioning and implement a fragment traverser
// (for TextBlock). Also allocate fragments in chunks.
public:
TextFragment(TextFragmentContent* content = nullptr) : content(content) {}
explicit TextFragment(TextFragmentContent* content = nullptr)
: content(content) {}
~TextFragment();
void Init(TextBlock* block, uint16_t ofs, uint16_t len);

View File

@@ -7,6 +7,8 @@
******************************************************************************
*/
#include <algorithm>
#include "el/text/text_fragment_content.h"
namespace el {

View File

@@ -76,7 +76,7 @@ class TextFragmentContentUnderline : public TextFragmentContent {
// Fragment content that changes color in a TextView.
class TextFragmentContentTextColor : public TextFragmentContent {
public:
TextFragmentContentTextColor(const Color& color) : color(color) {}
explicit TextFragmentContentTextColor(const Color& color) : color(color) {}
void Paint(TextFragment* fragment, int32_t translate_x, int32_t translate_y,
TextProps* props) override;
bool GetAllowBreakBefore() override { return true; }

View File

@@ -10,6 +10,8 @@
#ifndef EL_TEXT_TEXT_SELECTION_H_
#define EL_TEXT_TEXT_SELECTION_H_
#include <string>
#include "el/color.h"
namespace el {
@@ -44,7 +46,7 @@ class TextOffset {
// Handles the selected text in a TextView.
class TextSelection {
public:
TextSelection(TextView* style_edit);
explicit TextSelection(TextView* style_edit);
void Invalidate() const;
void Select(const TextOffset& new_start, const TextOffset& new_stop);
void Select(const Point& from, const Point& to);

View File

@@ -12,6 +12,7 @@
#include <algorithm>
#include <memory>
#include <string>
#include <vector>
#include "el/color.h"

View File

@@ -61,28 +61,29 @@ invalid:
int encode(UCS4 ch, char* dst) {
if (ch < 0x80) {
dst[0] = (char)ch;
dst[0] = static_cast<char>(ch);
return 1;
} else if (ch < 0x800) {
dst[0] = (char)(0xC0 + (ch >> 6));
dst[1] = (char)(0x80 + (ch & 0x3F));
dst[0] = static_cast<char>(0xC0 + (ch >> 6));
dst[1] = static_cast<char>(0x80 + (ch & 0x3F));
return 2;
} else if (ch < 0x10000) {
dst[0] = (char)(0xE0 + (ch >> 12));
dst[1] = (char)(0x80 + ((ch >> 6) & 0x3F));
dst[2] = (char)(0x80 + (ch & 0x3F));
dst[0] = static_cast<char>(0xE0 + (ch >> 12));
dst[1] = static_cast<char>(0x80 + ((ch >> 6) & 0x3F));
dst[2] = static_cast<char>(0x80 + (ch & 0x3F));
return 3;
} else if (ch <= 0x10FFFF) {
dst[0] = (char)(0xF0 + (ch >> 18));
dst[1] = (char)(0x80 + ((ch >> 12) & 0x3F));
dst[2] = (char)(0x80 + ((ch >> 6) & 0x3F));
dst[3] = (char)(0x80 + (ch & 0x3F));
dst[0] = static_cast<char>(0xF0 + (ch >> 18));
dst[1] = static_cast<char>(0x80 + ((ch >> 12) & 0x3F));
dst[2] = static_cast<char>(0x80 + ((ch >> 6) & 0x3F));
dst[3] = static_cast<char>(0x80 + (ch & 0x3F));
return 4;
} else {
// output UTF-8 encoding of 0xFFFF
dst[0] = (char)0xEF;
dst[1] = (char)0xBF;
dst[2] = (char)0xBF;
// output UTF-8 encoding of 0xFFFF
auto udst = reinterpret_cast<uint8_t*>(dst);
udst[0] = 0xEF;
udst[1] = 0xBF;
udst[2] = 0xBF;
return 3;
}
}

View File

@@ -21,9 +21,8 @@ typedef uint32_t UCS4;
/** Decodes UTF-8 from a string input to a UCS4 character.
@param src buffer in UTF-8 that should be decoded. If the buffer
represent
a valid character, the pointer will be incremented to the next
character.
represents a valid character, the pointer will be incremented to
the next character.
@param src_end The end of the string.
@return a UCS4 character, or 0xFFFF if the buffer didn't represent a
valid character.

View File

@@ -25,7 +25,7 @@ const TBID messageHide = TBIDC("TooltipManager.hide");
class TTMsgParam : public util::TypedObject {
public:
TTMsgParam(Element* hovered) : m_hovered(hovered) {}
explicit TTMsgParam(Element* hovered) : m_hovered(hovered) {}
Element* m_hovered;
};
@@ -38,7 +38,7 @@ class TooltipForm : public elements::PopupForm {
public:
TBOBJECT_SUBCLASS(TooltipForm, elements::PopupForm);
TooltipForm(Element* target);
explicit TooltipForm(Element* target);
~TooltipForm() override;
bool Show(int mouse_x, int mouse_y);
@@ -119,8 +119,10 @@ bool TooltipManager::OnElementInvokeEvent(Element* element, const Event& ev) {
tipped_element->ConvertToRoot(x, y);
y += tooltip_point_offset_y;
Point tt_point = m_tooltip->offset_point();
if (abs(tt_point.x - x) > (int)tooltip_hide_point_dist ||
abs(tt_point.y - y) > (int)tooltip_hide_point_dist) {
if (std::abs(tt_point.x - x) >
static_cast<int>(tooltip_hide_point_dist) ||
std::abs(tt_point.y - y) >
static_cast<int>(tooltip_hide_point_dist)) {
KillToolTip();
DeleteShowMessages();
}

View File

@@ -31,7 +31,7 @@ namespace el {
} \
inline const char* to_string(Enum value) { \
static const char* text[] = {__VA_ARGS__}; \
return text[int(value)]; \
return text[static_cast<int>(value)]; \
}
// Makes it possible to use the given enum types as flag combinations.
@@ -52,8 +52,8 @@ namespace el {
constexpr Enum operator^(Enum a, Enum b) { \
return static_cast<Enum>(static_cast<uint32_t>(a) ^ \
static_cast<uint32_t>(b)); \
}; \
inline void operator|=(Enum& a, Enum b) { \
} inline void \
operator|=(Enum& a, Enum b) { \
a = static_cast<Enum>(static_cast<uint32_t>(a) | \
static_cast<uint32_t>(b)); \
} \

View File

@@ -34,7 +34,7 @@ class DebugSettingsForm : public elements::Form, public ElementListener {
elements::TextBox* output;
DebugSettingsForm(Element* root) {
explicit DebugSettingsForm(Element* root) {
set_text("Debug settings");
LoadData(
"LayoutBox: axis: y, distribution: available, position: left\n"
@@ -70,8 +70,8 @@ class DebugSettingsForm : public elements::Form, public ElementListener {
void AddCheckbox(DebugInfo::Setting setting, const char* str) {
auto check = new elements::CheckBox();
check->set_value(DebugInfo::get()->settings[int(setting)]);
check->data.set_integer(int(setting));
check->set_value(DebugInfo::get()->settings[static_cast<int>(setting)]);
check->data.set_integer(static_cast<int>(setting));
check->set_id(TBIDC("check"));
auto label = new elements::LabelContainer();

View File

@@ -59,7 +59,7 @@ class DebugInfo {
kSettingCount,
};
int settings[int(Setting::kSettingCount)] = {0};
int settings[static_cast<int>(Setting::kSettingCount)] = {0};
private:
static DebugInfo debug_info_singleton_;
@@ -69,7 +69,7 @@ class DebugInfo {
void ShowDebugInfoSettingsForm(Element* root);
#define EL_DEBUG_SETTING(setting) \
el::util::DebugInfo::get()->settings[int(setting)]
el::util::DebugInfo::get()->settings[static_cast<int>(setting)]
#define EL_IF_DEBUG_SETTING(setting, code) \
if (EL_DEBUG_SETTING(setting)) { \
code; \

View File

@@ -13,7 +13,7 @@
#include "el/util/string.h"
#define NOMINMAX
#include <windows.h>
#include <windows.h> // NOLINT(build/include_order)
#ifdef EL_RUNTIME_DEBUG_INFO

View File

@@ -55,7 +55,7 @@ int DimensionConverter::MmToPx(int mm) const {
if (mm <= kInvalidDimension || mm == 0) {
return mm;
}
return int(mm * util::GetDPI() / 25.4f + 0.5f);
return static_cast<int>(mm * util::GetDPI() / 25.4f + 0.5f);
}
int DimensionConverter::GetPxFromString(const char* str, int def_value) const {
@@ -83,7 +83,7 @@ int DimensionConverter::GetPxFromValue(Value* value, int def_value) const {
return DpToPx(value->as_integer());
} else if (value->type() == Value::Type::kFloat) {
// FIX: We might want float versions of all dimension functions.
return DpToPx((int)value->as_float());
return DpToPx(static_cast<int>(value->as_float()));
}
return GetPxFromString(value->as_string(), def_value);
}

View File

@@ -47,15 +47,15 @@ class IntrusiveListIterator {
IntrusiveListEntry* current_link, bool forward);
~IntrusiveListIterator();
/** Set the iterator to the first link in we iterate forward,
or set it to the last link if we iterate backward. */
// Set the iterator to the first link in we iterate forward,
// or set it to the last link if we iterate backward.
void Reset();
/** Get the current link or nullptr if out of bounds. */
// Get the current link or nullptr if out of bounds.
IntrusiveListEntry* get() const { return current_entry_; }
/** Get the current link and step the iterator to the next (forward or
* backward). */
// Get the current link and step the iterator to the next (forward or
// backward).
IntrusiveListEntry* GetAndStep();
operator IntrusiveListEntry*() const { return current_entry_; }
@@ -63,15 +63,15 @@ class IntrusiveListIterator {
const IntrusiveListIterator& operator=(const IntrusiveListIterator& iter);
private:
/** RemoveLink is called when removing/deleting links in the target linklist.
This will make sure iterators skip the deleted item. */
// RemoveLink is called when removing/deleting links in the target linklist.
// This will make sure iterators skip the deleted item.
void RemoveLink(IntrusiveListEntry* link);
friend class IntrusiveList;
/** Add ourself to the chain of iterators in the linklist. */
// Add ourself to the chain of iterators in the linklist.
void Register();
/** Unlink ourself from the chain of iterators in the linklist. */
// Unlink ourself from the chain of iterators in the linklist.
void Unregister();
void UnregisterAndClear();
@@ -125,51 +125,49 @@ class IntrusiveListEntry : public impl::IntrusiveListEntry {
inline T* GetNext() const { return (T*)next; }
};
/** IntrusiveList is a double linked linklist. */
// IntrusiveList is a double linked linklist.
template <typename T>
class IntrusiveList {
public:
using TLink = IntrusiveListEntry<T>;
/** Remove link from this linklist. */
// Remove link from this linklist.
void Remove(T* link) { base_list_.Remove(static_cast<TLink*>(link)); }
/** Remove all links without deleting them. */
// Remove all links without deleting them.
void RemoveAll() { base_list_.RemoveAll(); }
/** Add link first in this linklist. */
// Add link first in this linklist.
void AddFirst(T* link) { base_list_.AddFirst(static_cast<TLink*>(link)); }
/** Add link last in this linklist. */
// Add link last in this linklist.
void AddLast(T* link) { base_list_.AddLast(static_cast<TLink*>(link)); }
/** Add link before the reference link (which must be added to this linklist).
*/
// Add link before the reference link (which must be added to this linklist).
void AddBefore(T* link, T* reference) {
base_list_.AddBefore(static_cast<TLink*>(link), reference);
}
/** Add link after the reference link (which must be added to this linklist).
*/
// Add link after the reference link (which must be added to this linklist).
void AddAfter(T* link, T* reference) {
base_list_.AddAfter(static_cast<TLink*>(link), reference);
}
/** Return true if the link is currently added to this linklist. */
// Return true if the link is currently added to this linklist.
bool ContainsLink(T* link) const {
return base_list_.ContainsLink(static_cast<TLink*>(link));
}
/** Get the first link, or nullptr. */
// Get the first link, or nullptr.
T* GetFirst() const { return (T*)static_cast<TLink*>(base_list_.first); }
/** Get the last link, or nullptr. */
// Get the last link, or nullptr.
T* GetLast() const { return (T*)static_cast<TLink*>(base_list_.last); }
/** Return true if this linklist contains any links. */
// Return true if this linklist contains any links.
bool HasLinks() const { return base_list_.HasLinks(); }
/** Count the number of links in this list by iterating through all links. */
// Count the number of links in this list by iterating through all links.
int CountLinks() const { return base_list_.CountLinks(); }
// Typed iterator for safe iteration. For more info, see
@@ -192,16 +190,16 @@ class IntrusiveList {
inline operator T*() const { return (T*)static_cast<TLink*>(get()); }
};
/** Get a forward iterator that starts with the first link. */
// Get a forward iterator that starts with the first link.
Iterator IterateForward() { return Iterator(this, true); }
/** Get a forward iterator that starts with the given link. */
// Get a forward iterator that starts with the given link.
Iterator IterateForward(T* link) { return Iterator(this, link, true); }
/** Get a backward iterator that starts with the last link. */
// Get a backward iterator that starts with the last link.
Iterator IterateBackward() { return Iterator(this, false); }
/** Get a backward iterator that starts with the given link. */
// Get a backward iterator that starts with the given link.
Iterator IterateBackward(T* link) { return Iterator(this, link, false); }
private:

View File

@@ -12,7 +12,7 @@
#include "el/util/metrics.h"
#define NOMINMAX
#include <windows.h>
#include <windows.h> // NOLINT(build/include_order)
namespace el {
namespace util {

View File

@@ -37,14 +37,14 @@ class TypedObject {
// Returns this object as the given type or nullptr if it's not that type.
template <class T>
T* SafeCastTo() const {
return (T*)(IsOfTypeId(GetTypeId<T>()) ? this : nullptr);
T* SafeCastTo() {
return reinterpret_cast<T*>(IsOfTypeId(GetTypeId<T>()) ? this : nullptr);
}
// Return true if this object can safely be casted to the given type.
template <class T>
bool IsOfType() const {
return SafeCastTo<T>() ? true : false;
return IsOfTypeId(GetTypeId<T>());
}
// Gets the classname of the object.
@@ -62,7 +62,7 @@ T* SafeCast(TypedObject* obj) {
// or if the object is nullptr.
template <class T>
const T* SafeCast(const TypedObject* obj) {
return obj ? obj->SafeCastTo<T>() : nullptr;
return obj ? const_cast<TypedObject*>(obj)->SafeCastTo<T>() : nullptr;
}
// Implements the methods for safe typecasting without requiring RTTI.

View File

@@ -23,7 +23,8 @@ class SpaceAllocator {
int width;
};
SpaceAllocator(int available_space) : m_available_space(available_space) {}
explicit SpaceAllocator(int available_space)
: m_available_space(available_space) {}
// Returns true if no allocations are currently live using this allocator.
bool empty() const { return !m_used_space_list.HasLinks(); }

View File

@@ -44,7 +44,8 @@ std::string format_string(const char* format, va_list args) {
std::string new_s;
while (true) {
new_s.resize(max_len);
int ret = std::vsnprintf((char*)new_s.data(), max_len, format, args);
int ret =
std::vsnprintf(const_cast<char*>(new_s.data()), max_len, format, args);
if (ret > max_len) {
// Needed size is known (+2 for termination and avoid ambiguity).
max_len = ret + 2;

View File

@@ -30,7 +30,7 @@ void StringBuilder::SetAppendPos(size_t append_pos) {
void StringBuilder::Reserve(size_t size) {
if (size > m_data_size) {
char* new_data = (char*)realloc(m_data, size);
char* new_data = reinterpret_cast<char*>(realloc(m_data, size));
assert(new_data);
m_data = new_data;
m_data_size = size;

View File

@@ -11,6 +11,7 @@
#define EL_UTIL_STRING_TABLE_H_
#include <memory>
#include <string>
#include <unordered_map>
#include "el/id.h"

View File

@@ -118,7 +118,7 @@ Value::Value(Type type) {
default:
assert(!"Not implemented!");
break;
};
}
}
Value::Value(int value) { set_integer(value); }
@@ -222,7 +222,7 @@ void Value::parse_string(const char* str, Set set) {
set_null();
} else if (is_number_only(str)) {
if (is_number_float(str)) {
set_float((float)atof(str));
set_float(static_cast<float>(std::atof(str)));
} else {
set_integer(atoi(str));
}
@@ -233,7 +233,7 @@ void Value::parse_string(const char* str, Set set) {
set_null();
ValueArray* arr = new ValueArray();
std::string tmpstr = str;
char* str_next = (char*)tmpstr.data();
char* str_next = const_cast<char*>(tmpstr.data());
while (char* token = next_token(str_next, ", ")) {
Value* new_val = arr->AddValue();
new_val->parse_string(token, Set::kNewCopy);
@@ -259,18 +259,18 @@ void Value::parse_string(const char* str, Set set) {
int Value::as_integer() const {
if (type() == Type::kString) {
return atoi(value_.string);
return std::atoi(value_.string);
} else if (type() == Type::kFloat) {
return (int)value_.float_number;
return static_cast<int>(value_.float_number);
}
return type() == Type::kInt ? value_.integer_number : 0;
}
float Value::as_float() const {
if (type() == Type::kString) {
return (float)atof(value_.string);
return static_cast<float>(std::atof(value_.string));
} else if (type() == Type::kInt) {
return (float)value_.integer_number;
return static_cast<float>(value_.integer_number);
}
return type() == Type::kFloat ? value_.float_number : 0;
}
@@ -278,11 +278,11 @@ float Value::as_float() const {
const char* Value::as_string() {
if (type() == Type::kInt) {
char tmp[32];
sprintf(tmp, "%d", value_.integer_number);
snprintf(tmp, sizeof(tmp), "%d", value_.integer_number);
set_string(tmp, Set::kNewCopy);
} else if (type() == Type::kFloat) {
char tmp[32];
sprintf(tmp, "%f", value_.float_number);
snprintf(tmp, sizeof(tmp), "%f", value_.float_number);
set_string(tmp, Set::kNewCopy);
} else if (type() == Type::kObject) {
return value_.object ? value_.object->GetTypeName() : "";

Some files were not shown because too many files have changed in this diff Show More