Freeciv-3.2
Loading...
Searching...
No Matches
graphics.c
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14/***********************************************************************
15 graphics.c - description
16 -------------------
17 begin : Mon Jul 1 2002
18 copyright : (C) 2000 by Michael Speck
19 : (C) 2002 by Rafał Bursig
20 email : Michael Speck <kulkanie@gmx.net>
21 : Rafał Bursig <bursig@poczta.fm>
22***********************************************************************/
23
24#ifdef HAVE_CONFIG_H
25#include <fc_config.h>
26#endif
27
28/* SDL3 */
29#include <SDL3_image/SDL_image.h>
30#include <SDL3_ttf/SDL_ttf.h>
31
32/* utility */
33#include "fcintl.h"
34#include "log.h"
35
36/* client */
37#include "tilespec.h"
38
39/* gui-sdl3 */
40#include "colors.h"
41#include "gui_tilespec.h"
42#include "mapview.h"
43#include "themebackgrounds.h"
44#include "themespec.h"
45
46#include "graphics.h"
47
48/* ------------------------------ */
49
51
53
54static bool render_dirty = TRUE;
55
56/**********************************************************************/
60{
61 struct gui_layer *result;
62
63 result = fc_calloc(1, sizeof(struct gui_layer));
64
65 result->dest_rect = (SDL_Rect){x, y, 0, 0};
66 result->surface = surface;
67
68 return result;
69}
70
71/**********************************************************************/
75{
76 FREESURFACE((*gui_layer)->surface);
78}
79
80/**********************************************************************/
84{
85 int i = 0;
86
87 while ((i < main_data.guis_count) && main_data.guis[i]) {
88 if (main_data.guis[i]->surface == surface) {
89 return main_data.guis[i];
90 }
91 i++;
92 }
93
94 return NULL;
95}
96
97/**********************************************************************/
106{
107 struct gui_layer *gui_layer = NULL;
108 SDL_Surface *buffer;
109
110 buffer = create_surf(width, height);
111 gui_layer = gui_layer_new(0, 0, buffer);
112
113 /* Add to buffers array */
114 if (main_data.guis) {
115 int i;
116
117 /* Find NULL element */
118 for (i = 0; i < main_data.guis_count; i++) {
119 if (!main_data.guis[i]) {
121 return gui_layer;
122 }
123 }
126 main_data.guis_count * sizeof(struct gui_layer *));
128 } else {
129 main_data.guis = fc_calloc(1, sizeof(struct gui_layer *));
132 }
133
134 return gui_layer;
135}
136
137/**********************************************************************/
142{
143 int i;
144
145 for (i = 0; i < main_data.guis_count - 1; i++) {
146 if (main_data.guis[i] && (main_data.guis[i] == gui_layer)) {
148 main_data.guis[i] = main_data.guis[i + 1];
149 main_data.guis[i + 1] = NULL;
150 } else {
151 if (!main_data.guis[i]) {
152 main_data.guis[i] = main_data.guis[i + 1];
153 main_data.guis[i + 1] = NULL;
154 }
155 }
156 }
157
160 }
161}
162
163/**********************************************************************/
168{
169 if (gui_layer) {
172 }
173}
174
175/**********************************************************************/
180{
181 if (gui_layer) {
184 }
185}
186
187/* ============ Freeciv sdl graphics function =========== */
188
189/**********************************************************************/
194 unsigned char alpha_mod)
195{
196 bool ret;
197
198 if (src == NULL || dst == NULL) {
199 return 1;
200 }
201
203
204 ret = SDL_BlitSurface(src, srcrect, dst, dstrect);
205
206 if (!ret) {
207 log_error("SDL_BlitSurface() fails: %s", SDL_GetError());
208
209 return -1;
210 }
211
212 return 0;
213}
214
215/**********************************************************************/
219 unsigned char alpha_mod)
220{
222
224}
225
226/**********************************************************************/
233{
235 prect ? prect->w : psource->w,
236 prect ? prect->h : psource->h);
237
238 if (alphablit(psource, prect, new_surf, NULL, 255) != 0) {
240
241 return NULL;
242 }
243
244 return new_surf;
245}
246
247/**********************************************************************/
258{
259 SDL_Surface *dest = NULL;
260 int row, col;
264 unsigned char src_alpha, mask_alpha;
266 = SDL_GetPixelFormatDetails(src->format);
270
271 dest = copy_surface(src);
272
274
275 lock_surf(src);
277 lock_surf(dest);
278
279 src_pixel = (Uint32 *)src->pixels;
280 dest_pixel = (Uint32 *)dest->pixels;
281
282 for (row = 0; row < src->h; row++) {
283 mask_pixel = (Uint32 *)mask->pixels
284 + mask->w * (row + mask_offset_y)
286
287 for (col = 0; col < src->w; col++) {
288 src_alpha = (*src_pixel & src_details->Amask) >> src_details->Ashift;
289 mask_alpha = (*mask_pixel & mask_details->Amask) >> mask_details->Ashift;
290
291 *dest_pixel = (*src_pixel & ~src_details->Amask)
292 | (((src_alpha * mask_alpha) / 255) << dest_details->Ashift);
293
295 }
296 }
297
298 unlock_surf(dest);
300 unlock_surf(src);
301
302 return dest;
303}
304
305/**********************************************************************/
309{
311
312 if (!fname) {
313 return NULL;
314 }
315
316 if ((buf = IMG_Load(fname)) == NULL) {
317 log_error(_("load_surf: Failed to load graphic file %s!"), fname);
318
319 return NULL;
320 }
321
322 return buf;
323}
324
325/**********************************************************************/
329 int width, int height)
330{
332
333 if (surf == NULL) {
334 log_error(_("Unable to create Sprite (Surface) of size "
335 "%d x %d %d Bits"),
337 return NULL;
338 }
339
340 return surf;
341}
342
343/**********************************************************************/
350
351/**********************************************************************/
358
359/**********************************************************************/
364{
366 SDL_Color color = {255, 255, 255, 128};
367
368 new_surf = create_surf(w, h);
369
370 if (!new_surf) {
371 return NULL;
372 }
373
374 if (!pcolor) {
375 /* pcolor->unused == ALPHA */
376 pcolor = &color;
377 }
378
381 NULL,
382 pcolor->r, pcolor->g, pcolor->b,
383 pcolor->a));
384
385 if (pcolor->a != 255) {
387 }
388
389 return new_surf;
390}
391
392/**********************************************************************/
397{
398 /* SDL_FillSurfaceRect() might change the rectangle, so we create a copy */
399 if (dstrect) {
401
402 return SDL_FillSurfaceRect(surf, &_dstrect,
404 NULL, 0, 0, 0, 0));
405 } else {
406 return SDL_FillSurfaceRect(surf, NULL,
408 NULL, 0, 0, 0, 0));
409 }
410}
411
412/**********************************************************************/
424
425/**********************************************************************/
431{
432 if (!surf) {
433 return 0x0;
434 }
435
436 switch (SDL_GetPixelFormatDetails(surf->format)->bytes_per_pixel) {
437 case 1:
438 return *(Uint8 *) ((Uint8 *) surf->pixels + y * surf->pitch + x);
439
440 case 2:
441 return *((Uint16 *)surf->pixels + y * surf->pitch / sizeof(Uint16) + x);
442
443 case 3:
444 {
445 /* Here ptr is the address to the pixel we want to retrieve */
446 Uint8 *ptr =
447 (Uint8 *) surf->pixels + y * surf->pitch + x * 3;
448
449 if (is_bigendian()) {
450 return ptr[0] << 16 | ptr[1] << 8 | ptr[2];
451 } else {
452 return ptr[0] | ptr[1] << 8 | ptr[2] << 16;
453 }
454 }
455 case 4:
456 return *((Uint32 *)surf->pixels + y * surf->pitch / sizeof(Uint32) + x);
457
458 default:
459 return 0; /* Shouldn't happen, but avoids warnings */
460 }
461}
462
463/**********************************************************************/
469{
470 if (!surf) {
471 return 0;
472 }
473
474 switch (SDL_GetPixelFormatDetails(surf->format)->bytes_per_pixel) {
475 case 1:
476 return *((Uint8 *)surf->pixels);
477
478 case 2:
479 return *((Uint16 *)surf->pixels);
480
481 case 3:
482 {
483 if (is_bigendian()) {
484 return (((Uint8 *)surf->pixels)[0] << 16)
485 | (((Uint8 *)surf->pixels)[1] << 8)
486 | ((Uint8 *)surf->pixels)[2];
487 } else {
488 return ((Uint8 *)surf->pixels)[0]
489 | (((Uint8 *)surf->pixels)[1] << 8)
490 | (((Uint8 *)surf->pixels)[2] << 16);
491 }
492 }
493 case 4:
494 return *((Uint32 *)surf->pixels);
495
496 default:
497 return 0; /* Shouldn't happen, but avoids warnings */
498 }
499}
500
501/* ===================================================================== */
502
503/**********************************************************************/
506void init_sdl(int flags)
507{
508 bool success;
509
514 main_data.dummy = NULL; /* Can't create yet -- hope we don't need it */
518
520 success = SDL_InitSubSystem(flags);
521 } else {
522 success = SDL_Init(flags);
523 }
524 if (!success) {
525 log_fatal(_("Unable to initialize SDL3 library: %s"), SDL_GetError());
527 }
528
530
531 /* Initialize the TTF library */
532 if (!TTF_Init()) {
533 log_fatal(_("Unable to initialize SDL3_ttf library: %s"), SDL_GetError());
535 }
536
538}
539
540/**********************************************************************/
543static void free_surfaces(void)
544{
545 if (main_data.renderer != NULL) {
548
550 }
551}
552
553/**********************************************************************/
557{
559
562
563 if (main_surface == NULL || main_data.map == NULL) {
564 log_fatal(_("Failed to create RGB surface: %s"), SDL_GetError());
565 return FALSE;
566 }
567
569
570 if (main_data.renderer == NULL) {
571 log_fatal(_("Failed to create renderer: %s"), SDL_GetError());
572 return FALSE;
573 }
574
578 width, height);
579
580 if (main_data.maintext == NULL) {
581 log_fatal(_("Failed to create texture: %s"), SDL_GetError());
582 return FALSE;
583 }
584
585 if (main_data.gui) {
588 } else {
590 }
591
593
594 return TRUE;
595}
596
597/**********************************************************************/
610
611/**********************************************************************/
614bool set_video_mode(unsigned width, unsigned height, unsigned flags_in)
615{
616 main_data.screen = SDL_CreateWindow(_("SDL3 Client for Freeciv"),
617 width, height, 0);
618
619 if (main_data.screen == NULL) {
620 log_fatal(_("Failed to create main window: %s"), SDL_GetError());
621 return FALSE;
622 }
623
625 const SDL_DisplayMode *mode;
626
629 width = mode->w;
630 height = mode->h;
631 }
632
634 return FALSE;
635 }
636
638 log_fatal(_("Failed to start text input: %s"), SDL_GetError());
639 return FALSE;
640 }
641
642 return TRUE;
643}
644
645/**********************************************************************/
660
661/**********************************************************************/
665{
666 return main_surface->w;
667}
668
669/**********************************************************************/
673{
674 return main_surface->h;
675}
676
677/**********************************************************************/
682{
684
685 if (prect && (prect->x < - prect->w || prect->x >= surf->w
686 || prect->y < - prect->h || prect->y >= surf->h)) {
687 return -2;
688 }
689
690 if (pcolor->a == 255) {
691 return SDL_FillSurfaceRect(surf, prect,
693 NULL,
694 pcolor->r, pcolor->g, pcolor->b));
695 }
696
697 if (!pcolor->a) {
698 return -3;
699 }
700
701 colorbar = create_surf(surf->w, surf->h);
702
705 NULL,
706 pcolor->r, pcolor->g, pcolor->b));
707
708 return alphablit(colorbar, NULL, surf, NULL, pcolor->a);
709}
710
711/**********************************************************************/
715{
716 int ww = prect->w, hh = prect->h;
717
718 if (prect->x < 0) {
719 ww += prect->x;
720 prect->x = 0;
721 }
722
723 if (prect->y < 0) {
724 hh += prect->y;
725 prect->y = 0;
726 }
727
728 if (prect->x + ww > main_window_width()) {
729 ww = main_window_width() - prect->x;
730 }
731
732 if (prect->y + hh > main_window_height()) {
733 hh = main_window_height() - prect->y;
734 }
735
736 /* End Correction */
737
738 if (ww <= 0 || hh <= 0) {
739 return FALSE; /* surprise :) */
740 } else {
741 prect->w = ww;
742 prect->h = hh;
743 }
744
745 return TRUE;
746}
747
748/**********************************************************************/
751bool is_in_rect_area(int x, int y, const SDL_Rect *rect)
752{
753 return ((x >= rect->x) && (x < rect->x + rect->w)
754 && (y >= rect->y) && (y < rect->y + rect->h));
755}
756
757/* ===================================================================== */
758
759/**********************************************************************/
763{
764 int w, h, x, y;
765 Uint16 minX, maxX, minY, maxY;
767 Uint32 mask;
768 const struct SDL_PixelFormatDetails *details
769 = SDL_GetPixelFormatDetails(surf->format);
770
771 fc_assert(surf != NULL);
772 fc_assert(rect != NULL);
773
774 minX = surf->w;
775 maxX = 0;
776 minY = surf->h;
777 maxY = 0;
778
779 if (!SDL_GetSurfaceColorKey(surf, &colorkey)) {
780 /* Use alpha instead of colorkey */
781 mask = details->Amask;
782 colorkey = 0;
783 } else {
784 mask = 0xffffffff;
785 }
786
787 lock_surf(surf);
788
789 switch (details->bytes_per_pixel) {
790 case 1:
791 {
792 Uint8 *pixel = (Uint8 *)surf->pixels;
793 Uint8 *start = pixel;
794
795 x = 0;
796 y = 0;
797 w = surf->w;
798 h = surf->h;
799 while (h--) {
800 do {
801 if (*pixel != colorkey) {
802 if (minY > y) {
803 minY = y;
804 }
805
806 if (minX > x) {
807 minX = x;
808 }
809 break;
810 }
811 pixel++;
812 x++;
813 } while (--w > 0);
814 w = surf->w;
815 x = 0;
816 y++;
817 pixel = start + surf->pitch;
818 start = pixel;
819 }
820
821 w = surf->w;
822 h = surf->h;
823 x = w - 1;
824 y = h - 1;
825 pixel = (Uint8 *)((Uint8 *)surf->pixels + (y * surf->pitch) + x);
826 start = pixel;
827 while (h--) {
828 do {
829 if (*pixel != colorkey) {
830 if (maxY < y) {
831 maxY = y;
832 }
833
834 if (maxX < x) {
835 maxX = x;
836 }
837 break;
838 }
839 pixel--;
840 x--;
841 } while (--w > 0);
842 w = surf->w;
843 x = w - 1;
844 y--;
845 pixel = start - surf->pitch;
846 start = pixel;
847 }
848 break;
849 }
850 case 2:
851 {
852 Uint16 *pixel = (Uint16 *)surf->pixels;
853 Uint16 *start = pixel;
854
855 x = 0;
856 y = 0;
857 w = surf->w;
858 h = surf->h;
859 while (h--) {
860 do {
861 if (*pixel != colorkey) {
862 if (minY > y) {
863 minY = y;
864 }
865
866 if (minX > x) {
867 minX = x;
868 }
869 break;
870 }
871 pixel++;
872 x++;
873 } while (--w > 0);
874 w = surf->w;
875 x = 0;
876 y++;
877 pixel = start + surf->pitch / 2;
878 start = pixel;
879 }
880
881 w = surf->w;
882 h = surf->h;
883 x = w - 1;
884 y = h - 1;
885 pixel = ((Uint16 *)surf->pixels + (y * surf->pitch / 2) + x);
886 start = pixel;
887 while (h--) {
888 do {
889 if (*pixel != colorkey) {
890 if (maxY < y) {
891 maxY = y;
892 }
893
894 if (maxX < x) {
895 maxX = x;
896 }
897 break;
898 }
899 pixel--;
900 x--;
901 } while (--w > 0);
902 w = surf->w;
903 x = w - 1;
904 y--;
905 pixel = start - surf->pitch / 2;
906 start = pixel;
907 }
908 break;
909 }
910 case 3:
911 {
912 Uint8 *pixel = (Uint8 *)surf->pixels;
913 Uint8 *start = pixel;
915
916 x = 0;
917 y = 0;
918 w = surf->w;
919 h = surf->h;
920 while (h--) {
921 do {
922 if (is_bigendian()) {
923 color = (pixel[0] << 16 | pixel[1] << 8 | pixel[2]);
924 } else {
925 color = (pixel[0] | pixel[1] << 8 | pixel[2] << 16);
926 }
927 if (color != colorkey) {
928 if (minY > y) {
929 minY = y;
930 }
931
932 if (minX > x) {
933 minX = x;
934 }
935 break;
936 }
937 pixel += 3;
938 x++;
939 } while (--w > 0);
940 w = surf->w;
941 x = 0;
942 y++;
943 pixel = start + surf->pitch / 3;
944 start = pixel;
945 }
946
947 w = surf->w;
948 h = surf->h;
949 x = w - 1;
950 y = h - 1;
951 pixel = (Uint8 *)((Uint8 *)surf->pixels + (y * surf->pitch) + x * 3);
952 start = pixel;
953 while (h--) {
954 do {
955 if (is_bigendian()) {
956 color = (pixel[0] << 16 | pixel[1] << 8 | pixel[2]);
957 } else {
958 color = (pixel[0] | pixel[1] << 8 | pixel[2] << 16);
959 }
960 if (color != colorkey) {
961 if (maxY < y) {
962 maxY = y;
963 }
964
965 if (maxX < x) {
966 maxX = x;
967 }
968 break;
969 }
970 pixel -= 3;
971 x--;
972 } while (--w > 0);
973 w = surf->w;
974 x = w - 1;
975 y--;
976 pixel = start - surf->pitch / 3;
977 start = pixel;
978 }
979 break;
980 }
981 case 4:
982 {
983 Uint32 *pixel = (Uint32 *)surf->pixels;
984 Uint32 *start = pixel;
985
986 x = 0;
987 y = 0;
988 w = surf->w;
989 h = surf->h;
990 while (h--) {
991 do {
992 if (((*pixel) & mask) != colorkey) {
993 if (minY > y) {
994 minY = y;
995 }
996
997 if (minX > x) {
998 minX = x;
999 }
1000 break;
1001 }
1002 pixel++;
1003 x++;
1004 } while (--w > 0);
1005 w = surf->w;
1006 x = 0;
1007 y++;
1008 pixel = start + surf->pitch / 4;
1009 start = pixel;
1010 }
1011
1012 w = surf->w;
1013 h = surf->h;
1014 x = w - 1;
1015 y = h - 1;
1016 pixel = ((Uint32 *)surf->pixels + (y * surf->pitch / 4) + x);
1017 start = pixel;
1018 while (h--) {
1019 do {
1020 if (((*pixel) & mask) != colorkey) {
1021 if (maxY < y) {
1022 maxY = y;
1023 }
1024
1025 if (maxX < x) {
1026 maxX = x;
1027 }
1028 break;
1029 }
1030 pixel--;
1031 x--;
1032 } while (--w > 0);
1033 w = surf->w;
1034 x = w - 1;
1035 y--;
1036 pixel = start - surf->pitch / 4;
1037 start = pixel;
1038 }
1039 break;
1040 }
1041 }
1042
1043 unlock_surf(surf);
1044 rect->x = minX;
1045 rect->y = minY;
1046 rect->w = maxX - minX + 1;
1047 rect->h = maxY - minY + 1;
1048}
1049
1050/**********************************************************************/
1061
1062/**********************************************************************/
1067{
1068 if (psrc == NULL) {
1069 return NULL;
1070 }
1071
1072 return zoomSurface((SDL_Surface*)psrc,
1073 (double)new_width / psrc->w,
1074 (double)new_height / psrc->h,
1075 smooth);
1076}
1077
1078/**********************************************************************/
1087 int smooth, bool scale_up,
1089{
1090 SDL_Surface *tmp_surface, *result;
1091
1092 if (psrc == NULL) {
1093 return NULL;
1094 }
1095
1096 if (!(!scale_up && ((new_width >= psrc->w) && (new_height >= psrc->h)))) {
1097 if ((new_width - psrc->w) <= (new_height - psrc->h)) {
1098 /* horizontal limit */
1100 (double)new_width / psrc->w,
1101 (double)new_width / psrc->w,
1102 smooth);
1103 } else {
1104 /* vertical limit */
1106 (double)new_height / psrc->h,
1107 (double)new_height / psrc->h,
1108 smooth);
1109 }
1110 } else {
1112 1.0,
1113 1.0,
1114 smooth);
1115 }
1116
1117 if (absolute_dimensions) {
1118 SDL_Rect area = {
1119 (new_width - tmp_surface->w) / 2,
1120 (new_height - tmp_surface->h) / 2,
1121 0, 0
1122 };
1123
1124 result = create_surf(new_width, new_height);
1125 alphablit(tmp_surface, NULL, result, &area, 255);
1127 } else {
1128 result = tmp_surface;
1129 }
1130
1131 return result;
1132}
1133
1134/**********************************************************************/
1138{
1139 SDL_Surface *copy = SDL_CreateSurface(src->w, src->h, src->format);
1140
1141 alphablit(src, NULL, copy, NULL, 255);
1142
1143 return copy;
1144}
1145
1146/* ============ Freeciv game graphics function =========== */
1147
1148/**********************************************************************/
1152{
1153 switch (type) {
1154 case TS_ISOMETRIC:
1155 case TS_OVERHEAD:
1156 return TRUE;
1157 }
1158
1159 return FALSE;
1160}
1161
1162/**********************************************************************/
1166{
1167}
1168
1169/**********************************************************************/
1175{
1176 struct color gsdl3_color = { .color = pcolor };
1179 SDL_Rect tmp, dst = { .x = left, .y = top, .w = 0, .h = 0 };
1180
1181 tmp = dst;
1182 alphablit(vertical->psurface, NULL, dest, &tmp, 255);
1183
1184 dst.x += width - 1;
1185 tmp = dst;
1186 alphablit(vertical->psurface, NULL, dest, &tmp, 255);
1187
1188 dst.x = left;
1189 tmp = dst;
1190 alphablit(horizontal->psurface, NULL, dest, &tmp, 255);
1191
1192 dst.y += height - 1;
1193 tmp = dst;
1194 alphablit(horizontal->psurface, NULL, dest, &tmp, 255);
1195
1198}
1199
1200/**********************************************************************/
1205{
1206 int xl = x0 < x1 ? x0 : x1;
1207 int xr = x0 < x1 ? x1 : x0;
1208 int yt = y0 < y1 ? y0 : y1;
1209 int yb = y0 < y1 ? y1 : y0;
1210 int w = (xr - xl) + 1;
1211 int h = (yb - yt) + 1;
1212 struct sprite *spr;
1213 SDL_Rect dst = { xl, yt, w, h };
1214 SDL_Color *pcol;
1215 struct color gsdl3_color;
1216 int l = MAX((xr - xl) + 1, (yb - yt) + 1);
1217 int i;
1218 const struct SDL_PixelFormatDetails *details;
1219
1220 pcol = fc_malloc(sizeof(pcol));
1221 pcol->r = pcolor->r;
1222 pcol->g = pcolor->g;
1223 pcol->b = pcolor->b;
1224 pcol->a = 0; /* Fill with transparency */
1225
1226 gsdl3_color.color = pcol;
1227 spr = create_sprite(w, h, &gsdl3_color);
1228
1229 lock_surf(spr->psurface);
1230 details = SDL_GetPixelFormatDetails(spr->psurface->format);
1231
1232 /* Set off transparency from pixels belonging to the line */
1233 if ((x0 <= x1 && y0 <= y1)
1234 || (x1 <= x0 && y1 <= y0)) {
1235 for (i = 0; i < l; i++) {
1236 int cx = (xr - xl) * i / l;
1237 int cy = (yb - yt) * i / l;
1238
1239 *((Uint32 *)spr->psurface->pixels + spr->psurface->w * cy + cx)
1240 |= (pcolor->a << details->Ashift);
1241 }
1242 } else {
1243 for (i = 0; i < l; i++) {
1244 int cx = (xr - xl) * i / l;
1245 int cy = yb - yt - (yb - yt) * i / l;
1246
1247 *((Uint32 *)spr->psurface->pixels + spr->psurface->w * cy + cx)
1248 |= (pcolor->a << details->Ashift);
1249 }
1250 }
1251
1252 unlock_surf(spr->psurface);
1253
1254 alphablit(spr->psurface, NULL, dest, &dst, 255);
1255
1257 free(pcol);
1258}
SDL_Surface * zoomSurface(SDL_Surface *src, double zoomx, double zoomy, int smooth)
Zoom a surface by independent horizontal and vertical factors with optional smoothing.
struct canvas int int struct sprite int int int int height
Definition canvas_g.h:44
struct canvas int int int int struct sprite *sprite struct canvas struct color * pcolor
Definition canvas_g.h:56
struct canvas int int struct sprite int int int width
Definition canvas_g.h:44
char * incite_cost
Definition comments.c:75
#define _(String)
Definition fcintl.h:67
bool is_view_supported(enum ts_type type)
Definition graphics.c:53
void tileset_type_set(enum ts_type type)
Definition graphics.c:67
GType type
Definition repodlgs.c:1313
void free_sprite(struct sprite *s)
Definition sprite.c:278
struct sprite * create_sprite(int width, int height, struct color *pcolor)
Definition sprite.c:84
SDL_Surface * resize_surface(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth)
Definition graphics.c:1235
bool set_video_mode(unsigned width, unsigned height, unsigned flags_in)
Definition graphics.c:634
int main_window_width(void)
Definition graphics.c:683
void layer_rect_to_screen_rect(struct gui_layer *gui_layer, SDL_Rect *dest_rect)
Definition graphics.c:183
SDL_Surface * load_surf(const char *fname)
Definition graphics.c:305
SDL_Surface * create_surf_with_format(SDL_PixelFormat *pf, int width, int height, Uint32 flags)
Definition graphics.c:326
void init_sdl(int flags)
Definition graphics.c:504
void update_main_screen(void)
Definition graphics.c:667
void remove_gui_layer(struct gui_layer *gui_layer)
Definition graphics.c:146
SDL_Surface * create_filled_surface(Uint16 w, Uint16 h, Uint32 flags, SDL_Color *pcolor)
Definition graphics.c:366
int fill_rect_alpha(SDL_Surface *surf, SDL_Rect *prect, SDL_Color *pcolor)
Definition graphics.c:863
void gui_layer_destroy(struct gui_layer **gui_layer)
Definition graphics.c:79
void create_line(SDL_Surface *dest, Sint16 x0, Sint16 y0, Sint16 x1, Sint16 y1, SDL_Color *pcolor)
Definition graphics.c:1377
SDL_Surface * copy_surface(SDL_Surface *src)
Definition graphics.c:1307
SDL_Surface * mask_surface(SDL_Surface *src, SDL_Surface *mask, int mask_offset_x, int mask_offset_y)
Definition graphics.c:260
struct gui_layer * gui_layer_new(int x, int y, SDL_Surface *surface)
Definition graphics.c:64
void quit_sdl(void)
Definition graphics.c:620
SDL_Surface * crop_visible_part_from_surface(SDL_Surface *psrc)
Definition graphics.c:1223
SDL_Surface * crop_rect_from_surface(SDL_Surface *psource, SDL_Rect *prect)
Definition graphics.c:234
int alphablit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Surface *dst, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:197
struct gui_layer * get_gui_layer(SDL_Surface *surface)
Definition graphics.c:88
bool is_in_rect_area(int x, int y, const SDL_Rect *rect)
Definition graphics.c:923
int screen_blit(SDL_Surface *src, SDL_Rect *srcrect, SDL_Rect *dstrect, unsigned char alpha_mod)
Definition graphics.c:221
struct sdl2_data main_data
Definition graphics.c:55
static SDL_Surface * main_surface
Definition graphics.c:57
int blit_entire_src(SDL_Surface *psrc, SDL_Surface *pdest, Sint16 dest_x, Sint16 dest_y)
Definition graphics.c:415
Uint32 get_first_pixel(SDL_Surface *surf)
Definition graphics.c:466
SDL_Surface * convert_surf(SDL_Surface *surf_in)
Definition graphics.c:357
SDL_Surface * create_surf(int width, int height, Uint32 flags)
Definition graphics.c:349
void get_smaller_surface_rect(SDL_Surface *surf, SDL_Rect *rect)
Definition graphics.c:934
struct gui_layer * add_gui_layer(int width, int height)
Definition graphics.c:110
int clear_surface(SDL_Surface *surf, SDL_Rect *dstrect)
Definition graphics.c:398
bool correct_rect_region(SDL_Rect *prect)
Definition graphics.c:886
void screen_rect_to_layer_rect(struct gui_layer *gui_layer, SDL_Rect *dest_rect)
Definition graphics.c:171
void create_frame(SDL_Surface *dest, Sint16 left, Sint16 top, Sint16 width, Sint16 height, SDL_Color *pcolor)
Definition graphics.c:1346
static void free_surfaces(void)
Definition graphics.c:541
bool create_surfaces(int width, int height)
Definition graphics.c:554
int main_window_height(void)
Definition graphics.c:691
static bool render_dirty
Definition graphics.c:59
SDL_Surface * resize_surface_box(const SDL_Surface *psrc, Uint16 new_width, Uint16 new_height, int smooth, bool scale_up, bool absolute_dimensions)
Definition graphics.c:1255
#define FREESURFACE(ptr)
Definition graphics.h:322
#define unlock_surf(surf)
Definition graphics.h:344
#define lock_surf(surf)
Definition graphics.h:333
Uint32 get_pixel(SDL_Surface *surf, int x, int y)
Definition graphics.c:430
#define fc_assert(condition)
Definition log.h:176
#define log_fatal(message,...)
Definition log.h:100
#define log_error(message,...)
Definition log.h:103
#define fc_calloc(n, esz)
Definition mem.h:38
#define FC_FREE(ptr)
Definition mem.h:41
#define fc_realloc(ptr, sz)
Definition mem.h:36
#define fc_malloc(sz)
Definition mem.h:34
#define MAX(x, y)
Definition shared.h:54
struct sprite int int int int struct sprite * mask
Definition sprite_g.h:32
struct sprite int int y
Definition sprite_g.h:31
struct sprite int int int int struct sprite int mask_offset_x
Definition sprite_g.h:32
struct sprite int x
Definition sprite_g.h:31
struct sprite int int int int struct sprite int int mask_offset_y
Definition sprite_g.h:32
Definition colors.h:21
GdkRGBA color
Definition colors.h:22
SDL_Surface * surface
Definition graphics.h:229
SDL_Rect dest_rect
Definition graphics.h:228
int guis_count
Definition graphics.h:207
SDL_Surface * dummy
Definition graphics.h:211
SDL_Renderer * renderer
Definition graphics.h:213
SDL_Texture * maintext
Definition graphics.h:212
struct gui_layer * gui
Definition graphics.h:215
int rects_count
Definition graphics.h:206
struct gui_layer ** guis
Definition graphics.h:216
SDL_Window * screen
Definition graphics.h:209
SDL_Surface * map
Definition graphics.h:210
static bool is_bigendian(void)
Definition support.h:235
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47