Mostly style-clean.

This commit is contained in:
Ben Vanik 2015-08-09 12:06:56 -07:00
parent 5da70a8d76
commit 696a19055a
33 changed files with 181 additions and 168 deletions

View File

@ -40,22 +40,22 @@ class Node {
Node& set(const char* key, int32_t value) {
auto v = el::Value(value);
return set(key, v);
return set(key, &v);
}
Node& set(const char* key, float value) {
auto v = el::Value(value);
return set(key, v);
return set(key, &v);
}
Node& set(const char* key, const char* value) {
auto v = el::Value(value);
return set(key, v);
return set(key, &v);
}
Node& set(const char* key, const std::string& value) {
auto v = el::Value(value.c_str());
return set(key, v);
return set(key, &v);
}
Node& set(const char* key, el::Rect value) {
@ -69,7 +69,7 @@ class Node {
return *this;
}
Node& set(const char* key, el::Value& value) {
Node& set(const char* key, el::Value* value) {
auto node = GetOrCreateNode(key);
node->TakeValue(value);
return *this;

View File

@ -117,18 +117,18 @@ void Element::LoadNodeTree(const dsl::Node& node) {
}
// Sets the id from the given node.
void Element::SetIdFromNode(TBID& id, parsing::ParseNode* node) {
void Element::SetIdFromNode(TBID* id, parsing::ParseNode* node) {
if (!node) return;
if (node->value().is_string()) {
id.reset(node->value().as_string());
id->reset(node->value().as_string());
} else {
id.reset(node->value().as_integer());
id->reset(node->value().as_integer());
}
}
void Element::OnInflate(const parsing::InflateInfo& info) {
Element::SetIdFromNode(id(), info.node->GetNode("id"));
Element::SetIdFromNode(group_id(), info.node->GetNode("group-id"));
Element::SetIdFromNode(&id(), info.node->GetNode("id"));
Element::SetIdFromNode(&group_id(), info.node->GetNode("group-id"));
if (info.sync_type == Value::Type::kFloat) {
set_double_value(info.node->GetValueFloat("value", 0));
@ -664,15 +664,15 @@ void Element::ScrollBy(int dx, int dy) {
ScrollTo(info.x + dx, info.y + dy);
}
void Element::ScrollByRecursive(int& dx, int& dy) {
void Element::ScrollByRecursive(int* dx, int* dy) {
Element* tmp = this;
while (tmp) {
ScrollInfo old_info = tmp->scroll_info();
tmp->ScrollTo(old_info.x + dx, old_info.y + dy);
tmp->ScrollTo(old_info.x + *dx, old_info.y + *dy);
ScrollInfo new_info = tmp->scroll_info();
dx -= new_info.x - old_info.x;
dy -= new_info.y - old_info.y;
if (!dx && !dy) {
*dx -= new_info.x - old_info.x;
*dy -= new_info.y - old_info.y;
if (!*dx && !*dy) {
break;
}
tmp = tmp->m_parent;
@ -1442,7 +1442,7 @@ void Element::InvokePaint(const PaintProps& parent_paint_props) {
Renderer::get()->set_opacity(old_opacity);
}
bool Element::InvokeEvent(Event& ev) {
bool Element::InvokeEvent(Event ev) {
ev.target = this;
// First call the global listener about this event.
@ -1544,12 +1544,12 @@ bool Element::InvokePointerDown(int x, int y, int click_count,
}
}
if (captured_element) {
captured_element->ConvertFromRoot(x, y);
captured_element->ConvertFromRoot(&x, &y);
pointer_move_element_x = pointer_down_element_x = x;
pointer_move_element_y = pointer_down_element_y = y;
Event ev(EventType::kPointerDown, x, y, touch, modifierkeys);
ev.count = click_count;
captured_element->InvokeEvent(ev);
captured_element->InvokeEvent(std::move(ev));
return true;
}
@ -1561,13 +1561,13 @@ bool Element::InvokePointerUp(int x, int y, ModifierKeys modifierkeys,
// If we have a captured element then we have a focused element so the pointer
// up event was handled
if (captured_element) {
captured_element->ConvertFromRoot(x, y);
captured_element->ConvertFromRoot(&x, &y);
Event ev_up(EventType::kPointerUp, x, y, touch, modifierkeys);
Event ev_click(EventType::kClick, x, y, touch, modifierkeys);
captured_element->InvokeEvent(ev_up);
captured_element->InvokeEvent(std::move(ev_up));
if (!cancel_click && captured_element &&
captured_element->GetHitStatus(x, y) != HitStatus::kNoHit) {
captured_element->InvokeEvent(ev_click);
Event ev_click(EventType::kClick, x, y, touch, modifierkeys);
captured_element->InvokeEvent(std::move(ev_click));
}
if (captured_element) { // && button == captured_button
captured_element->ReleaseCapture();
@ -1587,12 +1587,12 @@ void Element::MaybeInvokeLongClickOrContextMenu(bool touch) {
// Invoke long click.
Event ev_long_click(EventType::kLongClick, pointer_move_element_x,
pointer_move_element_y, touch, ModifierKeys::kNone);
bool handled = captured_element->InvokeEvent(ev_long_click);
bool handled = captured_element->InvokeEvent(std::move(ev_long_click));
if (!handled) {
// Long click not handled so invoke a context menu event instead.
Event ev_context_menu(EventType::kContextMenu, pointer_move_element_x,
pointer_move_element_y, touch, ModifierKeys::kNone);
handled = captured_element->InvokeEvent(ev_context_menu);
handled = captured_element->InvokeEvent(std::move(ev_context_menu));
}
// If any event was handled, suppress click when releasing pointer.
if (handled) {
@ -1607,12 +1607,12 @@ void Element::InvokePointerMove(int x, int y, ModifierKeys modifierkeys,
Element* target = captured_element ? captured_element : hovered_element;
if (target) {
target->ConvertFromRoot(x, y);
target->ConvertFromRoot(&x, &y);
pointer_move_element_x = x;
pointer_move_element_y = y;
Event ev(EventType::kPointerMove, x, y, touch, modifierkeys);
if (target->InvokeEvent(ev)) {
if (target->InvokeEvent(std::move(ev))) {
return;
}
// The move event was not handled, so handle panning of scrollable elements.
@ -1690,13 +1690,13 @@ bool Element::InvokeWheel(int x, int y, int delta_x, int delta_y,
if (!target) {
return false;
}
target->ConvertFromRoot(x, y);
target->ConvertFromRoot(&x, &y);
pointer_move_element_x = x;
pointer_move_element_y = y;
Event ev(EventType::kWheel, x, y, true, modifierkeys);
ev.delta_x = delta_x;
ev.delta_y = delta_y;
target->InvokeEvent(ev);
target->InvokeEvent(std::move(ev));
return true;
}
@ -1729,7 +1729,7 @@ bool Element::InvokeKey(int key, SpecialKey special_key,
// Invoke the click event.
if (!down) {
Event ev(EventType::kClick, m_rect.w / 2, m_rect.h / 2, true);
focused_element->InvokeEvent(ev);
focused_element->InvokeEvent(std::move(ev));
}
handled = true;
} else {
@ -1738,7 +1738,7 @@ bool Element::InvokeKey(int key, SpecialKey special_key,
ev.key = key;
ev.special_key = special_key;
ev.modifierkeys = modifierkeys;
handled = focused_element->InvokeEvent(ev);
handled = focused_element->InvokeEvent(std::move(ev));
}
}
@ -1760,36 +1760,36 @@ void Element::ReleaseCapture() {
}
}
void Element::ConvertToRoot(int& x, int& y) const {
void Element::ConvertToRoot(int* x, int* y) const {
const Element* tmp = this;
while (tmp->m_parent) {
x += tmp->m_rect.x;
y += tmp->m_rect.y;
*x += tmp->m_rect.x;
*y += tmp->m_rect.y;
tmp = tmp->m_parent;
if (tmp) {
int child_translation_x;
int child_translation_y;
tmp->GetChildTranslation(&child_translation_x, &child_translation_y);
x += child_translation_x;
y += child_translation_y;
*x += child_translation_x;
*y += child_translation_y;
}
}
}
void Element::ConvertFromRoot(int& x, int& y) const {
void Element::ConvertFromRoot(int* x, int* y) const {
const Element* tmp = this;
while (tmp->m_parent) {
x -= tmp->m_rect.x;
y -= tmp->m_rect.y;
*x -= tmp->m_rect.x;
*y -= tmp->m_rect.y;
tmp = tmp->m_parent;
if (tmp) {
int child_translation_x;
int child_translation_y;
tmp->GetChildTranslation(&child_translation_x, &child_translation_y);
x -= child_translation_x;
y -= child_translation_y;
*x -= child_translation_x;
*y -= child_translation_y;
}
}
}
@ -1914,7 +1914,7 @@ using el::SkinProperty;
using el::SkinTarget;
bool ElementSkinConditionContext::GetCondition(
SkinTarget target, const SkinCondition::ConditionInfo& info) {
SkinTarget target, const SkinCondition::ConditionInfo& info) const {
switch (target) {
case SkinTarget::kThis:
return GetCondition(m_element, info);
@ -1938,7 +1938,7 @@ bool ElementSkinConditionContext::GetCondition(
}
bool ElementSkinConditionContext::GetCondition(
Element* element, const SkinCondition::ConditionInfo& info) {
Element* element, const SkinCondition::ConditionInfo& info) const {
switch (info.prop) {
case SkinProperty::kSkin:
return element->background_skin() == info.value;

View File

@ -362,7 +362,7 @@ class Element : public util::TypedObject,
struct LookupPair {
template <typename T>
LookupPair(el::TBID& id, T** out_ptr)
LookupPair(const el::TBID& id, T** out_ptr)
: id(id),
type_id(GetTypeId<T>()),
out_ptr(reinterpret_cast<el::Element**>(out_ptr)) {}
@ -821,7 +821,7 @@ class Element : public util::TypedObject,
// Scrolls this element and/or any parent elements by the given delta.
// dx and dy will be reduced by the amount that was successfully scrolled.
void ScrollByRecursive(int& dx, int& dy);
void ScrollByRecursive(int* dx, int* dy);
// Makes this element visible by calling ScrollIntoView on all parent
// elements.
@ -974,7 +974,7 @@ class Element : public util::TypedObject,
// NOTE: remember that this elements may be deleted after this call! So if you
// really must do something after this call and are not sure what the event
// will cause, use WeakElementPointer to detect self deletion.
bool InvokeEvent(Event& ev);
bool InvokeEvent(Event ev);
bool InvokePointerDown(int x, int y, int click_count,
ModifierKeys modifierkeys, bool touch);
@ -999,11 +999,11 @@ class Element : public util::TypedObject,
// Makes x and y (relative to this element) relative to the upper left corner
// of the root element.
void ConvertToRoot(int& x, int& y) const;
void ConvertToRoot(int* x, int* y) const;
// Makes x and y (relative to the upper left corner of the root element)
// relative to this element.
void ConvertFromRoot(int& x, int& y) const;
void ConvertFromRoot(int* x, int* y) const;
// Gets the font description as set with SetFontDescription.
// Use computed_font_description() to get the calculated font description
@ -1113,7 +1113,7 @@ class Element : public util::TypedObject,
// true if the focused state should be painted automatically.
static bool show_focus_state;
static void SetIdFromNode(TBID& id, parsing::ParseNode* node);
static void SetIdFromNode(TBID* id, parsing::ParseNode* node);
private:
// Returns this element or the nearest parent that is scrollable in the given
@ -1149,10 +1149,11 @@ class ElementSkinConditionContext : public SkinConditionContext {
public:
explicit ElementSkinConditionContext(Element* element) : m_element(element) {}
bool GetCondition(SkinTarget target,
const SkinCondition::ConditionInfo& info) override;
const SkinCondition::ConditionInfo& info) const override;
private:
bool GetCondition(Element* element, const SkinCondition::ConditionInfo& info);
bool GetCondition(Element* element,
const SkinCondition::ConditionInfo& info) const;
Element* m_element = nullptr;
};

View File

@ -61,7 +61,7 @@ void Button::set_value(int new_value) {
if (can_toggle()) {
// Invoke a changed event.
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
if (new_value && group_id()) {
@ -109,7 +109,7 @@ void Button::OnMessageReceived(Message* msg) {
HitStatus::kNoHit) {
Event ev(EventType::kClick, pointer_move_element_x,
pointer_move_element_y, true);
captured_element->InvokeEvent(ev);
captured_element->InvokeEvent(std::move(ev));
}
if (kAutoClickRepeattDelayMillis > 0) {
PostMessageDelayed(TBIDC("auto_click"), nullptr,

View File

@ -62,7 +62,7 @@ void DropDownButton::set_value(int value) {
}
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
TBID DropDownButton::selected_item_id() {
@ -120,7 +120,7 @@ bool DropDownButton::OnEvent(const Event& ev) {
if (MenuForm* menu_form = menu_if_open()) {
// Redirect the key strokes to the list.
Event redirected_ev(ev);
return menu_form->list_box()->InvokeEvent(redirected_ev);
return menu_form->list_box()->InvokeEvent(std::move(redirected_ev));
}
}
return Element::OnEvent(ev);

View File

@ -63,7 +63,7 @@ bool LabelContainer::OnEvent(const Event& ev) {
Event target_ev(ev.type, ev.target_x - click_target->rect().x,
ev.target_y - click_target->rect().y, ev.touch,
ev.modifierkeys);
if (click_target->InvokeEvent(target_ev)) {
if (click_target->InvokeEvent(std::move(target_ev))) {
return true;
}
}

View File

@ -217,7 +217,7 @@ void ListBox::set_value(int value) {
if (Element* element = GetItemElement(m_value)) {
ev.ref_id = element->id();
}
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
TBID ListBox::selected_item_id() {
@ -295,7 +295,7 @@ bool ListBox::OnEvent(const Event& ev) {
if (Element* element = GetItemElement(m_value)) {
invoke_ev.ref_id = element->id();
}
target_list->InvokeEvent(invoke_ev);
target_list->InvokeEvent(std::move(invoke_ev));
}
return true;
} else if (ev.type == EventType::kKeyDown) {

View File

@ -42,7 +42,7 @@ bool MenuForm::OnEvent(const Event& ev) {
// Invoke the click on the target.
Event target_ev(EventType::kClick);
target_ev.ref_id = ev.ref_id;
InvokeEvent(target_ev);
InvokeEvent(std::move(target_ev));
// If target got deleted, close.
if (this_element.get()) {

View File

@ -117,7 +117,7 @@ bool MessageForm::OnEvent(const Event& ev) {
// Invoke the click on the target.
Event target_ev(EventType::kClick);
target_ev.ref_id = ev.target->id();
InvokeEvent(target_ev);
InvokeEvent(std::move(target_ev));
// If target got deleted, close.
if (this_element.get()) {
@ -126,8 +126,8 @@ bool MessageForm::OnEvent(const Event& ev) {
return true;
} else if (ev.type == EventType::kKeyDown &&
ev.special_key == SpecialKey::kEsc) {
Event click_ev(EventType::kClick);
title_close_button_.InvokeEvent(click_ev);
Event ev(EventType::kClick);
title_close_button_.InvokeEvent(std::move(ev));
return true;
}
return Form::OnEvent(ev);

View File

@ -43,7 +43,7 @@ void BaseRadioCheckBox::set_value(int value) {
set_state(Element::State::kSelected, value ? true : false);
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
if (value && group_id()) UpdateGroupElements(this);
}

View File

@ -123,7 +123,7 @@ bool Scroller::OnPan(int dx, int dy) {
// Pan the target.
const int in_dx = dx, in_dy = dy;
m_target->ScrollByRecursive(dx, dy);
m_target->ScrollByRecursive(&dx, &dy);
// Calculate the pan speed. Smooth it out with the
// previous pan speed to reduce fluctuation a little.
@ -233,7 +233,7 @@ void Scroller::AdjustToSnappingAndScroll(float ppms_x, float ppms_y) {
Element::ScrollInfo info = m_target->scroll_info();
int target_x = distance_x + info.x;
int target_y = distance_y + info.y;
m_snap_listener->OnScrollSnap(m_target, target_x, target_y);
m_snap_listener->OnScrollSnap(m_target, &target_x, &target_y);
distance_x = target_x - info.x;
distance_y = target_y - info.y;
@ -248,7 +248,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 = static_cast<double>(util::GetTimeMS());
GetTargetScrollXY(m_scroll_start_scroll_x, m_scroll_start_scroll_y);
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;
@ -265,7 +265,7 @@ void Scroller::Scroll(float start_speed_ppms_x, float start_speed_ppms_y) {
// Post the pan message if we don't already have one.
if (!GetMessageById(TBIDC("scroll"))) {
// Update expected translation.
GetTargetChildTranslation(m_expected_scroll_x, m_expected_scroll_y);
GetTargetChildTranslation(&m_expected_scroll_x, &m_expected_scroll_y);
PostMessageDelayed(TBIDC("scroll"), nullptr, kPanMessageDelayMillis);
}
@ -275,25 +275,25 @@ bool Scroller::IsScrolling() {
return GetMessageById(TBIDC("scroll")) ? true : false;
}
void Scroller::GetTargetChildTranslation(int& x, int& y) const {
void Scroller::GetTargetChildTranslation(int* x, int* y) const {
int root_x = 0, root_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->ConvertToRoot(&root_x, &root_y);
scroll_root->GetChildTranslation(&child_translation_x, &child_translation_y);
x = root_x + child_translation_x;
y = root_y + child_translation_y;
*x = root_x + child_translation_x;
*y = root_y + child_translation_y;
}
void Scroller::GetTargetScrollXY(int& x, int& y) const {
x = 0;
y = 0;
void Scroller::GetTargetScrollXY(int* x, int* y) const {
*x = 0;
*y = 0;
Element* tmp = m_target->scroll_root();
while (tmp) {
Element::ScrollInfo info = tmp->scroll_info();
x += info.x;
y += info.y;
*x += info.x;
*y += info.y;
tmp = tmp->parent();
}
}
@ -301,7 +301,7 @@ void Scroller::GetTargetScrollXY(int& x, int& y) const {
void Scroller::OnMessageReceived(Message* msg) {
if (msg->message_id() == TBIDC("scroll")) {
int actual_scroll_x = 0, actual_scroll_y = 0;
GetTargetChildTranslation(actual_scroll_x, actual_scroll_y);
GetTargetChildTranslation(&actual_scroll_x, &actual_scroll_y);
if (actual_scroll_x != m_expected_scroll_x ||
actual_scroll_y != m_expected_scroll_y) {
// Something else has affected the target child translation.
@ -332,15 +332,15 @@ void Scroller::OnMessageReceived(Message* msg) {
// Get the scroll delta and invoke ScrollByRecursive.
int curr_scroll_x, curr_scroll_y;
GetTargetScrollXY(curr_scroll_x, curr_scroll_y);
GetTargetScrollXY(&curr_scroll_x, &curr_scroll_y);
const int dx = scroll_x - curr_scroll_x;
const int dy = scroll_y - curr_scroll_y;
int idx = dx, idy = dy;
m_target->ScrollByRecursive(idx, idy);
m_target->ScrollByRecursive(&idx, &idy);
// Update expected translation.
GetTargetChildTranslation(m_expected_scroll_x, m_expected_scroll_y);
GetTargetChildTranslation(&m_expected_scroll_x, &m_expected_scroll_y);
if ((dx && actual_scroll_x == m_expected_scroll_x) &&
(dy && actual_scroll_y == m_expected_scroll_y)) {

View File

@ -58,8 +58,8 @@ class ScrollerSnapListener {
// NOTE: The scroll positions are relative to the target element (inner
// scrolled Element). If there's nested scrollable elements, only the
// inner scrolled element applies snapping.
virtual void OnScrollSnap(Element* target_element, int& target_x,
int& target_y) = 0;
virtual void OnScrollSnap(Element* target_element, int* target_x,
int* target_y) = 0;
};
// Scroller handles panning while the pointer is down and measure the pan speed
@ -112,8 +112,8 @@ class Scroller : private MessageHandler {
void Reset();
void AdjustToSnappingAndScroll(float ppms_x, float ppms_y);
void Scroll(float start_speed_ppms_x, float start_speed_ppms_y);
void GetTargetChildTranslation(int& x, int& y) const;
void GetTargetScrollXY(int& x, int& y) const;
void GetTargetChildTranslation(int* x, int* y) const;
void GetTargetScrollXY(int* x, int* y) const;
Element* m_target = nullptr;
ScrollerSnapListener* m_snap_listener = nullptr;

View File

@ -40,7 +40,7 @@ Rect PopupAlignment::GetAlignedRect(Element* popup, Element* target) const {
x = util::Clamp(x, 0, root->rect().w - w);
}
} else {
target->ConvertToRoot(x, y);
target->ConvertToRoot(&x, &y);
if (align == Align::kTop || align == Align::kBottom) {
if (expand_to_target_width) {

View File

@ -66,13 +66,13 @@ void ScrollBar::set_limits(double min, double max, double visible_range) {
// to root and then back after the applying the new limit.
// This prevents sudden jumps to unexpected positions when scrolling.
if (captured_element == &m_handle) {
m_handle.ConvertToRoot(pointer_down_element_x, pointer_down_element_y);
m_handle.ConvertToRoot(&pointer_down_element_x, &pointer_down_element_y);
}
UpdateHandle();
if (captured_element == &m_handle) {
m_handle.ConvertFromRoot(pointer_down_element_x, pointer_down_element_y);
m_handle.ConvertFromRoot(&pointer_down_element_x, &pointer_down_element_y);
}
}
@ -85,7 +85,7 @@ void ScrollBar::set_double_value(double value) {
UpdateHandle();
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
bool ScrollBar::OnEvent(const Event& ev) {

View File

@ -70,7 +70,7 @@ void Slider::set_double_value(double value) {
UpdateHandle();
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
bool Slider::OnEvent(const Event& ev) {

View File

@ -77,7 +77,7 @@ void SpinBox::SetValueInternal(int value, bool update_text) {
}
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
// Warning: Do nothing here since the event might have deleted us.
// If needed, check if we are alive using a safe pointer first.

View File

@ -77,7 +77,7 @@ void SplitContainer::set_value(int value) {
value_ = clamped_value;
InvalidateLayout(InvalidationMode::kTargetOnly);
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
int SplitContainer::computed_min_value() const {

View File

@ -282,7 +282,7 @@ bool TextBox::OnEvent(const Event& ev) {
return true;
} else if (ev.type == EventType::kContextMenu && ev.target == this) {
Point pos_in_root(ev.target_x, ev.target_y);
ev.target->ConvertToRoot(pos_in_root.x, pos_in_root.y);
ev.target->ConvertToRoot(&pos_in_root.x, &pos_in_root.y);
MenuForm* menu = new MenuForm(ev.target, TBIDC("popupmenu"));
GenericStringItemSource* source = menu->list_box()->default_source();
@ -462,7 +462,7 @@ void TextBox::OnChange() {
}
Event ev(EventType::kChanged);
InvokeEvent(ev);
InvokeEvent(std::move(ev));
}
bool TextBox::OnEnter() { return false; }

View File

@ -11,6 +11,7 @@
#define EL_GRAPHICS_BITMAP_FRAGMENT_MANAGER_H_
#include <memory>
#include <string>
#include <unordered_map>
#include <vector>

View File

@ -214,7 +214,7 @@ void GenericStringItemSource::ReadItemNodes(
const char* text = node->GetValueString("text", "");
TBID item_id;
if (auto id_node = node->GetNode("id")) {
Element::SetIdFromNode(item_id, id_node);
Element::SetIdFromNode(&item_id, id_node);
}
auto item = std::make_unique<GenericStringItem>(text, item_id);
target_source->push_back(std::move(item));

View File

@ -151,12 +151,12 @@ class ParseNodeTarget : public TextParserTarget {
error.c_str());
}
void OnComment(int line_nr, const char* comment) override {}
void OnToken(int line_nr, const char* name, Value& value) override {
void OnToken(int line_nr, const char* name, Value* value) override {
if (!m_target_node) return;
if (strcmp(name, "@file") == 0) {
IncludeFile(line_nr, value.as_string());
IncludeFile(line_nr, value->as_string());
} else if (strcmp(name, "@include") == 0) {
IncludeRef(line_nr, value.as_string());
IncludeRef(line_nr, value->as_string());
} else {
ParseNode* n = ParseNode::Create(name);
n->TakeValue(value);
@ -229,9 +229,9 @@ class ParseNodeTarget : public TextParserTarget {
std::string m_filename;
};
void ParseNode::TakeValue(Value& value) { m_value.TakeOver(value); }
void ParseNode::TakeValue(Value* value) { m_value.TakeOver(value); }
void ParseNode::EmplaceValue(Value value) { m_value.TakeOver(value); }
void ParseNode::EmplaceValue(Value value) { m_value.TakeOver(&value); }
bool ParseNode::ReadFile(const std::string& filename, ReadFlags flags) {
if (!any(flags & ReadFlags::kAppend)) {

View File

@ -43,7 +43,7 @@ class ParseNode : public util::IntrusiveListEntry<ParseNode> {
// Creates a new node with the given name.
static ParseNode* Create(const char* name);
void TakeValue(Value& value);
void TakeValue(Value* value);
void EmplaceValue(Value value);
// Reads a tree of nodes from file into this node.

View File

@ -23,7 +23,8 @@ bool is_hex(char c) {
(c >= 'A' && c <= 'F'));
}
uint32_t parse_hex(char*& src, int max_count) {
uint32_t parse_hex(char** inout_src, int max_count) {
auto src = *inout_src;
uint32_t hex = 0;
for (int i = 0; i < max_count; ++i) {
char c = *src;
@ -32,6 +33,7 @@ uint32_t parse_hex(char*& src, int max_count) {
hex |= isdigit(c) ? c - '0' : tolower(c) - 'a' + 10;
src++;
}
*inout_src = src;
return hex;
}
@ -85,7 +87,7 @@ void UnescapeString(char* str) {
// This should be safe. A utf-8 character can be at most 4 bytes,
// and we have 4 bytes to use for \xXX and 6 for \uXXXX.
src += 2;
if (auto hex = parse_hex(src, src[1] == 'x' ? 2 : 4)) {
if (auto hex = parse_hex(&src, src[1] == 'x' ? 2 : 4)) {
dst += text::utf8::encode(hex, dst);
}
continue;
@ -147,13 +149,13 @@ bool is_start_of_reference(const char* str) {
// Checks if the line is a comment or empty space. If it is, consume the leading
// whitespace from line.
bool is_space_or_comment(char*& line) {
char* tmp = line;
bool is_space_or_comment(char** inout_line) {
char* tmp = *inout_line;
while (is_white_space(tmp)) {
tmp++;
}
if (*tmp == '#' || *tmp == 0) {
line = tmp;
*inout_line = tmp;
return true;
}
return false;
@ -249,7 +251,7 @@ TextParser::Status TextParser::Read(TextParserStream* stream,
}
void TextParser::OnLine(char* line, TextParserTarget* target) {
if (is_space_or_comment(line)) {
if (is_space_or_comment(&line)) {
if (*line == '#') {
target->OnComment(current_line_nr, line + 1);
}
@ -310,7 +312,7 @@ void TextParser::OnLine(char* line, TextParserTarget* target) {
if (*line == '[' || *line == '\"' || *line == '\'' ||
util::is_start_of_number(line) || is_start_of_color(line) ||
is_start_of_reference(line)) {
ConsumeValue(value, line);
ConsumeValue(&value, &line);
if (pending_multiline) {
// The value wrapped to the next line, so we should remember the token
@ -324,7 +326,7 @@ void TextParser::OnLine(char* line, TextParserTarget* target) {
UnescapeString(line);
value.parse_string(line, Value::Set::kAsStatic);
}
target->OnToken(current_line_nr, token, value);
target->OnToken(current_line_nr, token, &value);
if (is_compact_line) {
OnCompactLine(line, target);
@ -357,7 +359,7 @@ void TextParser::OnCompactLine(char* line, TextParserTarget* target) {
}
Value v;
ConsumeValue(v, line);
ConsumeValue(&v, &line);
if (pending_multiline) {
// The value wrapped to the next line, so we should remember the token and
@ -370,7 +372,7 @@ void TextParser::OnCompactLine(char* line, TextParserTarget* target) {
}
// Ready.
target->OnToken(current_line_nr, token, v);
target->OnToken(current_line_nr, token, &v);
}
target->Leave();
@ -383,12 +385,12 @@ void TextParser::OnMultiline(char* line, TextParserTarget* target) {
}
Value value;
ConsumeValue(value, line);
ConsumeValue(&value, &line);
if (!pending_multiline) {
// Ready with all lines.
value.set_string(multi_line_value.data(), Value::Set::kAsStatic);
target->OnToken(current_line_nr, multi_line_token.c_str(), value);
target->OnToken(current_line_nr, multi_line_token.c_str(), &value);
if (multi_line_sub_level) {
target->Leave();
@ -400,8 +402,9 @@ void TextParser::OnMultiline(char* line, TextParserTarget* target) {
}
}
void TextParser::ConsumeValue(Value& dst_value, char*& line) {
void TextParser::ConsumeValue(Value* dst_value, char** inout_line) {
// Find value (As quoted string, or as auto).
char* line = *inout_line;
char* value = line;
if (*line == '\"' || *line == '\'') {
const char quote_type = *line;
@ -427,7 +430,7 @@ void TextParser::ConsumeValue(Value& dst_value, char*& line) {
}
UnescapeString(value);
dst_value.set_string(value, Value::Set::kAsStatic);
dst_value->set_string(value, Value::Set::kAsStatic);
} else {
// Find next comma or end.
while (*line != ',' && *line != 0) {
@ -439,7 +442,7 @@ void TextParser::ConsumeValue(Value& dst_value, char*& line) {
}
UnescapeString(value);
dst_value.parse_string(value, Value::Set::kAsStatic);
dst_value->parse_string(value, Value::Set::kAsStatic);
}
// Check if we still have pending value data on the following line and set
@ -449,8 +452,10 @@ void TextParser::ConsumeValue(Value& dst_value, char*& line) {
// Append the multi line value to the buffer.
if (continuing_multiline || pending_multiline) {
multi_line_value.AppendString(dst_value.as_string());
multi_line_value.AppendString(dst_value->as_string());
}
*inout_line = line;
}
} // namespace parsing

View File

@ -25,7 +25,7 @@ class TextParserTarget {
virtual ~TextParserTarget() = default;
virtual void OnError(int line_nr, const std::string& error) = 0;
virtual void OnComment(int line_nr, const char* comment) = 0;
virtual void OnToken(int line_nr, const char* name, Value& value) = 0;
virtual void OnToken(int line_nr, const char* name, Value* value) = 0;
virtual void Enter() = 0;
virtual void Leave() = 0;
};
@ -45,7 +45,7 @@ class TextParser {
void OnLine(char* line, TextParserTarget* target);
void OnCompactLine(char* line, TextParserTarget* target);
void OnMultiline(char* line, TextParserTarget* target);
void ConsumeValue(Value& dst_value, char*& line);
void ConsumeValue(Value* dst_value, char** line);
int current_indent = 0;
int current_line_nr = 0;

View File

@ -45,7 +45,7 @@ SkinCondition::SkinCondition(SkinTarget target, SkinProperty prop,
m_info.value = value;
}
bool SkinCondition::GetCondition(SkinConditionContext& context) const {
bool SkinCondition::GetCondition(const SkinConditionContext& context) const {
bool equal = context.GetCondition(m_target, m_info);
return equal == (m_test == Test::kEqual);
}
@ -225,7 +225,8 @@ SkinElement* Skin::GetSkinElementById(const TBID& skin_id) const {
}
SkinElement* Skin::GetSkinElementStrongOverride(
const TBID& skin_id, SkinState state, SkinConditionContext& context) const {
const TBID& skin_id, SkinState state,
const SkinConditionContext& context) const {
if (SkinElement* skin_element = GetSkinElementById(skin_id)) {
// Avoid eternal recursion when overrides refer to elements referring back.
if (skin_element->is_getting) {
@ -253,12 +254,14 @@ SkinElement* Skin::GetSkinElementStrongOverride(
}
SkinElement* Skin::PaintSkin(const Rect& dst_rect, const TBID& skin_id,
SkinState state, SkinConditionContext& context) {
SkinState state,
const SkinConditionContext& context) {
return PaintSkin(dst_rect, GetSkinElementById(skin_id), state, context);
}
SkinElement* Skin::PaintSkin(const Rect& dst_rect, SkinElement* element,
SkinState state, SkinConditionContext& context) {
SkinState state,
const SkinConditionContext& context) {
if (!element || element->is_painting) return nullptr;
// Avoid potential endless recursion in evil skins.
@ -315,7 +318,8 @@ SkinElement* Skin::PaintSkin(const Rect& dst_rect, SkinElement* element,
}
void Skin::PaintSkinOverlay(const Rect& dst_rect, SkinElement* element,
SkinState state, SkinConditionContext& context) {
SkinState state,
const SkinConditionContext& context) {
if (!element || element->is_painting) return;
// Avoid potential endless recursion in evil skins.
@ -602,7 +606,8 @@ void SkinElement::SetBitmapDPI(const util::DimensionConverter& dim_conv,
bitmap_dpi = new_bitmap_dpi;
}
bool SkinElement::has_state(SkinState state, SkinConditionContext& context) {
bool SkinElement::has_state(SkinState state,
const SkinConditionContext& context) const {
return m_override_elements.GetStateElement(
state, context, SkinElementState::MatchRule::kOnlySpecificState) ||
m_child_elements.GetStateElement(
@ -686,7 +691,7 @@ void SkinElement::Load(ParseNode* n, Skin* skin, const char* skin_path) {
}
bool SkinElementState::IsMatch(SkinState test_state,
SkinConditionContext& context,
const SkinConditionContext& context,
MatchRule rule) const {
if (rule == MatchRule::kOnlySpecificState && state == SkinState::kAll) {
return false;
@ -704,7 +709,7 @@ bool SkinElementState::IsMatch(SkinState test_state,
}
bool SkinElementState::IsExactMatch(SkinState test_state,
SkinConditionContext& context,
const SkinConditionContext& context,
MatchRule rule) const {
if (rule == MatchRule::kOnlySpecificState && state == SkinState::kAll) {
return false;
@ -729,7 +734,7 @@ SkinElementStateList::~SkinElementStateList() {
}
SkinElementState* SkinElementStateList::GetStateElement(
SkinState state, SkinConditionContext& context,
SkinState state, const SkinConditionContext& context,
SkinElementState::MatchRule rule) const {
// First try to get a state element with a exact match to the current state.
if (SkinElementState* element_state =
@ -748,7 +753,7 @@ SkinElementState* SkinElementStateList::GetStateElement(
}
SkinElementState* SkinElementStateList::GetStateElementExactMatch(
SkinState state, SkinConditionContext& context,
SkinState state, const SkinConditionContext& context,
SkinElementState::MatchRule rule) const {
SkinElementState* state_element = m_state_elements.GetFirst();
while (state_element) {

View File

@ -136,7 +136,7 @@ class SkinCondition : public util::IntrusiveListEntry<SkinCondition> {
const TBID& value, Test test);
// Returns true if the condition is true for the given context.
bool GetCondition(SkinConditionContext& context) const;
bool GetCondition(const SkinConditionContext& context) const;
private:
SkinTarget m_target;
@ -153,7 +153,7 @@ class SkinConditionContext {
public:
// Returns true if the given target and property equals the given value.
virtual bool GetCondition(SkinTarget target,
const SkinCondition::ConditionInfo& info) = 0;
const SkinCondition::ConditionInfo& info) const = 0;
};
// SkinElementState has a skin element id that should be used if its state and
@ -168,10 +168,10 @@ class SkinElementState : public util::IntrusiveListEntry<SkinElementState> {
kOnlySpecificState,
};
bool IsMatch(SkinState test_state, SkinConditionContext& context,
bool IsMatch(SkinState test_state, const SkinConditionContext& context,
MatchRule rule = MatchRule::kDefault) const;
bool IsExactMatch(SkinState test_state, SkinConditionContext& context,
bool IsExactMatch(SkinState test_state, const SkinConditionContext& context,
MatchRule rule = MatchRule::kDefault) const;
TBID element_id;
@ -185,12 +185,12 @@ class SkinElementStateList {
~SkinElementStateList();
SkinElementState* GetStateElement(
SkinState state, SkinConditionContext& context,
SkinState state, const SkinConditionContext& context,
SkinElementState::MatchRule rule =
SkinElementState::MatchRule::kDefault) const;
SkinElementState* GetStateElementExactMatch(
SkinState state, SkinConditionContext& context,
SkinState state, const SkinConditionContext& context,
SkinElementState::MatchRule rule =
SkinElementState::MatchRule::kDefault) const;
@ -295,7 +295,7 @@ class SkinElement {
// Checks if there's a exact or partial match for the given state in either
// override, child or overlay element list. State elements with state "all"
// will be ignored.
bool has_state(SkinState state, SkinConditionContext& context);
bool has_state(SkinState state, const SkinConditionContext& context) const;
// Returns true if this element has overlay elements.
bool has_overlay_elements() const {
@ -389,7 +389,7 @@ class Skin : private graphics::RendererListener {
// Returns nullptr if there's no match.
SkinElement* GetSkinElementStrongOverride(
const TBID& skin_id, SkinState state,
SkinConditionContext& context) const;
const SkinConditionContext& context) const;
Color default_text_color() const { return m_default_text_color; }
float default_disabled_opacity() const { return m_default_disabled_opacity; }
@ -429,16 +429,16 @@ class Skin : private graphics::RendererListener {
// Returns the skin element used (after following override elements), or
// nullptr if no skin element was found matching the skin_id.
SkinElement* PaintSkin(const Rect& dst_rect, const TBID& skin_id,
SkinState state, SkinConditionContext& context);
SkinState state, const SkinConditionContext& context);
// Paints the skin at dst_rect. Just like the PaintSkin above, but takes a
// specific skin element instead of looking it up from the id.
SkinElement* PaintSkin(const Rect& dst_rect, SkinElement* element,
SkinState state, SkinConditionContext& context);
SkinState state, const SkinConditionContext& context);
// Paints the overlay elements for the given skin element and state.
void PaintSkinOverlay(const Rect& dst_rect, SkinElement* element,
SkinState state, SkinConditionContext& context);
SkinState state, const SkinConditionContext& context);
// Draw fade out skin elements at the edges of dst_rect if needed.
// It indicates to the user that there is hidden content.

View File

@ -116,7 +116,7 @@ bool TooltipManager::OnElementInvokeEvent(Element* element, const Event& ev) {
m_tooltip) {
int x = Element::pointer_move_element_x;
int y = Element::pointer_move_element_y;
tipped_element->ConvertToRoot(x, y);
tipped_element->ConvertToRoot(&x, &y);
y += tooltip_point_offset_y;
Point tt_point = m_tooltip->offset_point();
if (std::abs(tt_point.x - x) >
@ -172,7 +172,7 @@ void TooltipManager::OnMessageReceived(Message* msg) {
int x = Element::pointer_move_element_x;
int y = Element::pointer_move_element_y;
Element::hovered_element->ConvertToRoot(x, y);
Element::hovered_element->ConvertToRoot(&x, &y);
y += tooltip_point_offset_y;
m_tooltip->Show(x, y);

View File

@ -51,7 +51,8 @@ bool is_number_float(const char* str) {
return false;
}
char* next_token(char*& str, const char* delim) {
char* next_token(char** inout_str, const char* delim) {
auto& str = *inout_str;
str += strspn(str, delim);
if (!*str) return nullptr;
char* token = str;
@ -131,19 +132,19 @@ Value::Value(util::TypedObject* object) { set_object(object); }
Value::~Value() { set_null(); }
void Value::TakeOver(Value& source_value) {
if (Type(source_value.packed_.type) == Type::kString) {
set_string(source_value.value_.string, source_value.packed_.allocated
? Set::kTakeOwnership
: Set::kNewCopy);
} else if (source_value.type() == Type::kArray) {
set_array(source_value.value_.value_array, source_value.packed_.allocated
? Set::kTakeOwnership
: Set::kNewCopy);
void Value::TakeOver(Value* source_value) {
if (Type(source_value->packed_.type) == Type::kString) {
set_string(source_value->value_.string, source_value->packed_.allocated
? Set::kTakeOwnership
: Set::kNewCopy);
} else if (source_value->type() == Type::kArray) {
set_array(source_value->value_.value_array, source_value->packed_.allocated
? Set::kTakeOwnership
: Set::kNewCopy);
} else {
*this = source_value;
*this = *source_value;
}
source_value.set_type(Type::kNull);
source_value->set_type(Type::kNull);
}
void Value::Copy(const Value& source_value) {
@ -234,7 +235,7 @@ void Value::parse_string(const char* str, Set set) {
ValueArray* arr = new ValueArray();
std::string tmpstr = str;
char* str_next = const_cast<char*>(tmpstr.data());
while (char* token = next_token(str_next, ", ")) {
while (char* token = next_token(&str_next, ", ")) {
Value* new_val = arr->AddValue();
new_val->parse_string(token, Set::kNewCopy);
}

View File

@ -85,7 +85,7 @@ class Value {
// NOTE: If source_value has string or array that are set with Set::kAsStatic,
// it will make new copies of those.
// NOTE: value will be nulled on source_value after this call.
void TakeOver(Value& source_value);
void TakeOver(Value* source_value);
// Copies the content of source_value to this value.
// NOTE: This value will become Type::kNull if source_value holds an object.

View File

@ -168,7 +168,7 @@ static bool InvokeShortcut(int key, SpecialKey special_key,
Event ev(EventType::kShortcut);
ev.modifierkeys = modifierkeys;
ev.ref_id = id;
return Element::focused_element->InvokeEvent(ev);
return Element::focused_element->InvokeEvent(std::move(ev));
}
static bool InvokeKey(GLFWwindow* window, unsigned int key,
@ -278,7 +278,7 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
if (Element::focused_element && !down) {
Event ev(EventType::kContextMenu);
ev.modifierkeys = modifier;
Element::focused_element->InvokeEvent(ev);
Element::focused_element->InvokeEvent(std::move(ev));
}
break;
case GLFW_KEY_LEFT_SHIFT:
@ -344,9 +344,9 @@ static void mouse_button_callback(GLFWwindow* window, int button, int action,
GetBackend(window)->GetRoot()->InvokePointerMove(x, y, modifier,
ShouldEmulateTouchEvent());
if (Element::hovered_element) {
Element::hovered_element->ConvertFromRoot(x, y);
Element::hovered_element->ConvertFromRoot(&x, &y);
Event ev(EventType::kContextMenu, x, y, false, modifier);
Element::hovered_element->InvokeEvent(ev);
Element::hovered_element->InvokeEvent(std::move(ev));
}
}
}
@ -399,7 +399,7 @@ static void drop_callback(GLFWwindow* window, int count,
for (int i = 0; i < count; ++i) {
ev.files.push_back(files_utf8[i]);
}
target->InvokeEvent(ev);
target->InvokeEvent(std::move(ev));
}
}
#endif

View File

@ -182,8 +182,8 @@ void ResourceEditWindow::OnPaintChildren(const PaintProps& paint_props) {
if (Element* selected_element = GetSelectedElement()) {
Rect element_rect(0, 0, selected_element->rect().w,
selected_element->rect().h);
selected_element->ConvertToRoot(element_rect.x, element_rect.y);
ConvertFromRoot(element_rect.x, element_rect.y);
selected_element->ConvertToRoot(&element_rect.x, &element_rect.y);
ConvertFromRoot(&element_rect.x, &element_rect.y);
graphics::Renderer::get()->DrawRect(element_rect, Color(255, 205, 0));
}
}

View File

@ -376,7 +376,7 @@ bool DemoWindow::OnEvent(const Event& ev) {
// That way the window has a chance of intercepting the close and f.ex ask
// if it really should be closed.
Event click_ev(EventType::kClick);
title_close_button_.InvokeEvent(click_ev);
title_close_button_.InvokeEvent(std::move(click_ev));
return true;
}
return Form::OnEvent(ev);
@ -677,11 +677,11 @@ PageWindow::PageWindow() {
bool PageWindow::OnEvent(const Event& ev) { return DemoWindow::OnEvent(ev); }
void PageWindow::OnScrollSnap(Element* target_element, int& target_x,
int& target_y) {
void PageWindow::OnScrollSnap(Element* target_element, int* target_x,
int* target_y) {
int page_w = target_element->padding_rect().w;
int target_page = (target_x + page_w / 2) / page_w;
target_x = target_page * page_w;
int target_page = (*target_x + page_w / 2) / page_w;
*target_x = target_page * page_w;
}
// == AnimationsWindow ========================================================

View File

@ -87,8 +87,8 @@ class PageWindow : public DemoWindow,
public:
PageWindow();
virtual bool OnEvent(const Event& ev);
virtual void OnScrollSnap(Element* target_element, int& target_x,
int& target_y);
virtual void OnScrollSnap(Element* target_element, int* target_x,
int* target_y);
};
class AnimationsWindow : public DemoWindow {