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                 zoomx = (0.5f * (double)video_width) / (double)NICO_WIDTH;
79                 //zoomy = (0.5f * (double)video_height) / (double)NICO_HEIGHT;
80         }
81
82         /*スケールの調整*/
83         //if(((double)ret->h * zoomy) > ((double)video_height/3.0f)){
84         if(((double)ret->h * zoomx) > ((double)video_height/3.0f)){
85                 zoomx *= 0.5f;
86                 //zoomy *= 0.5f;
87         }
88         if(item->location != CMD_LOC_DEF && (ret->w * zoomx) > (double)video_width){
89                 double scale = ((double)video_width) / (ret->w * zoomx);
90                 zoomx *= scale;
91                 //zoomy *= scale;
92         }
93         //画面サイズに合わせて変更
94         //if(zoomx != 1.0f || zoomy != 1.0f){
95         if(zoomx != 1.0f){
96                 //fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%,%5.2f%%)\n",item->no,zoomx*100,zoomy*100);
97                 fprintf(data->common->log,"[comsurface/make]comment %04d resized.(%5.2f%%)\n",item->no,zoomx*100);
98                 fflush(data->common->log);
99                 SDL_Surface* tmp = ret;
100                 ret = zoomSurface(tmp,zoomx,zoomx,SMOOTHING_ON);
101                 SDL_FreeSurface(tmp);
102         }
103
104         return ret;
105 }
106 /**
107  * 文字を描画
108  */
109
110 SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str){
111         if(str[0] == '\0'){
112                 return SDL_CreateRGBSurface(    SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
113                                                                                 0,COMMENT_FONT_SIZE[size],32,
114                                                                                         #if SDL_BYTEORDER == SDL_BIG_ENDIAN
115                                                                                             0xff000000,
116                                                                                             0x00ff0000,
117                                                                                             0x0000ff00,
118                                                                                             0x000000ff
119                                                                                         #else
120                                                                                             0x000000ff,
121                                                                                             0x0000ff00,
122                                                                                             0x00ff0000,
123                                                                                             0xff000000
124                                                                                         #endif
125                                                                         );
126         }
127         /*
128         SDL_Surface* fmt = SDL_CreateRGBSurface(        SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
129                                                                                                 0,
130                                                                                                 0,
131                                                                                                 32,
132                                                                                                 #if SDL_BYTEORDER == SDL_BIG_ENDIAN
133                                                                                                     0xff000000,
134                                                                                                     0x00ff0000,
135                                                                                                     0x0000ff00,
136                                                                                                     0x000000ff
137                                                                                                 #else
138                                                                                                     0x000000ff,
139                                                                                                     0x0000ff00,
140                                                                                                     0x00ff0000,
141                                                                                                     0xff000000
142                                                                                                 #endif
143                                                                                         );
144
145         SDL_Surface* tmp = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);
146         SDL_SetAlpha(tmp,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
147         SDL_Surface* surf = SDL_ConvertSurface(tmp,fmt->format,SDL_SRCALPHA | SDL_HWSURFACE);
148         SDL_FreeSurface(tmp);
149         SDL_FreeSurface(fmt);
150         */
151         SDL_Surface* surf = TTF_RenderUNICODE_Blended(data->common->font[size],str,COMMENT_COLOR[color]);
152         return surf;
153 }