[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.4,1.1.2.5 c
From: |
VENNIN Joel <address@hidden> |
Subject: |
[Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.4,1.1.2.5 container.cc,1.1.2.4,1.1.2.5 container.h,1.1.2.3,1.1.2.4 font.cc,1.1.2.2,1.1.2.3 font.h,1.1.2.2,1.1.2.3 label.h,1.1.2.1,1.1.2.2 manager.cc,1.1.2.1,1.1.2.2 theme.cc,1.1.2.2,1.1.2.3theme.h,1.1.2.2,1.1.2.3 |
Date: |
Sat, 01 Feb 2003 09:39:43 -0500 |
Update of /cvsroot/adonthell/adonthell/src/gui
In directory subversions:/tmp/cvs-serv29992
Modified Files:
Tag: Branch_road_to_0-4
Makefile.am container.cc container.h font.cc font.h label.h
manager.cc manager.h theme.cc theme.h
Log Message:
Introducing Joel's new-old Window system.
event.cc won't compile - that's just normal.
Gee, there's a lot of snow here! :/
Index: Makefile.am
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/Makefile.am,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -r1.1.2.4 -r1.1.2.5
*** Makefile.am 18 Oct 2002 22:58:28 -0000 1.1.2.4
--- Makefile.am 1 Feb 2003 14:39:40 -0000 1.1.2.5
***************
*** 1,17 ****
noinst_LIBRARIES = libgui.a
! libgui_a_SOURCES = box.cc misc.cc container.cc label.cc \
! font.cc widget.cc fixed.cc \
! bin.cc window.cc manager.cc border_template.cc \
! border_ui.cc theme.cc background_template.cc \
! button_template.cc button.cc button_ui.cc \
! background_ui.cc object_template.cc\
! box.h misc.h container.h label.h \
! font.h widget.h fixed.h \
! bin.h window.h manager.h border_template.h \
! border_ui.h theme.h background_template.h \
! button_template.h button.h button_ui.h \
! background_ui.h object_template.h
!
CPPFLAGS = -I$(srcdir)/.. $(SDL_DEFS) $(SDL_CFLAGS) $(FT2_CFLAGS) $(PY_CFLAGS)
--- 1,11 ----
noinst_LIBRARIES = libgui.a
! libgui_a_SOURCES = background.cc base.cc border.cc \
! container.cc font.cc keys.cc \
! manager.cc scrollbar.cc scroll.cc select_list.cc theme.cc \
! event.cc \
! font.h image.h label.h \
! scrollbar.h scroll.h select_list.h theme.h keys.h event.h types.h \
! write.h manager.h object.h window.h mapview.h
CPPFLAGS = -I$(srcdir)/.. $(SDL_DEFS) $(SDL_CFLAGS) $(FT2_CFLAGS) $(PY_CFLAGS)
Index: container.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/container.cc,v
retrieving revision 1.1.2.4
retrieving revision 1.1.2.5
diff -C2 -r1.1.2.4 -r1.1.2.5
*** container.cc 21 Oct 2002 10:42:48 -0000 1.1.2.4
--- container.cc 1 Feb 2003 14:39:40 -0000 1.1.2.5
***************
*** 1,6 ****
/*
! $Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 1,4 ----
/*
! (C) Copyright 2000 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,94 ****
*/
- #include "border_ui.h"
#include "container.h"
using namespace gui;
! container::container () : my_border_width (5), my_object_ui (NULL)
! {
}
! void container::set_border_width (const u_int16 b)
{
! my_border_width = b;
}
! u_int16 container::get_border_width () const
{
! return my_border_width;
}
! container::~container ()
{
! /* destroy the decoration */
! if (my_object_ui) delete my_object_ui;
}
! void container::set_border_ui (border_template * bd_tmp)
{
! /* if there is already object remove it */
! if ( my_object_ui) delete my_object_ui;
! /* build a new border */
! my_object_ui = new border_ui (this);
! /* define the new border */
! ((border_ui*)my_object_ui)->set_border (bd_tmp);
}
! bool container::draw (gfx::drawing_area * da, gfx::surface * sf)
{
! /* call the widget draw */
! if (widget::draw (da, sf) )
{
! /* attach drawing area */
! assign_drawing_area (da);
! /* draw the theme */
! if (my_object_ui) my_object_ui->draw(da, sf);
! /* detach the drawing area */
! detach_drawing_area ();
!
return true;
}
-
return false;
}
! void container::update_size ()
{
! /* update widget size */
! widget::update_size ();
! /* if there is is a ui object update it */
! if (my_object_ui) my_object_ui->resize();
}
! void container::update_position ()
{
! widget::update_position();
! /* we move the decoration associated at this container*/
! if (my_object_ui) my_object_ui->move();
}
! void container::realize()
{
- widget::realize();
! /* we call resize for objet_ui */
! if (my_object_ui) my_object_ui->resize ();
}
--- 11,194 ----
*/
#include "container.h"
using namespace gui;
! container::container()
! {
! move(0,0);
! /* no layout */
! set_layout(NO_LAYOUT);
!
! /* define space between border */
! set_space_with_border(SPACE_WITH_BORDER);
!
! /* define space between objet */
! set_space_with_object(SPACE_WITH_OBJECT);
!
! /* objet focused inside the container */
! focus_object_ = NULL;
}
+ container::~container()
+ {
+ destroy();
+ }
! void container::move(s_int16 tx, s_int16 ty)
{
! base::move(tx,ty);
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! (*i)->update_position();
}
+ void container::resize(u_int16 tl, u_int16 th)
+ {
+ base::resize(tl,th);
! update_layout();
! }
!
! void container::update_position()
{
! base::update_position();
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! (*i)->update_position();
}
+ void container::add(base * w)
+ {
+ list_wb_.push_back(w);
+
+ w->set_container(this);
+
+ update_layout();
+ }
! void container::remove(base * w)
{
! list_wb_.remove(w);
!
! w->set_container(NULL);
!
! update_layout();
}
+ void container::remove_all()
+ {
+ for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
+ {
+ (*i)->set_container(NULL);
+ list_wb_.erase(i);
+ }
+ }
! void container::destroy()
{
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! delete *i;
! list_wb_.clear();
}
! bool container::update()
{
! if(base::update())
{
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! {
! if(!(*i)->update())
! {
! list_wb_.erase(i);
! delete *i--;
! }
! }
! return true;
! }
! return false;
! }
!
!
! bool container::input_update()
! {
! if(base::input_update())
! {
! if(focus_object_) focus_object_->input_update();
return true;
}
return false;
}
!
! void container::set_focus_object(base * f)
{
! if(focus_object_) focus_object_->set_focus(false);
! if(f) f->set_focus(true);
! focus_object_ = f;
}
! void container::set_brightness(bool b)
{
! base::set_brightness(b);
!
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! (*i)->set_brightness(b);
}
+ void container::set_trans(bool b)
+ {
+ base::set_trans(b);
+
+ for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
+ (*i)->set_trans(b);
+ }
! void container::set_visible_all(bool b)
! {
! set_visible(b);
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! (*i)->set_visible(b);
! }
!
!
!
! bool container::draw()
! {
! if(base::draw())
! {
! assign_drawing_area(wb_father_);
!
! background::draw(this);
!
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! (*i)->draw();
!
! border::draw(wb_father_);
!
! detach_drawing_area();
!
! return true;
! }
! return false;
! }
!
!
!
! void container::update_layout()
{
! u_int16 indice_h=space_with_border_;
!
! switch(layout_)
! {
! case LIST_LAYOUT:
!
! for(lwb::iterator i=list_wb_.begin();i!=list_wb_.end();i++)
! {
! (*i)->move((*i)->x(),indice_h);
!
! indice_h+=(*i)->height()+space_with_object_;
! }
!
! break;
! }
}
Index: container.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/container.h,v
retrieving revision 1.1.2.3
retrieving revision 1.1.2.4
diff -C2 -r1.1.2.3 -r1.1.2.4
*** container.h 18 Oct 2002 22:58:29 -0000 1.1.2.3
--- container.h 1 Feb 2003 14:39:40 -0000 1.1.2.4
***************
*** 2,6 ****
$Id$
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 2,6 ----
$Id$
! (C) Copyright 2000/2001 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,145 ****
*/
! /**
! * @file container.h
! * @author Joel Vennin <address@hidden>
! *
! * @brief Declares the container base class.
! *
! *
! */
! #ifndef CONTAINER_H_
! #define CONTAINER_H_
! #include <vector>
!
! #include "../callback_sig.h"
! #include "widget.h"
! #include "object_ui.h"
!
! namespace gui
! {
!
! class border_template;
!
! /** It's an abstract class, it's can contains lots of widget, there are
some method, add, remove a container...
! *
*/
!
! class container : public widget
{
! public :
!
!
! /**Initialize some variable, child to NULL and border_width (5); */
! container ();
!
/**
! * Add a widget in the list.
! * on_add event is executed
! * @param a widget to add
*/
! virtual void add (widget * w) = 0;
! /** Remove a widget, don't delete the object
! * on_remove event is executed
! * @param remove the widget
*/
! virtual void remove (widget * w) = 0;
!
!
! /** Set space between widget and container
! * @param border width
*/
! void set_border_width (const u_int16);
! /** get border width
! * @return the border width
*/
! u_int16 get_border_width () const;
! /** clear all widget of the vector and child, they are deleted
! * No event is called
! */
! virtual void clear () = 0;
! /**
! * draw the container
! */
! bool draw (gfx::drawing_area * da = NULL, gfx::surface * sf = NULL);
! /**
! * Destructor
! */
! ~container ();
! /**
! * Set the border for this container
! * @param bd_tmp : the border template use to display border, this
objet alloc a border but not the template
! * futur change : change set_border in set_ui : ?? maybe
! */
! void set_border_ui (border_template * bd_tmp);
! /**
! * update size
! */
! virtual void update_size ();
! /**
! * update position
! */
! virtual void update_position();
! /**
! * it's used to build the widget.
! */
! virtual void realize ();
!
! /* call back */
! callback_sig on_add; //call when an objet is added
! callback_sig on_remove; //call when an objet is removed
!
! protected :
!
! /* the space between container and widgets childs */
! u_int16 my_border_width;
! /* the border used by this container */
! object_ui * my_object_ui;
- private :
- };
- };
- #endif
--- 13,123 ----
*/
+ #ifndef GUI_CONTAINER_H_
+ #define GUI_CONTAINER_H_
! #include<list>
! #include "../gfx/drawing_area.h"
! #include "base.h"
! namespace gui {
!
! typedef std::list<base*> lwb;
! /**
! * Define a container. A container is able to contains an infinity of objet
derived from base objet.
*/
! class container : public base
{
! public:
/**
! * Constructor
*/
! container();
+ /**
+ * Move the container.
+ */
+ void move(s_int16, s_int16);
! /**
! * Resize the container
*/
! void resize(u_int16, u_int16);
!
! /**
! * Add base objet
*/
! virtual void add(base *);
+ /**
+ * Remove an objet of the container
+ */
+ virtual void remove(base *);
! /**
! * Remove all objet
*/
! virtual void remove_all();
+ virtual void destroy();
! virtual ~container();
+ virtual bool update();
! virtual bool input_update();
+ virtual bool draw();
! void set_visible_all(bool b);
+ virtual void set_brightness(bool b);
! virtual void set_trans(bool b);
+ virtual void set_space_with_border(u_int16
b){space_with_border_=b;update_layout();}
! virtual void set_space_with_object(u_int16
o){space_with_object_=o;update_layout();}
+ u_int16 space_with_border(){return space_with_border_;}
! u_int16 space_with_object(){return space_with_object_;}
+ void set_layout(u_int8 l){layout_=l;update_layout();}
! void set_focus_object(base * f);
!
! base * focus_object(){return focus_object_;}
!
! const static u_int8 SPACE_WITH_BORDER = 10;
! const static u_int8 SPACE_WITH_OBJECT = 10;
! const static u_int8 LIST_LAYOUT = 1;
! const static u_int8 NO_LAYOUT = 0;
! protected:
+ void update_position();
+ void update_layout();
! u_int16 space_with_object_;
! u_int16 space_with_border_;
! u_int8 layout_;
!
! lwb list_wb_;
!
! base * focus_object_;
!
! };
! }
! #endif
!
!
!
Index: font.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/font.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** font.cc 18 Oct 2002 22:58:29 -0000 1.1.2.2
--- font.cc 1 Feb 2003 14:39:40 -0000 1.1.2.3
***************
*** 1,6 ****
/*
! $Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 1,5 ----
/*
!
! (C) Copyright 2000 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,268 ****
*/
- #include <iostream>
-
- #include "gfx/image.h"
#include "font.h"
using namespace gui;
! int font::UTF8_to_UNICODE(u_int16 * unicode, const char *utf8, int len)
{
! int i, j;
! Uint16 ch;
!
! for ( i=0, j=0; i < len; ++i, ++j ) {
! ch = ((const unsigned char *)utf8)[i];
! if ( ch >= 0xF0 ) {
! ch = (Uint16)(utf8[i]&0x07) << 18;
! ch |= (Uint16)(utf8[++i]&0x3F) << 12;
! ch |= (Uint16)(utf8[++i]&0x3F) << 6;
! ch |= (Uint16)(utf8[++i]&0x3F);
! } else
! if ( ch >= 0xE0 ) {
! ch = (Uint16)(utf8[i]&0x3F) << 12;
! ch |= (Uint16)(utf8[++i]&0x3F) << 6;
! ch |= (Uint16)(utf8[++i]&0x3F);
! } else
! if ( ch >= 0xC0 ) {
! ch = (Uint16)(utf8[i]&0x3F) << 6;
! ch |= (Uint16)(utf8[++i]&0x3F);
! }
! unicode[j] = ch;
! }
! unicode[j] = 0;
!
! return j;
}
!
!
! font::font ()
{
! // by default no file, so no valid font
! my_valid = false;
! // init color
! set_color (0, 0, 0);
! // set default size
! set_size (12);
! // set_default dpi
! set_dpi (72);
}
!
! bool font::load (const std::string & filename)
{
! int error;
! close ();
!
! // copy the new filename
! my_filename = filename;
!
! my_valid = false;
!
! // Initialise library
! error = FT_Init_FreeType( &my_library );
! if (error)
! {
! std::cout << "FONT : Initialisation error!\n";
! return false;
! }
!
! // load TTF font in face
! error = FT_New_Face( my_library, my_filename.c_str () , 0, &my_face );
! if ( error == FT_Err_Unknown_File_Format )
! {
! std::cout << "FONT : Unknown font format\n";
! close ();
! return false;
! }
! else if ( error )
! {
! std::cout << "FONT : Error undefined\n";
! close ();
! return false;
! }
!
! // Check if the font is no scalable
! // WARNING : Implement in the futur
! if (my_face->num_fixed_sizes)
! {
! std::cout << "FONT : Fixed font not only supported\n";
! close ();
! return false;
! }
!
! my_valid = true;
! return true;
}
!
! inline void font::set_dpi (int i) { my_dpi = i; }
!
! inline void font::set_size (int i) { my_size = i; }
!
!
! bool font::build ()
{
! FT_Set_Char_Size( my_face, my_size << 6, my_size << 6, my_dpi, my_dpi);
! return true;
}
!
!
!
! void font::close ()
{
! if (!my_valid) return;
! FT_Done_Face(my_face);
! FT_Done_FreeType(my_library);
}
! void font::copy_bitmap_to_image (u_int8 * bitmap_data, gfx::image * dest,
s_int16 dx, s_int16 dy)
{
! u_int8 * pbmp = bitmap_data;
! dest->lock ();
! u_int32 pixelcol = gfx::screen::display.map_color (my_r, my_g, my_b);
! for (int j = 0; j < dest->height (); j++)
! for (int i = 0; i < dest->length () ; i++)
! {
! if (*pbmp > 128) dest->put_pix (dx + i, dy +j, pixelcol);
! else dest->put_pix (dx + i, dy + j, gfx::screen::trans_col ());
! pbmp++;
! }
! dest->unlock ();
! }
!
! void font::info ()
! {
! std::cout << "Filename : " << my_filename << std::endl;
! std::cout << "Number face : " << my_face->num_faces << std::endl;
! std::cout << "Num_glyphs : " << my_face->num_glyphs << std::endl;
! std::cout << "Fixed size : " << my_face->num_fixed_sizes << std::endl;
! std::cout << "Num char map: " << my_face->num_charmaps << std::endl;
! }
!
!
! void font::draw (const std::string & text, s_int32 x, s_int32 y,
! gfx::drawing_area * da, gfx::surface * target)
! {
! FT_GlyphSlot slot = my_face->glyph; /* the slot */
! u_int16 *unicode_text; /* the unicode pointer text */
! FT_UInt glyph_index;
! int error;
! u_int32 pixelcol = gfx::screen::display.map_color (my_r, my_g, my_b);
! u_int8 * pbmp;
!
! /* get the surface */
! if (target == NULL) target = &(gfx::screen::display);
!
! /* translate to unicode */
! unicode_text = new u_int16[ (text.length()+1)*(sizeof *unicode_text) ];
! int len = UTF8_to_UNICODE(unicode_text, text.c_str(), text.length());
! s_int16 txx = x;
! s_int16 tyy = y;
! for (int n =0; n < len; n++)
! {
! /* retrieve glyph index from character code */
! glyph_index = FT_Get_Char_Index( my_face, unicode_text[n] );
!
! /* load glyph image into the slot (erase previous one) */
! error = FT_Load_Glyph( my_face, glyph_index, FT_LOAD_DEFAULT );
! if (error) continue;
!
! /* convert to an anti-aliased bitmap */
! error = FT_Render_Glyph( my_face->glyph, ft_render_mode_normal );
! if (error) continue;
!
! pbmp = slot->bitmap.buffer;
! for (int j = 0; j < slot->bitmap.rows; j++)
! for (int i = 0; i < slot->bitmap.width ; i++)
! {
! if (*pbmp > 128) target->put_pix (txx + i, tyy + j -
((slot->metrics.horiBearingY)>>6)
! , pixelcol);
! else target->put_pix (txx + i, tyy + j -
((slot->metrics.horiBearingY)>>6),
! gfx::screen::trans_col ());
! pbmp++;
! }
!
! /* must improve this */
! txx += (slot->metrics.horiAdvance>>6);
! }
! /* delete unicode_text */
! delete [] unicode_text;
! }
!
!
!
! u_int32 font::get_length_of (const std::string & text)
! {
! u_int32 size = 0;
! FT_GlyphSlot slot = my_face->glyph; /* the slot */
! u_int16 *unicode_text; /* the unicode pointer text */
! FT_UInt glyph_index;
! int error;
!
! /* translate to unicode */
! unicode_text = new u_int16[ (text.length()+1)*(sizeof *unicode_text) ];
! int len = UTF8_to_UNICODE(unicode_text, text.c_str(), text.length());
! for (int n =0; n < len; n++)
{
- /* retrieve glyph index from character code */
- glyph_index = FT_Get_Char_Index( my_face, unicode_text[n] );
-
- /* load glyph image into the slot (erase previous one) */
- error = FT_Load_Glyph( my_face, glyph_index, FT_LOAD_DEFAULT );
- if (error) continue;
! size += (slot->metrics.horiAdvance>>6);
}
! delete [] unicode_text;
! return size;
}
! u_int16 font::get_size()
! {
! return my_size;
! }
!
! font::~font ()
{
! close ();
}
! void font::set_color (u_int8 r, u_int8 g, u_int8 b)
{
! my_r = r;
! my_g = g;
! my_b = b;
}
! void font::set_color (u_int32 col)
{
! my_r = col & 255;
! my_g = (col >> 8) & 255;
! my_b = (col >> 16) & 255;
}
--- 12,135 ----
*/
#include "font.h"
+ #include "../game.h"
using namespace gui;
! font::font()
{
! table=NULL;
! cursor=NULL;
}
! font::font(char * fic)
{
! cursor=NULL;
! table=NULL;
! load(fic);
}
! font::font(font & tmpfont)
{
! *this=tmpfont;
}
! font::~font()
{
! erase();
}
! void font::erase()
{
! if(cursor) delete cursor;
! if(table) delete [] table;
! table=NULL;
}
! void font::load(char * rep)
{
! if(table!=NULL) erase();
! //file which contains font information and cursor
! igzstream f;
! //path where is the file
! std::string path = DIRECTORY;
! //add win font directory path
! path += FONT_DIRECTORY;
! //add theme pass
! path += std::string (rep) + "/";
! //add font filename
! path += FONT_FILE;
+ path = game::find_file (path);
+
+ //open gzfile
+ if (!f.open (path))
+ {
+ std::cout << path << " not found !\n";
+ exit(1);
+ }
+
+ //create image wich contain the main font image
+ gfx::image * font = new gfx::image();
+ font->get(f);
+
+ //get the cursor
+ cursor=new gfx::image();
+ cursor->get(f);
! //create a table for each letter
! table=new gfx::image[NB_TABLE_CHAR];
! //init the boolean table
! init_in_table();
!
! char i;int j=0;
! u_int16 pos,tl;
!
! while(!f.eof())
{
! i << f;
! pos << f;
! tl << f;
! if(i>0 && i<NB_TABLE_CHAR)
! {
! table_core[i]=true;
! table[i].resize(tl + 1,font->height()-1);
! font->draw (0, 0, pos, 0, tl + 1, font->height () -1, NULL,
&(table[i]));
! }
! j++;
}
! height_=font->height()-1;
!
! length_=table[' '].length();
!
! if(font)delete font;
!
! f.close ();
}
! bool font::in_table(u_int16 tmp)
{
! if(tmp>NB_TABLE_CHAR) return false;
! return table_core[tmp];
}
! void font::init_in_table()
{
! register u_int16 i;
! for(i=0;i<NB_TABLE_CHAR;i++)
! table_core[i]=false;
}
! gfx::image & font::operator[](int i)
{
! return table[i];
}
Index: font.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/font.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** font.h 18 Oct 2002 22:58:29 -0000 1.1.2.2
--- font.h 1 Feb 2003 14:39:40 -0000 1.1.2.3
***************
*** 1,6 ****
/*
! $Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 1,4 ----
/*
! (C) Copyright 2000 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,177 ****
*/
! /**
! * @file font.h
! * @author Joel Vennin <address@hidden>
! *
! * @brief Declares the font TFF class.
! *
! *
! */
! #ifndef FONT_H_
! #define FONT_H_
!
! #include <string>
! #include <vector>
!
! #include <ft2build.h>
! #include FT_FREETYPE_H
#include "types.h"
! #include "gfx/drawing_area.h"
! #include "gfx/surface.h"
! #include "gfx/image.h"
!
!
! namespace gui
! {
!
! /**
! * Designed to manipulate font TTF. You can load TTF font, you set up your
configuration (size, dpi, color), next call build () to apply changement.
! *
! *
! */
! class font
! {
! public :
!
! /** Constructor initialize some variables :
! * - Set color to black color
! * - Set size to 12
! * - Set dpi to 72
! */
! font ();
!
!
! /** Destructor
! * - Free memory used by font
! */
! ~font ();
!
!
! /** Load a TTF font file, before load free memory
! * Important : this method doesn't call build () method
! *
! * @param filename the TTF file
! * @return true : if open successful, false otherwise
! */
! bool load (const std::string & filename);
! /** Set dots per inch
! * You must set to 72 or 96, Why ? see documentation on
www.freetype.org
! *
! * @param dots per inch
! */
! inline void set_dpi (int);
!
! /** Set police size
! *
! * @param font size
! */
! inline void set_size (int size);
!
! /** Set color
! *
! * @param r : red color
! * @param g : green color
! * @param b : blue color
! */
! void set_color (u_int8 r, u_int8 g, u_int8 b);
!
!
! /** Set color
! *
! * @param col : color
! */
! void set_color (u_int32 col);
!
!
! /** Information on the TTF font, write font information in console
! *
! */
! void info ();
!
!
! /**
! * Build the font with cur configuration (size, color, dpi)
! * After build, you can draw some text;)
! */
! bool build ();
!
!
! /**
! * Draw text at x, y position on target, if target is NULL draw text
on the screen
! * Important, your font must be build
! *
! * @param text : text to draw
! * @param x : x position
! * @param y : y position
! * @param target : draw on target, if not target, draw on the screen
! */
! void draw (const std::string & text, s_int32 x, s_int32 y,
gfx::drawing_area * da = NULL, gfx::surface * target = NULL);
!
!
! /**
! * length_of calcul and return length of text
! * Important : if your text is "foo\nfoo" and length of "foo" is 12 px,
this method return 24.
! *
! * @param text : text to calcul
! * @return length of the text in pixel
! */
! u_int32 get_length_of (const std::string & text);
!
! /**
! *
! */
! u_int16 get_size();
!
! private :
!
! /* copy bitmap to image */
! void copy_bitmap_to_image (u_int8 * bitmap_data, gfx::image * dest,
s_int16 dx, s_int16 dy);
!
! /* close the library and face */
! void close ();
! int UTF8_to_UNICODE(u_int16 * unicode, const char *utf8, int len);
!
! /* filename of the font */
! std::string my_filename;
! /* valid font, true if valid */
! bool my_valid;
!
! /* library FT */
! FT_Library my_library;
!
! /* FT_Face */
! FT_Face my_face;
!
! /* dpi, dots-per-inch */
! int my_dpi;
!
! /* size */
! u_int16 my_size;
!
! /* color variable */
! u_int8 my_r, my_g, my_b;
! };
! };
#endif
-
--- 11,63 ----
*/
+ #ifndef GUI_FONT_H_
+ #define GUI_FONT_H_
! #include <iostream>
! #include <stdlib.h>
! #include <string.h>
! #include "../types.h"
#include "types.h"
! #include "../gfx/image.h"
+ namespace gui {
+
+ class font{
! private:
! void erase();
! void init_in_table();
! bool table_core[NB_TABLE_CHAR];
! gfx::image * table;
! u_int8 height_;
! u_int8 length_; //just for space bar
!
! public:
!
! font(char *);
!
! font(font &);
!
! font();
!
! ~font();
!
! void load(char *);
!
! bool in_table(u_int16 tmp);
!
! gfx::image & operator[](int);
!
! u_int16 height(){return height_;}
!
! u_int16 length(){return length_;}
!
! gfx::image * cursor;
! };
! }
#endif
Index: label.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/label.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** label.h 2 Jul 2002 07:20:30 -0000 1.1.2.1
--- label.h 1 Feb 2003 14:39:40 -0000 1.1.2.2
***************
*** 2,6 ****
$Id$
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 2,6 ----
$Id$
! (C) Copyright 2000/2001 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,106 ****
*/
! /**
! * @file label.h
! * @author Joel Vennin <address@hidden>
! *
! * @brief Declares the misc base class.
! *
! *
! */
!
! #ifndef LABEL_H_
! #define LABEL_H_
!
! #include "font.h"
! #include "misc.h"
!
! #include <string>
! #include <vector>
!
! namespace gui
! {
!
! class label : public misc
! {
! public :
!
! /**Constructor initialise some parameters
! */
! label ();
!
!
! /**Set text
! * @param text
! */
! void set_text (const std::string & text);
!
!
! /** get text
! * @return text of this label
! */
! std::string & get_text ();
!
!
! /** set font
! * @param the font to used
! */
! void set_font (font & font);
!
!
! /**get font used by this label
! * @return the font used
! */
! font * get_font () const;
!
!
! /* clear the vector*/
! ~label ();
!
!
! /**Realize this object, not draw but adapt this object with his
contains
! */
! void realize ();
!
!
! /**
! * draw the label
! */
! virtual bool draw (gfx::drawing_area * da = NULL, gfx::surface * sf =
NULL);
!
! protected :
!
!
!
! private :
!
! /** transform text in line, if the text contain some line
! */
! void transform_in_line ();
!
! /* a line vector */
! std::vector <std::string> line_;
!
! /* text of the label */
! std::string text_;
!
! /* font used */
! font * font_;
! };
- };
#endif
--- 13,24 ----
*/
+ #ifndef WIN_LABEL_H_
+ #define WIN_LABEL_H_
! #include "win_object.h"
! #include "label.h"
!
! typedef win_object<label> win_label;
#endif
Index: manager.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/manager.cc,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** manager.cc 2 Jul 2002 07:20:30 -0000 1.1.2.1
--- manager.cc 1 Feb 2003 14:39:40 -0000 1.1.2.2
***************
*** 1,6 ****
/*
$Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 1,6 ----
/*
$Id$
!
! (C) Copyright 2000/2001 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,191 ****
*/
!
! #include "gfx/screen.h"
#include "manager.h"
using namespace gui;
! // window * manager::cur_window_ = NULL;
! // bool manager::alive_ = true;
manager::manager ()
{
! init ();
}
!
!
! void manager::init ()
{
!
! cur_window_ = NULL;
! alive_ = true;
!
!
! // connect keyboard function callback
! il_.connect_function (input::event::KEYBOARD_EVENT,
! MemberTranslator1wRet<input::event
*,int,manager,int (manager::*)(input::event *)>
! (*this, &manager::input_update));
!
!
!
! //connect mouse function callback
! il_.connect_function (input::event::MOUSE_EVENT,
! MemberTranslator1wRet<input::event
*,int,manager,int (manager::*)(input::event *)>
! (*this, &manager::input_update));
!
!
!
! input::manager::add(&il_);
}
!
! void manager::add (window *w)
! {
! v_window_.push_back (w);
}
!
!
! void manager::remove (window *w)
{
- std::deque <window * >::iterator it = v_window_.begin ();
-
- while (it != v_window_.end () && * it != w)it++;
-
- if (it != v_window_.end ())
- v_window_.erase (it);
}
!
! void manager::clear ()
{
! for (std::deque <window* >::iterator it = v_window_.begin (); it !=
v_window_.end (); it++)
! delete *it;
!
! v_window_.clear ();
}
!
!
! void manager::draw ()
{
! for (std::deque <window* >::iterator it = v_window_.begin (); it !=
v_window_.end (); it++)
! (*it)->draw ();
!
!
! /* draw cursor */
! // WARNING IMPROVE IT !
! if (mouse_x_ <= 0 || mouse_y_ <= 0 || mouse_x_ >= gfx::screen::length
() - 5 || mouse_y_ >= gfx::screen::height () - 10 ) return;
! gfx::screen::display.draw_line (mouse_x_, mouse_y_, mouse_x_ + 5,
mouse_y_, 0x000000);
! gfx::screen::display.draw_line (mouse_x_, mouse_y_, mouse_x_, mouse_y_ +
5, 0x000000);
! gfx::screen::display.draw_line (mouse_x_, mouse_y_, mouse_x_ + 10,
mouse_y_ + 10, 0x000000);
!
}
!
!
! void manager::shutdown ()
{
! alive_ = false;
}
! /*
! int manager::keyboard_event (input_event * ev)
{
! cout << "key event\n";
! return 0;
}
!
! int manager::mouse_event (input_event * ev)
{
! cout << "Mouse event\n";
! return 1;
}
- */
! int manager::input_update (input::event * ev)
{
! // get mouse position for the cursor
! input::mouse_event * mev = (input::mouse_event*) ev;
! mouse_x_ = mev->x ();
! mouse_y_ = mev->y ();
!
!
! // if the window is a modal window, only modal window receive input
event.
! // if it is not a modal window all the event are dispatch for all window
in the deque.
! // In this way if a window catch an event, the event is not longer
dispatched
! if (cur_window_ && cur_window_->is_modal ())
{
! cur_window_->input_update (ev);
}
! else
! {
! // std::deque <window* >::iterator it = v_window_.rend ();
! // while (it != v_window_.rbegin () && (*it)->input_update (ev) ==
0)it--;
! int i = v_window_.size () - 1;
! while ( i > -1 && v_window_[i]->input_update (ev) == 0) i--;
!
! }
! return 1;
}
!
! void manager::set_focus (window * w)
{
! // WARNING : call lost focus for the window
! cur_window_ = w;
! remove (w);
! add (w);
}
!
! bool manager::update ()
{
! if (cur_window_ && cur_window_->is_modal ())
! {
! if (cur_window_->update () == false)
! {
! remove (cur_window_);
! delete cur_window_;
! cur_window_ = NULL;
! }
! }
! else
! {
! int i = v_window_.size () - 1;
! window * tmp;
!
! while ( i > -1)
! {
! if (v_window_[i]->update () == false)
! {
! remove (tmp = v_window_[i]);
! delete tmp;
! }
! i--;
! }
! }
! return alive_;
}
! manager::~manager ()
{
! clear ();
}
-
--- 13,228 ----
*/
! /**
! * @file win_theme.cc
! *
! * @author Joel Vennin
! * @brief Implements the win_theme class.
! */
!
! #include "../types.h"
! #include "../gfx/image.h"
! #include "types.h"
#include "manager.h"
using namespace gui;
! // Pointer to the active window(s)
! manager * manager::active = NULL;
! // List of loaded themes
! std::hash_map<std::string, theme *> manager::my_theme;
! // List of loaded fonts
! std::hash_map<std::string, font *> manager::my_font;
!
! using namespace std;
manager::manager ()
{
! // save a pointer to the parent window(s)
! prev = active;
! // make the current window(s) active
! active = this;
! // no window in focus at that point
! wnd_focus = NULL;
! // we're not iterating over the window_list
! current = wnd_list.end ();
}
! manager::~manager ()
{
! // restore parent window(s)
! active = prev;
}
! // Close and delete all windows
! void manager::destroy()
! {
! std::list<base *>::iterator i;
! for (i = wnd_list.begin(); i != wnd_list.end(); i++) delete *i;
!
! wnd_list.clear ();
! wnd_focus = NULL;
}
! void manager::init ()
{
}
! // Delete all fonts and themes
! void manager::cleanup ()
{
! // Cleaning up themes
! for (std::hash_map <std::string, theme *>::iterator it = my_theme.begin ();
! it != my_theme.end (); it++)
! delete it->second;
! my_theme.clear ();
!
! // Cleaning up fonts
! for (std::hash_map <std::string, font *>::iterator ifo = my_font.begin ();
! ifo != my_font.end (); ifo++)
! delete ifo->second;
! my_font.clear ();
}
! // add a window
! void manager::add (base *tmp)
{
! wnd_list.push_back (tmp);
}
!
! // remove a window
! void manager::remove (base *tmp)
{
! // if the window has focus take it away
! if (tmp->is_focus ())
! {
! tmp->set_focus (false);
! wnd_focus = NULL;
! }
!
! // be careful if the iterator points to the element
! // we want to remove. This may happen if remove() is called
! // from a window's update() method or from manager::update().
! if (tmp == *current)
! {
! // make sure that the iterator remains valid
! current++;
! }
!
! // remove it from the window list
! wnd_list.remove (tmp);
!
! // if no window has the focus, give it to the topmost window
! if (!wnd_focus) set_focus (wnd_list.back ());
! }
!
! // draw all windows
! void manager::draw ()
! {
! // first descent recursively down the list of parents
! if (prev != NULL) prev->draw ();
!
! // on the way up, draw every window
! for (current = wnd_list.begin (); current != wnd_list.end(); current++)
! (*current)->draw ();
! }
!
! // grab keyboard input
! void manager::input_update ()
! {
! // only the window with the focus may recieve input
! if (wnd_focus) wnd_focus->input_update ();
! }
!
! // update the state of the topmost window(s)
! void manager::update ()
! {
! for (current = wnd_list.begin (); current != wnd_list.end ();)
! // a window signals that it wants to be closed by returning 0 here
! if (!(*current)->update ())
! {
! // remove and delete it
! base *tmp = *current;
!
! remove (tmp);
! delete tmp;
! }
! else current++;
}
! // give the focus to a window
! void manager::set_focus (base *tmp)
{
! // but only if there are any windows at all
! if (!wnd_list.empty ())
! {
! // remove focus from the old window
! if (wnd_focus) wnd_focus->set_focus (false);
!
! // and give it to the new one
! wnd_focus = tmp;
! wnd_focus->set_focus (true);
! }
}
! // load a theme from disk
! void manager::add_theme (std::string name)
{
! my_theme[name] = new theme ((char *) name.c_str ());
}
! // remove a theme
! bool manager::remove_theme (std::string name)
{
+ std::hash_map <std::string, theme *>::iterator it = my_theme.find (name);
+ if (it == my_theme.end ()) return false;
+
+ delete it->second;
+ my_theme.erase (it);
+ return true;
+ }
! // return a pointer to a theme
! theme * manager::get_theme (std::string name)
! {
! hash_map <std::string, theme *>::iterator it = my_theme.find (name);
!
! // try to load it if it's not in memory yet
! if (it == my_theme.end ())
{
! add_theme (name);
! return get_theme (name);
}
! else return it->second;
}
! // load a font from disk
! void manager::add_font (std::string name)
{
! my_font[name] = new font ((char *) name.c_str ());
}
! // remove a font
! bool manager::remove_font (std::string name)
{
! std::hash_map <std::string, font *>::iterator it = my_font.find (name);
! if (it == my_font.end ()) return false;
!
! delete it->second;
! my_font.erase (it);
! return true;
}
! // return a pointer to a font
! font * manager::get_font (std::string name)
{
! std::hash_map <std::string, font *>::iterator it = my_font.find (name);
!
! // try to load the font if it's not in memory yet
! if (it == my_font.end ())
! {
! add_font (name);
! return get_font (name);
! }
! else return it->second;
}
Index: manager.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/manager.h,v
retrieving revision 1.1.2.1
retrieving revision 1.1.2.2
diff -C2 -r1.1.2.1 -r1.1.2.2
*** manager.h 2 Jul 2002 07:20:30 -0000 1.1.2.1
--- manager.h 1 Feb 2003 14:39:40 -0000 1.1.2.2
***************
*** 1,6 ****
/*
$Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
--- 1,6 ----
/*
$Id$
!
! (C) Copyright 2000/2001 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
***************
*** 13,145 ****
*/
!
! /**
! * @file manager.h
! * @author Joel Vennin <address@hidden>
! *
! * @brief Declares the manager base class.
! *
! *
*/
! #ifndef MANAGER_H_
! #define MANAGER_H_
! #include <deque>
!
! #include "widget.h"
! #include "window.h"
! #include "input/manager.h"
! namespace gui
! {
- /** This class is the window manager. it catch all event, keyboard, mouse
... It display all window.
- */
class manager
{
! public :
!
! manager ();
!
!
/**
! * init method
*/
! void init ();
!
!
! /** Add at the end of list a window
! * @param widget to add
*/
! void add (window *w);
!
!
! /** Remove a window
! * @param widget to remove
*/
! void remove (window * w);
!
!
! /** Clear the manager and remove window of the memory
*/
! void clear ();
!
!
/**
! * draw all contains.
*/
! void draw ();
!
!
/**
! * update all the window system
! * @return false if the system is shutdown
*/
! bool update ();
!
!
! // protected :
!
/**
! * Executed when an keyboard event is processed
*/
! // int keyboard_event (input_event * ev);
!
!
/**
! * Executed when an keyboard event is processed
*/
! // int mouse_event (input_event * ev);
!
! int input_update (input::event *ev);
!
!
/**
! * If this function is call, alive_ variable become false and update
function return false
*/
! void shutdown ();
!
/**
! * set the focus windows, this function put the window on the
foreground and cur_window_ at the param, in this contexte it is the first
window updated
! * by input event.
! * @param a window
*/
! void set_focus (window *);
-
/**
! * Destructor
! * Delelte from memory all component
*/
! ~manager ();
!
! private :
!
! /* input listener */
! input::listener il_;
!
!
! /**current selected window*/
! window * cur_window_;
!
!
! /* list of all window that contain this class */
! std::deque<window*> v_window_;
!
! /* alive, return by update */
! bool alive_;
!
! /* mouse position
! WARNING replace this with a cursor*/
! u_int16 mouse_x_;
! u_int16 mouse_y_;
!
};
! };
#endif
!
!
--- 13,244 ----
*/
! /**
! * @file win_manager.h
! *
! * @author Joel Vennin
! * @brief Declares the win_manager class.
*/
! #ifndef GUI_MANAGER_
! #define GUI_MANAGER_
! #include <list>
! #if __GNUG__ > 2
! #include <ext/hash_map>
! #else
! #include <hash_map>
! #endif
! #include "theme.h"
! #include "font.h"
! #include "base.h"
! #include "../str_hash.h"
!
! /**
! * The window manager takes care of basic GUI functions, such as
! * %input focus, window state updates and displaying everything in
! * the right order.
! * It also provides centralised access to fonts and themes, so
! * that they can be used by different windows without having to
! * load them multiple times.
! * For something to appear on screen, it has to be passes to the
! * window manager.
! *
! * Before the window manager can be used, adonthell::main() has
! * to be called. This instanciates a window manager object and
! * makes it available to other classes via the static
! * win_manager::active pointer. All windows added to that instance
! * have access to the input focus, although only one window can
! * own it at any given time.
! *
! * Another call to adonthell::main() will create a new window
! * manager instance that grabs the input focus. As long as it
! * is in existance, none of the parent windows are updated, nor may
! * they recieve the focus. A call to adonthell::main_quit() will
! * delete the topmost window manager and return focus to the underlying
! * windows.
! *
! * That way it is possible to create a hierarchie of windows, where
! * where only windows on the same level may share the input focus,
! * but only those on the highest level receive input.
! */
! namespace gui {
class manager
{
! public:
/**
! * Standard constructor
*/
! manager ();
!
! /**
! * Destructor
*/
! ~manager ();
!
! /**
! * @name Window handling methods
! *
! */
! //@{
!
! /**
! * Add a window to the window manager.
! *
! * @param wnd The window to be added
! */
! void add (base *wnd);
!
! // static bool exist (base *);
!
! /**
! * Remove a window from the window manager. The
! * window is erased from the window list, but not deleted.
! * If it had the %input focus, it is passed on to the topmost
! * window, i.e. the last one in the window list (if such a
! * window exists).
! *
! * @param wnd The window to be removed
! */
! void remove (base *wnd);
!
! /**
! * Update the state of all top level windows. Calls the
! * %update() method of all windows in the window list. If
! * that method returns 0, it will be removed from the window
! * list and deleted.
! */
! void update ();
!
! /**
! * Checks for user input. Calls the %input_update() method of
! * the window that has the %input focus.
! *
! * @sa set_focus ()
! */
! void input_update ();
!
! /**
! * Draws <b>all</b> windows. If the window hierarchie consists
! * of multiple levels, the lowest windows are drawn first. Within
! * each level, windows are drawn in the order they appear in the
! * window list.
! */
! void draw ();
!
! /**
! * Gives the input focus to wnd. Only one window can have the
! * focus at a time, so focus will be removed from the window
! * that had it so far. Only the window with the focus will
! * receive user input.
! *
! * @sa input_update ()
! */
! void set_focus (base *wnd);
!
! /**
! * Closes and deletes all windows of the current level.
! */
! void destroy ();
!
! #ifndef SWIG
! /**
! * Pointer to the active, i.e. topmost window manager.
*/
! static manager *active;
! #endif
!
! /**
! * Use this method to get the active manger from Python
*/
! static manager *get_active ()
! {
! return active;
! }
! //@}
!
! /**
! * @name Theme and font related methods
! *
! */
! //@{
!
/**
! * Empty for now
*/
! static void init ();
!
/**
! * Delete all themes and fonts currently loaded.
*/
! static void cleanup ();
!
/**
! * Load a theme from disk.
! *
! * @param name The name of the theme to load.
*/
! static void add_theme (std::string name);
!
/**
! * Delete a theme.
! *
! * @param name The name of the theme to delete.
! * @return
! * @li true in case of success.
! * @li false in case of error.
*/
! static bool remove_theme (std::string name);
!
/**
! * Returns a pointer to a theme. Loads the theme from disk
! * if it isn't in memory yet.
! *
! * @param name The name of the theme to get.
! * @return Pointer to the theme.
*/
! static theme *get_theme (std::string name);
/**
! * Load a font from disk.
! *
! * @param name The name of the font to load.
*/
! static void add_font (std::string name);
/**
! * Delete a font.
! *
! * @param name The name of the font to delete.
! * @return
! * @li true in case of success.
! * @li false in case of error.
*/
! static bool remove_font (std::string name);
!
! /**
! * Returns a pointer to a font. Loads the font from disk
! * if it isn't in memory yet.
! *
! * @param name The name of the font to get.
! * @return Pointer to the font.
! */
! static font *get_font (std::string name);
! //@}
! private:
! #ifndef SWIG
! static std::hash_map<std::string, theme *> my_theme;
! static std::hash_map<std::string, font *> my_font;
!
! std::list<base *> wnd_list;
! std::list<base *>::iterator current;
! base *wnd_focus;
! manager *prev;
! #endif // SWIG
};
! }
#endif
!
Index: theme.cc
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/theme.cc,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** theme.cc 18 Oct 2002 22:58:29 -0000 1.1.2.2
--- theme.cc 1 Feb 2003 14:39:40 -0000 1.1.2.3
***************
*** 1,8 ****
/*
! $Id$
!
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
!
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
--- 1,8 ----
/*
! $Id$
!
! (C) Copyright 2000 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
!
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
***************
*** 13,197 ****
*/
! #include <iostream>
#include "theme.h"
using namespace gui;
!
! theme::theme ()
! {
!
! }
!
!
! void theme::load (const std::string & filename)
! {
! /* init hash_map border */
! destroy ();
!
! /* open file with gz stream */
! igzstream fd;
!
! if (!fd.open (filename))
! {
! std::cerr << "error theme::load " << filename << std::endl;
! return;
! }
!
! /* load name */
! my_name << fd;
!
! /* start to read number of border */
! u_int8 nb_border;
! nb_border << fd;
!
! // std::cout << nb_border << std::endl;
!
! border_template * tmp;
! for (u_int8 i = 0; i < nb_border; i++)
! {
! tmp = new border_template ();
! tmp->load (fd);
! add_border (tmp);
! }
!
! /* close the fd */
! fd.close ();
! }
!
!
!
! void theme::save (const std::string & filename)
! {
! /* open a gz output stream */
! ogzstream fd;
! if (!fd.open (filename))
! {
! std::cerr << "error theme::save " << filename << std::endl;
! return;
! }
!
! /* save name */
! my_name >> fd;
!
! /* save number of border */
! u_int8 nb_border = my_border.size ();
! nb_border >> fd;
!
! /* save the border */
! for (std::hash_map <std::string, border_template * >::iterator it =
my_border.begin (); it != my_border.end (); it++)
! it->second->save (fd);
!
!
! /* save number of button */
! u_int8 nb_button = my_button.size ();
! nb_button >> fd;
!
! /* save the button */
! for (std::hash_map <std::string, button_template * >::iterator ot =
my_button.begin (); ot != my_button.end (); ot++)
! ot->second->save (fd);
!
! fd.close ();
! }
!
!
! std::string theme::get_name () const
! {
! return my_name;
! }
!
!
! void theme::set_name (const std::string & name)
! {
! my_name = name;
! }
!
!
! void theme::add_border (border_template * border)
! {
! my_border[border->get_name () ] = border;
! }
!
!
! void theme::remove_border (const std::string & name)
{
! std::hash_map <std::string, border_template * >::iterator it =
my_border.find (name);
! if ( it == my_border.end ()) return;
! delete it->second;
! my_border.erase (it);
}
!
! border_template * theme::get_border (const std::string & name)
{
! std::hash_map <std::string, border_template * >::iterator it =
my_border.find (name);
! if ( it == my_border.end ()) return NULL;
! return it->second;
! }
!
!
! void theme::add_button (button_template * button)
! {
! my_button[button->get_name () ] = button;
! }
!
!
! void theme::remove_button (const std::string & name)
! {
! std::hash_map <std::string, button_template * >::iterator it =
my_button.find (name);
! if ( it == my_button.end ()) return;
! delete it->second;
! my_button.erase (it);
! }
!
! button_template * theme::get_button (const std::string & name)
{
! std::hash_map <std::string, button_template * >::iterator it =
my_button.find (name);
! if ( it == my_button.end ()) return NULL;
! return it->second;
}
!
!
! void theme::destroy ()
{
! // free border
! for (std::hash_map <std::string, border_template * >::iterator it =
my_border.begin (); it != my_border.end (); it++)
! delete it->second;
! my_border.clear ();
!
! // free button
! for (std::hash_map <std::string, button_template * >::iterator it =
my_button.begin (); it != my_button.end (); it++)
! delete it->second;
! my_button.clear ();
!
}
!
! theme::~theme ()
{
! destroy ();
}
!
!
! void theme::display_info ()
{
! std::cout << "Theme name : " << my_name << std::endl;
! std::cout << "List of border : \n";
!
!
! for (std::hash_map <std::string, border_template * >::iterator it =
my_border.begin (); it != my_border.end (); it++)
! it->second->display_info ();
!
! std::cout << "List of button : \n";
!
! for (std::hash_map <std::string, button_template * >::iterator it =
my_button.begin (); it != my_button.end (); it++)
! it->second->display_info ();
}
-
-
-
-
-
--- 13,67 ----
*/
! #include <string>
#include "theme.h"
using namespace gui;
! theme::theme()
{
! my_border_normal = NULL;
! my_border_mini = NULL;
! my_background = NULL;
! my_scrollbar = NULL;
}
! theme::theme(char * theme)
{
! std::string strtheme = std::string (theme) + "/";
! my_border_normal = new border((char *) strtheme.c_str(),
BORDER_NORMAL_SIZE);
! my_border_mini = new border((char *) strtheme.c_str(), BORDER_MINI_SIZE);
! my_background = new background((char *) strtheme.c_str() );
! my_scrollbar = new scrollbar((char *) strtheme.c_str() );
! }
! theme::theme(theme & th)
{
! my_border_normal=NULL;
! my_border_mini=NULL;
! my_background=NULL;
! my_scrollbar=NULL;
! *this=th;
}
! theme::~theme()
{
! destroy();
}
! theme & theme::operator=(theme & th)
{
! destroy();
! my_border_normal = new border(*(th.my_border_normal));
! my_border_mini = new border(*(th.my_border_mini));
! my_background = new background(*(th.my_background));
! my_scrollbar = new scrollbar(*(th.my_scrollbar));
! return *this;
}
! void theme::destroy()
{
! if(my_border_normal)delete my_border_normal;
! if(my_border_mini) delete my_border_mini;
! if(my_background) delete my_background;
! if(my_scrollbar) delete my_scrollbar;
}
Index: theme.h
===================================================================
RCS file: /cvsroot/adonthell/adonthell/src/gui/Attic/theme.h,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -C2 -r1.1.2.2 -r1.1.2.3
*** theme.h 18 Oct 2002 22:58:29 -0000 1.1.2.2
--- theme.h 1 Feb 2003 14:39:40 -0000 1.1.2.3
***************
*** 2,8 ****
$Id$
! (C) Copyright 2002 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
!
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
--- 2,8 ----
$Id$
! (C) Copyright 2000 Joel Vennin
Part of the Adonthell Project http://adonthell.linuxgames.com
!
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License.
***************
*** 13,159 ****
*/
! /**
! * @file theme.h
! * @author Joel Vennin <address@hidden>
! *
! * @brief Declares the theme class.
! *
! *
! */
!
!
! #ifndef THEME_H_
! #define THEME_H_
!
! #if __GNUG__ > 2
! #include <ext/hash_map>
! #else
! #include <hash_map>
! #endif
!
! #include "str_hash.h"
!
! #include <string>
! #include "border_template.h"
! #include "button_template.h"
!
! namespace gui
! {
class theme
{
! public :
! /**
! * Initialize this object
! */
! theme ();
!
!
! /**
! *Load a theme
! * @param filename : filename of the theme
! */
! void load (const std::string & filename);
!
!
! /**
! *Save a theme
! * @param filename : filename used to save
! */
! void save (const std::string & filename);
!
!
! /**
! * get name of the theme
! * @return name of the theme
! */
! std::string get_name () const;
!
!
! /**
! * set name of the theme
! * @param name : name of the theme
! */
! void set_name (const std::string & name);
!
!
! /**
! * add a border
! * @param border : border to add
! */
! void add_border (border_template * border);
!
!
! /**
! * remove a border
! * @param name : name of the border to remove
! */
! void remove_border (const std::string & name);
!
!
! /**
! * get border
! * @param name : name of the border
! * @return the border associated with the name
! */
! border_template * get_border( const std::string & name);
!
!
! /**
! * add a button
! * @param button : button to add
! */
! void add_button (button_template * button);
!
!
! /**
! * remove a button
! * @param name : name of the button to remove
! */
! void remove_button (const std::string & name);
!
!
! /**
! * get button
! * @param name : name of the button
! * @return the button associated with the name
! */
! button_template * get_button( const std::string & name);
!
!
!
!
! /**
! * write in standart ouput theme information
! */
! void display_info ();
!
!
! /**
! * Free memory
! */
! ~theme ();
!
! private :
! /**
! * free memory delete all object from the memory
! */
! void destroy ();
!
!
! /* name of the theme */
! std::string my_name;
!
! /* a hash_map for border */
! std::hash_map <std::string, border_template* > my_border;
!
! /* a hash_map for button */
! std::hash_map <std::string, button_template* > my_button;
! };
! };
!
!
!
#endif
--- 13,55 ----
*/
+ #ifndef GUI_THEME_H_
+ #define GUI_THEME_H_
! #include "border.h"
! #include "background.h"
! #include "scroll.h"
! #include "scrollbar.h"
! namespace gui {
class theme
{
! public:
! theme();
!
! theme(char *);
!
! theme(theme &);
!
! theme & operator=(theme &);
!
! ~theme();
!
! void destroy();
!
! friend class border;
! friend class background;
! friend class scrollbar;
!
! private:
!
! border * my_border_normal;
!
! border * my_border_mini;
!
! background * my_background;
!
! scrollbar * my_scrollbar;
! };
! }
#endif
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Adonthell-commits] CVS: adonthell/src/gui Makefile.am,1.1.2.4,1.1.2.5 container.cc,1.1.2.4,1.1.2.5 container.h,1.1.2.3,1.1.2.4 font.cc,1.1.2.2,1.1.2.3 font.h,1.1.2.2,1.1.2.3 label.h,1.1.2.1,1.1.2.2 manager.cc,1.1.2.1,1.1.2.2 theme.cc,1.1.2.2,1.1.2.3theme.h,1.1.2.2,1.1.2.3,
VENNIN Joel <address@hidden> <=