Mercurial > otakunoraifu
comparison window/render.cc @ 52:15a18fbe6f21
* Known bugs added to the README
* Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author | thib |
---|---|
date | Sat, 18 Apr 2009 18:35:39 +0000 |
parents | 223b71206888 |
children | c7bcc0ec2267 |
comparison
equal
deleted
inserted
replaced
51:cbb301016a4e | 52:15a18fbe6f21 |
---|---|
23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 */ | 26 */ |
27 | 27 |
28 #include"font/font.h" | 28 #include "font/font.h" |
29 #include"font/text.h" | 29 #include "font/text.h" |
30 #include"rect.h" | 30 #include "rect.h" |
31 #include"SDL.h" | 31 #include "SDL.h" |
32 #include"surface.h" | 32 #include "surface.h" |
33 #include<stdio.h> | 33 #include <stdio.h> |
34 | 34 |
35 Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect, | 35 Rect DSurfaceRenderText(TextGlyphStream::iterator start, TextGlyphStream::iterator end, const Rect& srcrect, |
36 Surface* dst, const Rect& dstrect); // 文字描画 | 36 Surface* dst, const Rect& dstrect); // 文字描画 |
37 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a); // クリア | 37 void DSurfaceFill(Surface* src, const Rect& rect, int r, int g, int b, int a); // クリア |
38 void DSurfaceFillA(Surface* src, const Rect& rect, int r, int g, int b, int a); // テキストウィンドウ背景の設定 | 38 void DSurfaceFillA(Surface* src, const Rect& rect, int r, int g, int b, int a); // テキストウィンドウ背景の設定 |
56 Rect::Rect(const class Surface& so) { | 56 Rect::Rect(const class Surface& so) { |
57 SDL_Surface* s = (SDL_Surface*)(&so); | 57 SDL_Surface* s = (SDL_Surface*)(&so); |
58 lx = 0; ty = 0; | 58 lx = 0; ty = 0; |
59 rx = s->w; by = s->h; | 59 rx = s->w; by = s->h; |
60 } | 60 } |
61 | |
61 inline Rect _Rect(const SDL_Rect& r) { | 62 inline Rect _Rect(const SDL_Rect& r) { |
62 return Rect(r.x, r.y, r.x+r.w, r.y+r.h); | 63 return Rect(r.x, r.y, r.x+r.w, r.y+r.h); |
63 }; | 64 } |
65 | |
64 inline SDL_Rect SDLed(const Rect& rect) { | 66 inline SDL_Rect SDLed(const Rect& rect) { |
65 SDL_Rect r; | 67 SDL_Rect r; |
66 r.x = rect.lx; | 68 r.x = rect.lx; |
67 r.y = rect.ty; | 69 r.y = rect.ty; |
68 r.w = rect.rx-rect.lx; | 70 r.w = rect.rx-rect.lx; |
149 } | 151 } |
150 SDL_UnlockSurface(dst); | 152 SDL_UnlockSurface(dst); |
151 drawn_rect.rmove(dif_x, dif_y); | 153 drawn_rect.rmove(dif_x, dif_y); |
152 return drawn_rect; | 154 return drawn_rect; |
153 } | 155 } |
156 | |
154 void DSurfaceFill(Surface* src_o, const Rect& rect, int r, int g, int b, int a) { | 157 void DSurfaceFill(Surface* src_o, const Rect& rect, int r, int g, int b, int a) { |
155 SDL_Rect sr = SDLed(rect); | 158 SDL_Rect sr = SDLed(rect); |
156 SDL_Surface* src = (SDL_Surface*)src_o; | 159 SDL_Surface* src = (SDL_Surface*)src_o; |
157 SDL_FillRect( src, &sr, SDL_MapRGBA(src->format, r, g, b, a)); | 160 SDL_FillRect( src, &sr, SDL_MapRGBA(src->format, r, g, b, a)); |
158 return; | |
159 } | 161 } |
160 | 162 |
161 static void clip_rect(Rect& srcrect, Rect& dstrect, SDL_Surface* dstsurf) { | 163 static void clip_rect(Rect& srcrect, Rect& dstrect, SDL_Surface* dstsurf) { |
162 Rect confine_to(srcrect); | 164 Rect confine_to(srcrect); |
163 Rect dst_clip(_Rect(dstsurf->clip_rect)); | 165 Rect dst_clip(_Rect(dstsurf->clip_rect)); |
210 dmem += dbpl; smem += sbpl; | 212 dmem += dbpl; smem += sbpl; |
211 } | 213 } |
212 } | 214 } |
213 SDL_UnlockSurface(dst); | 215 SDL_UnlockSurface(dst); |
214 SDL_UnlockSurface(src); | 216 SDL_UnlockSurface(src); |
215 return; | |
216 } | 217 } |
217 | 218 |
218 void DSurfaceFillA(Surface* dsto, const Rect& rect, int r, int g, int b, int a) { | 219 void DSurfaceFillA(Surface* dsto, const Rect& rect, int r, int g, int b, int a) { |
219 SDL_Surface* dst = (SDL_Surface*)dsto; | 220 SDL_Surface* dst = (SDL_Surface*)dsto; |
220 SDL_LockSurface( dst); | 221 SDL_LockSurface( dst); |
227 | 228 |
228 char* dmem = (char*)(dst->pixels) + rect.ty*dbpl + rect.lx*bpp; | 229 char* dmem = (char*)(dst->pixels) + rect.ty*dbpl + rect.lx*bpp; |
229 unsigned int pixel = SDL_MapRGBA(dst->format, r, g, b, 0); | 230 unsigned int pixel = SDL_MapRGBA(dst->format, r, g, b, 0); |
230 unsigned int pixela = SDL_MapRGBA(dst->format, r, g, b, a); | 231 unsigned int pixela = SDL_MapRGBA(dst->format, r, g, b, a); |
231 a += a>>7; /* 0-256 にする */ | 232 a += a>>7; /* 0-256 にする */ |
232 int i,j; | 233 int i, j; |
233 for (i=0; i<height; i++) { | 234 for (i=0; i<height; i++) { |
234 char* d = dmem; | 235 char* d = dmem; |
235 if (bpp == 4) { | 236 if (bpp == 4) { |
236 for (j=0; j<width; j++) { | 237 for (j=0; j<width; j++) { |
237 int alpha = (*(Uint32*)d)>>ashift; | 238 int alpha = (*(Uint32*)d)>>ashift; |
250 } | 251 } |
251 } | 252 } |
252 dmem += dbpl; | 253 dmem += dbpl; |
253 } | 254 } |
254 SDL_UnlockSurface( dst); | 255 SDL_UnlockSurface( dst); |
255 return; | |
256 } | 256 } |
257 | 257 |
258 #define ASHIFT 24 | 258 #define ASHIFT 24 |
259 #define CMASK1 0xff00ff | 259 #define CMASK1 0xff00ff |
260 #define CMASK2 0x00ff00 | 260 #define CMASK2 0x00ff00 |
277 s &= CMASK2; | 277 s &= CMASK2; |
278 d &= CMASK2; | 278 d &= CMASK2; |
279 d = (d + (((s-d) * as) >> 8)) & CMASK2; | 279 d = (d + (((s-d) * as) >> 8)) & CMASK2; |
280 *dmem = d1 | d | 0xff000000; | 280 *dmem = d1 | d | 0xff000000; |
281 } | 281 } |
282 | |
282 static void blit_line(Uint32* dmem, Uint32* smem, const unsigned char* amem,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { | 283 static void blit_line(Uint32* dmem, Uint32* smem, const unsigned char* amem,int ax0, int ax1, int awidth, int aj0, int aj1, bool use_srcalpha) { |
283 int j; | 284 int j; |
284 int ax = ax0; | 285 int ax = ax0; |
285 const unsigned char* a = amem + ax0; | 286 const unsigned char* a = amem + ax0; |
286 Uint32* d = dmem; | 287 Uint32* d = dmem; |
349 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, true); | 350 blit_line( (Uint32*)dmem, (Uint32*)smem, amem,ax0, ax1, awidth, aj0, aj1, true); |
350 amem += awidth; dmem += dbpl; smem += sbpl; | 351 amem += awidth; dmem += dbpl; smem += sbpl; |
351 } | 352 } |
352 SDL_UnlockSurface(src); | 353 SDL_UnlockSurface(src); |
353 SDL_UnlockSurface(dst); | 354 SDL_UnlockSurface(dst); |
354 return; | 355 } |
355 } | 356 |
356 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { | 357 void DSurfaceBlitSaturate(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o, unsigned char alpha) { |
357 SDL_Surface* dst = (SDL_Surface*)dst_o; | 358 SDL_Surface* dst = (SDL_Surface*)dst_o; |
358 SDL_Surface* src = (SDL_Surface*)src_o; | 359 SDL_Surface* src = (SDL_Surface*)src_o; |
359 | 360 |
360 if (dst->format->BytesPerPixel != src->format->BytesPerPixel) return; // RGB変換はできない | 361 if (dst->format->BytesPerPixel != src->format->BytesPerPixel) return; // RGB変換はできない |
405 } | 406 } |
406 dmem += dbpl; smem += sbpl; | 407 dmem += dbpl; smem += sbpl; |
407 } | 408 } |
408 SDL_UnlockSurface(src); | 409 SDL_UnlockSurface(src); |
409 SDL_UnlockSurface(dst); | 410 SDL_UnlockSurface(dst); |
410 return; | 411 } |
411 } | 412 |
412 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o) { | 413 void DSurfaceBlitMultiply(Surface* src_o, const Rect& srcrect_o, Surface* dst_o, const Rect& dstrect_o) { |
413 SDL_Surface* dst = (SDL_Surface*)dst_o; | 414 SDL_Surface* dst = (SDL_Surface*)dst_o; |
414 SDL_Surface* src = (SDL_Surface*)src_o; | 415 SDL_Surface* src = (SDL_Surface*)src_o; |
415 | 416 |
416 Rect srcrect(srcrect_o), dstrect(dstrect_o); | 417 Rect srcrect(srcrect_o), dstrect(dstrect_o); |
468 fprintf(stderr,"multipy_blit : surface does not have unique color(%08x); %d pixels in width %d, height %d\n", | 469 fprintf(stderr,"multipy_blit : surface does not have unique color(%08x); %d pixels in width %d, height %d\n", |
469 src_pixel, err_count, width, height); | 470 src_pixel, err_count, width, height); |
470 } | 471 } |
471 SDL_UnlockSurface(dst); | 472 SDL_UnlockSurface(dst); |
472 SDL_UnlockSurface(src); | 473 SDL_UnlockSurface(src); |
473 return; | 474 } |
474 } |