File: graphicalCell.cpp

package info (click to toggle)
attal 0.9.2-1.2
  • links: PTS
  • area: main
  • in suites: etch, etch-m68k
  • size: 2,992 kB
  • ctags: 5,972
  • sloc: cpp: 44,510; sh: 160; makefile: 45
file content (146 lines) | stat: -rw-r--r-- 3,417 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
/****************************************************************
**
** Attal : Lords of Doom
**
** graphicalCell.cpp
** this class draws an animated cell
**
** Version : $Id: graphicalCell.cpp,v 1.6 2004/12/18 11:52:52 audoux Exp $
**
** Author(s) : Pascal Audoux - Cyrille Verrier
**
** Date : 02/08/2000
**
** Licence :    
**	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, 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.
**
****************************************************************/

#include "graphicalCell.h"

// generic include files
// include files for QT
#include <qapplication.h>
#include <qcanvas.h>
#include <qcolor.h>
#include <qpointarray.h>
// application specific include
#include "libClient/cell.h"
#include "libClient/imageTheme.h"

#include "libCommon/dataTheme.h"
#include "libCommon/genericDecoration.h"
#include "libCommon/log.h"

#include "conf.h"

/** size in pixel of a cell */
const int GraphicalCell::_size = 30 ;

/** rtti number for GraphicalCell class */
const int GraphicalCell::RTTI = 2345;

extern QString IMAGE_PATH;
extern ImageTheme ImageTheme;
extern DataTheme DataTheme;


//
// ----- GraphicalCell -----
//

/** create an animated cell from pixmaps at position row,col */
GraphicalCell::GraphicalCell( int row, int col , QCanvas *canvas)
	: QCanvasSprite( ImageTheme.cells[0], canvas )
{
	collisions( true );
	setFrame( 0 );
	move( _size*col, _size*row );
	setZ( CAN_GROUND );
	show();
}

GraphicalCell::~GraphicalCell()
{

}

void GraphicalCell::setType( int type )
{
	setSequence( ImageTheme.cells[type] );
	setFrame( 0 );
}

void GraphicalCell::setDiversification( uint divers )
{
	setFrame( divers );
}

/** return if a point is on the cell */
bool GraphicalCell::hit( const QPoint &p ) const
{
	return boundingRect().contains( p );
}

//
// ----- Transition -----
//

Transition::Transition( Cell * parent, QCanvas *canvas)
	: GraphicalCell( parent->getRow(), parent->getCol(), canvas )
{
	_parent = parent;
}

void Transition::setTransition( int transition, int type )
{
	setZ( CAN_TRANS );

	// XXX: Ugly
	if( type == 0) {
		type = 1;
	}
	setSequence( ImageTheme.transition[type-1] );
	
	setFrame( transition - 1 );	
}

//
// ----- Decoration -----
//

Decoration::Decoration( Cell * parent, QCanvas *canvas)
	: GraphicalCell( parent->getRow(), parent->getCol(), canvas )
{
	_parent = parent;
	setZ( CAN_DECO );
	setFrame( 0 );
}

void Decoration::setDecoration( uint group, uint item )
{
	setSequence( ImageTheme.decoration[ group-1 ] );
	setFrame( item );

	DecorationGroup * decoGroup = DataTheme.decorations.at( group );
	
	GenericDecoration * decor = decoGroup->at( item );
	if( ( decor->getWidth() > 1 ) || ( decor->getHeight() > 1 ) ) {
		int offsetRow = decor->getHeight() - ( 1 + decor->getDoorRow() );
		int offsetCol = 0 - decor->getDoorCol();

		QRect rect = _parent->boundingRect();
		move( rect.x() + ( offsetCol * rect.width() ),
		rect.y() + rect.height() - boundingRect().height() + ( offsetRow * rect.height() ) );

		canvas()->update();
	}
}