OSDN Git Service

ワイドサイズの動画を考慮した処理
[coroid/inqubus.git] / vhook / comment / com_surface.c
1 #include <SDL/SDL.h>
2 #include <SDL/SDL_ttf.h>
3 #include <SDL/SDL_rotozoom.h>
4 #include "com_surface.h"
5 #include "surf_util.h"
6 #include "../chat/chat.h"
7 #include "../chat/chat_slot.h"
8 #include "../nicodef.h"
9 #include "../mydef.h"
10 #include "../main.h"
11 #include "shadow.h"
12
13
14 SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str);
15
16 SDL_Surface* makeCommentSurface(COMMDATA* data,const CHAT_ITEM* item,int video_width,int video_height){
17         Uint16* index = item->str;
18         Uint16* last = item->str;
19         SDL_Surface* ret = NULL;
20         int color = item->color;
21         int size = item->size;
22
23         /*
24          * 影は置いておいて、とりあえず文字の描画
25          */
26         while(*index != '\0'){
27                 if(*index == '\n'){
28                         *index = '\0';//ここで一旦切る
29                         if(ret == null){//結局改行は無い
30                                 ret = drawText(data,size,color,last);
31                         }else{/*改行あり*/
32                                 ret = connectSurface(ret,drawText(data,size,color,last));
33                         }
34                         *index = '\n';//ここで一旦切る
35                         last = index+1;
36                 }
37                 index++;
38         }
39         if(ret == null){//結局改行は無い
40                 ret = drawText(data,size,color,item->str);
41         }else{/*改行あり*/
42                 ret = connectSurface(ret,drawText(data,size,color,last));
43         }
44         
45         if(ret->w == 0 || ret->h == 0){
46                 fprintf(data->common->log,"[comsurface/make]comment %04d has no char.\n",item->no);
47                 fflush(data->common->log);
48                 return ret;
49         }
50         
51          /*
52           * 影処理
53           */
54           int shadow = data->common->shadow_kind;
55           if(shadow >= SHADOW_MAX){
56                 shadow = SHADOW_DEFAULT;
57           }
58           ret = (*ShadowFunc[shadow])(ret,item->color == CMD_COLOR_BLACK,data->common->fontsize_fix);
59
60         /*
61          * アルファ値の設定
62          */
63          if(!data->opaque_comment){
64                 float alpha_t = (((float)(item->no)/(item->chat->max_no)) * 0.4) + 0.6;
65                 fprintf(data->common->log,"[comsurface/make]comment %04d set alpha:%5.2f%%.\n",item->no,alpha_t*100);
66                 setAlpha(ret,alpha_t);
67          }
68
69         /*
70          * スケール設定
71          */
72
73         double zoomx = 1.0f;
74         //double zoomy = 1.0f;
75         //縮小
76
77     if (data->common->fontsize_fix) {
78         const double width = (data->common->aspect_mode != 1) ? NICO_WIDTH : NICO_HD_WIDTH;
79         zoomx = (0.5f * (double) video_width) / width;
80         //zoomy = (0.5f * (double)video_height) / (double)NICO_HEIGHT;
81     }
82
83         /*スケールの調整*/
84         //if(((double)ret->h * zoomy) > ((double)video_height/3.0f)){
85         if(((double)ret->h * zoomx) > ((double)video_height/3.0f)){
86                 zoomx *= 0.5f;
87                 //zoomy *= 0.5f;
88         }
89         if(item->location != CMD_LOC_DEF && (ret->w * zoomx) > (double)video_width){
90                 double scale = ((double)video_width) / (ret->w * zoomx);
91                 zoomx *= scale;
92                 //zoomy *= scale;
93         }
94         //画面サイズに合わせて変更
95         //if(zoomx != 1.0f || zoomy != 1.0f){
96         if(zoomx != 1.0f){
97                 //fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%,%5.2f%%)\n",item->no,zoomx*100,zoomy*100);
98                 fprintf(data->common->log,"[comsurface/make]comment %04d resized.(%5.2f%%)\n",item->no,zoomx*100);
99                 fflush(data->common->log);
100                 SDL_Surface* tmp = ret;
101                 ret = zoomSurface(tmp,zoomx,zoomx,SMOOTHING_ON);
102                 SDL_FreeSurface(tmp);
103         }
104
105         return ret;
106 }
107 /**
108  * 文字を描画
109  */
110
111 SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str){
112         if(str[0] == '\0'){
113                 return SDL_CreateRGBSurface(    SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
114                                                                                 0,COMMENT_FONT_SIZE[size],32,
115                                                                                         #if SDL_BYTEORDER == SDL_BIG_ENDIAN
116                                                                                             0xff000000,
117                                                                                             0x00ff0000,
118                                                                                             0x0000ff00,
119                                                                                             0x000000ff
120                                                                                         #else
121                                                                                             0x000000ff,
122                                                                                             0x0000ff00,
123                                                                                             0x00ff0000,
124                                                                                             0xff000000
125                                                                                         #endif
126                                                                         );
127         }
128         /*
129         SDL_Surface* fmt = SDL_CreateRGBSurface(        SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
130                                                                                                 0,
131                                                                                                 0,
132                                                                                                 32,
133                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
134                                                                                                     0xff000000,
135                                                                                                     0x00ff0000,
136                                                                                                     0x0000ff00,
137                                                                                                     0x000000ff
138                                                                                                 #else
139                                                                                                     0x000000ff,
140                                                                                                     0x0000ff00,
141                                                                                                     0x00ff0000,
142                                                                                                     0xff000000
143                                                                                                 #endif
144                                                                                         );
145
146         SDL_Surface* tmp = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);
147         SDL_SetAlpha(tmp,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
148         SDL_Surface* surf = SDL_ConvertSurface(tmp,fmt->format,SDL_SRCALPHA | SDL_HWSURFACE);
149         SDL_FreeSurface(tmp);
150         SDL_FreeSurface(fmt);
151         */
152         SDL_Surface* surf = TTF_RenderUNICODE_Blended(data->common->font[size],str,COMMENT_COLOR[color]);
153         return surf;
154 }