pingus-cvs
[Top][All Lists]
Advanced

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

[Pingus-CVS] CVS: Games/Pingus/src/editor generic_property_frame.cxx,NON


From: grumbel
Subject: [Pingus-CVS] CVS: Games/Pingus/src/editor generic_property_frame.cxx,NONE,1.1 generic_property_frame.hxx,NONE,1.1 Makefile.am,1.26,1.27 groundpiece_window.cxx,1.10,1.11 property_frame.hxx,1.7,1.8
Date: 29 Nov 2002 00:17:07 -0000

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

Modified Files:
        Makefile.am groundpiece_window.cxx property_frame.hxx 
Added Files:
        generic_property_frame.cxx generic_property_frame.hxx 
Log Message:
added stuff to ease the creation of object property gui's


--- NEW FILE: generic_property_frame.cxx ---
//  $Id: generic_property_frame.cxx,v 1.1 2002/11/29 00:17:05 grumbel Exp $
//
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 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 <ClanLib/GUI/label.h>
#include <ClanLib/GUI/inputbox.h>
#include <ClanLib/GUI/listbox.h>
#include <ClanLib/GUI/checkbox.h>
#include "../string_converter.hxx"
#include "generic_property_frame.hxx"

namespace EditorNS {

class IntegerDataBox : public DataBox
{
public:
  CL_Label*    label;
  CL_InputBox* input_box;
  int* value;

  IntegerDataBox(CL_Component* parent, int y_pos, const std::string& name, int* 
_value) 
    : value(_value)
  {
    label     = new CL_Label(CL_Rect(10, y_pos, 90, y_pos + 20), name, parent);
    input_box = new CL_InputBox(CL_Rect(110, y_pos, 190, y_pos + 20), 
to_string(*value), parent);
  }

  virtual ~IntegerDataBox()
  {
    delete label;
    delete input_box;
  }

  void read_data() 
  {
    input_box->set_text(to_string(*value));
  }
  
  void write_data() 
  {
    from_string(input_box->get_text(), *value);
  }
};

class FloatDataBox : public DataBox
{
public:
  CL_Label*    label;
  CL_InputBox* input_box;
  float* value;

  FloatDataBox(CL_Component* parent, int y_pos, const std::string& name, float* 
_value) 
    : value(_value)
  {
    label     = new CL_Label(CL_Rect(10, y_pos, 90, y_pos + 20), name, parent);
    input_box = new CL_InputBox(CL_Rect(110, y_pos, 190, y_pos + 20), 
to_string(*value), parent);
  }

  virtual ~FloatDataBox()
  {
    delete label;
    delete input_box;
  }

  void read_data() 
  {
    input_box->set_text(to_string(*value));
  }
  
  void write_data() 
  {
    from_string(input_box->get_text(), *value);
  }
};

class StringDataBox : public DataBox
{
public:
  CL_Label*    label;
  CL_InputBox* input_box;
  std::string* value;

  StringDataBox(CL_Component* parent, int y_pos, const std::string& name, 
std::string* _value) 
    : value(_value)
  {
    label     = new CL_Label(CL_Rect(10, y_pos, 90, y_pos + 20), name, parent);
    input_box = new CL_InputBox(CL_Rect(110, y_pos, 190, y_pos + 20), *value, 
parent);
  }

  virtual ~StringDataBox()
  {
    delete label;
    delete input_box;
  }

  void read_data() 
  {
    input_box->set_text(*value);
  }
  
  void write_data() 
  {
    *value = input_box->get_text();
  }
};

class BoolDataBox : public DataBox
{
public:
  CL_CheckBox* check_box;
  bool* value;

  BoolDataBox(CL_Component* parent, int y_pos, const std::string& name, bool* 
_value) 
    : value(_value)
  {
    check_box = new CL_CheckBox(CL_Point(10, y_pos), name, parent);
    read_data();
  }

  virtual ~BoolDataBox()
  {
    delete check_box;
  }

  void read_data() 
  {
    check_box->set_checked(*value);
  }
  
  void write_data() 
  {
    *value = check_box->is_checked();
  }
};

class EnumDataBox : public DataBox
{
public:
  CL_ListBox list_box;
  int* value;

  EnumDataBox(CL_Component* parent, int y_pos, const std::string& name, int* 
_value) 
    : list_box(CL_Rect(110, y_pos, 190, y_pos+20), parent), value(_value)
  {
  }

  virtual ~EnumDataBox() {}

  void read_data() 
  {
    
  }
  
  void write_data() 
  {
    
  }

  void add_item(const std::string&)
  {
  }
};

GenericPropertyFrame::GenericPropertyFrame(const std::string& _title, 
CL_Component* parent)
  : PropertyFrame(200, 300, parent), title(_title), y_pos(10), enum_data_box(0)
{
}

GenericPropertyFrame::~GenericPropertyFrame()
{
  for (std::vector<DataBox*>::iterator i = data_boxes.begin(); i != 
data_boxes.end(); ++i)
    {
      std::cout << "GenericPropertyFrame: Writing data for: " << *i << 
std::endl;
      (*i)->write_data();
      delete *i;
    }
}

void
GenericPropertyFrame::add_string_box(const std::string& name, std::string* 
value)
{
  data_boxes.push_back(new StringDataBox(this, y_pos, name, value));
  y_pos += 20;
  set_height(y_pos);
}

void
GenericPropertyFrame::add_integer_box(const std::string& name, int* value)
{
  data_boxes.push_back(new IntegerDataBox(this, y_pos, name, value));
  y_pos += 20;
  set_height(y_pos);
}

void
GenericPropertyFrame::add_float_box(const std::string& name, float* value)
{
  data_boxes.push_back(new FloatDataBox(this, y_pos, name, value));
  y_pos += 20;
  set_height(y_pos);
}

void
GenericPropertyFrame::begin_add_enum_box(const std::string& title, int*)
{
}

void
GenericPropertyFrame::add_enum_value(const std::string name, int value)
{
}

void
GenericPropertyFrame::end_add_enum_box()
{
  enum_data_box = 0;
}

void
GenericPropertyFrame::add_check_box(const std::string& name, bool* value)
{
  data_boxes.push_back(new BoolDataBox(this, y_pos, name, value));
  y_pos += 20;
  set_height(y_pos);
}

} // namespace EditorNS

/* EOF */

--- NEW FILE: generic_property_frame.hxx ---
//  $Id: generic_property_frame.hxx,v 1.1 2002/11/29 00:17:05 grumbel Exp $
// 
//  Pingus - A free Lemmings clone
//  Copyright (C) 2002 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_GENERIC_PROPERTY_FRAME_HXX
#define HEADER_PINGUS_GENERIC_PROPERTY_FRAME_HXX

#include <vector>
#include <string>
#include "property_frame.hxx"

class CL_Component;

namespace EditorNS {

/** Interface for holding data pointers */
class DataBox {
public:
  /** Read the data from the data pointer */
  virtual void read_data() =0;
    
  /** Write the data from the GUI to the data pointer */
  virtual void write_data() =0;
};

class EnumDataBox;

/** PropertyFrame which can be used for simple name/value configurations */
class GenericPropertyFrame : public PropertyFrame
{
private:
  /** The title of this PropertyFrame */
  std::string title;

  /** This vector holds all the data_boxes that read and write to client data */
  std::vector<DataBox*> data_boxes;

  /** start position of the next data handler */
  int y_pos;

  /** temporary state variable for *add_enum* stuff */
  EnumDataBox* enum_data_box;
public:
  GenericPropertyFrame(const std::string& _title, CL_Component* parent);
  ~GenericPropertyFrame();

  std::string get_title () { return title; }

  /** Representation of an std::string value */
  void add_string_box(const std::string& name, std::string* value);

  /** Representation of an int value */
  void add_integer_box(const std::string& name, int* value);

  /** Representation of an float value */
  void add_float_box(const std::string& name, float* value);

  /** Representation of a boolean value */
  void add_check_box(const std::string& name, bool* value);
  
  /** Creates a listbox to represent an enumeration */
  void begin_add_enum_box(const std::string& title, int*);
  void add_enum_value(const std::string name, int value);
  void end_add_enum_box();

private:
  GenericPropertyFrame (const GenericPropertyFrame&);
  GenericPropertyFrame& operator= (const GenericPropertyFrame&);
};

} // namespace EditorNS

#endif

/* EOF */

Index: Makefile.am
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/Makefile.am,v
retrieving revision 1.26
retrieving revision 1.27
diff -u -d -r1.26 -r1.27
--- Makefile.am 27 Sep 2002 16:01:55 -0000      1.26
+++ Makefile.am 29 Nov 2002 00:17:05 -0000      1.27
@@ -28,6 +28,7 @@
        entrance_window.cxx entrance_window.hxx \
        exit_window.cxx exit_window.hxx \
        groundpiece_window.cxx groundpiece_window.hxx \
+        generic_property_frame.cxx generic_property_frame.hxx \
        level_property_window.cxx level_property_window.hxx \
        object_manager.cxx object_manager.hxx \
        object_selector.cxx object_selector.hxx \

Index: groundpiece_window.cxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/groundpiece_window.cxx,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -d -r1.10 -r1.11
--- groundpiece_window.cxx      27 Sep 2002 11:26:45 -0000      1.10
+++ groundpiece_window.cxx      29 Nov 2002 00:17:05 -0000      1.11
@@ -29,8 +29,6 @@
  Type: [ground|bridger|transparent|...]
 
  [convert to hotspot]
- ------------------------
- [ok] [cancel]
 *************************/
 
 using namespace WorldObjsData;

Index: property_frame.hxx
===================================================================
RCS file: /usr/local/cvsroot/Games/Pingus/src/editor/property_frame.hxx,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -d -r1.7 -r1.8
--- property_frame.hxx  28 Nov 2002 20:09:54 -0000      1.7
+++ property_frame.hxx  29 Nov 2002 00:17:05 -0000      1.8
@@ -27,7 +27,9 @@
 
 namespace EditorNS {
 
-/** FIXME: Document Me */
+/** Class for things that should be placed in the PropertyWindow, it
+    basically just provides a get_title() function to switch the
+    window title */
 class PropertyFrame : public CL_Frame
 {
 public:





reply via email to

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