Mercurial > hg > dmlib
annotate src/dmgfx.c @ 1315:7687412f9aef
Fix jssmod sample conversion flags storing .. urgh.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Sun, 20 Aug 2017 01:54:54 +0300 |
parents | e06abfde6c39 |
children |
rev | line source |
---|---|
0 | 1 #include "dmlib.h" |
2 | |
3 | |
4 void dmFillRect(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 col) | |
5 { | |
6 SDL_Rect rc; | |
7 rc.x = x0; | |
8 rc.y = y0; | |
9 rc.w = x1 - x0 + 1; | |
10 rc.h = y1 - y0 + 1; | |
11 SDL_FillRect(screen, &rc, col); | |
12 } | |
13 | |
14 | |
15 void dmDrawHLine(SDL_Surface *screen, int x0, int x1, int yc, const Uint32 col) | |
16 { | |
17 const int bpp = screen->format->BytesPerPixel, | |
18 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, | |
19 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, | |
20 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
21 |
0 | 22 DM_SWAP(int, x0, x1); |
23 if (yc < cy0|| yc > cy1 || x1 < cx0 || x0 > cx1) return; | |
24 if (x0 < cx0) x0 = cx0; | |
25 if (x1 > cx1) x1 = cx1; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
26 |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
27 int x = x1 - x0 + 1; |
867 | 28 Uint8 *pix = ((Uint8 *) screen->pixels) + yc * screen->pitch + (x0 * bpp); |
0 | 29 switch (screen->format->BitsPerPixel) |
30 { | |
31 case 8: | |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
32 while (x--) |
0 | 33 *pix++ = col; |
34 break; | |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
35 |
0 | 36 case 32: |
37 { | |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
38 Uint32 *p = (Uint32 *) pix; |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
39 while (x--) |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
40 *p++ = col; |
0 | 41 } |
42 break; | |
43 } | |
44 } | |
45 | |
46 | |
47 void dmDrawVLine(SDL_Surface *screen, int y0, int y1, int xc, const Uint32 col) | |
48 { | |
49 const int bpp = screen->format->BytesPerPixel, | |
50 pitch = screen->pitch / bpp, | |
51 cx0 = screen->clip_rect.x, cy0 = screen->clip_rect.y, | |
52 cx1 = screen->clip_rect.x + screen->clip_rect.w - 1, | |
53 cy1 = screen->clip_rect.y + screen->clip_rect.h - 1; | |
54 | |
55 DM_SWAP(int, y0, y1); | |
56 if (xc < cx0 || xc > cx1 || y1 < cy0 || y0 > cy1) return; | |
57 if (y0 < cy0) y0 = cy0; | |
58 if (y1 > cy1) y1 = cy1; | |
59 | |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
60 int y = y1 - y0 + 1; |
867 | 61 Uint8 *pix = ((Uint8 *) screen->pixels) + y0 * screen->pitch + (xc * bpp); |
0 | 62 switch (screen->format->BitsPerPixel) |
63 { | |
64 case 8: | |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
65 while (y--) |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
66 { |
0 | 67 *pix = col; |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
68 pix += pitch; |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
69 } |
0 | 70 break; |
1102
e06abfde6c39
Cosmetics pass: Remove excess whitespace.
Matti Hamalainen <ccr@tnsp.org>
parents:
867
diff
changeset
|
71 |
0 | 72 case 32: |
73 { | |
717
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
74 Uint32 *p = (Uint32 *) pix; |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
75 while (y--) |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
76 { |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
77 *p = col; |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
78 p += pitch; |
451fde45e116
Slightly optimize h/v-line routines.
Matti Hamalainen <ccr@tnsp.org>
parents:
325
diff
changeset
|
79 } |
0 | 80 } |
81 break; | |
82 } | |
83 } | |
84 | |
85 | |
150
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
86 void dmDrawBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 ucol, Uint32 dcol) |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
87 { |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
88 dmDrawHLine(screen, x0 , x1 - 1, y0, ucol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
89 dmDrawHLine(screen, x0 + 1, x1 , y1, dcol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
90 |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
91 dmDrawVLine(screen, y0 , y1 - 1, x0, ucol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
92 dmDrawVLine(screen, y0 + 1, y1 , x1, dcol); |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
93 } |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
94 |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
95 |
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
96 void dmFillBox3D(SDL_Surface *screen, int x0, int y0, int x1, int y1, Uint32 bgcol, Uint32 ucol, Uint32 dcol) |
0 | 97 { |
98 SDL_Rect rc; | |
99 | |
100 rc.x = x0 + 1; | |
101 rc.y = y0 + 1; | |
102 rc.w = x1 - x0 - 1; | |
103 rc.h = y1 - y0 - 1; | |
104 SDL_FillRect(screen, &rc, bgcol); | |
105 | |
150
e147c07e41cb
Add dmDrawBox3D() and dmFillBox3D().
Matti Hamalainen <ccr@tnsp.org>
parents:
118
diff
changeset
|
106 dmDrawBox3D(screen, x0, y0, x1, y1, ucol, dcol); |
0 | 107 } |