From 8699104339217cf6b7e9fe46332c73f4a0c7901f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Mon, 28 Jan 2019 23:01:27 +0100 Subject: Remove almost every -Wshadow warning --- engine/actor.cpp | 6 +- engine/collector.cpp | 38 +++++------ engine/component.cpp | 7 +- engine/exception.cpp | 4 +- engine/flatland.cpp | 2 +- engine/focusable.cpp | 6 +- engine/include/actor.hpp | 2 +- engine/include/collector.hpp | 8 +-- engine/include/component.hpp | 2 +- engine/include/core/signal.hpp | 33 ++++----- engine/include/exception.hpp | 3 +- engine/include/exceptions/forcequit.hpp | 4 +- engine/include/flatland.hpp | 28 ++++---- engine/include/serial/focusable.hpp | 3 +- engine/include/surface.hpp | 10 +-- engine/include/window.hpp | 35 +++++----- engine/labelled.cpp | 4 +- engine/signal.cpp | 80 +++++++++++----------- engine/surface.cpp | 114 +++++++++++++++----------------- engine/window.cpp | 105 ++++++++++++++--------------- test/signal_test.cpp | 14 ++-- 21 files changed, 246 insertions(+), 262 deletions(-) diff --git a/engine/actor.cpp b/engine/actor.cpp index 8eb27da..4991f91 100644 --- a/engine/actor.cpp +++ b/engine/actor.cpp @@ -6,7 +6,7 @@ using namespace flat; FlatActor::FlatActor(FlatCollector *parent, FlatBound *bounds) - : FlatCollector(parent), bounds(bounds) + : FlatCollector(parent), m_bounds(bounds) { } @@ -17,11 +17,11 @@ FlatActor::~FlatActor() void FlatActor::setBounds(FlatBound * bounds) { - this->bounds = bounds; + m_bounds = m_bounds; } FlatBound * FlatActor::getBounds() const { - return bounds; + return m_bounds; } diff --git a/engine/collector.cpp b/engine/collector.cpp index 3fc2a0e..be95b72 100644 --- a/engine/collector.cpp +++ b/engine/collector.cpp @@ -5,19 +5,19 @@ using namespace flat; FlatCollector::FlatCollector(FlatCollector *parent) - : parent(parent), released(!parent) + : m_parent(parent), m_released(!parent) { } FlatCollector::~FlatCollector() { - if (parent != 0) - parent->detach(this); + if (m_parent != 0) + m_parent->detach(this); - parent = 0; + m_parent = 0; - for (FlatCollector * child : children) + for (FlatCollector * child : m_children) { if (!child->isReleased()) delete child; @@ -26,12 +26,12 @@ FlatCollector::~FlatCollector() bool FlatCollector::isReleased() const { - return released; + return m_released; } void FlatCollector::release() { - released = true; + m_released = true; } void FlatCollector::attach(FlatCollector *obj) @@ -39,55 +39,55 @@ void FlatCollector::attach(FlatCollector *obj) if (obj == 0) return; - children.insert(obj); + m_children.insert(obj); obj->setParent(this); } void FlatCollector::detach(FlatCollector *obj) { - children.erase(obj); + m_children.erase(obj); obj->releaseParent(); } void FlatCollector::setParent(FlatCollector *obj) { - parent = obj; - released = false; + m_parent = obj; + m_released = false; } void FlatCollector::releaseParent() { - parent = 0; - released = true; + m_parent = 0; + m_released = true; } FlatCollector * FlatCollector::getParent() { - return parent; + return m_parent; } bool FlatCollector::isParentOf(FlatCollector* obj) const { - return this == obj->parent; + return this == obj->m_parent; } set::iterator FlatCollector::begin() { - return children.begin(); + return m_children.begin(); } set::iterator FlatCollector::end() { - return children.end(); + return m_children.end(); } set::const_iterator FlatCollector::begin() const { - return children.begin(); + return m_children.begin(); } set::const_iterator FlatCollector::end() const { - return children.end(); + return m_children.end(); } diff --git a/engine/component.cpp b/engine/component.cpp index a3eccae..5c1db80 100644 --- a/engine/component.cpp +++ b/engine/component.cpp @@ -8,8 +8,7 @@ component::component(component *parent, const std::string& id) { // TODO, check flatland initialization - if (parent == 0) - { + if (parent == nullptr) { // TODO set screen as parent layer } } @@ -21,11 +20,11 @@ component::~component() void component::set_parent(component *parent) { - if (parent == 0) { + if (parent == nullptr) { // TODO set screen as parent layer } - this->m_parent = m_parent; + m_parent = parent; } component * component::parent() diff --git a/engine/exception.cpp b/engine/exception.cpp index d4f1a74..f3bed3d 100644 --- a/engine/exception.cpp +++ b/engine/exception.cpp @@ -3,7 +3,7 @@ using namespace flat; -FlatException::FlatException(const char* error) : error(error) {} +FlatException::FlatException(const char* error) : m_error(error) {} FlatException::~FlatException() {} @@ -11,7 +11,7 @@ char buffer[256]; const char* FlatException::what() const throw() { - sprintf(buffer, "%s thrown: %s", specific(), error); + sprintf(buffer, "%s thrown: %s", specific(), m_error); return &buffer[0]; } diff --git a/engine/flatland.cpp b/engine/flatland.cpp index da0f58d..309c18b 100644 --- a/engine/flatland.cpp +++ b/engine/flatland.cpp @@ -192,7 +192,7 @@ int flat::init_flatland(FlatWindow* w, const flat_status& s, float _fps) } catch (const ForceQuit& f) { cerr << "Flatland: a force quit call was thrown" << endl; - cerr << "Possible reason: " << f.reason << endl; + cerr << "Possible reason: " << f.m_reason << endl; quit(); } diff --git a/engine/focusable.cpp b/engine/focusable.cpp index cdf8b1f..1f82a2b 100644 --- a/engine/focusable.cpp +++ b/engine/focusable.cpp @@ -4,7 +4,7 @@ using namespace flat; -Focusable::Focusable(bool focused) : focused(focused) +Focusable::Focusable(bool focused) : m_focused(focused) { // event_trigger = new flat::core::task(this, &Focusable::serial_precall, 0); } @@ -16,12 +16,12 @@ Focusable::~Focusable() void Focusable::setFocused(bool flag) { - focused = flag; + m_focused = flag; } bool Focusable::isFocused() const { - return focused; + return m_focused; } void Focusable::serial_precall(void*) diff --git a/engine/include/actor.hpp b/engine/include/actor.hpp index 75a3474..1902704 100644 --- a/engine/include/actor.hpp +++ b/engine/include/actor.hpp @@ -13,7 +13,7 @@ class FlatActor : public FlatCollector // TODO, serial binding /* Bounds */ - FlatBound * bounds; + FlatBound * m_bounds; public: diff --git a/engine/include/collector.hpp b/engine/include/collector.hpp index 45a3e74..448dba9 100644 --- a/engine/include/collector.hpp +++ b/engine/include/collector.hpp @@ -8,11 +8,11 @@ namespace flat { class FlatCollector : virtual public flat::object { - FlatCollector * parent; +private: + FlatCollector * m_parent; + bool m_released; - bool released; - - std::set children; + std::set m_children; public: diff --git a/engine/include/component.hpp b/engine/include/component.hpp index fdde28d..76b7d6c 100644 --- a/engine/include/component.hpp +++ b/engine/include/component.hpp @@ -9,7 +9,7 @@ namespace flat { class component : virtual public object, virtual public core::labelled { - +private: component * m_parent; public: diff --git a/engine/include/core/signal.hpp b/engine/include/core/signal.hpp index e21b73e..9c38d8b 100644 --- a/engine/include/core/signal.hpp +++ b/engine/include/core/signal.hpp @@ -12,13 +12,8 @@ #include "priority.hpp" #include "labelled.hpp" -namespace flat +namespace flat::core { - //class object; - - namespace core - { - class signal : virtual public labelled, virtual public prioritized { @@ -37,13 +32,13 @@ namespace flat void * data; }; - object * sender; + object *m_sender; package m_package; - signal( object * sender, - const std::string& id = "", - void * data = 0, - priority_t prior = priority_t::none); + signal(object * sender, + const std::string& id = "", + void * data = 0, + priority_t prior = priority_t::none); /* Alias to flat::core::channel::emit() */ bool emit(const std::string& channel) const; @@ -80,7 +75,7 @@ namespace flat callback m_callback; - std::list filters; + std::list m_filters; bool check_in_filters(const std::string&) const; }; @@ -88,19 +83,20 @@ namespace flat /* Channel class */ class channel : virtual public labelled, public std::enable_shared_from_this { + private: /* Post processing signal stacking */ - queue stack; + queue m_stack; /* Listeners list */ - std::list> listeners; + std::list> m_listeners; /* Synchronous task checking for signals */ - task::ptr checker; + task::ptr m_checker; /* Channel mapping */ - static std::map> channels; + static std::map> m_channels; - bool mapped; + bool m_mapped; public: @@ -137,8 +133,5 @@ namespace flat void check_and_call(); }; - - - } } diff --git a/engine/include/exception.hpp b/engine/include/exception.hpp index 6f578e8..5648df8 100644 --- a/engine/include/exception.hpp +++ b/engine/include/exception.hpp @@ -7,7 +7,8 @@ namespace flat { class FlatException : public std::exception { - const char * error; +private: + const char * m_error; protected: diff --git a/engine/include/exceptions/forcequit.hpp b/engine/include/exceptions/forcequit.hpp index 451190e..336b9c0 100644 --- a/engine/include/exceptions/forcequit.hpp +++ b/engine/include/exceptions/forcequit.hpp @@ -3,9 +3,9 @@ namespace flat { struct ForceQuit { - const char * reason; + const char * m_reason; - ForceQuit(const char *reason) : reason(reason) {} + ForceQuit(const char *reason) : m_reason(reason) {} }; } diff --git a/engine/include/flatland.hpp b/engine/include/flatland.hpp index 5d3cfbf..592a629 100644 --- a/engine/include/flatland.hpp +++ b/engine/include/flatland.hpp @@ -8,20 +8,20 @@ class FlatWindow; struct flat_status { - flat_status(unsigned char video = 1, - unsigned char audio = 1, - unsigned char timer = 1, - unsigned char events = 1, - unsigned char joystick = 0, - unsigned char controller = 0, - unsigned char haptic = 0, - unsigned char error = 0, - unsigned char running = 0, - unsigned char loop = 0) - - : video(video), audio(audio), timer(timer), events(events), - joystick(joystick), controller(controller), haptic(haptic), - error(error), running(running), loop(loop) {} + flat_status(unsigned char _video = 1, + unsigned char _audio = 1, + unsigned char _timer = 1, + unsigned char _events = 1, + unsigned char _joystick = 0, + unsigned char _controller = 0, + unsigned char _haptic = 0, + unsigned char _error = 0, + unsigned char _running = 0, + unsigned char _loop = 0) + + : video(_video), audio(_audio), timer(_timer), events(_events), + joystick(_joystick), controller(_controller), haptic(_haptic), + error(_error), running(_running), loop(_loop) {} unsigned char video; unsigned char audio; diff --git a/engine/include/serial/focusable.hpp b/engine/include/serial/focusable.hpp index 8a05051..e5f5d5b 100644 --- a/engine/include/serial/focusable.hpp +++ b/engine/include/serial/focusable.hpp @@ -10,7 +10,8 @@ namespace flat { class Focusable : virtual public flat::object { - bool focused; +private: + bool m_focused; protected: diff --git a/engine/include/surface.hpp b/engine/include/surface.hpp index 6e9026a..0c1ac78 100644 --- a/engine/include/surface.hpp +++ b/engine/include/surface.hpp @@ -9,13 +9,13 @@ namespace flat { class surface : virtual public object, virtual public core::labelled { - SDL_Surface * sdl_surface; - SDL_Surface * parent; + SDL_Surface * m_sdl_surface; + SDL_Surface * m_parent; - SDL_Rect * offset; - SDL_Rect * viewport; + SDL_Rect * m_offset; + SDL_Rect * m_viewport; - bool hide; + bool m_hide; public: diff --git a/engine/include/window.hpp b/engine/include/window.hpp index 586a6eb..ddc9472 100644 --- a/engine/include/window.hpp +++ b/engine/include/window.hpp @@ -13,17 +13,17 @@ namespace flat { struct window_status { - window_status( unsigned char fullscreen = 0, - unsigned char hidden = 0, - unsigned char borderless = 0, - unsigned char resizable = 1, - unsigned char minimized = 0, - unsigned char maximized = 0, - unsigned char focus = 1) - - : fullscreen(fullscreen), hidden(hidden), borderless(borderless), - resizable(resizable), minimized(minimized), maximized(maximized), - focus(focus) {} + window_status( unsigned char _fullscreen = 0, + unsigned char _hidden = 0, + unsigned char _borderless = 0, + unsigned char _resizable = 1, + unsigned char _minimized = 0, + unsigned char _maximized = 0, + unsigned char _focus = 1) + + : fullscreen(_fullscreen), hidden(_hidden), borderless(_borderless), + resizable(_resizable), minimized(_minimized), maximized(_maximized), + focus(_focus) {} unsigned char fullscreen; unsigned char hidden; @@ -39,14 +39,15 @@ class FlatLayer; class FlatWindow : virtual public object, public KeyFocusable { - std::string title; - window_status status; +private: + std::string m_title; + window_status m_status; - SDL_Rect * bounds; - SDL_Window * sdl_window; - SDL_Surface * screen; + SDL_Rect * m_bounds; + SDL_Window * m_sdl_window; + SDL_Surface * m_screen; - FlatLayer * main_layer; + FlatLayer * m_main_layer; void key_cb(const SDL_KeyboardEvent*) override; diff --git a/engine/labelled.cpp b/engine/labelled.cpp index 48e6091..e39686c 100644 --- a/engine/labelled.cpp +++ b/engine/labelled.cpp @@ -5,8 +5,8 @@ using namespace std; using namespace flat::core; -labelled::labelled(const std::string& label, bool allow_null) - : label((!allow_null && label.empty()) ? random_label() : label) {} +labelled::labelled(const std::string& _label, bool allow_null) + : label((!allow_null && _label.empty()) ? random_label() : _label) {} string labelled::random_label(uint8_t length) { diff --git a/engine/signal.cpp b/engine/signal.cpp index 7688785..512b456 100644 --- a/engine/signal.cpp +++ b/engine/signal.cpp @@ -7,17 +7,17 @@ using namespace flat::core; -std::map> channel::channels; +std::map> channel::m_channels; -channel::channel(const std::string& id) : labelled(id), mapped(false) +channel::channel(const std::string& id) : labelled(id), m_mapped(false) { } channel::~channel() { // by default it should be there - if (mapped) - channels.erase(label); + if (m_mapped) + m_channels.erase(label); } void channel::start(priority_t prior) @@ -25,35 +25,34 @@ void channel::start(priority_t prior) npdebug("Starting channel: ", label); // Initialize task - checker = flat::main_job().delegate_task(&channel::check_and_call, this, prior); + m_checker = flat::main_job().delegate_task(&channel::check_and_call, this, prior); } bool channel::map() { - if (!mapped) { + if (!m_mapped) { channel::ptr other = channel::find(label); if (!other) { - - channels.insert(std::pair>(label, weak_from_this())); - mapped = true; + m_channels.insert(std::pair>(label, weak_from_this())); + m_mapped = true; } } - return mapped; + return m_mapped; } void channel::emit(const signal& sig) { - stack.insert(sig); + m_stack.insert(sig); npdebug("Emitted signal: ", sig.label, " ", this); } bool channel::connect(listener::ptr l) { /* Control not to double */ - for (auto lis : listeners) + for (auto lis : m_listeners) { auto pt = lis.lock(); @@ -61,16 +60,16 @@ bool channel::connect(listener::ptr l) return false; } - listeners.push_back(l); + m_listeners.push_back(l); return true; } void channel::disconnect(listener::ptr l) { - listeners.erase( + m_listeners.erase( std::remove_if( - listeners.begin(), - listeners.end(), + m_listeners.begin(), + m_listeners.end(), [&l](std::weak_ptr p){ listener::ptr pt = p.lock(); return pt.get() == l.get(); @@ -115,19 +114,18 @@ channel::ptr channel::create(const std::string& id, priority_t prior) channel::ptr channel::find(const std::string& id) { + // what about anonymous (unlabeled) channels? if (id.empty()) return nullptr; - auto it = channels.find(id); + auto it = m_channels.find(id); - return (it == channels.end()) ? nullptr : (*it).second.lock(); + return (it == m_channels.end()) ? nullptr : (*it).second.lock(); } -int step = 0; - void channel::check_and_call() { - if (!stack.empty()) { + if (!m_stack.empty()) { npdebug("Signal detected: ", label, " ", this) @@ -136,13 +134,13 @@ void channel::check_and_call() // TODO, maybe it exists pop /* for each listener_s, catch signal */ - for (auto l : listeners) + for (auto l : m_listeners) { listener::ptr pt; if (pt = l.lock()) { - for (const auto& sig : stack) + for (const auto& sig : m_stack) pt->invoke(sig); } else @@ -150,29 +148,29 @@ void channel::check_and_call() } /* Erase invalidated listeners */ - listeners.erase( + m_listeners.erase( std::remove_if( - listeners.begin(), - listeners.end(), + m_listeners.begin(), + m_listeners.end(), [](std::weak_ptr e) { return e.expired(); } ) ); - stack.clear(); // TODO not so efficient + m_stack.clear(); // TODO not so efficient } } /* signal class */ -signal::signal( object *sender, - const std::string& id, - void *data, - priority_t priority) +signal::signal(object *sender, + const std::string& id, + void *data, + priority_t p) : labelled(id, true), - prioritized(priority), - sender(sender), + prioritized(p), + m_sender(sender), m_package(package(data)) { } @@ -193,9 +191,9 @@ bool signal::emit(const std::string& chan) const /* listener_s class */ -listener::listener(callback m_callback, const std::initializer_list& filters) +listener::listener(callback callback, const std::initializer_list& filters) - : m_callback(m_callback), filters(filters) + : m_callback(callback), m_filters(filters) { } @@ -206,7 +204,7 @@ listener::~listener() bool listener::check_in_filters(const std::string& filter) const { - for (const auto& f : filters) + for (const auto& f : m_filters) { if (filter == f) return true; @@ -217,12 +215,12 @@ bool listener::check_in_filters(const std::string& filter) const void listener::add_filter(const std::string& f) { - filters.push_back(f); + m_filters.push_back(f); } void listener::remove_filter(const std::string& f) { - filters.remove(f); + m_filters.remove(f); } bool listener::connect(const std::string& chan) @@ -247,8 +245,8 @@ bool listener::disconnect(const std::string& chan) void listener::invoke(const signal& sig) { - if ( (!sig.label.empty() && check_in_filters(sig.label)) || - (sig.label.empty() && filters.empty())) - m_callback(sig.sender, sig.m_package); + if ((!sig.label.empty() && check_in_filters(sig.label)) || + (sig.label.empty() && m_filters.empty())) + m_callback(sig.m_sender, sig.m_package); } diff --git a/engine/surface.cpp b/engine/surface.cpp index 3ea38d4..6145690 100644 --- a/engine/surface.cpp +++ b/engine/surface.cpp @@ -2,149 +2,145 @@ #include -using namespace std; using namespace flat; surface::surface(const char *filename, uint32_t format, SDL_Surface *parent) - : core::labelled(filename, true), parent(parent), hide(false) + : core::labelled(filename, true), m_parent(parent), m_hide(false) { - cout << "surface: loading " << filename << endl; - sdl_surface = loadOptimizedSurface(filename, format); + std::cout << "surface: loading " << filename << std::endl; + m_sdl_surface = loadOptimizedSurface(filename, format); - if (!sdl_surface) + if (!m_sdl_surface) { - cout << "Warning: could not load surface " << filename << endl; + std::cout << "Warning: could not load surface " << filename << std::endl; } - offset = new SDL_Rect; + m_offset = new SDL_Rect; - offset->x = 0; - offset->y = 0; - offset->w = sdl_surface->w; - offset->h = sdl_surface->h; + m_offset->x = 0; + m_offset->y = 0; + m_offset->w = m_sdl_surface->w; + m_offset->h = m_sdl_surface->h; - viewport = new SDL_Rect; + m_viewport = new SDL_Rect; - viewport->x = 0; - viewport->y = 0; - viewport->w = sdl_surface->w; - viewport->h = sdl_surface->h; + m_viewport->x = 0; + m_viewport->y = 0; + m_viewport->w = m_sdl_surface->w; + m_viewport->h = m_sdl_surface->h; } surface::surface(SDL_Surface *sdl_surface, SDL_Surface *parent) - : flat::object(), parent(parent), hide(false) + : flat::object(), m_parent(parent), m_hide(false) { - this->sdl_surface = new SDL_Surface(*sdl_surface); + m_sdl_surface = new SDL_Surface(*sdl_surface); - offset = new SDL_Rect; + m_offset = new SDL_Rect; - offset->x = 0; - offset->y = 0; - offset->w = sdl_surface->w; - offset->h = sdl_surface->h; + m_offset->x = 0; + m_offset->y = 0; + m_offset->w = sdl_surface->w; + m_offset->h = sdl_surface->h; - viewport = new SDL_Rect; + m_viewport = new SDL_Rect; - viewport->x = 0; - viewport->y = 0; - viewport->w = sdl_surface->w; - viewport->h = sdl_surface->h; + m_viewport->x = 0; + m_viewport->y = 0; + m_viewport->w = sdl_surface->w; + m_viewport->h = sdl_surface->h; } -surface::surface(const surface &sprite) - : flat::object(sprite), parent(sprite.parent), hide(sprite.hide) +surface::surface(const surface& sprite) + : flat::object(sprite), m_parent(sprite.m_parent), m_hide(sprite.m_hide) { - offset = new SDL_Rect(*sprite.offset); - - viewport = new SDL_Rect(*sprite.viewport); - - sdl_surface = copySurface(sprite.sdl_surface); + m_offset = new SDL_Rect(*sprite.m_offset); + m_viewport = new SDL_Rect(*sprite.m_viewport); + m_sdl_surface = copySurface(sprite.m_sdl_surface); } surface::~surface() { - SDL_FreeSurface(sdl_surface); + SDL_FreeSurface(m_sdl_surface); - delete offset; - delete viewport; + delete m_offset; + delete m_viewport; } void surface::setOffset(int x, int y, int w, int h) { - offset->x = x; - offset->y = y; + m_offset->x = x; + m_offset->y = y; if (w > 0) - offset->w = w; + m_offset->w = w; if (h > 0) - offset->h = h; + m_offset->h = h; } void surface::setViewport(int x, int y, int w, int h) { - viewport->x = x; - viewport->y = y; - viewport->w = w; - viewport->h = h; + m_viewport->x = x; + m_viewport->y = y; + m_viewport->w = w; + m_viewport->h = h; } void surface::setViewport(const SDL_Rect &rect) { - *viewport = rect; + *m_viewport = rect; } void surface::setOffset(const SDL_Rect &offset) { - *this->offset = offset; + *m_offset = offset; } const SDL_Rect * surface::getOffset() const { - return offset; + return m_offset; } const SDL_Rect * surface::getViewport() const { - return viewport; + return m_viewport; } void surface::setParent(SDL_Surface *parent) { - this->parent = parent; + m_parent = parent; } SDL_Surface * surface::getParent() { - return parent; + return m_parent; } SDL_Surface * surface::getSurface() { - return sdl_surface; + return m_sdl_surface; } void surface::setHidden(bool flag) { - hide = flag; + m_hide = flag; } bool surface::isHidden() const { - return hide; + return m_hide; } void surface::blit() { - if (!hide) - SDL_BlitSurface(sdl_surface, viewport, parent, offset); + if (!m_hide) + SDL_BlitSurface(m_sdl_surface, m_viewport, m_parent, m_offset); } SDL_Surface * surface::loadOptimizedSurface(const char *filename, uint32_t format) { - SDL_Surface * optimized = 0; - + SDL_Surface * optimized = nullptr; SDL_Surface * loaded = SDL_LoadBMP(filename); if (loaded) diff --git a/engine/window.cpp b/engine/window.cpp index 20da675..d5425be 100644 --- a/engine/window.cpp +++ b/engine/window.cpp @@ -5,89 +5,86 @@ #include "layer.hpp" #include "core/signal.hpp" -using namespace std; using namespace flat; FlatWindow::FlatWindow( int x, int y, int width, int height, - const string& title, + const std::string& title, window_status status) - : title(title), status(status), - sdl_window(0), screen(0) + : m_title(title), m_status(status), + m_sdl_window(nullptr), m_screen(nullptr) { - bounds = new SDL_Rect; - - bounds->x = x; - bounds->y = y; - bounds->w = width; - bounds->h = height; + m_bounds = new SDL_Rect; + + m_bounds->x = x; + m_bounds->y = y; + m_bounds->w = width; + m_bounds->h = height; - main_layer = new FlatLayer(0); + m_main_layer = new FlatLayer(nullptr); } FlatWindow::FlatWindow( SDL_Rect *bounds, - const string& title, + const std::string& title, window_status status) : FlatWindow(bounds->x, bounds->y, bounds->w, bounds->h, title, status) -{ -} +{} FlatWindow::FlatWindow( int width, int height, - const string &title, + const std::string &title, window_status status) - : FlatWindow( SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, + : FlatWindow(SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, title, status) { } FlatWindow::FlatWindow(const FlatWindow& win) - - : flat::object(win), - title(win.title), status(win.status), - sdl_window(0), screen(0) + : flat::object(win), Focusable(false), + m_title(win.m_title), m_status(win.m_status), + m_sdl_window(nullptr), m_screen(nullptr) { - bounds = new SDL_Rect; + m_bounds = new SDL_Rect; - *bounds = *win.bounds; + *m_bounds = *win.m_bounds; - main_layer = new FlatLayer(0); + m_main_layer = new FlatLayer(nullptr); } FlatWindow::~FlatWindow() { close(); - delete bounds; - delete main_layer; + delete m_bounds; + delete m_main_layer; } int FlatWindow::open() { - uint32_t win_flags = winstatus_to_flags(status); + uint32_t win_flags = winstatus_to_flags(m_status); - sdl_window = SDL_CreateWindow( title.c_str(), - bounds->x, - bounds->y, - bounds->w, - bounds->h, - win_flags); - - if (sdl_window == 0) + m_sdl_window = SDL_CreateWindow(m_title.c_str(), + m_bounds->x, + m_bounds->y, + m_bounds->w, + m_bounds->h, + win_flags); + + if (m_sdl_window == nullptr) { - cout << "Error: failed to initialize window" << endl; + std::cout << "Error: failed to initialize window" << std::endl; // throw exception return -1; } - screen = SDL_GetWindowSurface(sdl_window); + m_screen = SDL_GetWindowSurface(m_sdl_window); - if (screen == 0) + if (m_screen == nullptr) { - cout << "Error: SDL_SetVideoMode failed" << endl; + std::cout << "Error: SDL_SetVideoMode failed" << std::endl; // throw exception return -1; } @@ -97,62 +94,60 @@ int FlatWindow::open() void FlatWindow::close() { - if (screen != 0) - { - SDL_FreeSurface(screen); - screen = 0; + if (m_screen != nullptr) { + SDL_FreeSurface(m_screen); + m_screen = nullptr; } - if (sdl_window != 0) - { - SDL_DestroyWindow(sdl_window); - sdl_window = 0; + if (m_sdl_window != nullptr) { + SDL_DestroyWindow(m_sdl_window); + m_sdl_window = nullptr; } } int FlatWindow::getWidth() const { - return bounds->w; + return m_bounds->w; } int FlatWindow::getHeight() const { - return bounds->h; + return m_bounds->h; } const SDL_Rect * FlatWindow::getBounds() const { - return bounds; + return m_bounds; } SDL_Window * FlatWindow::getSDLWindow() { - return sdl_window; + return m_sdl_window; } SDL_Surface * FlatWindow::getScreenSurface() { - return screen; + return m_screen; } const std::string& FlatWindow::getTitle() const { - return title; + return m_title; } void FlatWindow::setTitle(const std::string& title) { - this->title = title; + m_title = title; } window_status FlatWindow::getWindowStatus() const { - return status; + return m_status; } void FlatWindow::setWindowStatus(window_status status) { - this->status = status; + m_status = status; } void FlatWindow::key_cb(const SDL_KeyboardEvent *event) diff --git a/test/signal_test.cpp b/test/signal_test.cpp index 4dcb635..01fbe2d 100644 --- a/test/signal_test.cpp +++ b/test/signal_test.cpp @@ -14,19 +14,19 @@ using namespace flat::core; class sender : public object { - const char * message; - channel::ptr chan; + const char *m_message; + channel::ptr m_chan; public: - sender(const char * message, channel::ptr chan) : message(message), chan(chan) + sender(const char * message, channel::ptr chan) : m_message(message), m_chan(chan) { } void send() { - signal msg(this, "", (void*)message); - chan->emit(msg); + signal msg(this, "", (void*)m_message); + m_chan->emit(msg); } }; @@ -38,13 +38,13 @@ void function_listener(const object*, core::signal::package msg) class c_listener { - listener::ptr lis; + listener::ptr m_lis; public: c_listener(channel::ptr chan) { - lis = chan->connect(&c_listener::method_listener, this); + m_lis = chan->connect(&c_listener::method_listener, this); } void method_listener(const object *o, signal::package msg) -- cgit v1.2.1