File: surface.cpp

package info (click to toggle)
epiphany 0.7.0+0-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, sid
  • size: 7,532 kB
  • sloc: cpp: 6,404; ansic: 141; makefile: 78; sh: 7
file content (75 lines) | stat: -rw-r--r-- 2,026 bytes parent folder | download | duplicates (6)
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
/***************************************************************************
                          surface.cpp  -  description
                             -------------------
    begin                : Jun 13 2007
    copyright            : (C) 2007 by Giuseppe D'Aqui'
    email                : kumber@tiscalinet.it
 ***************************************************************************/

/***************************************************************************
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License, Version 2,      *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 ***************************************************************************/

#include "dephine.h"
#include "SDL/SDL.h"
#include "screen.h"
#include "surface.h"

void Surface::init(SDL_Surface* surface, Uint32 frame_size_x=32, Uint32 frame_size_y=32)
{
	m_surface = SDL_DisplayFormat(surface);
	
	if( m_surface == NULL )
	{
		DEBWARN( "Image display format conversion failed: "<<SDL_GetError()<<"\n");
	}
	
	m_frame_size_x=frame_size_x;
	m_frame_size_y=frame_size_y;
}

void Surface::put_screen(Sint32 x, Sint32 y, Uint32 size_x, Uint32 size_y, int frame_no)
{
	
	SDL_Rect src;
	SDL_Rect dest;
	SDL_Surface* screen = Screen::instance()->get_screen();
	if(frame_no == -1)
	{
	
		dest.x = x;
		dest.y = y;

		dest.w = size_x;
		dest.h = size_y;
		SDL_BlitSurface(m_surface, NULL,  screen, &dest);
	}
	else
	{
		src.x = (frame_no%k_max_anim)*m_frame_size_x;
		src.y = (frame_no/k_max_anim)*m_frame_size_y;
	
		src.w = m_frame_size_x;
		src.h = m_frame_size_y;
	
		dest.x = x;
		dest.y = y;

		dest.w = m_frame_size_x;
		dest.h = m_frame_size_y;
		SDL_BlitSurface(m_surface, &src,  screen, &dest);
	}
	
	
	
	
}

Surface::~Surface()
{
	SDL_FreeSurface(m_surface);
}