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

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

[Wesnoth-cvs-commits] wesnoth/src widgets/progressbar.cpp widgets/pro...


From: David White
Subject: [Wesnoth-cvs-commits] wesnoth/src widgets/progressbar.cpp widgets/pro...
Date: Thu, 12 May 2005 20:47:57 -0400

CVSROOT:        /cvsroot/wesnoth
Module name:    wesnoth
Branch:         
Changes by:     David White <address@hidden>    05/05/13 00:47:56

Modified files:
        src/widgets    : progressbar.cpp progressbar.hpp 
        src            : show_dialog.cpp 

Log message:
        made data download dialog more attractive by using a proper progress bar

CVSWeb URLs:
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/progressbar.cpp.diff?tr1=1.9&tr2=1.10&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/widgets/progressbar.hpp.diff?tr1=1.4&tr2=1.5&r1=text&r2=text
http://savannah.gnu.org/cgi-bin/viewcvs/wesnoth/wesnoth/src/show_dialog.cpp.diff?tr1=1.127&tr2=1.128&r1=text&r2=text

Patches:
Index: wesnoth/src/show_dialog.cpp
diff -u wesnoth/src/show_dialog.cpp:1.127 wesnoth/src/show_dialog.cpp:1.128
--- wesnoth/src/show_dialog.cpp:1.127   Tue May 10 22:15:57 2005
+++ wesnoth/src/show_dialog.cpp Fri May 13 00:47:56 2005
@@ -1,4 +1,4 @@
-/* $Id: show_dialog.cpp,v 1.127 2005/05/10 22:15:57 Sirp Exp $ */
+/* $Id: show_dialog.cpp,v 1.128 2005/05/13 00:47:56 Sirp Exp $ */
 /*
    Copyright (C) 2003 by David White <address@hidden>
    Part of the Battle for Wesnoth Project http://wesnoth.whitevine.net
@@ -34,7 +34,8 @@
 #include "util.hpp"
 #include "video.hpp"
 #include "widgets/button.hpp"
-#include "widgets/menu.hpp"
+#include "widgets/menu.hpp"
+#include "widgets/progressbar.hpp"
 #include "widgets/textbox.hpp"
 #include "wassert.hpp"
 
@@ -830,64 +831,57 @@
 
 }
 
-namespace {
-class dialog_action_receive_network : public gui::dialog_action
-{
-public:
-       dialog_action_receive_network(network::connection connection, config& 
cfg, const std::pair<int,int>& connection_stats);
-       int do_action();
-       network::connection result() const;
-
-       enum { CONNECTION_COMPLETE = 1, CONNECTION_CONTINUING = 2 };
-private:
-       config& cfg_;
-       network::connection connection_, res_;
-       std::pair<int,int> stats_;
-};
-
-dialog_action_receive_network::dialog_action_receive_network(network::connection
 connection, config& cfg,
-                                                                               
                                         const std::pair<int,int>& stats)
-: cfg_(cfg), connection_(connection), res_(0), stats_(stats)
-{
-}
-
-int dialog_action_receive_network::do_action()
-{
-       res_ = network::receive_data(cfg_,connection_,100);
-       if(res_ != 0)
-               return CONNECTION_COMPLETE;
-       else if(network::current_transfer_stats().first != stats_.first) {
-               LOG_STREAM(info, network) << "continuing connection...\n";
-               return CONNECTION_CONTINUING;
-       } else
-               return CONTINUE_DIALOG;
-}
-
-network::connection dialog_action_receive_network::result() const
-{
-       return res_;
-}
-
-}
-
 namespace gui {
 
 network::connection network_data_dialog(display& disp, const std::string& msg, 
config& cfg, network::connection connection_num)
-{
-       cfg.clear();
-       for(;;) {
-               const std::pair<int,int> stats = 
network::current_transfer_stats();
-               std::stringstream str;
-               str << msg;
-               if(stats.first != -1) {
-                       str << ": " << (stats.first/1024) << "/" << 
(stats.second/1024) << _("KB");
-               }
+{
+       const std::string title = _("Downloading...");
+
+       const size_t width = 300;
+       const size_t height = 80;
+       const size_t border = 20;
+       const int left = disp.x()/2 - width/2;
+       const int top = disp.y()/2 - height/2;
+
+       gui::button cancel_button(disp.video(),_("Cancel"));
+       std::vector<gui::button*> buttons_ptr(1,&cancel_button);
+
+       surface_restorer restorer;
+       
gui::draw_dialog(left,top,width,height,disp.video(),title,NULL,&buttons_ptr,&restorer);
+
+       const SDL_Rect progress_rect = 
{left+border,top+border,width-border*2,height-border*2};
+       gui::progress_bar progress(disp.video());
+       progress.set_location(progress_rect);
+
+       events::raise_draw_event();
+       disp.flip();
+
+       std::pair<int,int> old_stats = network::current_transfer_stats();
 
-               dialog_action_receive_network 
receiver(connection_num,cfg,stats);
-               const int res = 
show_dialog(disp,NULL,"",str.str(),CANCEL_ONLY,NULL,NULL,"",NULL,-1,&receiver);
-               if(res != 
int(dialog_action_receive_network::CONNECTION_CONTINUING)) {
-                       return receiver.result();
-               }
+       cfg.clear();
+       for(;;) {
+               const network::connection res = 
network::receive_data(cfg,connection_num,100);
+
+               const std::pair<int,int> stats = 
network::current_transfer_stats();
+               if(stats.first != -1 && stats.second != 0 && stats != 
old_stats) {
+                       old_stats = stats;
+                       
progress.set_progress_percent((stats.first*100)/stats.second);
+                       std::ostringstream stream;
+                       stream << stats.first/1024 << "/" << stats.second/1024 
<< _("KB");
+                       progress.set_text(stream.str());
+               }
+
+               events::raise_draw_event();
+               disp.flip();
+
+               if(res != 0) {
+                       return res;
+               }
+
+               events::pump();
+               if(cancel_button.pressed()) {
+                       return res;
+               }
        }
 }
 
Index: wesnoth/src/widgets/progressbar.cpp
diff -u wesnoth/src/widgets/progressbar.cpp:1.9 
wesnoth/src/widgets/progressbar.cpp:1.10
--- wesnoth/src/widgets/progressbar.cpp:1.9     Fri Mar 18 21:21:48 2005
+++ wesnoth/src/widgets/progressbar.cpp Fri May 13 00:47:55 2005
@@ -14,8 +14,14 @@
 void progress_bar::set_progress_percent(int progress)
 {
        progress_ = progress;
-       set_dirty(true);
+       set_dirty();
 }
+
+void progress_bar::set_text(const std::string& text)
+{
+       text_ = text;
+       set_dirty();
+}
 
 void progress_bar::draw_contents()
 {
@@ -30,7 +36,8 @@
                inner_area.w = (inner_area.w*progress_)/100;
                SDL_FillRect(surf,&inner_area,SDL_MapRGB(surf->format,150,0,0));
 
-               const std::string text = str_cast(progress_) + "%";
+               const std::string text = text_.empty() ? str_cast(progress_) + 
"%" :
+                                        text_ + " (" + str_cast(progress_) + 
"%)";
                SDL_Rect text_area = font::text_area(text,font::SIZE_NORMAL);
 
                text_area.x = area.x + area.w/2 - text_area.w/2;
Index: wesnoth/src/widgets/progressbar.hpp
diff -u wesnoth/src/widgets/progressbar.hpp:1.4 
wesnoth/src/widgets/progressbar.hpp:1.5
--- wesnoth/src/widgets/progressbar.hpp:1.4     Fri Mar 18 21:21:48 2005
+++ wesnoth/src/widgets/progressbar.hpp Fri May 13 00:47:56 2005
@@ -10,12 +10,14 @@
 public:
        progress_bar(CVideo& video);
 
-       void set_progress_percent(int progress);
+       void set_progress_percent(int progress);
+       void set_text(const std::string& text);
 
        void draw_contents();
 
 private:
-       int progress_;
+       int progress_;
+       std::string text_;
 };
 
 }




reply via email to

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