Some style tweaks
This commit is contained in:
@@ -92,11 +92,11 @@ eScrollStyle cScrollbar::getStyle() {
|
||||
|
||||
// TODO: centralize this translation somewhere
|
||||
// Translate raw x/y position using the view of the current rendering target
|
||||
location cScrollbar::translated_location(sf::Vector2i const point) const {
|
||||
location cScrollbar::translated_location(const sf::Vector2i point) const {
|
||||
return location { this->inWindow->mapPixelToCoords(point) };
|
||||
}
|
||||
|
||||
bool cScrollbar::handle_event(sf::Event const & event) {
|
||||
bool cScrollbar::handle_event(const sf::Event& event) {
|
||||
// Not visible -> not interested
|
||||
if(!this->isVisible())
|
||||
return false;
|
||||
@@ -121,7 +121,7 @@ bool cScrollbar::handle_event(sf::Event const & event) {
|
||||
return false;
|
||||
}
|
||||
|
||||
bool cScrollbar::handle_mouse_wheel_scrolled(sf::Event const & event) {
|
||||
bool cScrollbar::handle_mouse_wheel_scrolled(const sf::Event& event) {
|
||||
location event_location = this->translated_location({
|
||||
event.mouseWheelScroll.x,
|
||||
event.mouseWheelScroll.y
|
||||
@@ -137,9 +137,9 @@ bool cScrollbar::handle_mouse_wheel_scrolled(sf::Event const & event) {
|
||||
}
|
||||
|
||||
// Given a (translated) location, determine which part of the scrollbar it corresponds to
|
||||
auto cScrollbar::location_to_part(location const & location) const -> eScrollbarPart {
|
||||
auto cScrollbar::location_to_part(const location& location) const -> eScrollbarPart {
|
||||
|
||||
cScrollbar::eScrollbarPart part;
|
||||
eScrollbarPart part;
|
||||
|
||||
// Yes, this is a mess, but at least it's relatively small.
|
||||
int clickPos = this->vert ? location.y : location.x;
|
||||
@@ -148,28 +148,28 @@ auto cScrollbar::location_to_part(location const & location) const -> eScrollbar
|
||||
int total_bar_size = this->vert ? this->frame.height() : this->frame.width();
|
||||
|
||||
int btn_size = this->vert
|
||||
? this->up_rect[this->style][cScrollbar::VERT].height()
|
||||
: this->up_rect[this->style][cScrollbar::HORZ].width();
|
||||
? this->up_rect[this->style][VERT].height()
|
||||
: this->up_rect[this->style][HORZ].width();
|
||||
|
||||
int bar_size = total_bar_size - btn_size * 2;
|
||||
int thumbPos = bar_start + btn_size + this->pos * (bar_size - btn_size) / this->max;
|
||||
|
||||
if(clickPos < bar_start + btn_size) {
|
||||
part = cScrollbar::PART_UP;
|
||||
part = PART_UP;
|
||||
} else if(clickPos < thumbPos) {
|
||||
part = cScrollbar::PART_PGUP;
|
||||
part = PART_PGUP;
|
||||
} else if(clickPos < thumbPos + btn_size) {
|
||||
part = cScrollbar::PART_THUMB;
|
||||
part = PART_THUMB;
|
||||
} else if(clickPos < bar_end - btn_size) {
|
||||
part = cScrollbar::PART_PGDN;
|
||||
part = PART_PGDN;
|
||||
} else {
|
||||
part = cScrollbar::PART_DOWN;
|
||||
part = PART_DOWN;
|
||||
}
|
||||
|
||||
return part;
|
||||
}
|
||||
|
||||
bool cScrollbar::handle_mouse_pressed(sf::Event const & event) {
|
||||
bool cScrollbar::handle_mouse_pressed(const sf::Event& event) {
|
||||
location event_location = this->translated_location({
|
||||
event.mouseButton.x,
|
||||
event.mouseButton.y
|
||||
@@ -183,7 +183,7 @@ bool cScrollbar::handle_mouse_pressed(sf::Event const & event) {
|
||||
this->pressedPart = this->location_to_part(event_location);
|
||||
|
||||
// If the thumb is being dragged, record the initial click location
|
||||
if(this->pressedPart == cScrollbar::eScrollbarPart::PART_THUMB) {
|
||||
if(this->pressedPart == PART_THUMB) {
|
||||
this->mouse_pressed_at = event_location;
|
||||
this->drag_start_position = this->pos;
|
||||
}
|
||||
@@ -191,7 +191,7 @@ bool cScrollbar::handle_mouse_pressed(sf::Event const & event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
bool cScrollbar::handle_mouse_moved(sf::Event const & event) {
|
||||
bool cScrollbar::handle_mouse_moved(const sf::Event& event) {
|
||||
// Mouse movements while not pressed -> not interested
|
||||
// NOTE: depressed actually means pressed
|
||||
if(!this->depressed) return false;
|
||||
@@ -203,7 +203,7 @@ bool cScrollbar::handle_mouse_moved(sf::Event const & event) {
|
||||
event.mouseMove.y
|
||||
});
|
||||
|
||||
if(this->pressedPart == cScrollbar::eScrollbarPart::PART_THUMB) {
|
||||
if(this->pressedPart == PART_THUMB) {
|
||||
// Thumb being dragged.
|
||||
this->handle_thumb_drag(event_location);
|
||||
return true;
|
||||
@@ -224,12 +224,12 @@ bool cScrollbar::handle_mouse_moved(sf::Event const & event) {
|
||||
return true;
|
||||
}
|
||||
|
||||
void cScrollbar::handle_thumb_drag(location const & event_location) {
|
||||
void cScrollbar::handle_thumb_drag(const location& event_location) {
|
||||
int bar_start = this->vert ? this->frame.top : this->frame.left;
|
||||
int bar_end = this->vert ? this->frame.bottom : this->frame.right;
|
||||
int btn_size = this->vert
|
||||
? this->up_rect[this->style][cScrollbar::VERT].height()
|
||||
: this->up_rect[this->style][cScrollbar::HORZ].width();
|
||||
? this->up_rect[this->style][VERT].height()
|
||||
: this->up_rect[this->style][HORZ].width();
|
||||
|
||||
// XXX A lot of this looks like it can be precalculated once, but
|
||||
// be careful with the integer rounding.
|
||||
@@ -248,19 +248,19 @@ void cScrollbar::handle_thumb_drag(location const & event_location) {
|
||||
this->setPosition(this->drag_start_position + diff_in_steps);
|
||||
}
|
||||
|
||||
bool cScrollbar::handle_mouse_released(sf::Event const & event) {
|
||||
bool cScrollbar::handle_mouse_released(const sf::Event&) {
|
||||
// Mouse released while not pressed -> not interested
|
||||
// NOTE: depressed actually means pressed
|
||||
if(!this->depressed) return false;
|
||||
|
||||
switch(this->pressedPart) {
|
||||
case cScrollbar::PART_UP: this->pos--; break;
|
||||
case cScrollbar::PART_DOWN: this->pos++; break;
|
||||
case PART_UP: this->pos--; break;
|
||||
case PART_DOWN: this->pos++; break;
|
||||
|
||||
case cScrollbar::PART_PGUP: this->pos -= this->pgsz; break;
|
||||
case cScrollbar::PART_PGDN: this->pos += this->pgsz; break;
|
||||
case PART_PGUP: this->pos -= this->pgsz; break;
|
||||
case PART_PGDN: this->pos += this->pgsz; break;
|
||||
|
||||
case cScrollbar::PART_THUMB: break;
|
||||
case PART_THUMB: break;
|
||||
|
||||
default: break;
|
||||
}
|
||||
|
@@ -52,15 +52,15 @@ class cScrollbar : public cControl, public iEventListener, public iDrawable {
|
||||
// in the inventory area).
|
||||
rectangle wheel_event_rect {0, 0, 0, 0};
|
||||
void draw_vertical(), draw_horizontal();
|
||||
location translated_location(sf::Vector2i const) const;
|
||||
eScrollbarPart location_to_part(location const & location) const;
|
||||
location translated_location(const sf::Vector2i) const;
|
||||
eScrollbarPart location_to_part(const location& location) const;
|
||||
location mouse_pressed_at;
|
||||
int drag_start_position;
|
||||
bool handle_mouse_pressed(sf::Event const &);
|
||||
bool handle_mouse_moved(sf::Event const &);
|
||||
bool handle_mouse_released(sf::Event const &);
|
||||
bool handle_mouse_wheel_scrolled(sf::Event const &);
|
||||
void handle_thumb_drag(location const &);
|
||||
bool handle_mouse_pressed(const sf::Event&);
|
||||
bool handle_mouse_moved(const sf::Event&);
|
||||
bool handle_mouse_released(const sf::Event&);
|
||||
bool handle_mouse_wheel_scrolled(const sf::Event&);
|
||||
void handle_thumb_drag(const location&);
|
||||
public:
|
||||
/// @copydoc cDialog::init()
|
||||
static void init();
|
||||
@@ -131,7 +131,7 @@ public:
|
||||
void setStyle(eScrollStyle newStyle);
|
||||
void set_wheel_event_rect(rectangle);
|
||||
virtual void draw() override;
|
||||
virtual bool handle_event(sf::Event const &) override;
|
||||
virtual bool handle_event(const sf::Event&) override;
|
||||
/// @copydoc cControl::getSupportedHandlers
|
||||
///
|
||||
/// @todo Document possible handlers
|
||||
|
@@ -60,7 +60,7 @@ extern location spell_targets[8];
|
||||
extern std::shared_ptr<cScrollbar> text_sbar,item_sbar,shop_sbar;
|
||||
extern std::shared_ptr<cButton> done_btn, help_btn;
|
||||
extern sf::Texture bg_gworld;
|
||||
extern rectangle const sbar_rect,item_sbar_rect,shop_sbar_rect;
|
||||
extern const rectangle sbar_rect,item_sbar_rect,shop_sbar_rect;
|
||||
extern rectangle startup_top;
|
||||
extern rectangle talk_area_rect, word_place_rect;
|
||||
extern location store_anim_ul;
|
||||
@@ -202,7 +202,7 @@ sf::FloatRect compute_viewport(const sf::RenderWindow& mainPtr, int mode, float
|
||||
|
||||
// Buffer in pixels between ui edge and window edge. There seem to be
|
||||
// implicit (builtin) buffers the top and bottom of the UI so this is just for the sides.
|
||||
int const extra_horizontal_buffer { 7 };
|
||||
const int extra_horizontal_buffer { 7 };
|
||||
|
||||
// Left and top: where the viewport is.
|
||||
// Left and top seem to be in terms *target* dimensions,
|
||||
|
@@ -49,7 +49,7 @@ bool is_nature(short i, short j, unsigned short ground_t);
|
||||
void put_dialog_graphic(short graphic_num,short spec_g,rectangle draw_rect);
|
||||
void draw_startup_stats();
|
||||
void draw_trim(short q,short r,short which_trim,ter_num_t ground_ter);
|
||||
sf::FloatRect compute_viewport (sf::RenderWindow const &, int mode, float ui_scale, float width, float height);
|
||||
sf::FloatRect compute_viewport(const sf::RenderWindow&, int mode, float ui_scale, float width, float height);
|
||||
|
||||
void draw_startup_anim(bool advance);
|
||||
|
||||
|
@@ -46,9 +46,9 @@ bool party_in_memory = false;
|
||||
std::shared_ptr<cScrollbar> text_sbar, item_sbar, shop_sbar;
|
||||
std::shared_ptr<cButton> done_btn, help_btn;
|
||||
// TODO: move these 3 to boe.ui.cpp ?
|
||||
extern rectangle const sbar_rect = {285,560,423,576};
|
||||
extern rectangle const shop_sbar_rect = {69,272,359,288};
|
||||
extern rectangle const item_sbar_rect = {148,560,255,576};
|
||||
extern const rectangle sbar_rect = {285,560,423,576};
|
||||
extern const rectangle shop_sbar_rect = {69,272,359,288};
|
||||
extern const rectangle item_sbar_rect = {148,560,255,576};
|
||||
bool bgm_on = false,bgm_init = false;
|
||||
location store_anim_ul;
|
||||
cUniverse univ;
|
||||
@@ -147,7 +147,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_sbar(std::shared_ptr<cScrollbar>& sbar, std::string const name, rectangle rect, rectangle events_rect, int max, int pgSz, int start = 0) {
|
||||
static void init_sbar(std::shared_ptr<cScrollbar>& sbar, const std::string& name, rectangle rect, rectangle events_rect, int max, int pgSz, int start = 0) {
|
||||
sbar.reset(new cScrollbar(mainPtr));
|
||||
sbar->setBounds(rect);
|
||||
sbar->setMaximum(max);
|
||||
@@ -163,7 +163,7 @@ static void init_sbar(std::shared_ptr<cScrollbar>& sbar, std::string const name,
|
||||
static void init_scrollbars() {
|
||||
|
||||
// Cover entire transcript + scrollbar
|
||||
rectangle const transcript_events_rect {
|
||||
const rectangle transcript_events_rect {
|
||||
win_to_rects[WINRECT_TRANSCRIPT].top,
|
||||
win_to_rects[WINRECT_TRANSCRIPT].left,
|
||||
sbar_rect.bottom,
|
||||
@@ -171,7 +171,7 @@ static void init_scrollbars() {
|
||||
};
|
||||
|
||||
// Cover entire inventory + scrollbar
|
||||
rectangle const inventory_events_rect {
|
||||
const rectangle inventory_events_rect {
|
||||
win_to_rects[WINRECT_INVEN].top,
|
||||
win_to_rects[WINRECT_INVEN].left,
|
||||
item_sbar_rect.bottom,
|
||||
@@ -402,7 +402,7 @@ void redraw_everything() {
|
||||
if(map_visible) draw_map(false);
|
||||
}
|
||||
|
||||
void Mouse_Pressed(sf::Event const & event) {
|
||||
void Mouse_Pressed(const sf::Event& event) {
|
||||
|
||||
// What is this stuff? Why is it here?
|
||||
if(had_text_freeze > 0) {
|
||||
|
@@ -4,7 +4,7 @@
|
||||
int main(int argc, char* argv[]);
|
||||
void update_everything();
|
||||
void redraw_everything();
|
||||
void Mouse_Pressed(sf::Event const &);
|
||||
void Mouse_Pressed(const sf::Event&);
|
||||
void close_program();
|
||||
void change_cursor(location where_curs);
|
||||
void set_up_apple_events(int argc, char* argv[]);
|
||||
@@ -18,6 +18,6 @@ void plop_fancy_startup();
|
||||
void update_terrain_animation();
|
||||
void update_startup_animation();
|
||||
void handle_events();
|
||||
void handle_one_event(sf::Event const &);
|
||||
void handle_one_minimap_event(sf::Event const &);
|
||||
void handle_one_event(const sf::Event&);
|
||||
void handle_one_minimap_event(const sf::Event &);
|
||||
|
||||
|
@@ -16,7 +16,7 @@ extern sf::RenderWindow mainPtr;
|
||||
extern cUniverse univ;
|
||||
extern bool party_in_memory;
|
||||
extern eGameMode overall_mode;
|
||||
extern std::unordered_map<std::string, std::shared_ptr<iEventListener>>event_listeners;
|
||||
extern std::unordered_map<std::string, std::shared_ptr<iEventListener>> event_listeners;
|
||||
extern cDrawableManager drawable_mgr;
|
||||
|
||||
std::shared_ptr<OpenBoEMenu> menu_ptr;
|
||||
|
@@ -28,7 +28,7 @@ extern rectangle name_rect;
|
||||
extern rectangle pc_race_rect;
|
||||
extern rectangle edit_rect[5];
|
||||
|
||||
bool handle_action(sf::Event const & event) {
|
||||
bool handle_action(const sf::Event & event) {
|
||||
location the_point = translate_mouse_coordinates({event.mouseButton.x, event.mouseButton.y});
|
||||
|
||||
bool to_return = false;
|
||||
|
@@ -68,7 +68,7 @@ extern rectangle terrain_buttons_rect;
|
||||
extern void set_up_apple_events(int argc, char* argv[]);
|
||||
|
||||
// TODO: these should be members of some global entity instead of being here
|
||||
std::unordered_map <std::string, std::shared_ptr <iEventListener>> event_listeners;
|
||||
std::unordered_map<std::string, std::shared_ptr <iEventListener>> event_listeners;
|
||||
cDrawableManager drawable_mgr;
|
||||
|
||||
//Changed to ISO C specified argument and return type.
|
||||
@@ -100,7 +100,7 @@ int main(int argc, char* argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
static void init_sbar(std::shared_ptr<cScrollbar>& sbar, std::string const name, rectangle rect, rectangle events_rect, int pgSz) {
|
||||
static void init_sbar(std::shared_ptr<cScrollbar>& sbar, const std::string& name, rectangle rect, rectangle events_rect, int pgSz) {
|
||||
sbar.reset(new cScrollbar(mainPtr));
|
||||
sbar->setBounds(rect);
|
||||
sbar->set_wheel_event_rect(events_rect);
|
||||
@@ -108,10 +108,10 @@ static void init_sbar(std::shared_ptr<cScrollbar>& sbar, std::string const name,
|
||||
sbar->hide();
|
||||
|
||||
drawable_mgr.add_drawable(UI_LAYER_DEFAULT, name, sbar);
|
||||
event_listeners[name] = std::dynamic_pointer_cast <iEventListener> (sbar);
|
||||
event_listeners[name] = std::dynamic_pointer_cast<iEventListener>(sbar);
|
||||
}
|
||||
|
||||
static void init_scrollbars () {
|
||||
static void init_scrollbars() {
|
||||
right_sbar_rect.top = RIGHT_AREA_UL_Y - 1;
|
||||
right_sbar_rect.left = RIGHT_AREA_UL_X + RIGHT_AREA_WIDTH - 1 - 16;
|
||||
right_sbar_rect.bottom = RIGHT_AREA_UL_Y + RIGHT_AREA_HEIGHT + 1;
|
||||
@@ -128,10 +128,10 @@ static void init_scrollbars () {
|
||||
init_sbar(pal_sbar, "pal_sbar", pal_sbar_rect, pal_sbar_event_rect, 16);
|
||||
}
|
||||
|
||||
sf::FloatRect compute_viewport(sf::RenderWindow const & mainPtr, float ui_scale) {
|
||||
sf::FloatRect compute_viewport(const sf::RenderWindow & mainPtr, float ui_scale) {
|
||||
|
||||
// See compute_viewport() in boe.graphics.cpp
|
||||
int const os_specific_y_offset =
|
||||
const int os_specific_y_offset =
|
||||
#if defined(SFML_SYSTEM_WINDOWS) || defined(SFML_SYSTEM_MAC)
|
||||
0;
|
||||
#else
|
||||
@@ -155,8 +155,8 @@ void init_main_window (sf::RenderWindow & mainPtr, sf::View & mainView) {
|
||||
// In particular, the white area on the right side of the main menu needs fixing.
|
||||
float ui_scale = get_float_pref("UIScale", 1.0);
|
||||
|
||||
int const width = ui_scale * 584;
|
||||
int const height = ui_scale * 420
|
||||
const int width = ui_scale * 584;
|
||||
const int height = ui_scale * 420
|
||||
#ifndef SFML_SYSTEM_WINDOWS
|
||||
+ getMenubarHeight()
|
||||
#endif
|
||||
@@ -238,10 +238,10 @@ void handle_events() {
|
||||
}
|
||||
}
|
||||
|
||||
void handle_one_event(sf::Event const & event) {
|
||||
void handle_one_event(const sf::Event& event) {
|
||||
|
||||
// Check if any of the event listeners want this event.
|
||||
for (auto & listener : event_listeners) {
|
||||
for (auto& listener : event_listeners) {
|
||||
if(listener.second->handle_event(event)) return;
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ void handle_menu_choice(eMenu item_hit) {
|
||||
redraw_screen();
|
||||
}
|
||||
|
||||
void Mouse_Pressed(sf::Event const & event) {
|
||||
void Mouse_Pressed(const sf::Event & event) {
|
||||
location mousePos { translate_mouse_coordinates({event.mouseButton.x, event.mouseButton.y}) };
|
||||
handle_action(mousePos,event);
|
||||
}
|
||||
|
@@ -1,8 +1,8 @@
|
||||
#include "drawable_manager.hpp"
|
||||
|
||||
void cDrawableManager::draw_all () {
|
||||
void cDrawableManager::draw_all() {
|
||||
// layer order from lowest to highest is ensured by std::map
|
||||
for (auto & layer : this->layers) {
|
||||
for(auto & layer : this->layers) {
|
||||
for (auto & drawable : layer.second) {
|
||||
drawable.second->draw();
|
||||
}
|
||||
|
@@ -13,13 +13,13 @@ public:
|
||||
|
||||
void draw_all();
|
||||
|
||||
template<typename T>void add_drawable (int layer_id, std::string const name, std::shared_ptr<T>drawable) {
|
||||
template<typename T> void add_drawable(int layer_id, const std::string& name, std::shared_ptr<T> drawable) {
|
||||
this->layers[layer_id][name] = std::dynamic_pointer_cast<iDrawable>(drawable);
|
||||
}
|
||||
|
||||
private:
|
||||
|
||||
using Layer = std::unordered_map <std::string, std::shared_ptr<iDrawable>>;
|
||||
using Layer = std::unordered_map<std::string, std::shared_ptr<iDrawable>>;
|
||||
|
||||
std::map <int, Layer> layers;
|
||||
};
|
||||
|
@@ -7,7 +7,7 @@ class iEventListener {
|
||||
|
||||
public:
|
||||
|
||||
virtual bool handle_event(sf::Event const &) = 0;
|
||||
virtual bool handle_event(const sf::Event&) = 0;
|
||||
|
||||
virtual ~iEventListener() {}
|
||||
|
||||
|
Reference in New Issue
Block a user