[Supertux-Commit] r5402 - trunk/supertux/src/gui

grumbel at millhouse.dreamhost.com grumbel at millhouse.dreamhost.com
Mon May 5 04:30:53 PDT 2008


Author: grumbel
Date: 2008-05-05 04:30:52 -0700 (Mon, 05 May 2008)
New Revision: 5402

Modified:
   trunk/supertux/src/gui/menu.cpp
   trunk/supertux/src/gui/menu.hpp
Log:
Changed effect when switching menus

Modified: trunk/supertux/src/gui/menu.cpp
===================================================================
--- trunk/supertux/src/gui/menu.cpp	2008-05-04 18:49:09 UTC (rev 5401)
+++ trunk/supertux/src/gui/menu.cpp	2008-05-05 11:30:52 UTC (rev 5402)
@@ -48,6 +48,7 @@
 
 std::vector<Menu*> Menu::last_menus;
 Menu* Menu::current_ = 0;
+Menu* Menu::previous = 0;
 Font* Menu::default_font;
 Font* Menu::active_font;
 Font* Menu::deactive_font;
@@ -114,23 +115,29 @@
 
   return false;
 }
-
+
 void
 Menu::push_current(Menu* pmenu)
 {
+  previous = current_;
+
   if (current_)
     last_menus.push_back(current_);
 
   current_ = pmenu;
-  current_->effect_time = real_time;
+  current_->effect_start_time = real_time;
+  current_->effect_progress   = 0.0f;
 }
 
 void
 Menu::pop_current()
 {
+  previous = current_;
+
   if (last_menus.size() >= 1) {
     current_ = last_menus.back();
-    current_->effect_time = real_time;
+    current_->effect_start_time = real_time;
+    current_->effect_progress   = 0.0f;
     last_menus.pop_back();
   } else {
     current_ = 0;
@@ -140,16 +147,20 @@
 void
 Menu::set_current(Menu* menu)
 {
+  previous = current_;
+
   last_menus.clear();
 
   if (menu)
-    menu->effect_time = real_time;
-
+    {
+      menu->effect_start_time = real_time;
+      menu->effect_progress = 0.0f;
+    }
   current_ = menu;
   // just to be sure...
   main_controller->reset();
 }
-
+
 MenuItem::MenuItem(MenuItemKind _kind, int _id)
   : kind(_kind) , id(_id)
 {
@@ -188,7 +199,7 @@
 
   return string;
 }
-
+
 Menu::~Menu()
 {
   for(std::vector<MenuItem*>::iterator i = items.begin();
@@ -210,6 +221,9 @@
   arrange_left = 0;
   active_item  = -1;
 
+  effect_progress   = 0.0f;
+  effect_start_time = 0.0f;
+
   checkbox.reset(new Surface("images/engine/menu/checkbox-unchecked.png"));
   checkbox_checked.reset(new Surface("images/engine/menu/checkbox-checked.png"));
   back.reset(new Surface("images/engine/menu/arrow-back.png"));
@@ -322,6 +336,14 @@
 void
 Menu::update()
 {
+  effect_progress = (real_time - effect_start_time) * 6.0f;
+
+  if(effect_progress >= 1.0f) {
+    effect_progress = 1.0f;
+  } else if (effect_progress <= 0.0f) {
+    effect_progress = 0.0f;
+  }
+
   /** check main input controller... */
   if(main_controller->pressed(Controller::UP)) {
     menuaction = MENU_ACTION_UP;
@@ -494,19 +516,9 @@
 
   MenuItem& pitem = *(items[index]);
 
-  int effect_offset = 0;
-  if(effect_time != 0) {
-    if(real_time - effect_time > 0.5) {
-      effect_time = 0;
-    } else {
-      float effect_delta = (0.5 - (real_time - effect_time)) * 250;
-      effect_offset = (int) ((index % 2) ? effect_delta : -effect_delta);
-    }
-  }
-
   Font* text_font = default_font;
   float x_pos       = pos_x;
-  float y_pos       = pos_y + 24*index - menu_height/2 + 12 + effect_offset;
+  float y_pos       = pos_y + 24*index - menu_height/2 + 12;
   int shadow_size = 2;
   int text_width  = int(text_font->get_text_width(pitem.text));
   int input_width = int(text_font->get_text_width(pitem.input) + 10);
@@ -552,7 +564,7 @@
       {
         // TODO
         float x = pos_x - menu_width/2;
-        float y = y_pos - 12 - effect_offset;
+        float y = y_pos - 12;
         /* Draw a horizontal line with a little 3d effect */
         context.draw_filled_rect(Vector(x, y + 6),
                                  Vector(menu_width, 4),
@@ -718,26 +730,42 @@
     MouseCursor::current()->draw(context);
   }
 
+  float menu_width  = get_width();
   float menu_height = get_height();
-  float menu_width  = get_width();
 
+  if (effect_progress != 1.0f)
+    {
+    if (Menu::previous)
+      {
+        menu_width  = (menu_width  * effect_progress) + (Menu::previous->get_width()  * (1.0f - effect_progress));
+        menu_height = (menu_height * effect_progress) + (Menu::previous->get_height() * (1.0f - effect_progress));
+        //std::cout << effect_progress << " " << this << " " << last_menus.back() << std::endl;
+      }
+    else
+      {
+        menu_width  *= effect_progress;
+        menu_height *= effect_progress;
+      }
+    }
+
   /* Draw a transparent background */
-  context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2-4, pos_y - 24*items.size()/2 - 10-4),
-                                Vector(pos_x + menu_width/2+4, pos_y - 24*items.size()/2 + 10 + menu_height+4)),
+  context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2-4, pos_y - menu_height/2 - 10-4),
+                                Vector(pos_x + menu_width/2+4, pos_y - menu_height/2 + 10 + menu_height+4)),
                            Color(0.2f, 0.3f, 0.4f, 0.8f), 
                            20.0f,
                            LAYER_GUI-10);
 
-  context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2, pos_y - 24*items.size()/2 - 10),
-                                Vector(pos_x + menu_width/2, pos_y - 24*items.size()/2 + 10 + menu_height)),
+  context.draw_filled_rect(Rect(Vector(pos_x - menu_width/2, pos_y - menu_height/2 - 10),
+                                Vector(pos_x + menu_width/2, pos_y - menu_height/2 + 10 + menu_height)),
                            Color(0.6f, 0.7f, 0.8f, 0.5f), 
                            16.0f,
                            LAYER_GUI-10);
 
-  for(unsigned int i = 0; i < items.size(); ++i)
-    {
-      draw_item(context, i);
-    }
+  if (effect_progress == 1.0f)
+    for(unsigned int i = 0; i < items.size(); ++i)
+      {
+        draw_item(context, i);
+      }
 }
 
 MenuItem&
@@ -783,7 +811,7 @@
 void
 Menu::event(const SDL_Event& event)
 {
-  if(effect_time != 0)
+  if(effect_progress != 1.0f)
     return;
 
   switch(event.type) {

Modified: trunk/supertux/src/gui/menu.hpp
===================================================================
--- trunk/supertux/src/gui/menu.hpp	2008-05-04 18:49:09 UTC (rev 5401)
+++ trunk/supertux/src/gui/menu.hpp	2008-05-05 11:30:52 UTC (rev 5402)
@@ -51,7 +51,7 @@
 };
 
 class Menu;
-
+
 class MenuItem
 {
 public:
@@ -84,11 +84,12 @@
   /// keyboard key or joystick button
   bool input_flickering;
 };
-
+
 class Menu
 {
 private:
   static std::vector<Menu*> last_menus;
+  static Menu* previous;
   static Menu* current_;
 
   static void pop_current();
@@ -193,7 +194,8 @@
 private:
   void check_controlfield_change_event(const SDL_Event& event);
   void draw_item(DrawingContext& context, int index);
-  float effect_time;
+  float effect_progress;
+  float effect_start_time;
   int arrange_left;
   int active_item;
 




More information about the Supertux-Commit mailing list