pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,NONE,1.1 action_but


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src action_button.cxx,NONE,1.1 action_button.hxx,NONE,1.1 action_data.hxx,NONE,1.1 action_holder.cxx,NONE,1.1 action_holder.hxx,NONE,1.1 algo.cxx,NONE,1.1 algo.hxx,NONE,1.1 alpha_button.cxx,NONE,1.1 alpha_button.hxx,NONE,1.1 anim_counter.cxx,NONE,1.1 anim_counter.hxx,NONE,1.1 audio.cxx,NONE,1.1 audio.hxx,NONE,1.1
Date: 12 Jun 2002 19:04:12 -0000

Update of /usr/local/cvsroot/Games/Pingus/src
In directory dark:/tmp/cvs-serv12739

Added Files:
        action_button.cxx action_button.hxx action_data.hxx 
        action_holder.cxx action_holder.hxx algo.cxx algo.hxx 
        alpha_button.cxx alpha_button.hxx anim_counter.cxx 
        anim_counter.hxx audio.cxx audio.hxx 
Log Message:
The big rename...

--- NEW FILE: action_button.cxx ---
//  $Id: action_button.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <cstdio>
#include <ClanLib/Core/Math/cl_vector.h>
#include <ClanLib/Display/Display/display.h>
#include <ClanLib/Display/Font/font.h>
#include <ClanLib/Display/Input/mouse.h>
#include "algo.hxx"
#include "globals.hxx"
#include "pingus_resource.hxx"
#include "action_button.hxx"
#include "server.hxx"
#include "string_converter.hxx"

Button::Button()
{
}

Button::Button (int x, int y) : x_pos(x), y_pos(y)
{
}

Button::~Button()
{
}

EventButton::EventButton(int x, int y, std::string str) : Button(x, y) 
{ 
  surface = PingusResource::load_surface(str, "global");
}

EventButton::~EventButton() {}

void
EventButton::draw()
{
  if (mouse_over(CL_Vector() /* FIXME */))
    {
      CL_Display::fill_rect(x_pos, y_pos, 
                            x_pos + surface.get_width(), y_pos + 
surface.get_height(),
                            1.0, 1.0, 1.0, 1.0);
    }
  surface.put_screen(x_pos, y_pos);
}

bool
EventButton::mouse_over(const CL_Vector& pos)
{
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
    {
      return true;
    }
  else 
    {
      return false;
    }
}

ActionButton::ActionButton() {}

ActionButton::~ActionButton() {}

void
ActionButton::init(int x, int y, std::string str, int owner_id)
{
  //  make_action = func;
  x_pos = x;
  y_pos = y;
  name = str;
 
  if (name == "digger" || name == "bomber" 
      || name == "floater" || name == "blocker")
    {
      is_multi_direct = false;
    }
  else
    {
      is_multi_direct = true;
    }

  /*
  font = PingusResource::load_font("Fonts/courier_small", "fonts");
  font_h = PingusResource::load_font("Fonts/smallfont","fonts");
  font_b = PingusResource::load_font("Fonts/pingus","fonts");
  */

  font = PingusResource::load_font("Fonts/pingus_small", "fonts");
  font_h = PingusResource::load_font("Fonts/pingus_small","fonts");
  font_b = PingusResource::load_font("Fonts/pingus","fonts");

  if (str != "empty") 
    {
      surface   = PingusResource::load_surface("Pingus/" + str + 
to_string(owner_id),
                                               "pingus");
      if (is_multi_direct)
        {
          action_c.set_size(surface.get_num_frames()/2);
        }
      else
        {
          action_c.set_size(surface.get_num_frames());
        }

      action_c.set_speed(50);
    }
}

bool
ActionButton::is_pressed()
{
  return false;
}

void
ActionButton::update(float /*delta*/)
{
  ++action_c;
}

std::string
ActionButton::get_action_name()
{
  return name;
}

void
ActionButton::set_action_holder(ActionHolder* h)
{
  action_holder = h;
}

VerticalActionButton::VerticalActionButton(int x, int y, std::string str, int 
owner_id) :
    background (PingusResource::load_surface("buttons/buttonbackground", 
"core")),
    backgroundhl (PingusResource::load_surface("buttons/buttonbackgroundhl", 
"core"))
{
  init(x, y, str, owner_id);
}

VerticalActionButton::~VerticalActionButton() {}

bool
VerticalActionButton::mouse_over(const CL_Vector& pos)
{
  if (pos.x > x_pos && pos.x < x_pos + 60
      && pos.y > y_pos && pos.y <= y_pos + 35) 
    {
      return true;
    } 
  else 
    {
      return false;
    }
}

void
VerticalActionButton::draw()
{
  std::string str;
  // FIXME: This could need some optimization, throwing strings all
  // FIXME: around, doesn't look like a good idea. 
  available = action_holder->get_available(name);

  if (unlimited_actions) {
    str = "";
  } else {
    str = to_string(available);
  }

  if (pressed) 
    {
      if (fast_mode) {
        CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
                              1.0, 1.0, 1.0, 1.0);
      } else {
        //CL_Display::fill_rect(x_pos, y_pos, x_pos + 60, y_pos + 35 ,
        //1.0, 1.0, 1.0, 0.5);
        backgroundhl.put_screen (x_pos, y_pos);
      }
      font_h->print_center(x_pos + 46, y_pos + 10, str.c_str ());
    }
  else
    {
      action_c = 0;

      if (fast_mode) {
        // do nothing
      } else {
        background.put_screen (x_pos, y_pos);
      }
      font->print_center(x_pos + 46, y_pos + 10, str.c_str ());
    }

  // print the action name next to the button, when mouse pointer is on
  // the button.
  if(action_help 
     && CL_Mouse::get_x() > x_pos && CL_Mouse::get_x() < x_pos + 60
     && CL_Mouse::get_y() < y_pos + 35 && CL_Mouse::get_y() > y_pos) 
  {
        font_b->print_left (x_pos + 65, y_pos, name.c_str());
  }

  surface.put_screen(x_pos + 20 - surface.get_width ()/2,
                     y_pos + 17 - surface.get_height ()/2,
                     action_c);
}

ArmageddonButton::ArmageddonButton(int x, int y) : 
        Button      (x, y),
        background  (PingusResource::load_surface("buttons/hbuttonbgb", 
"core")),
        backgroundhl(PingusResource::load_surface("buttons/hbuttonbg", "core"))
{
  pressed      = false;
  surface      = PingusResource::load_surface("buttons/armageddon_anim", 
"core");
  counter.set_size(surface.get_num_frames());
  counter = 0;
}

ArmageddonButton::~ArmageddonButton() { }

void
ArmageddonButton::draw()
{
  if (pressed)
    {
      backgroundhl.put_screen (x_pos, y_pos);
      surface.put_screen(x_pos, y_pos, ++counter);
    } 
  else 
    {
      background.put_screen (x_pos, y_pos);
      surface.put_screen(x_pos, y_pos, 7);
    }
}

bool
ArmageddonButton::mouse_over(const CL_Vector& pos)
{
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
    {
      return true;
    } else  {
      return false;
    } 
}

ForwardButton::ForwardButton(int x, int y) :
        Button      (x, y),
        background  (PingusResource::load_surface("buttons/hbuttonbgb", 
"core")),
        backgroundhl(PingusResource::load_surface("buttons/hbuttonbg", "core"))
{ 
  surface = PingusResource::load_surface("buttons/fast_forward", "core");
}

ForwardButton::~ForwardButton() {}

void
ForwardButton::draw()
{
  if (server->get_fast_forward())
    backgroundhl.put_screen (x_pos, y_pos);
  else
    background.put_screen (x_pos, y_pos);
  
  surface.put_screen(x_pos, y_pos);
}

bool
ForwardButton::mouse_over(const CL_Vector& pos)
{
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
    {
      return true;
    } else  {
      return false;
    } 
}

PauseButton::PauseButton(int x, int y) :
        Button      (x, y),
        background  (PingusResource::load_surface("buttons/hbuttonbgb", 
"core")),
        backgroundhl(PingusResource::load_surface("buttons/hbuttonbg", "core"))
{ 
  surface = PingusResource::load_surface("buttons/pause", "core");
}

PauseButton::~PauseButton() {}

void
PauseButton::draw()
{
  if (server->get_pause()) 
    backgroundhl.put_screen (x_pos, y_pos);
  else
    background.put_screen (x_pos, y_pos);
  
  surface.put_screen(x_pos, y_pos);
}

bool
PauseButton::mouse_over(const CL_Vector& pos)
{
  if (pos.x > x_pos && pos.x < x_pos + int(surface.get_width())
      && pos.y > y_pos && pos.y < y_pos + int(surface.get_height()))
    {
      return true;
    } else  {
      return false;
    } 
}

/* EOF */

--- NEW FILE: action_button.hxx ---
//  $Id: action_button.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef ACTIONBUTTON_HH
#define ACTIONBUTTON_HH

#include <ClanLib/Display/Display/surface.h>
#include <string>
#include "anim_counter.hxx"

class Server;
class ActionHolder;
class CL_Font;
class CL_Vector;

// ----------------- snip --------------------
///
class Button
{
protected:
  ///
  int x_pos;
  ///
  int y_pos;
  ///
  CL_Surface surface;
  ///
  bool pressed;
public:
  ///
  Button();
  
  Button (int x, int y);
  ///
  virtual ~Button();

  ///
  virtual void   draw() = 0;
  ///
  virtual bool   mouse_over(const CL_Vector& pos) = 0;
};

// ----------------- snip --------------------
///
class EventButton : public Button
{
private: 
public:
  ///
  EventButton(int x, int y, std::string);
  ///
  virtual ~EventButton();
  
  ///
  void   draw();
  ///
  bool   mouse_over(const CL_Vector& pos);
};

// ----------------- snip --------------------
///
class ArmageddonButton : public Button
{
private:
  CL_Surface background;
  CL_Surface backgroundhl;

  AnimCounter counter;
  Server* server;
  friend class ButtonPanel;
public:
  ArmageddonButton(int x, int y);
  virtual ~ArmageddonButton();

  void draw();
  bool mouse_over(const CL_Vector& pos);
};

// ----------------- snip --------------------

///
class ForwardButton : public Button
{
private:
  CL_Surface background;
  CL_Surface backgroundhl;
  Server* server;
  friend class ButtonPanel;
public:
  ForwardButton(int x, int y);
  virtual ~ForwardButton();

  void draw();
  bool mouse_over(const CL_Vector& pos);
};

// ----------------- snip --------------------

///
class PauseButton : public Button
{
private:
  CL_Surface background;
  CL_Surface backgroundhl;
  Server* server;
  friend class ButtonPanel;
public:
  PauseButton(int x, int y);
  virtual ~PauseButton();

  void draw();
  bool mouse_over(const CL_Vector& pos);
};

// ----------------- snip --------------------

/** The button class manage a simple button for the button_panel. It
    keeps his position, his surfaces and his font. */
class ActionButton : public Button
{
protected:
  ///
  CL_Font*    font;
  ///
  CL_Font*    font_h;
  // Added for printing action names next to the button.
  CL_Font*    font_b;

  /// The x and y position of the button
  std::string name;
  ///
  int available;
  ///
  bool is_multi_direct;

  ///
  ActionHolder* action_holder;
  ///
  AnimCounter action_c;
public:  
  ///
  bool pressed;

  ///
  ActionButton();
  ///
  virtual ~ActionButton();

  ///
  void init(int x, int y, std::string str, int owner_id);

  /// Draws the button and increase the animation counter.
  virtual void   draw() = 0;
 
  /// Not used.
  void   update(float delta);

  /// Returns the name of the action the button represents.
  std::string get_action_name();

  /// Returns true if the button is pressed.
  bool   is_pressed();

  ///
  virtual bool   mouse_over(const CL_Vector& pos) = 0;

  ///
  void set_action_holder(ActionHolder* h);
};

// ----------------- snip --------------------
///
class VerticalActionButton : public ActionButton 
{
private:
  CL_Surface background;
  CL_Surface backgroundhl;

public:
  VerticalActionButton(int x, int y, std::string str, int owner_id);
  virtual ~VerticalActionButton();

  void draw();
  bool mouse_over(const CL_Vector& pos);
};

// ----------------- snip --------------------

#endif /* ACTIONBUTTON */

/* EOF */





--- NEW FILE: action_data.hxx ---
//  $Id: action_data.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef BUTTON_DATA_HH
#define BUTTON_DATA_HH

#include <string>

///
class ActionData
{
public:
  ///
  ActionData() {}

  ///
  ActionData(const std::string& str, int i) : name(str), number_of(i)
  {
  }

  ///
  std::string   name;
  ///
  int number_of;
};

#endif

/* EOF */

--- NEW FILE: action_holder.cxx ---
//  $Id: action_holder.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <iostream>
#include "globals.hxx"

#include "pingus_error.hxx"
#include "timer.hxx"
#include "globals.hxx"
#include "plf.hxx"

#include "pingu_action_factory.hxx"
#include "action_holder.hxx"

using namespace boost;

ActionHolder::ActionHolder (PLF* plf)
{
  std::vector<ActionData> action_data = plf->get_actions ();
  
  for(std::vector<ActionData>::iterator i = action_data.begin(); i != 
action_data.end(); ++i) {
    set_actions(i->name, i->number_of);
  }
}

ActionHolder::~ActionHolder ()
{
  //FIXME: This is not really a good place to free the actions
  //FIXME: But not otherwise to possible at the moment due to the
  //FIXME: singleton thing.
  PinguActionFactory::instance ()->delete_actions ();
}

void
ActionHolder::set_actions(const std::string& name, int available)
{
  available_actions[name] = available;
}

void
ActionHolder::push_action(const std::string& name)
{
  available_actions[name]++;
}

int
ActionHolder::get_available(const std::string& name)
{
  return available_actions[name];
}

PinguAction*
ActionHolder::get_action(const std::string& name)
{
  if (unlimited_actions) // runtime option; defined in global.hh
    {    
      return PinguActionFactory::instance ()->create(name);
    } 
  else 
    {
      int& count = available_actions[name];
      if (count > 0) 
        {
          --count;
          return PinguActionFactory::instance ()->create(name);
        }
      else // Out of actions
        {
          return 0;
        }
    }
}

/* EOF */

--- NEW FILE: action_holder.hxx ---
//  $Id: action_holder.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef ACTIONHOLDER_HH
#define ACTIONHOLDER_HH

#include <string>
#include <map>

class PLF;
class PinguAction;

/**
 * The ActionHolder is the backend of the ButtonPanel. It is responsible for
 * creating new PinguActions and (if necessary) restricting the number of
 * actions that can be created.
 *
 */
class ActionHolder
{
private:
  /** A map holding the number of available actions. 
   *  For each action <i>name</i> there is a map (<i>name</i>, <i>n</i>)
   *  where the integer <i>n</i> indicates how much more actions 
   *  called <i>name</i> can be created.
   */
  std::map<std::string, int> available_actions;

public:
  ActionHolder (PLF* plf);
  ~ActionHolder ();

  /** Sets the number of actions, which are available in the pool.
   * @param name the name of the action
   * @param available the number of actions available
   */
  void set_actions(const std::string& name, int available);
  
  /** Adds an action to the pool of actions, making one more action available
   * @param name the name of the action
   */
  void push_action(const std::string& name);

  /** Sets a given number of actions to the pool.
   * @deprecated This method does the same as 'set_actions', there is no
   *  implementation and no-one uses it anyways.
   */
  void set_action(const std::string& name, int available);

  /** Returns the number of actions of the specified name which are available 
   *  thru get_action() 
   * @return 0 if the name is unknown
   */
  int  get_available(const std::string&);

  /** Returns a newly allocated or cached action by a given name. It
   *  returns it from the action pool and decreases the number of available
   *  actions if necessary. If the actions are out, it returns 0. 
   *  The deletion of the action is handled by this class.  
   */
  PinguAction* get_action(const std::string&);
};

#endif

/* EOF */







--- NEW FILE: algo.cxx ---
//  $Id: algo.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
//  02111-1307, USA. 

#include "system.hxx"
#include "algo.hxx"
#include <cctype>
#include <iostream>

#include "globals.hxx"

// Die algo, die.

bool rect_col(int ax1, int ax2, int ay1, int ay2,
              int bx1, int bx2, int by1, int by2)
{
 if (ax1 > bx2)
   return 0;
 if (ax2 < bx1)
   return 0;
 if (ay1 > by2)
   return 0;
 if (ay2 < by1)
   return 0;
 return 1;
}

// Returns the directory name, of a complete file name:
// /usr/bin/bla would return /usr/bin/
std::string
get_directory(std::string filename)
{
  char* str;
  std::string t_str;

  str = strdup(filename.c_str());

  for(int i=strlen(str); i >= 0; --i) {
    if (str[i] == '/') {
      str[i+1] = '\0';
      break;
    }
  }

  t_str = str;
  free (str);
  return t_str;
}

// Adds the ending slash to a directory name, if it is not pressent.
std::string
add_slash(std::string& str)
{
#ifndef WIN32
  if (str[str.size() - 1] != '/') 
      str += "/";
#else /* !WIN32 */
  if (str[str.size() - 1] != '\\') 
      str += "\\";
#endif /* !WIN32 */     
  return str;
}

char*
tolowerstr(char* s)
{
  //  puts(s);
  for(unsigned int i=0; i < strlen(s); ++i) {
    s[i] = tolower(s[i]);
  }
  //  puts(s);
  return s;
}

// Searches the given path to find the given file, it returns the
// complete filename of the searched file.
// FIXME: Remove this function...
std::string
find_file(const std::string& paths, const std::string& filename)
{
  char* path;
  char* token;
  std::string token_str;
  path = strdup(paths.c_str());

  for(token = strtok(path, ":"); token != 0; token = strtok(0, ":")) {
    token_str = token;
#ifndef WIN32
    if (System::exist(token_str + "/" + filename)) { 
      return token_str + "/" + filename;
    }
#else /* !WIN32 */
    if (System::exist(token_str + "\\" + filename)) { 
      return token_str + "\\" + filename;
    }
#endif
  }
  if (verbose) std::cout << "find_file(): " << filename << ": File not found!" 
<< std::endl;
  free(path);
  return filename;
}
/*
string
basename(std::string filename)
{
  const char* str = filename.c_str();
  int i;
  std::cout << "Getting basename of: " << str << std::endl;
  for(i = filename.size() - 1; i >= 0; --i) {
    //cout << str[i] << std::endl;
    if (*(str + i) == '/') {
        break;
    }
  }
  std::cout << "Basename: " << (str+i + 1) << std::endl;
  return (str+i + 1);
}
*/
/* EOF */

--- NEW FILE: algo.hxx ---
//  $Id: algo.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
//  02111-1307, USA. 

#ifndef ALGO_HH
#define ALGO_HH

#include <string>

#ifndef WIN32
#include <unistd.h>
#else /* WIN32 */
#include <io.h>
#include <iostream>
#define F_OK 0
#endif /* WIN32 */

/** This file contains different algorithmens and other usefull
    routines which are completly indepentantly of the game. */
#define frand() ((double) rand() / (RAND_MAX+1.0))

/** Check if the two given rectangles collide.
    @return Return true if they collide. */
bool rect_col(int ax1, int ax2, int ay1, int ay2,
              int bx1, int bx2, int by1, int by2);

/** Add the tailing string to a directory name, if it is not allready
    there. */
std::string add_slash(std::string& str);

/// Returns the directory part of a filename.
std::string get_directory(std::string s);

///
char*  tolowerstr(char*);

/** Search for a filename in the given path.
    @return The complete filename when found, else the given filename 
    @param path A colon seperated list of directories 
    @param filename An uncomplete/relative filename, it might consist
           of directories */
std::string find_file(const std::string& path, const std::string& filename);

//std::string basename(std::string filename);
/*template<class T> inline std::string to_string(const T& n)
{
 std::ostringstream tmp;
 tmp << n;
 return tmp.str();
 }*/
/*
template<class T> inline void from_string(const std::string& s, T& n)
{
 std::istringstream tmp(s);
 tmp >> n;
}
*/

#endif

/* EOF */

--- NEW FILE: alpha_button.cxx ---
//  $Id: alpha_button.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include <ClanLib/Display/Display/display.h>
#include <ClanLib/Display/Font/font.h>
#include <ClanLib/Display/Input/mouse.h>
#include "pingus_resource.hxx"

#include "alpha_button.hxx"

AlphaButton::AlphaButton(std::string str, int x1, int y1, int w, int h) :
    font  (PingusResource::load_font("Fonts/smallfont_h", "fonts")),
    font_h(PingusResource::load_font("Fonts/smallfont", "fonts")),
    name  (str),
    x1_pos(x1),
    y1_pos(y1),
    x2_pos(x1 + w - 1),
    y2_pos(y1 + h - 1)
{
}

void
AlphaButton::draw(void)
{
  if (is_pressed()) {
    CL_Display::fill_rect(x1_pos, y1_pos, x2_pos, y2_pos,
                          1.0, 1.0, 1.0, 0.5);
    font_h->print_center(x1_pos + (x2_pos - x1_pos)/2, y1_pos + (y2_pos - 
y1_pos)/2,
                         name.c_str());
  } else {
    CL_Display::fill_rect(x1_pos, y1_pos, x2_pos, y2_pos,
                          0.0, 0.0, 0.0, 0.5);
    font->print_center(x1_pos + (x2_pos - x1_pos)/2, y1_pos + (y2_pos - 
y1_pos)/2,
                       name.c_str());
  }
}

bool 
AlphaButton::is_pressed()
{
  if (mouse_over() && CL_Mouse::left_pressed()) {
    return true;
  } else {
    return false;
  }
}

bool
AlphaButton::mouse_over(void)
{
  if (   CL_Mouse::get_x() > x1_pos
      && CL_Mouse::get_x() < x2_pos 
      && CL_Mouse::get_y() > y1_pos
      && CL_Mouse::get_y() < y2_pos)
    {
      return true;
    }
  else 
    {
      return false;
    }
}

/* EOF */

--- NEW FILE: alpha_button.hxx ---
//  $Id: alpha_button.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef ALPHABUTTON_HH
#define ALPHABUTTON_HH

#include <string>

class CL_Font;

///
class AlphaButton
{
private:
  ///
  bool pressed;
  ///
  CL_Font* font;
  ///
  CL_Font* font_h;
  ///
  std::string name;
  ///
  int x1_pos, y1_pos, x2_pos, y2_pos;
public:
  ///
  AlphaButton(std::string str, int, int, int, int);
  ///
  bool is_pressed();
  ///
  void draw(void);
  ///
  bool mouse_over(void);
}///
;

#endif

/* EOF */

--- NEW FILE: anim_counter.cxx ---
//  $Id: anim_counter.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "anim_counter.hxx"
#include <ClanLib/Core/System/system.h>

AnimCounter::AnimCounter() : last_time(0), speed(100)
{
}

AnimCounter::AnimCounter(int s) : last_time(0), speed(s)
{
}

bool 
AnimCounter::enough_time_passed(void) const
{
  if (speed < CL_System::get_time() - last_time) 
    return true;
  else
    return false;  
}

int
AnimCounter::operator=(int i)
{
  return Counter::operator=(i);
}

int
AnimCounter::operator++()
{
  if (enough_time_passed()) {
    last_time = CL_System::get_time();
    Counter::operator++();
  }
  return int(*this);
}

void
AnimCounter::set_speed(int s)
{
  speed = s;
}

int
AnimCounter::get_speed() const
{
  return speed;
}

/* EOF */




--- NEW FILE: anim_counter.hxx ---
//  $Id: anim_counter.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 1999 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef ANIM_COUNTER_HH
#define ANIM_COUNTER_HH

#include "counter.hxx"

// AnimCounter is an inherit class from Counter, it act like a normal
// counter, but it only increase its counter if a specific amount of
// time is passed. The AnimCounter is mostly used in the sprite
/// animation, to keep them at a constant speed.
class AnimCounter : public Counter
{
private:
  ///
  bool enough_time_passed(void) const;
  ///
  int last_time;
  ///
  unsigned int speed;
public:
  ///
  AnimCounter(int s);
  ///
  AnimCounter();
  ///
  int operator=(int i);
  ///
  int operator++();

  /// Set the number of miliseconds between a count increase
  void set_speed(int s);

  /// Returs the speed which is used for this counter
  int  get_speed() const;
}///
;

#endif

/* EOF */

--- NEW FILE: audio.cxx ---
//  $Id: audio.cxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#include "audio.hxx"

// Sound data
Uint16 pingus_audio_format   = AUDIO_S16;
int    pingus_audio_rate     = 44000;
int    pingus_audio_channels = 2;
int    pingus_audio_buffers  = 4096;


/* EOF */

--- NEW FILE: audio.hxx ---
//  $Id: audio.hxx,v 1.1 2002/06/12 19:04:10 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2000 Ingo Ruhnke <address@hidden>
//
//  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 2
//  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, write to the Free Software
//  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#ifndef AUDIO_HH
#define AUDIO_HH

// Simple wrapper header around SDL.h and SDL_mixer.h.

#ifdef HAVE_LIBSDL_MIXER
#  include <SDL/SDL.h>
#  include <SDL/SDL_mixer.h>
#else
///
typedef unsigned short Uint16;
///
typedef void *Mix_Music;
///
typedef void *Mix_Chunk;

/* Audio format flags (defaults to LSB byte order) */
#define AUDIO_U8        0x0008  /* Unsigned 8-bit samples */
#define AUDIO_S8        0x8008  /* Signed 8-bit samples */
#define AUDIO_U16LSB    0x0010  /* Unsigned 16-bit samples */
#define AUDIO_S16LSB    0x8010  /* Signed 16-bit samples */
#define AUDIO_U16MSB    0x1010  /* As above, but big-endian byte order */
#define AUDIO_S16MSB    0x9010  /* As above, but big-endian byte order */
#define AUDIO_U16       AUDIO_U16LSB
#define AUDIO_S16       AUDIO_S16LSB
#endif

/// Sound data
extern Uint16 pingus_audio_format;
///
extern int pingus_audio_rate;
///
extern int pingus_audio_channels;
///
extern int pingus_audio_buffers;

#endif

/* EOF */




reply via email to

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