OSDN Git Service

index on dev20110528_setting_reduce: 9817594 フィールド名修正
[coroid/inqubus.git] / vhook / comment / com_surface.c
1 #include <SDL/SDL.h>\r
2 #include <SDL/SDL_ttf.h>\r
3 #include <SDL/SDL_rotozoom.h>\r
4 #include "com_surface.h"\r
5 #include "surf_util.h"\r
6 #include "../chat/chat.h"\r
7 #include "../chat/chat_slot.h"\r
8 #include "../nicodef.h"\r
9 #include "../mydef.h"\r
10 #include "../main.h"\r
11 #include "shadow.h"\r
12 \r
13 \r
14 SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str);\r
15 \r
16 SDL_Surface* makeCommentSurface(COMMDATA* data,const CHAT_ITEM* item,int video_width,int video_height){\r
17         Uint16* index = item->str;\r
18         Uint16* last = item->str;\r
19         SDL_Surface* ret = NULL;\r
20         int color = item->color;\r
21         int size = item->size;\r
22 \r
23         /*\r
24          * \89e\82Í\92u\82¢\82Ä\82¨\82¢\82Ä\81A\82Æ\82è\82 \82¦\82¸\95\8e\9a\82Ì\95`\89æ\r
25          */\r
26         while(*index != '\0'){\r
27                 if(*index == '\n'){\r
28                         *index = '\0';//\82±\82±\82Å\88ê\92U\90Ø\82é\r
29                         if(ret == null){//\8c\8b\8bÇ\89ü\8ds\82Í\96³\82¢\r
30                                 ret = drawText(data,size,color,last);\r
31                         }else{/*\89ü\8ds\82 \82è*/\r
32                                 ret = connectSurface(ret,drawText(data,size,color,last));\r
33                         }\r
34                         *index = '\n';//\82±\82±\82Å\88ê\92U\90Ø\82é\r
35                         last = index+1;\r
36                 }\r
37                 index++;\r
38         }\r
39         if(ret == null){//\8c\8b\8bÇ\89ü\8ds\82Í\96³\82¢\r
40                 ret = drawText(data,size,color,item->str);\r
41         }else{/*\89ü\8ds\82 \82è*/\r
42                 ret = connectSurface(ret,drawText(data,size,color,last));\r
43         }\r
44         \r
45         if(ret->w == 0 || ret->h == 0){\r
46                 fprintf(data->common->log,"[comsurface/make]comment %04d has no char.\n",item->no);\r
47                 fflush(data->common->log);\r
48                 return ret;\r
49         }\r
50         \r
51          /*\r
52           * \89e\8f\88\97\9d\r
53           */\r
54           int shadow = data->common->shadow_kind;\r
55           if(shadow >= SHADOW_MAX){\r
56                 shadow = SHADOW_DEFAULT;\r
57           }\r
58           ret = (*ShadowFunc[shadow])(ret,item->color == CMD_COLOR_BLACK,data->common->fontsize_fix);\r
59 \r
60         /*\r
61          * \83A\83\8b\83t\83@\92l\82Ì\90Ý\92è\r
62          */\r
63          if(!data->opaque_comment){\r
64                 float alpha_t = (((float)(item->no)/(item->chat->max_no)) * 0.4) + 0.6;\r
65                 fprintf(data->common->log,"[comsurface/make]comment %04d set alpha:%5.2f%%.\n",item->no,alpha_t*100);\r
66                 setAlpha(ret,alpha_t);\r
67          }\r
68 \r
69         /*\r
70          * \83X\83P\81[\83\8b\90Ý\92è\r
71          */\r
72 \r
73         double zoomx = 1.0f;\r
74         //double zoomy = 1.0f;\r
75         //\8fk\8f¬\r
76         \r
77         if(data->common->fontsize_fix){\r
78                 zoomx = (0.5f * (double)video_width) / (double)NICO_WIDTH;\r
79                 //zoomy = (0.5f * (double)video_height) / (double)NICO_HEIGHT;\r
80         }\r
81 \r
82         /*\83X\83P\81[\83\8b\82Ì\92²\90®*/\r
83         //if(((double)ret->h * zoomy) > ((double)video_height/3.0f)){\r
84         if(((double)ret->h * zoomx) > ((double)video_height/3.0f)){\r
85                 zoomx *= 0.5f;\r
86                 //zoomy *= 0.5f;\r
87         }\r
88         if(item->location != CMD_LOC_DEF && (ret->w * zoomx) > (double)video_width){\r
89                 double scale = ((double)video_width) / (ret->w * zoomx);\r
90                 zoomx *= scale;\r
91                 //zoomy *= scale;\r
92         }\r
93         //\89æ\96Ê\83T\83C\83Y\82É\8d\87\82í\82¹\82Ä\95Ï\8dX\r
94         //if(zoomx != 1.0f || zoomy != 1.0f){\r
95         if(zoomx != 1.0f){\r
96                 //fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%,%5.2f%%)\n",item->no,zoomx*100,zoomy*100);\r
97                 fprintf(data->common->log,"[comsurface/make]comment %04d resized.(%5.2f%%)\n",item->no,zoomx*100);\r
98                 fflush(data->common->log);\r
99                 SDL_Surface* tmp = ret;\r
100                 ret = zoomSurface(tmp,zoomx,zoomx,SMOOTHING_ON);\r
101                 SDL_FreeSurface(tmp);\r
102         }\r
103 \r
104         return ret;\r
105 }\r
106 /**\r
107  * \95\8e\9a\82ð\95`\89æ\r
108  */\r
109 \r
110 SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str){\r
111         if(str[0] == '\0'){\r
112                 return SDL_CreateRGBSurface(    SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,\r
113                                                                                 0,COMMENT_FONT_SIZE[size],32,\r
114                                                                                         #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
115                                                                                             0xff000000,\r
116                                                                                             0x00ff0000,\r
117                                                                                             0x0000ff00,\r
118                                                                                             0x000000ff\r
119                                                                                         #else\r
120                                                                                             0x000000ff,\r
121                                                                                             0x0000ff00,\r
122                                                                                             0x00ff0000,\r
123                                                                                             0xff000000\r
124                                                                                         #endif\r
125                                                                         );\r
126         }\r
127         /*\r
128         SDL_Surface* fmt = SDL_CreateRGBSurface(        SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,\r
129                                                                                                 0,\r
130                                                                                                 0,\r
131                                                                                                 32,\r
132                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
133                                                                                                     0xff000000,\r
134                                                                                                     0x00ff0000,\r
135                                                                                                     0x0000ff00,\r
136                                                                                                     0x000000ff\r
137                                                                                                 #else\r
138                                                                                                     0x000000ff,\r
139                                                                                                     0x0000ff00,\r
140                                                                                                     0x00ff0000,\r
141                                                                                                     0xff000000\r
142                                                                                                 #endif\r
143                                                                                         );\r
144 \r
145         SDL_Surface* tmp = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);\r
146         SDL_SetAlpha(tmp,SDL_SRCALPHA | SDL_RLEACCEL,0xff);\r
147         SDL_Surface* surf = SDL_ConvertSurface(tmp,fmt->format,SDL_SRCALPHA | SDL_HWSURFACE);\r
148         SDL_FreeSurface(tmp);\r
149         SDL_FreeSurface(fmt);\r
150         */\r
151         SDL_Surface* surf = TTF_RenderUNICODE_Blended(data->common->font[size],str,COMMENT_COLOR[color]);\r
152         return surf;\r
153 }\r