wesnoth-cvs-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Wesnoth-cvs-commits] wesnoth/src Makefile.am help.cpp widgets/menu.c...


From: Guillaume Melquiond
Subject: [Wesnoth-cvs-commits] wesnoth/src Makefile.am help.cpp widgets/menu.c...
Date: Sat, 06 Nov 2004 04:25:17 -0500

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     Guillaume Melquiond <address@hidden>    04/11/06 09:19:28

Modified files:
        src            : Makefile.am help.cpp 
        src/widgets    : menu.cpp menu.hpp scrollbar.cpp scrollbar.hpp 
                         scrollpane.cpp scrollpane.hpp textbox.cpp 
                         textbox.hpp widget.cpp 
Added files:
        src/widgets    : scrollarea.cpp scrollarea.hpp 

Log message:
        Add a scrollarea widget as an ancestor of menu, textbox, help_textarea, 
and scrollpane, in order to factor the common code. Advantage: now the textbox 
gets back its scrollbar. Drawback: the downarrow button of a menu scrollbar 
sometimes gets stuck (???).

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/Makefile.am.diff?tr1=1.58&tr2=1.59&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/help.cpp.diff?tr1=1.49&tr2=1.50&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollarea.cpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollarea.hpp?rev=1.1
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/menu.cpp.diff?tr1=1.67&tr2=1.68&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/menu.hpp.diff?tr1=1.26&tr2=1.27&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollbar.cpp.diff?tr1=1.18&tr2=1.19&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollbar.hpp.diff?tr1=1.8&tr2=1.9&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollpane.cpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/scrollpane.hpp.diff?tr1=1.1&tr2=1.2&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/textbox.cpp.diff?tr1=1.61&tr2=1.62&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/textbox.hpp.diff?tr1=1.34&tr2=1.35&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/widget.cpp.diff?tr1=1.23&tr2=1.24&r1=text&r2=text

Patches:
Index: wesnoth/src/Makefile.am
diff -u wesnoth/src/Makefile.am:1.58 wesnoth/src/Makefile.am:1.59
--- wesnoth/src/Makefile.am:1.58        Mon Nov  1 18:06:36 2004
+++ wesnoth/src/Makefile.am     Sat Nov  6 09:19:27 2004
@@ -97,6 +97,7 @@
                  widgets/label.cpp \
                  widgets/menu.cpp \
                  widgets/progressbar.cpp \
+                 widgets/scrollarea.cpp \
                  widgets/scrollbar.cpp \
                  widgets/scrollpane.cpp \
                  widgets/slider.cpp \
@@ -251,6 +252,7 @@
                         widgets/menu.cpp \
                         widgets/progressbar.cpp \
                         widgets/textbox.cpp \
+                        widgets/scrollarea.cpp \
                         widgets/scrollbar.cpp \
                         widgets/slider.cpp \
                         widgets/widget.cpp \
Index: wesnoth/src/help.cpp
diff -u wesnoth/src/help.cpp:1.49 wesnoth/src/help.cpp:1.50
--- wesnoth/src/help.cpp:1.49   Wed Nov  3 21:46:58 2004
+++ wesnoth/src/help.cpp        Sat Nov  6 09:19:27 2004
@@ -224,7 +224,7 @@
 };
 
 /// The area where the content is shown in the help browser.
-class help_text_area : public gui::widget, public gui::scrollable {
+class help_text_area : public gui::scrollarea {
 public:
        help_text_area(display &disp, const section &toplevel);
        /// Display the topic.
@@ -235,13 +235,9 @@
        /// empty string.
        std::string ref_at(const int x, const int y);
 
-       /// Return the width of the area where text fit.
-       int text_width() const;
-
-       void scroll(int pos);
-
-       virtual void set_location(const SDL_Rect& rect);
-       using gui::widget::set_location;
+protected:
+       virtual void scroll(int pos);
+       virtual void set_inner_location(const SDL_Rect& rect);
 
 private:
        enum ALIGNMENT {LEFT, MIDDLE, RIGHT, HERE};
@@ -358,7 +354,6 @@
        std::pair<int, int> curr_loc_;
        const unsigned min_row_height_;
        unsigned curr_row_height_;
-       gui::scrollbar scrollbar_;
        /// The height of all items in total.
        int contents_height_;
 };
@@ -1612,25 +1607,17 @@
 }
 
 help_text_area::help_text_area(display &disp, const section &toplevel)
-       : gui::widget(disp), toplevel_(toplevel), shown_topic_(NULL),
+       : gui::scrollarea(disp), toplevel_(toplevel), shown_topic_(NULL),
          title_spacing_(16), curr_loc_(0, 0),
          min_row_height_(font::get_max_height(normal_font_size)), 
curr_row_height_(min_row_height_),
-         scrollbar_(disp, *this, this), contents_height_(0)
+         contents_height_(0)
 {}
 
-void help_text_area::set_location(SDL_Rect const &rect) {
-       widget::set_location(rect);
-       SDL_Rect r = rect;
-       int w = scrollbar_.width();
-       r.w -= w;
-       register_rectangle(r);
-       r.x += r.w;
-       r.w = w;
-       scrollbar_.set_location(r);
+void help_text_area::set_inner_location(SDL_Rect const &rect) {
+       register_rectangle(rect);
 }
 
 void help_text_area::show_topic(const topic &t) {
-       bg_restore();
        shown_topic_ = &t;
        set_items(t.text, t.title);
        set_dirty(true);
@@ -1666,7 +1653,7 @@
        curr_row_height_ = min_row_height_;
        // Add the title item.
        const std::string show_title =
-               font::make_text_ellipsis(shown_topic_->title, title_size, 
text_width());
+               font::make_text_ellipsis(shown_topic_->title, title_size, 
inner_location().w);
        surface surf(font::get_rendered_text(show_title, title_size,
                                             font::NORMAL_COLOUR, 
TTF_STYLE_BOLD));
        if (surf != NULL) {
@@ -1723,9 +1710,8 @@
        }
        down_one_line(); // End the last line.
        int h = height();
-       scrollbar_.set_full_size(contents_height_);
-       scrollbar_.set_shown_size(h);
-       scrollbar_.hide(h >= contents_height_);
+       set_full_size(contents_height_);
+       set_shown_size(h);
 }
 
 void help_text_area::handle_ref_cfg(const config &cfg) {
@@ -1842,10 +1828,6 @@
        add_text_item(text, "", font_size, bold, italic, color);
 }
 
-int help_text_area::text_width() const {
-       return width() - scrollbar_.width();
-}
-
 void help_text_area::add_text_item(const std::string text, const std::string 
ref_dst,
                                                                   int 
_font_size, bool bold, bool italic,
                                                                   SDL_Color 
text_color) {
@@ -1933,6 +1915,7 @@
        const int width = surf->w + (box ? box_width * 2 : 0);
        int xpos;
        int ypos = curr_loc_.second;
+       int text_width = inner_location().w;
        switch (align) {
        case HERE:
                xpos = curr_loc_.first;
@@ -1941,14 +1924,14 @@
                xpos = 0;
                break;
        case MIDDLE:
-               xpos = text_width() / 2 - width / 2 - (box ? box_width : 0);
+               xpos = text_width / 2 - width / 2 - (box ? box_width : 0);
                break;
        case RIGHT:
-               xpos = text_width() - width - (box ? box_width * 2 : 0);
+               xpos = text_width - width - (box ? box_width * 2 : 0);
                break;
        }
        if (curr_loc_.first != get_min_x(curr_loc_.second, curr_row_height_)
-               && (xpos < curr_loc_.first || xpos + width > text_width())) {
+               && (xpos < curr_loc_.first || xpos + width > text_width)) {
                down_one_line();
                add_img_item(path, alignment, floating, box);
        }
@@ -1991,16 +1974,16 @@
 }
 
 int help_text_area::get_max_x(const int y, const int height) {
-       int max_x = text_width();
+       int text_width = inner_location().w;
+       int max_x = text_width;
        for (std::list<item>::const_iterator it = items_.begin(); it != 
items_.end(); it++) {
                const item& itm = *it;
                if (itm.floating) {
                        if (itm.rect.y < y + height && itm.rect.y + itm.rect.h 
> y) {
                                if (itm.align == RIGHT) {
-                                       max_x = minimum<int>(max_x, 
text_width() - itm.rect.w - 5);
-                               }
-                               if (itm.align == MIDDLE) {
-                                       max_x = minimum<int>(max_x, 
text_width() / 2 - itm.rect.w / 2 - 5);
+                                       max_x = minimum<int>(max_x, text_width 
- itm.rect.w - 5);
+                               } else if (itm.align == MIDDLE) {
+                                       max_x = minimum<int>(max_x, text_width 
/ 2 - itm.rect.w / 2 - 5);
                                }
                        }
                }
@@ -2064,14 +2047,13 @@
 }
 
 void help_text_area::draw_contents() {
-       SDL_Rect const &loc = location();
-       SDL_Rect clip_rect = { loc.x, loc.y, text_width(), loc.h };
-       bg_restore(clip_rect);
+       SDL_Rect const &loc = inner_location();
+       bg_restore();
        surface const screen = disp().video().getSurface();
-       clip_rect_setter clip_rect_set(screen, clip_rect);
+       clip_rect_setter clip_rect_set(screen, loc);
        for(std::list<item>::const_iterator it = items_.begin(), end = 
items_.end(); it != end; ++it) {
                SDL_Rect dst = it->rect;
-               dst.y -= scrollbar_.get_position();
+               dst.y -= get_position();
                if (dst.y < (int)loc.h && dst.y + it->rect.h > 0) {
                        dst.x += loc.x;
                        dst.y += loc.y;
@@ -2086,7 +2068,7 @@
                        SDL_BlitSurface(it->surf, NULL, screen, &dst);
                }
        }
-       update_rect(clip_rect);
+       update_rect(loc);
 }
 
 void help_text_area::scroll(int) {
@@ -2104,7 +2086,7 @@
        const int local_x = x - location().x;
        const int local_y = y - location().y;
        if (local_y < (int)height() && local_y > 0) {
-               const int cmp_y = local_y + scrollbar_.get_position();
+               const int cmp_y = local_y + get_position();
                const std::list<item>::const_iterator it =
                        std::find_if(items_.begin(), items_.end(), 
item_at(local_x, cmp_y));
                if (it != items_.end()) {
Index: wesnoth/src/widgets/menu.cpp
diff -u wesnoth/src/widgets/menu.cpp:1.67 wesnoth/src/widgets/menu.cpp:1.68
--- wesnoth/src/widgets/menu.cpp:1.67   Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/menu.cpp        Sat Nov  6 09:19:28 2004
@@ -22,13 +22,12 @@
 
 menu::menu(display& disp, const std::vector<std::string>& items,
            bool click_selects, int max_height, int max_width)
-        : widget(disp),
+        : scrollarea(disp),
           max_height_(max_height), max_width_(max_width), max_items_(-1), 
item_height_(-1),
          cur_help_(-1,-1), help_string_(-1),
          selected_(0), click_selects_(click_selects),
          previous_button_(true), show_result_(false),
          double_clicked_(false),
-         scrollbar_(disp, *this, this),
          num_selects_(true),
          ignore_next_doubleclick_(false),
          last_was_doubleclick_(false)
@@ -82,13 +81,13 @@
 
 void menu::update_scrollbar_grip_height()
 {
-       scrollbar_.set_full_size(items_.size());
-       scrollbar_.set_shown_size(max_items_onscreen());
+       set_full_size(items_.size());
+       set_shown_size(max_items_onscreen());
 }
 
 void menu::update_size() {
        SDL_Rect rect = location();
-       for(size_t i = scrollbar_.get_position(),
+       for(size_t i = get_position(),
            i_end = minimum(items_.size(), i + max_items_onscreen());
            i != i_end; ++i)
                rect.h += get_item_rect(i).h;
@@ -97,8 +96,8 @@
 
        std::vector<int> const &widths = column_widths();
        rect.w = std::accumulate(widths.begin(), widths.end(), 0);
-       if (show_scrollbar())
-               rect.w += scrollbar_.width();
+       if (items_.size() > max_items_onscreen())
+               rect.w += scrollbar_width();
        if (max_width_ > 0 && rect.w > max_width_)
                rect.w = max_width_;
 
@@ -107,19 +106,11 @@
 
 int menu::selection() const { return selected_; }
 
-void menu::set_location(SDL_Rect const &rect)
+void menu::set_inner_location(SDL_Rect const &rect)
 {
-       widget::set_location(rect);
        itemRects_.clear();
-       bool scr = show_scrollbar();
-       if (scr) {
-               int scr_width = scrollbar_.width();
-               SDL_Rect scroll_rect = { rect.x + rect.w - scr_width, rect.y, 
scr_width, rect.h };
-               scrollbar_.set_location(scroll_rect);
-               update_scrollbar_grip_height();
-       }
-       scrollbar_.hide(!scr);
-       register_rectangle(get_list_rect());
+       update_scrollbar_grip_height();
+       register_rectangle(rect);
 }
 
 void menu::change_item(int pos1, int pos2,std::string str)
@@ -152,17 +143,14 @@
        itemRects_.clear();
        column_widths_.clear();
        //undrawn_items_.clear();
-       set_dirty();
        max_items_ = -1; // Force recalculation of the max items.
        item_height_ = -1; // Force recalculation of the item height.
-       // Scrollbar will be reenabled if it is needed.
-       scrollbar_.hide(true);
        selected_ = 0;
        fill_items(items, strip_spaces);
        if (!keep_viewport)
-               scrollbar_.set_position(0);
-       set_location(location()); // Force some more updating.
+               set_position(0);
        update_scrollbar_grip_height();
+       set_location(location()); // Force some more updating.
        adjust_viewport_to_selection();
        set_dirty();
 }
@@ -204,7 +192,7 @@
 {
        if(click_selects_)
                return;
-       scrollbar_.adjust_position(selected_);
+       adjust_position(selected_);
 }
 
 void menu::move_selection_up(size_t dep)
@@ -260,6 +248,7 @@
 
 void menu::handle_event(const SDL_Event& event)
 {
+       scrollarea::handle_event(event);
        if(event.type == SDL_KEYDOWN) {
                key_press(event.key.keysym.sym);
        } else if(event.type == SDL_MOUSEBUTTONDOWN &&
@@ -312,8 +301,6 @@
 
 int menu::process()
 {
-       scrollbar_.hide(!show_scrollbar());
-
        if(show_result_) {
                show_result_ = false;
                return selected_;
@@ -322,11 +309,6 @@
        }
 }
 
-bool menu::show_scrollbar() const
-{
-       return items_.size() > max_items_onscreen();
-}
-
 bool menu::double_clicked()
 {
        bool old = double_clicked_;
@@ -419,7 +401,7 @@
 
        SDL_Rect const &area = disp().screen_area();
        //SDL_Rect area = { 0, 0, rect.w, rect.h };
-       SDL_Rect const &loc = location();
+       SDL_Rect const &loc = inner_location();
 
        const std::vector<int>& widths = column_widths();
 
@@ -478,20 +460,11 @@
 
        for(size_t i = 0; i != items_.size(); ++i)
                draw_item(i);
-
-       update_rect(get_list_rect());
-}
-
-SDL_Rect menu::get_list_rect() const
-{
-       SDL_Rect loc = location();
-       if (!scrollbar_.hidden()) loc.w -= scrollbar_.width();
-       return loc;
 }
 
 int menu::hit(int x, int y) const
 {
-       SDL_Rect const &loc = get_list_rect();
+       SDL_Rect const &loc = inner_location();
        if (x >= loc.x  && x < loc.x + loc.w && y >= loc.y && y < loc.y + 
loc.h) {
                for(size_t i = 0; i != items_.size(); ++i) {
                        const SDL_Rect& rect = get_item_rect(i);
@@ -523,7 +496,7 @@
 SDL_Rect menu::get_item_rect(int item) const
 {
        const SDL_Rect empty_rect = {0,0,0,0};
-       int first_item_on_screen = scrollbar_.get_position();
+       int first_item_on_screen = get_position();
        if (item < first_item_on_screen ||
            size_t(item) >= first_item_on_screen + max_items_onscreen()) {
                return empty_rect;
@@ -533,7 +506,7 @@
        if(i != itemRects_.end())
                return i->second;
 
-       SDL_Rect const &loc = get_list_rect();
+       SDL_Rect const &loc = inner_location();
 
        int y = loc.y;
        if (item != first_item_on_screen) {
Index: wesnoth/src/widgets/menu.hpp
diff -u wesnoth/src/widgets/menu.hpp:1.26 wesnoth/src/widgets/menu.hpp:1.27
--- wesnoth/src/widgets/menu.hpp:1.26   Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/menu.hpp        Sat Nov  6 09:19:28 2004
@@ -8,14 +8,13 @@
 #include "../events.hpp"
 #include "../sdl_utils.hpp"
 
-#include "scrollbar.hpp"
-#include "button.hpp"
+#include "scrollarea.hpp"
 
 #include "SDL.h"
 
 namespace gui {
 
-class menu : public widget, public scrollable
+class menu : public scrollarea
 {
 public:
        menu(display& disp, const std::vector<std::string>& items,
@@ -54,11 +53,9 @@
        enum { HELP_STRING_SEPARATOR = '|', DEFAULT_ITEM = '*' };
        enum { IMG_TEXT_SEPARATOR = 1 }; // Re-evaluate if this should be 
something else to be settable from WML.
 
-       virtual void set_location(const SDL_Rect& rect);
-       using widget::set_location;
-
 protected:
        void handle_event(const SDL_Event& event);
+       void set_inner_location(const SDL_Rect& rect);
 
 private:
        size_t max_items_onscreen() const;
@@ -69,8 +66,6 @@
        void adjust_viewport_to_selection();
        void key_press(SDLKey key);
 
-       bool show_scrollbar() const;
-
        std::vector<std::vector<std::string> > items_, help_;
 
        void create_help_strings();
@@ -100,7 +95,6 @@
 
        mutable std::map<int,SDL_Rect> itemRects_;
 
-       SDL_Rect get_list_rect() const;
        SDL_Rect get_item_rect(int item) const;
        size_t get_item_height_internal(int item) const;
        size_t get_item_height(int item) const;
@@ -110,7 +104,6 @@
        int items_height() const;
 
        void update_scrollbar_grip_height();
-       gui::scrollbar scrollbar_;
 
        ///variable which determines whether a numeric keypress should
        ///select an item on the dialog
Index: wesnoth/src/widgets/scrollbar.cpp
diff -u wesnoth/src/widgets/scrollbar.cpp:1.18 
wesnoth/src/widgets/scrollbar.cpp:1.19
--- wesnoth/src/widgets/scrollbar.cpp:1.18      Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/scrollbar.cpp   Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: scrollbar.cpp,v 1.18 2004/11/01 18:06:37 gruikya Exp $*/
+/* $Id: scrollbar.cpp,v 1.19 2004/11/06 09:19:28 silene Exp $*/
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -36,11 +36,11 @@
 
 namespace gui {
 
-scrollbar::scrollbar(display& d, widget const &pane, scrollable* callback)
-       : widget(d), pane_(pane), mid_scaled_(NULL), groove_scaled_(NULL), 
callback_(callback),
+scrollbar::scrollbar(display &d)
+       : widget(d), mid_scaled_(NULL), groove_scaled_(NULL),
          uparrow_(d, "", button::TYPE_TURBO, "uparrow-button"),
          downarrow_(d, "", button::TYPE_TURBO, "downarrow-button"),
-         state_(NORMAL), grip_position_(0), old_position_(0), grip_height_(0), 
full_height_(0)
+         state_(NORMAL), grip_position_(0), grip_height_(0), full_height_(0)
 {
        static const surface img(image::get_image(scrollbar_mid, 
image::UNSCALED));
        
@@ -131,12 +131,6 @@
                move_position(-1);
        if (downarrow_.pressed())
                move_position(1);
-
-       if (grip_position_ == old_position_)
-               return;
-       old_position_ = grip_position_;
-       if (callback_)
-               callback_->scroll(grip_position_);
 }
 
 SDL_Rect scrollbar::groove_area() const
@@ -226,7 +220,7 @@
        disp().blit_surface(grip.x, grip.y + top_img->h + mid_height, 
bottom_img);
 
        update_rect(groove);
-}      
+}
 
 void scrollbar::handle_event(const SDL_Event& event)
 {
@@ -250,10 +244,9 @@
                SDL_MouseButtonEvent const &e = event.button;
                bool on_grip = point_in_rect(e.x, e.y, grip);
                bool on_groove = point_in_rect(e.x, e.y, groove);
-               bool on_scrollable = point_in_rect(e.x, e.y, pane_.location()) 
|| on_groove;
-               if (on_scrollable && e.button == SDL_BUTTON_WHEELDOWN) {
+               if (on_groove && e.button == SDL_BUTTON_WHEELDOWN) {
                        move_position(1);
-               } else if (on_scrollable && e.button == SDL_BUTTON_WHEELUP) {
+               } else if (on_groove && e.button == SDL_BUTTON_WHEELUP) {
                        move_position(-1);
                } else if (on_grip && e.button == SDL_BUTTON_LEFT) {
                        mousey_on_grip_ = e.y - grip.y;
Index: wesnoth/src/widgets/scrollbar.hpp
diff -u wesnoth/src/widgets/scrollbar.hpp:1.8 
wesnoth/src/widgets/scrollbar.hpp:1.9
--- wesnoth/src/widgets/scrollbar.hpp:1.8       Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/scrollbar.hpp   Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: scrollbar.hpp,v 1.8 2004/11/01 18:06:37 gruikya Exp $ */
+/* $Id: scrollbar.hpp,v 1.9 2004/11/06 09:19:28 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -21,11 +21,7 @@
 
 namespace gui {
 
-class scrollable
-{
-public:
-       virtual void scroll(int pos) = 0;
-};
+class scrollarea;
 
 class scrollbar : public widget
 {
@@ -34,7 +30,7 @@
        /// \param d the display object
        /// \param pane the widget where wheel events take place
        /// \param callback a callback interface for warning that the grip has 
been moved
-       scrollbar(display &d, widget const &pane, scrollable *callback);
+       scrollbar(display &d);
 
        virtual void set_location(SDL_Rect const &rect);
        using widget::set_location;
@@ -68,10 +64,8 @@
 private:
        SDL_Rect grip_area() const;
        SDL_Rect groove_area() const;
-       widget const &pane_;
        surface mid_scaled_, groove_scaled_;
 
-       scrollable* callback_;
        button uparrow_, downarrow_;
 
        enum STATE { UNINIT, NORMAL, ACTIVE, DRAGGED };
@@ -80,6 +74,8 @@
        int minimum_grip_height_, mousey_on_grip_;
        // Relative data
        int grip_position_, old_position_, grip_height_, full_height_;
+
+       friend class scrollarea;
 };
 
 }
Index: wesnoth/src/widgets/scrollpane.cpp
diff -u wesnoth/src/widgets/scrollpane.cpp:1.1 
wesnoth/src/widgets/scrollpane.cpp:1.2
--- wesnoth/src/widgets/scrollpane.cpp:1.1      Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/scrollpane.cpp  Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: scrollpane.cpp,v 1.1 2004/11/01 18:06:37 gruikya Exp $ */
+/* $Id: scrollpane.cpp,v 1.2 2004/11/06 09:19:28 silene Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -31,7 +31,7 @@
 
 namespace gui {
 
-scrollpane::scrollpane(display& d) : widget(d), border_(5), scrollbar_(d, 
*this, this)
+scrollpane::scrollpane(display& d) : scrollarea(d), border_(5)
 {
        content_pos_.x = 0;
        content_pos_.y = 0;
@@ -75,28 +75,13 @@
        update_content_size();
 }
 
-void scrollpane::set_location(const SDL_Rect& rect)
+void scrollpane::set_inner_location(const SDL_Rect& rect)
 {
-       widget::set_location(rect);
-       SDL_Rect bar_rect = rect;
-
-       bar_rect.x = rect.x + rect.w - scrollbar_.width();
-       bar_rect.y = rect.y;
-       bar_rect.w = scrollbar_.width();
-       bar_rect.h = rect.h;
-       scrollbar_.set_location(bar_rect);
-
        for(widget_map::iterator itor = content_.begin(); itor != 
content_.end(); ++itor) {
                itor->second.w->set_clip_rect(client_area());
        }
 }
 
-void scrollpane::hide(bool value)
-{
-       widget::hide(value);
-       scrollbar_.hide(value);
-}
-
 void scrollpane::draw()
 {
        //draws the scrollpane background
@@ -149,14 +134,6 @@
        return res;
 }
 
-bool scrollpane::show_scrollbar() const
-{
-       if (content_pos_.h > client_area().h)
-               return true;
-
-       return false;
-}
-
 void scrollpane::update_content_size()
 {
        int maxx = 0;
@@ -174,14 +151,8 @@
        content_pos_.w = maxx;
        content_pos_.h = maxy;
 
-       if(client_area().h < maxy) {
-               scrollbar_.hide(false);
-       } else {
-               scrollbar_.hide();
-       }
-
-       scrollbar_.set_full_size(maxy);
-       scrollbar_.set_shown_size(client_area().h);
+       set_full_size(maxy);
+       set_shown_size(client_area().h);
 
        set_dirty();
 }
Index: wesnoth/src/widgets/scrollpane.hpp
diff -u wesnoth/src/widgets/scrollpane.hpp:1.1 
wesnoth/src/widgets/scrollpane.hpp:1.2
--- wesnoth/src/widgets/scrollpane.hpp:1.1      Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/scrollpane.hpp  Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: scrollpane.hpp,v 1.1 2004/11/01 18:06:37 gruikya Exp $ */
+/* $Id: scrollpane.hpp,v 1.2 2004/11/06 09:19:28 silene Exp $ */
 /*
    Copyright (C) 2004 by Philippe Plantier <address@hidden>
    Part of the Battle for Wesnoth Project http://www.wesnoth.org
@@ -14,17 +14,17 @@
 #ifndef SCROLLPANE_HPP_INCLUDED
 #define SCROLLPANE_HPP_INCLUDED
 
-#include <vector>
 #include <map>
+#include <vector>
 
 #include "SDL.h"
 #include "../sdl_utils.hpp"
+#include "scrollarea.hpp"
 #include "widget.hpp"
-#include "scrollbar.hpp"
 
 namespace gui {
 
-class scrollpane : public widget, public scrollable
+class scrollpane : public scrollarea
 {
 public:
        struct scrollpane_widget {
@@ -43,11 +43,6 @@
        /// \param callback a callback interface for warning that the grip has 
been moved
        scrollpane(display &d);
 
-       virtual void set_location(SDL_Rect const &rect);
-       using widget::set_location;
-
-       virtual void hide(bool value = true);
-
        void add_widget(widget* w, int x, int x, int z_order = 0);
        void remove_widget(widget* w);
        void clear();
@@ -56,16 +51,15 @@
        //virtual void handle_event(const SDL_Event& event);
        //virtual void process_event();
        virtual void draw();
+       virtual void set_inner_location(SDL_Rect const &rect);
+       virtual void scroll(int pos);
 
 private:
-       void scroll(int pos);
        void position_widget(scrollpane_widget& spw);
        SDL_Rect client_area() const;
-       bool show_scrollbar() const;
        void update_content_size();
 
        int border_;
-       scrollbar scrollbar_;
        typedef std::multimap<int, scrollpane_widget> widget_map;
        widget_map content_;
        SDL_Rect content_pos_;
Index: wesnoth/src/widgets/textbox.cpp
diff -u wesnoth/src/widgets/textbox.cpp:1.61 
wesnoth/src/widgets/textbox.cpp:1.62
--- wesnoth/src/widgets/textbox.cpp:1.61        Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/textbox.cpp     Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: textbox.cpp,v 1.61 2004/11/01 18:06:37 gruikya Exp $ */
+/* $Id: textbox.cpp,v 1.62 2004/11/06 09:19:28 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -29,12 +29,11 @@
 const int font_size = font::SIZE_PLUS;
 
 textbox::textbox(display& d, int width, const std::string& text, bool 
editable, size_t max_size)
-          : widget(d), max_size_(max_size), text_(string_to_wstring(text)),
+          : scrollarea(d), max_size_(max_size), text_(string_to_wstring(text)),
             cursor_(text_.size()), selstart_(-1), selend_(-1),
             grabmouse_(false), text_pos_(0), editable_(editable),
             show_cursor_(true), show_cursor_at_(0), text_image_(NULL),
-            scrollbar_(d, *this, this),
-            scroll_bottom_(false), wrap_(false), line_height_(0), yscroll_(0)
+            wrap_(false), line_height_(0), yscroll_(0)
 {
        // static const SDL_Rect area = d.screen_area();
        // const int height = 
font::draw_text(NULL,area,font_size,font::NORMAL_COLOUR,"ABCD",0,0).h;
@@ -43,9 +42,8 @@
        update_text_cache(true);
 }
 
-void textbox::set_location(SDL_Rect const &rect)
+void textbox::set_inner_location(SDL_Rect const &rect)
 {
-       widget::set_location(rect);
        register_rectangle(rect);
 }
 
@@ -117,18 +115,16 @@
 
 void textbox::draw_contents()
 {
-       const bool has_scrollbar = show_scrollbar();
-       SDL_Rect loc = location();
-       if (has_scrollbar)
-               loc.w -= scrollbar_.width();
+       SDL_Rect const &loc = inner_location();
 
+       surface surf = disp().video().getSurface();
        gui::draw_solid_tinted_rectangle(loc.x,loc.y,loc.w,loc.h,0,0,0,
-                                 focus() ? 0.2 : 0.4, 
disp().video().getSurface());
+                                 focus() ? 0.2 : 0.4, surf);
        
        SDL_Rect src;
 
        if(text_image_ != NULL) {
-               src.y = 0;
+               src.y = yscroll_;
                src.w = minimum<size_t>(loc.w,text_image_->w);
                src.h = minimum<size_t>(loc.h,text_image_->h);
                src.x = text_pos_;
@@ -136,8 +132,6 @@
                dest.x = loc.x;
                dest.y = loc.y;
 
-               scroll_bottom_ = false;
-
                // Fills the selected area
                if(is_selection()) {
                        const int start = minimum<int>(selstart_,selend_);
@@ -153,21 +147,19 @@
                                        break;
                                }
 
-                               SDL_Rect rect = {location().x + 
startx,location().y + starty - src.y,right - startx,line_height_};
+                               SDL_Rect rect = { loc.x + startx, loc.y + 
starty - src.y, right - startx, line_height_ };
 
-                               SDL_Rect clip = location();
-                               const clip_rect_setter 
clipper(disp().video().getSurface(),clip);
+                               const clip_rect_setter clipper(surf, loc);
 
-                               Uint32 colour = 
SDL_MapRGB(disp().video().getSurface()->format, 160, 0, 0);
-                               
fill_rect_alpha(rect,colour,140,disp().video().getSurface());
+                               Uint32 colour = SDL_MapRGB(surf->format, 160, 
0, 0);
+                               fill_rect_alpha(rect, colour, 140, surf);
 
                                starty += int(line_height_);
                                startx = 0;
                        }
                }
 
-               yscroll_ = src.y;
-               
SDL_BlitSurface(text_image_,&src,disp().video().getSurface(),&dest);
+               SDL_BlitSurface(text_image_, &src, surf, &dest);
        }
 
        draw_cursor((cursor_pos_ == 0 ? 0 : cursor_pos_ - 1), disp());
@@ -190,7 +182,7 @@
                        set_dirty();
                }
        }
-       
+
        draw();
 }
 
@@ -206,8 +198,7 @@
 
 void textbox::scroll_to_bottom()
 {
-       scroll_bottom_ = true;
-       set_dirty(true);
+       set_position((unsigned)-1);
 }
 
 void textbox::set_wrap(bool val)
@@ -221,6 +212,7 @@
 
 void textbox::scroll(int pos)
 {
+       yscroll_ = pos;
        set_dirty(true);
 }
 
@@ -260,7 +252,7 @@
 
                int w = font::line_width(visible_string, font_size);
 
-               if(wrap_ && w >= location().w - scrollbar_.width()) {
+               if(wrap_ && w >= inner_location().w) {
                        if(backup_itor != text.end()) {
                                int backup = itor - backup_itor;
                                itor = backup_itor + 1;
@@ -307,6 +299,11 @@
                text_pos_ = cursor_x;
        }
        cursor_pos_ = cursor_x - text_pos_;
+
+       if (!text_image_.null()) {
+               set_full_size(text_image_->h);
+               set_shown_size(location().h);
+       }
 }
 
 bool textbox::is_selection() 
@@ -342,13 +339,13 @@
                grabmouse_ = false;
        }
 
-       if( (grabmouse_ && (event.type == SDL_MOUSEMOTION)) ||  (
-                   event.type == SDL_MOUSEBUTTONDOWN  && (mousebuttons & 
SDL_BUTTON(1))  && ! 
-                       (mousex < location().x || mousex > location().x + 
location().w - (show_scrollbar() ? scrollbar_.width() : 0) ||
-                   mousey < location().y || mousey > location().y + 
location().h))) {
+       SDL_Rect const &loc = inner_location();
 
-               const int x = mousex - location().x + text_pos_;
-               const int y = mousey - location().y;
+       if ((grabmouse_ && (event.type == SDL_MOUSEMOTION)) ||
+           (event.type == SDL_MOUSEBUTTONDOWN && (mousebuttons & 
SDL_BUTTON(1)) &&
+            point_in_rect(mousex, mousey, loc))) {
+               const int x = mousex - loc.x + text_pos_;
+               const int y = mousey - loc.y;
                int pos = 0;
                int distance = x;
 
@@ -389,11 +386,8 @@
        //if we don't have the focus, then see if we gain the focus,
        //otherwise return
        if(focus() == false) {
-               if(event.type == SDL_MOUSEMOTION &&
-                  mousex >= location().x && mousey >= location().y &&
-                  mousex < location().x + location().w && mousey < 
location().y + location().h) {
+               if (event.type == SDL_MOUSEMOTION && point_in_rect(mousex, 
mousey, loc))
                        events::focus_handler(this);
-               }
                   
                return;
        }
@@ -517,9 +511,4 @@
        draw();
 }
 
-bool textbox::show_scrollbar() const
-{
-       return text_image_ != NULL && text_image_->h > location().h;
-}
-
 } //end namespace gui
Index: wesnoth/src/widgets/textbox.hpp
diff -u wesnoth/src/widgets/textbox.hpp:1.34 
wesnoth/src/widgets/textbox.hpp:1.35
--- wesnoth/src/widgets/textbox.hpp:1.34        Mon Nov  1 18:06:37 2004
+++ wesnoth/src/widgets/textbox.hpp     Sat Nov  6 09:19:28 2004
@@ -1,4 +1,4 @@
-/* $Id: textbox.hpp,v 1.34 2004/11/01 18:06:37 gruikya Exp $ */
+/* $Id: textbox.hpp,v 1.35 2004/11/06 09:19:28 silene Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -19,15 +19,13 @@
 #include "../language.hpp"
 #include "../sdl_utils.hpp"
 
-#include "button.hpp"
-#include "scrollbar.hpp"
-#include "widget.hpp"
+#include "scrollarea.hpp"
 
 #include "SDL.h"
 
 namespace gui {
 
-class textbox : public widget, public scrollable
+class textbox : public scrollarea
 {
 public:
        textbox(display& d, int width, const std::string& text="", bool 
editable=true, size_t max_size = 256);
@@ -45,15 +43,14 @@
 
        void set_wrap(bool val);
 
-       void draw_contents();
-       virtual void set_location(SDL_Rect const &);
-       using widget::set_location;
+protected:
+       virtual void draw_contents();
+       virtual void set_inner_location(SDL_Rect const &);
+       virtual void scroll(int pos);
 
 private:
        size_t max_size_;
 
-       void scroll(int pos);
-
        wide_string text_;
        
        // mutable unsigned int firstOnScreen_;
@@ -76,11 +73,6 @@
        int show_cursor_at_;
        surface text_image_;
 
-       //variable used for multi-line textboxes which support scrolling
-       scrollbar scrollbar_;
-
-       bool scroll_bottom_;
-
        bool wrap_;
 
        size_t line_height_, yscroll_;
Index: wesnoth/src/widgets/widget.cpp
diff -u wesnoth/src/widgets/widget.cpp:1.23 wesnoth/src/widgets/widget.cpp:1.24
--- wesnoth/src/widgets/widget.cpp:1.23 Tue Nov  2 19:46:39 2004
+++ wesnoth/src/widgets/widget.cpp      Sat Nov  6 09:19:28 2004
@@ -40,8 +40,8 @@
 
 void widget::set_location(SDL_Rect const &rect)
 {
-       if (rect_.x == rect.x && rect_.y == rect.y && rect_.w == rect.w && 
rect_.h == rect.h)
-               return;
+       //if (rect_.x == rect.x && rect_.y == rect.y && rect_.w == rect.w && 
rect_.h == rect.h)
+       //      return;
        if (state_ == UNINIT && rect.x != -1234 && rect.y != -1234)
                state_ = DRAWN;
        bg_restore();




reply via email to

[Prev in Thread] Current Thread [Next in Thread]