pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/input button_factory.cxx,NONE,1.1 but


From: torangan
Subject: [Pingus-CVS] CVS: Games/Pingus/src/input button_factory.cxx,NONE,1.1 button_factory.hxx,NONE,1.1
Date: 9 Jul 2002 15:26:57 -0000

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

Added Files:
        button_factory.cxx button_factory.hxx 
Log Message:
create a specific button


--- NEW FILE: button_factory.cxx ---
//  $Id: button_factory.cxx,v 1.1 2002/07/09 15:26:55 torangan 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 <stdlib.h>
#include "../xml_helper.hxx"
#include "../pingus_error.hxx"
#include "key_button.hxx"
#include "key_helper.hxx"
#include "mouse_button.hxx"
#include "joystick_button.hxx"
#include "multiple_button.hxx"
#include "button_factory.hxx"

namespace Input {

  Button* ButtonFactory::create(xmlNodePtr cur)
  {
    cur = cur->children;
    
    if (xmlIsBlankNode(cur)) 
      cur = cur->next;

    if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "joystick-button"))
      return joystick_button(cur);
      
    else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), "key-button"))
      return key_button(cur);
      
    else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"mouse-button"))
      return mouse_button(cur);

    else if ( ! strcmp(reinterpret_cast<const char*>(cur->name), 
"multiple-button"))
      return multiple_button(cur);
    
    else
      throw PingusError("Unknown button type: " + 
std::string(reinterpret_cast<const char*>(cur->name)));
  }
  
  Button* ButtonFactory::joystick_button (xmlNodePtr cur)
  {
    char * id_str     = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("id")));
    char * button_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("button")));
    
    int id     = atoi(id_str);
    int button = atoi(button_str);
    
    free(id_str);
    free(button_str);
    
    return new JoystickButton(id, button);
  }
  
  Button* ButtonFactory::key_button (xmlNodePtr cur)
  {
    char * key_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("key")));
    
    int key = KeyHelper::string_to_key(key_str);
    
    free(key_str);
    
    return new KeyButton(key);
  }
  
  Button* ButtonFactory::mouse_button (xmlNodePtr cur)
  {
    char * button_str = reinterpret_cast<char *>(xmlGetProp(cur, 
reinterpret_cast<const xmlChar*>("button")));
    
    int button = atoi(button_str);
    
    free(button_str);
    
    return new MouseButton(button);
  }

  Button* ButtonFactory::multiple_button (xmlNodePtr cur)
  {
    std::vector<Button*> buttons;
    
    cur = cur->children;
    
    while (cur)
      {
        if (xmlIsBlankNode(cur)) {
          cur = cur->next;
          continue;
        }
        
        buttons.push_back(create(cur));
        cur = cur->next;
      }
      
    return new MultipleButton(buttons);
  }

}

/* EOF */

--- NEW FILE: button_factory.hxx ---
//  $Id: button_factory.hxx,v 1.1 2002/07/09 15:26:55 torangan 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 HEADER_PINGUS_INPUT_BUTTON_FACTORY_HXX
#define HEADER_PINGUS_INPUT_BUTTON_FACTORY_HXX

#include "../libxmlfwd.hxx"

class Button;

namespace Input {

  class ButtonFactory 
  {
    private:
      static inline Button* joystick_button (xmlNodePtr cur);
      static inline Button* key_button      (xmlNodePtr cur);
      static inline Button* mouse_button    (xmlNodePtr cur);
      static inline Button* multiple_button (xmlNodePtr cur);
    
    public:
      static Button* create (xmlNodePtr cur);
  };
}

#endif

/* EOF */




reply via email to

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