Debian Codegraph @

src/videomanager.cpp

raw symbols SCIP
1 /***************************************************************************
2 videomanager.cpp - description
3 -------------------
4 begin : Thu Aug 17 2000
5 copyright : (C) 2000 by Waldemar Baraldi
6 email : [email protected]
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
18 #include "videomanager.h"
19
20 int max(int a, int b){
21 return (a>b?a:b);
22 }
23
24 int min(int a, int b){
25 return (a<b?a:b);
26 }
27
28 VideoManager::VideoManager(int flags):Graphic(){
29 int depth;
30
31
32 Uint32 video_flags=0;
33 if (flags && FullScreen) video_flags|=SDL_FULLSCREEN;
34
35 //Init video in 640x480x16 by default
36
37 if ((depth=SDL_VideoModeOK(640, 480, 16, 0)))
38 surface=SDL_SetVideoMode(640, 480, depth, video_flags);
39 else printf("Modo no soportado\n");
40
41 im=new ImageManager();
42 nrects=0;
43 }
44
45 VideoManager::~VideoManager(){
46 surface=NULL;
47 delete im;
48 }
49
50 void VideoManager::setCaption(Str * str){
51 SDL_WM_SetCaption(str->get(), NULL);
52 delete str;
53 }
54
55 void VideoManager::blit(Surface * s, int x, int y, int rx, int ry, int rw, int rh){
56 SDL_Rect rsrc, rdst;
57
58 rsrc.x=rx;
59 rsrc.y=ry;
60 rsrc.w=rw;
61 rsrc.h=rh;
62
63 rdst.x=x;
64 rdst.y=y;
65
66 SDL_BlitSurface(s->surface, &rsrc, surface, &rdst);
67 addRect(rdst.x, rdst.y, (unsigned int)rdst.w, (unsigned int)rdst.h);
68 }
69
70 void VideoManager::blit(Surface * s, int x, int y){
71 SDL_Rect rdst;
72
73 rdst.x=x;
74 rdst.y=y;
75 SDL_BlitSurface(s->surface, NULL, surface, &rdst);
76 addRect(rdst.x, rdst.y, (unsigned int)rdst.w, (unsigned int)rdst.h);
77 }
78
79 void VideoManager::flush(){
80 SDL_UpdateRects(surface, nrects, rects);
81 nrects=0;
82 }
83
84 ImageManager * VideoManager::getImageManager(){
85 return im;
86 }
87
88 void VideoManager::fillRect(int x, int y, int w, int h, int r, int g, int b, int a){
89 Graphic::fillRect(x,y,w,h,r,g,b,a);
90
91 SDL_Rect rect;
92 rect.x=x;
93 rect.y=y;
94 rect.w=w;
95 rect.h=h;
96 addRect(rect.x, rect.y, (unsigned int)rect.w, (unsigned int)rect.h);
97 }
98
99 void VideoManager::addRect(int x, int y, unsigned int w, unsigned int h){
100 SDL_Rect rect;
101 rect.x=x;
102 rect.y=y;
103 rect.w=w;
104 rect.h=h;
105 int i=0;
106 bool ready=false;
107 while (i<nrects && !ready){
108 if ((rects[i].x==rect.x && rects[i].y==rect.y) ||
109 ((rects[i].x + rects[i].w)==(rect.x + rect.w) && rects[i].y==rect.y) ||
110 (rects[i].x==rect.x && (rects[i].y + rects[i].h)==(rect.y + rect.w)) ||
111 ((rects[i].x + rects[i].w)==(rect.x + rect.w) && (rects[i].y + rects[i].h)==(rect.y + rect.w))){
112 rects[i].x = min(rects[i].x, rect.x);
113 rects[i].y = min(rects[i].y, rect.y);
114 rects[i].w = max(rects[i].w, rect.w);
115 rects[i].h = max(rects[i].h, rect.h);
116 ready=true;
117 }
118 i++;
119 }
120 if (!ready) {
121 rects[nrects].x = rect.x;
122 rects[nrects].y = rect.y;
123 rects[nrects].w = rect.w;
124 rects[nrects].h = rect.h;
125 nrects++;
126 }
127 }
128
129