From 9e13d634f043761ef889b2007404f18980a390f2 Mon Sep 17 00:00:00 2001 From: Ingo Ruhnke Date: Wed, 30 Jul 2014 20:55:31 +0200 Subject: [PATCH] Removed unused GUI classes Button and ButtonGroup --- src/gui/button.cpp | 128 ------------------------------- src/gui/button.hpp | 69 ----------------- src/gui/button_group.cpp | 191 ----------------------------------------------- src/gui/button_group.hpp | 67 ----------------- 4 files changed, 455 deletions(-) delete mode 100644 src/gui/button.cpp delete mode 100644 src/gui/button.hpp delete mode 100644 src/gui/button_group.cpp delete mode 100644 src/gui/button_group.hpp diff --git a/src/gui/button.cpp b/src/gui/button.cpp deleted file mode 100644 index 8561dd4ed..000000000 --- a/src/gui/button.cpp +++ /dev/null @@ -1,128 +0,0 @@ -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "gui/button.hpp" - -#include "supertux/globals.hpp" -#include "video/drawing_context.hpp" - -FontPtr Button::info_font; - -Button::Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_) : - pos(), - size(), - image(), - binding(binding_), - id(), - state(), - info() -{ - image = image_; - size = Vector(image->get_width(), image->get_height()); - id = 0; - info = info_; -} - -Button::Button(const Button& rhs) : - pos(rhs.pos), - size(rhs.size), - image(rhs.image), - binding(rhs.binding), - id(rhs.id), - state(rhs.state), - info(rhs.info) -{ -} - -Button::~Button() -{ -} - -Button& -Button::operator=(const Button& rhs) -{ - if (this != &rhs) - { - pos = rhs.pos; - size = rhs.size; - image = rhs.image; - binding = rhs.binding; - id = rhs.id; - state = rhs.state; - info = rhs.info; - } - return *this; -} - -void Button::draw(DrawingContext &context, bool selected) -{ - if(selected) - context.draw_filled_rect(pos, size, Color (200,240,220), LAYER_GUI); - else - context.draw_filled_rect(pos, size, Color (200,200,220), LAYER_GUI); - - Vector tanslation = -context.get_translation(); - if(state == BT_SHOW_INFO) - { - Vector offset; - if(pos.x + tanslation.x < 100 && pos.y + tanslation.y > SCREEN_HEIGHT - 20) - offset = Vector(size.x, - 10); - else if(pos.x + tanslation.x < 100) - offset = Vector(size.x, 0); - else - offset = Vector(-30, -size.y/2); - context.draw_text(info_font, info, pos + offset, ALIGN_LEFT, LAYER_GUI+2); - if(binding != 0) - context.draw_text(info_font, "(" + std::string(SDL_GetKeyName(binding)) + - ")", pos + offset + Vector(0,12), - ALIGN_LEFT, LAYER_GUI+2); - } - - context.draw_surface_part(image, Vector(0,0), size, pos, LAYER_GUI+1); -} - -int Button::event(SDL_Event &event, int x_offset, int y_offset) -{ - state = BT_NONE; - switch(event.type) - { - case SDL_MOUSEBUTTONDOWN: - if(event.button.x > pos.x + x_offset && event.button.x < pos.x + x_offset + size.x && - event.button.y > pos.y + y_offset && event.button.y < pos.y + y_offset + size.y) - { - if(event.button.button == SDL_BUTTON_RIGHT) - state = BT_SHOW_INFO; - } - break; - case SDL_MOUSEBUTTONUP: - if(event.button.x > pos.x + x_offset && event.button.x < pos.x + x_offset + size.x && - event.button.y > pos.y + y_offset && event.button.y < pos.y + y_offset + size.y) - { - if(event.button.button == SDL_BUTTON_LEFT) - state = BT_SELECTED; - } - break; - case SDL_KEYDOWN: // key pressed - if(event.key.keysym.sym == binding) - state = BT_SELECTED; - break; - default: - break; - } - return state; -} - -/* EOF */ diff --git a/src/gui/button.hpp b/src/gui/button.hpp deleted file mode 100644 index e0229b4c1..000000000 --- a/src/gui/button.hpp +++ /dev/null @@ -1,69 +0,0 @@ -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef HEADER_SUPERTUX_GUI_BUTTON_HPP -#define HEADER_SUPERTUX_GUI_BUTTON_HPP - -#include -#include - -#include "math/vector.hpp" -#include "video/font_ptr.hpp" -#include "video/surface_ptr.hpp" - -class DrawingContext; -class Font; -class ButtonGroup; - -enum { - BT_NONE, - BT_HOVER, - BT_SELECTED, - BT_SHOW_INFO -}; - -class Button -{ -public: - Button(SurfacePtr image_, std::string info_, SDL_Keycode binding_); - Button(const Button& rhs); - ~Button(); - - Button& operator=(const Button& rhs); - - void draw(DrawingContext& context, bool selected); - int event(SDL_Event& event, int x_offset = 0, int y_offset = 0); - - static FontPtr info_font; - -private: - friend class ButtonGroup; - -private: - Vector pos; - Vector size; - - SurfacePtr image; - SDL_Keycode binding; - - int id; - int state; - std::string info; -}; - -#endif - -/* EOF */ diff --git a/src/gui/button_group.cpp b/src/gui/button_group.cpp deleted file mode 100644 index fcc31acda..000000000 --- a/src/gui/button_group.cpp +++ /dev/null @@ -1,191 +0,0 @@ -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#include "gui/button_group.hpp" - -#include "supertux/globals.hpp" -#include "video/drawing_context.hpp" - -ButtonGroup::ButtonGroup(Vector pos_, Vector buttons_size_, Vector buttons_box_) : - pos(pos_), - buttons_size(buttons_size_), - buttons_box(buttons_box_), - buttons(), - button_selected(), - row(), - mouse_hover(), - mouse_left_button(), - buttons_pair_nb() -{ - buttons.clear(); - row = 0; - button_selected = -1; - mouse_hover = false; - mouse_left_button = false; - buttons_pair_nb = 0; -} - -ButtonGroup::~ButtonGroup() -{ -} - -void -ButtonGroup::add_button(Button button, int id, bool select) -{ - button.pos.x = ((buttons.size()-buttons_pair_nb) % (int)buttons_box.x) * buttons_size.x; - button.pos.y = ((int)((buttons.size()-buttons_pair_nb) / buttons_box.x)) * buttons_size.y; - button.size = buttons_size; - button.id = id; - if(select) - button_selected = id; - - buttons.push_back(button); -} - -void -ButtonGroup::add_pair_of_buttons(Button button1, int id1, Button button2, int id2) -{ - button1.pos.x = button2.pos.x = ((buttons.size()-buttons_pair_nb) % (int)buttons_box.x) * buttons_size.x; - button1.pos.y = button2.pos.y = ((int)((buttons.size()-buttons_pair_nb) / buttons_box.x)) * buttons_size.y; - button1.size.x = button2.size.x = buttons_size.x; - button1.size.y = button2.size.y = buttons_size.y / 2; - button2.pos.y += buttons_size.y / 2; - button1.id = id1; - button2.id = id2; - - buttons_pair_nb++; - buttons.push_back(button1); - buttons.push_back(button2); -} - -void -ButtonGroup::draw(DrawingContext &context) -{ - context.draw_filled_rect(pos - Vector(12,4), - Vector(buttons_size.x*buttons_box.x + 16, buttons_size.y*buttons_box.y + 8), - Color (0,0,0, 128), LAYER_GUI-1); - - context.push_transform(); - context.set_translation(Vector(-pos.x, -pos.y + buttons_size.y*row)); - for(Buttons::iterator i = buttons.begin(); i != buttons.end(); ++i) - { - if(i->pos.y < row*buttons_size.y || - i->pos.y + i->size.y > (row + buttons_box.y) * buttons_size.y) - continue; - - i->draw(context, i->id == button_selected); - } - context.pop_transform(); -} - -bool -ButtonGroup::event(SDL_Event &event) -{ - bool caught_event = false; - - switch(event.type) - { - case SDL_MOUSEMOTION: - mouse_hover = false; - - if(mouse_left_button) - { -#ifdef OLD_SDL1 - pos.x += int(event.motion.xrel * float(SCREEN_WIDTH)/g_screen->w); - pos.y += int(event.motion.yrel * float(SCREEN_HEIGHT)/g_screen->h); - caught_event = true; -#endif - } - if(event.button.x > pos.x-12 && event.button.x < pos.x+16 + buttons_box.x*buttons_size.x && - event.button.y > pos.y-4 && event.button.y < pos.y+8 + buttons_box.y*buttons_size.y) - mouse_hover = true; - break; - case SDL_MOUSEBUTTONDOWN: - if(event.button.x < pos.x-12 || event.button.x > pos.x+16 + - buttons_box.x*buttons_size.x || event.button.y < pos.y-4 || - event.button.y > pos.y+8 + buttons_box.y*buttons_size.y) - break; - - caught_event = true; - -#ifdef OLD_SDL1 - if(event.button.button == SDL_MOUSEBUTTONUP) - { - row--; - if(row < 0) - row = 0; - } - else if(event.button.button == SDL_MOUSEBUTTONDOWN) - { - row++; - if(row > (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y + - ((int)(buttons.size()-buttons_pair_nb)%(int)buttons_box.x != 0 ? 1 : 0)) - row = (int)((buttons.size()-buttons_pair_nb)/buttons_box.x) - (int)buttons_box.y + - ((int)(buttons.size()-buttons_pair_nb)%(int)buttons_box.x != 0 ? 1 : 0); - } - else if(event.button.button == SDL_BUTTON_LEFT) - mouse_left_button = true; - else - caught_event = false; -#endif - break; - case SDL_MOUSEBUTTONUP: - mouse_left_button = false; - break; - default: - break; - } - - if(caught_event) - return true; - - for(Buttons::iterator i = buttons.begin(); i != buttons.end(); ++i) - { - if(i->pos.y < row*buttons_size.y || - i->pos.y + i->size.y > (row + buttons_box.y) * buttons_size.y) - continue; - - if(i->event(event, (int)pos.x, - (int)pos.y - row*(int)buttons_size.y) == BT_SELECTED) - { - button_selected = i->id; - caught_event = true; - break; - } - } - - return caught_event; -} - -int -ButtonGroup::selected_id() -{ - return button_selected; -} - -void -ButtonGroup::set_unselected() -{ - button_selected = -1; -} - -bool -ButtonGroup::is_hover() -{ - return mouse_hover; -} - -/* EOF */ diff --git a/src/gui/button_group.hpp b/src/gui/button_group.hpp deleted file mode 100644 index 5c52fb517..000000000 --- a/src/gui/button_group.hpp +++ /dev/null @@ -1,67 +0,0 @@ -// SuperTux -// Copyright (C) 2006 Matthias Braun -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -#ifndef HEADER_SUPERTUX_GUI_BUTTON_GROUP_HPP -#define HEADER_SUPERTUX_GUI_BUTTON_GROUP_HPP - -#include -#include -#include - -#include "math/vector.hpp" -#include "gui/button.hpp" - -class DrawingContext; - -class ButtonGroup -{ -public: - ButtonGroup(Vector pos_, Vector size_, Vector button_box_); - ~ButtonGroup(); - - void draw(DrawingContext& context); - bool event(SDL_Event& event); - - void add_button(Button button, int id, bool select = false); - void add_pair_of_buttons(Button button1, int id1, Button button2, int id2); - - int selected_id(); - void set_unselected(); - bool is_hover(); - -private: - typedef std::vector