1 /***************************************************************************
2                   cardcontainer.cpp  -  Tab container widget
3                              -------------------
4     begin                : Thu Aug 28 2003
5     copyright            : (C) 2003 by Gabor Torok
6     email                : cctorok@yahoo.com
7  ***************************************************************************/
8 
9 /***************************************************************************
10  *                                                                         *
11  *   This program is free software; you can redistribute it and/or modify  *
12  *   it under the terms of the GNU General Public License as published by  *
13  *   the Free Software Foundation; either version 2 of the License, or     *
14  *   (at your option) any later version.                                   *
15  *                                                                         *
16  ***************************************************************************/
17 #include "../common/constants.h"
18 #include "cardcontainer.h"
19 
20 using namespace std;
21 
22 /**
23   *@author Gabor Torok
24   */
25 
CardContainer(Window * window)26 CardContainer::CardContainer( Window *window ) {
27 	this->window = window;
28 	cardCount = 0;
29 	for ( int i = 0; i < MAX_CARDS; i++ ) {
30 		widgetCount[i] = 0;
31 	}
32 	activeCard = 0;
33 }
34 
~CardContainer()35 CardContainer::~CardContainer() {
36 }
37 
setActiveCard(int card)38 void CardContainer::setActiveCard( int card ) {
39 	for ( int i = 0; i < widgetCount[activeCard]; i++ ) {
40 		containedWidget[activeCard][i]->setVisible( false );
41 	}
42 	activeCard = card;
43 	for ( int i = 0; i < widgetCount[activeCard]; i++ ) {
44 		containedWidget[activeCard][i]->setVisible( true );
45 	}
46 }
47 
addWidget(Widget * w,int card,bool addToWindow)48 void CardContainer::addWidget( Widget *w, int card, bool addToWindow ) {
49 	containedWidget[card][widgetCount[card]++] = w;
50 	w->setVisible( card == activeCard );
51 
52 	// Add to window only if not already done
53 	if ( addToWindow ) {
54 		window->addWidget( w );
55 	}
56 }
57 
58 
createButton(int x1,int y1,int x2,int y2,char * label,int card,bool toggle,Texture const & texture)59 Button *CardContainer::createButton( int x1, int y1, int x2, int y2, char *label, int card, bool toggle, Texture const& texture ) {
60 	if ( widgetCount[card] < MAX_WIDGETS ) {
61 		Button *b;
62 		b = window->createButton( x1, y1, x2, y2, label, toggle, texture );
63 		addWidget( ( Widget * )b, card, false );
64 		return b;
65 	} else {
66 		cerr << "Gui/CardContainer.cpp : max widget limit reached!" << endl;
67 		return NULL;
68 	}
69 }
70 
createLabel(int x1,int x2,char const * label,int card,int color)71 Label * CardContainer::createLabel( int x1, int x2, char const* label, int card, int color ) {
72 	if ( widgetCount[card] < MAX_WIDGETS ) {
73 		Label *l;
74 		l = window->createLabel( x1, x2, label, color );
75 		addWidget( ( Widget * )l, card, false );
76 		return l;
77 	} else {
78 		cerr << "Gui/CardContainer.cpp : max widget limit reached!" << endl;
79 		return NULL;
80 	}
81 }
82 
createCheckbox(int x1,int y1,int x2,int y2,char * label,int card)83 Checkbox * CardContainer::createCheckbox( int x1, int y1, int x2, int y2, char *label, int card ) {
84 	if ( widgetCount[card] < MAX_WIDGETS ) {
85 		Checkbox * c;
86 		c = window->createCheckbox( x1, y1, x2, y2, label );
87 		addWidget( ( Widget * )c, card, false );
88 		return c;
89 	} else {
90 		cerr << "Gui/CardContainer.cpp : max widget limit reached!" << endl;
91 		return NULL;
92 	}
93 }
94 
95