-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcase_type.c
More file actions
93 lines (73 loc) · 2.23 KB
/
case_type.c
File metadata and controls
93 lines (73 loc) · 2.23 KB
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#include "main.h"
int is_piece_a_piece(enum CaseType p)
{
if(p!=wblank&&p!=bblank)return 1;
else return 0;
}
enum piece find_piece_from_CT(enum CaseType p)
{
if(p/12==2)return NOTPIECE;
p%=12;
p/=2;
return p;
}
enum piece_color find_piece_color(enum CaseType p)
{
// if(find_piece_from_CT(p)!=NOTPIECE)
if(p%2) return BLACK;
else return WHITE;
//return NOCOL;
}
enum piece_color find_piece_bg_color(enum CaseType p)
{
if(p==wblank)return WHITE;
if(p<12) return WHITE;
else return BLACK;
}
enum CaseType change_piece_bg_color(enum CaseType p, enum piece_color bg)
{
//check if bg color match with target color;
int c=find_piece_bg_color(p);
if(c==bg);
else p+=12*(1-2*c); //hack modify bg color of piece
return p;
}
enum piece_color square_color(int i, int j)
{
if((i+j)%2)return BLACK;
else return WHITE;
}
char CaseType_char_association[]="klqwrtbvnmpoKLQWRTBVNMPO +";
SDL_Texture* CaseType_texture_association[NBCASETYPE];
int translate_char_to_case_type(char c)
{
int i; for(i=0;i<NBCASETYPE;i++)if(CaseType_char_association[i]==c)return i;
return 0;
}
int init_CaseType()
{
// load font.ttf at size 16 into font
TTF_Font *font;
font=TTF_OpenFont("CHESS3.TTF", G.B.Csize);
if(!font)
printf("TTF_OpenFont: %s\n", TTF_GetError());
SDL_Color color={0x00,0x00,0x00};
SDL_Surface *s;
int i; for(i=0;i<NBCASETYPE;i++){char Cur[2];Cur[0]=CaseType_char_association[i];Cur[1]=0;
if(!(s=TTF_RenderText_Blended(font,Cur,color)))
printf("TTF_OpenFont: %s\n", TTF_GetError());
CaseType_texture_association[i] = SDL_CreateTextureFromSurface(V.renderer, s);
SDL_SetTextureBlendMode(CaseType_texture_association[i],
SDL_BLENDMODE_BLEND);
SDL_SetTextureAlphaMod(CaseType_texture_association[i],
255);
SDL_FreeSurface(s);
}
G.B.back=SDL_CreateTexture(V.renderer,
SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING,
G.B.Csize,
G.B.Csize); //create texture of dynamic background behind piece to be dragged
G.B.img=calloc(G.B.Vscreen_board_association.w*G.B.Vscreen_board_association.h,4);
TTF_CloseFont(font);
return 1;
}