OSDN Git Service

ソースの文字コードと改行コードを修正
[coroid/inqubus.git] / vhook / comment / com_surface.c
index 8841821..0590620 100644 (file)
-#include <SDL/SDL.h>\r
-#include <SDL/SDL_ttf.h>\r
-#include <SDL/SDL_rotozoom.h>\r
-#include "com_surface.h"\r
-#include "surf_util.h"\r
-#include "../chat/chat.h"\r
-#include "../chat/chat_slot.h"\r
-#include "../nicodef.h"\r
-#include "../mydef.h"\r
-#include "../main.h"\r
-#include "shadow.h"\r
-\r
-\r
-SDL_Surface* drawText(DATA* data,int size,int color,Uint16* str);\r
-\r
-SDL_Surface* makeCommentSurface(DATA* data,const CHAT_ITEM* item,int video_width,int video_height){\r
-       Uint16* index = item->str;\r
-       Uint16* last = item->str;\r
-       SDL_Surface* ret = NULL;\r
-       int color = item->color;\r
-       int size = item->size;\r
-\r
-       /*\r
-        * \89e\82Í\92u\82¢\82Ä\82¨\82¢\82Ä\81A\82Æ\82è\82 \82¦\82¸\95\8e\9a\82Ì\95`\89æ\r
-        */\r
-       while(*index != '\0'){\r
-               if(*index == '\n'){\r
-                       *index = '\0';//\82±\82±\82Å\88ê\92U\90Ø\82é\r
-                       if(ret == null){//\8c\8b\8bÇ\89ü\8ds\82Í\96³\82¢\r
-                               ret = drawText(data,size,color,last);\r
-                       }else{/*\89ü\8ds\82 \82è*/\r
-                               ret = connectSurface(ret,drawText(data,size,color,last));\r
-                       }\r
-                       *index = '\n';//\82±\82±\82Å\88ê\92U\90Ø\82é\r
-                       last = index+1;\r
-               }\r
-               index++;\r
-       }\r
-       if(ret == null){//\8c\8b\8bÇ\89ü\8ds\82Í\96³\82¢\r
-               ret = drawText(data,size,color,item->str);\r
-       }else{/*\89ü\8ds\82 \82è*/\r
-               ret = connectSurface(ret,drawText(data,size,color,last));\r
-       }\r
-       \r
-       if(ret->w == 0 || ret->h == 0){\r
-               fprintf(data->log,"[comsurface/make]comment %04d has no char.\n",item->no);\r
-               fflush(data->log);\r
-               return ret;\r
-       }\r
-       \r
-        /*\r
-         * \89e\8f\88\97\9d\r
-         */\r
-         int shadow = data->shadow_kind;\r
-         if(shadow >= SHADOW_MAX){\r
-               shadow = SHADOW_DEFAULT;\r
-         }\r
-         ret = (*ShadowFunc[shadow])(ret,item->color == CMD_COLOR_BLACK,data->fontsize_fix);\r
-\r
-       /*\r
-        * \83A\83\8b\83t\83@\92l\82Ì\90Ý\92è\r
-        */\r
-        if(!data->opaque_comment){\r
-               float alpha_t = (((float)(item->no)/(item->chat->max_no)) * 0.4) + 0.6;\r
-               fprintf(data->log,"[comsurface/make]comment %04d set alpha:%5.2f%%.\n",item->no,alpha_t*100);\r
-               setAlpha(ret,alpha_t);\r
-        }\r
-\r
-       /*\r
-        * \83X\83P\81[\83\8b\90Ý\92è\r
-        */\r
-\r
-       double zoomx = 1.0f;\r
-       //double zoomy = 1.0f;\r
-       //\8fk\8f¬\r
-       \r
-       if(data->fontsize_fix){\r
-               zoomx = (0.5f * (double)video_width) / (double)NICO_WIDTH;\r
-               //zoomy = (0.5f * (double)video_height) / (double)NICO_HEIGHT;\r
-       }\r
-\r
-       /*\83X\83P\81[\83\8b\82Ì\92²\90®*/\r
-       //if(((double)ret->h * zoomy) > ((double)video_height/3.0f)){\r
-       if(((double)ret->h * zoomx) > ((double)video_height/3.0f)){\r
-               zoomx *= 0.5f;\r
-               //zoomy *= 0.5f;\r
-       }\r
-       if(item->location != CMD_LOC_DEF && (ret->w * zoomx) > (double)video_width){\r
-               double scale = ((double)video_width) / (ret->w * zoomx);\r
-               zoomx *= scale;\r
-               //zoomy *= scale;\r
-       }\r
-       //\89æ\96Ê\83T\83C\83Y\82É\8d\87\82í\82¹\82Ä\95Ï\8dX\r
-       //if(zoomx != 1.0f || zoomy != 1.0f){\r
-       if(zoomx != 1.0f){\r
-               //fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%,%5.2f%%)\n",item->no,zoomx*100,zoomy*100);\r
-               fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%)\n",item->no,zoomx*100);\r
-               fflush(data->log);\r
-               SDL_Surface* tmp = ret;\r
-               ret = zoomSurface(tmp,zoomx,zoomx,SMOOTHING_ON);\r
-               SDL_FreeSurface(tmp);\r
-       }\r
-\r
-       return ret;\r
-}\r
-/**\r
- * \95\8e\9a\82ð\95`\89æ\r
- */\r
-\r
-SDL_Surface* drawText(DATA* data,int size,int color,Uint16* str){\r
-       if(str[0] == '\0'){\r
-               return SDL_CreateRGBSurface(    SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,\r
-                                                                               0,COMMENT_FONT_SIZE[size],32,\r
-                                                                                       #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
-                                                                                           0xff000000,\r
-                                                                                           0x00ff0000,\r
-                                                                                           0x0000ff00,\r
-                                                                                           0x000000ff\r
-                                                                                       #else\r
-                                                                                           0x000000ff,\r
-                                                                                           0x0000ff00,\r
-                                                                                           0x00ff0000,\r
-                                                                                           0xff000000\r
-                                                                                       #endif\r
-                                                                       );\r
-       }\r
-       /*\r
-       SDL_Surface* fmt = SDL_CreateRGBSurface(        SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,\r
-                                                                                               0,\r
-                                                                                               0,\r
-                                                                                               32,\r
-                                                                                               #if SDL_BYTEORDER == SDL_BIG_ENDIAN\r
-                                                                                                   0xff000000,\r
-                                                                                                   0x00ff0000,\r
-                                                                                                   0x0000ff00,\r
-                                                                                                   0x000000ff\r
-                                                                                               #else\r
-                                                                                                   0x000000ff,\r
-                                                                                                   0x0000ff00,\r
-                                                                                                   0x00ff0000,\r
-                                                                                                   0xff000000\r
-                                                                                               #endif\r
-                                                                                       );\r
-\r
-       SDL_Surface* tmp = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);\r
-       SDL_SetAlpha(tmp,SDL_SRCALPHA | SDL_RLEACCEL,0xff);\r
-       SDL_Surface* surf = SDL_ConvertSurface(tmp,fmt->format,SDL_SRCALPHA | SDL_HWSURFACE);\r
-       SDL_FreeSurface(tmp);\r
-       SDL_FreeSurface(fmt);\r
-       */\r
-       SDL_Surface* surf = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);\r
-       return surf;\r
-}\r
+#include <SDL/SDL.h>
+#include <SDL/SDL_ttf.h>
+#include <SDL/SDL_rotozoom.h>
+#include "com_surface.h"
+#include "surf_util.h"
+#include "../chat/chat.h"
+#include "../chat/chat_slot.h"
+#include "../nicodef.h"
+#include "../mydef.h"
+#include "../main.h"
+#include "shadow.h"
+
+
+SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str);
+
+SDL_Surface* makeCommentSurface(COMMDATA* data,const CHAT_ITEM* item,int video_width,int video_height){
+       Uint16* index = item->str;
+       Uint16* last = item->str;
+       SDL_Surface* ret = NULL;
+       int color = item->color;
+       int size = item->size;
+
+       /*
+        * 影は置いておいて、とりあえず文字の描画
+        */
+       while(*index != '\0'){
+               if(*index == '\n'){
+                       *index = '\0';//ここで一旦切る
+                       if(ret == null){//結局改行は無い
+                               ret = drawText(data,size,color,last);
+                       }else{/*改行あり*/
+                               ret = connectSurface(ret,drawText(data,size,color,last));
+                       }
+                       *index = '\n';//ここで一旦切る
+                       last = index+1;
+               }
+               index++;
+       }
+       if(ret == null){//結局改行は無い
+               ret = drawText(data,size,color,item->str);
+       }else{/*改行あり*/
+               ret = connectSurface(ret,drawText(data,size,color,last));
+       }
+       
+       if(ret->w == 0 || ret->h == 0){
+               fprintf(data->common->log,"[comsurface/make]comment %04d has no char.\n",item->no);
+               fflush(data->common->log);
+               return ret;
+       }
+       
+        /*
+         * 影処理
+         */
+         int shadow = data->common->shadow_kind;
+         if(shadow >= SHADOW_MAX){
+               shadow = SHADOW_DEFAULT;
+         }
+         ret = (*ShadowFunc[shadow])(ret,item->color == CMD_COLOR_BLACK,data->common->fontsize_fix);
+
+       /*
+        * アルファ値の設定
+        */
+        if(!data->opaque_comment){
+               float alpha_t = (((float)(item->no)/(item->chat->max_no)) * 0.4) + 0.6;
+               fprintf(data->common->log,"[comsurface/make]comment %04d set alpha:%5.2f%%.\n",item->no,alpha_t*100);
+               setAlpha(ret,alpha_t);
+        }
+
+       /*
+        * スケール設定
+        */
+
+       double zoomx = 1.0f;
+       //double zoomy = 1.0f;
+       //縮小
+       
+       if(data->common->fontsize_fix){
+               zoomx = (0.5f * (double)video_width) / (double)NICO_WIDTH;
+               //zoomy = (0.5f * (double)video_height) / (double)NICO_HEIGHT;
+       }
+
+       /*スケールの調整*/
+       //if(((double)ret->h * zoomy) > ((double)video_height/3.0f)){
+       if(((double)ret->h * zoomx) > ((double)video_height/3.0f)){
+               zoomx *= 0.5f;
+               //zoomy *= 0.5f;
+       }
+       if(item->location != CMD_LOC_DEF && (ret->w * zoomx) > (double)video_width){
+               double scale = ((double)video_width) / (ret->w * zoomx);
+               zoomx *= scale;
+               //zoomy *= scale;
+       }
+       //画面サイズに合わせて変更
+       //if(zoomx != 1.0f || zoomy != 1.0f){
+       if(zoomx != 1.0f){
+               //fprintf(data->log,"[comsurface/make]comment %04d resized.(%5.2f%%,%5.2f%%)\n",item->no,zoomx*100,zoomy*100);
+               fprintf(data->common->log,"[comsurface/make]comment %04d resized.(%5.2f%%)\n",item->no,zoomx*100);
+               fflush(data->common->log);
+               SDL_Surface* tmp = ret;
+               ret = zoomSurface(tmp,zoomx,zoomx,SMOOTHING_ON);
+               SDL_FreeSurface(tmp);
+       }
+
+       return ret;
+}
+/**
+ * 文字を描画
+ */
+
+SDL_Surface* drawText(COMMDATA* data,int size,int color,Uint16* str){
+       if(str[0] == '\0'){
+               return SDL_CreateRGBSurface(    SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
+                                                                               0,COMMENT_FONT_SIZE[size],32,
+                                                                                       #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+                                                                                           0xff000000,
+                                                                                           0x00ff0000,
+                                                                                           0x0000ff00,
+                                                                                           0x000000ff
+                                                                                       #else
+                                                                                           0x000000ff,
+                                                                                           0x0000ff00,
+                                                                                           0x00ff0000,
+                                                                                           0xff000000
+                                                                                       #endif
+                                                                       );
+       }
+       /*
+       SDL_Surface* fmt = SDL_CreateRGBSurface(        SDL_SRCALPHA | SDL_HWSURFACE | SDL_HWACCEL,
+                                                                                               0,
+                                                                                               0,
+                                                                                               32,
+                                                                                               #if SDL_BYTEORDER == SDL_BIG_ENDIAN
+                                                                                                   0xff000000,
+                                                                                                   0x00ff0000,
+                                                                                                   0x0000ff00,
+                                                                                                   0x000000ff
+                                                                                               #else
+                                                                                                   0x000000ff,
+                                                                                                   0x0000ff00,
+                                                                                                   0x00ff0000,
+                                                                                                   0xff000000
+                                                                                               #endif
+                                                                                       );
+
+       SDL_Surface* tmp = TTF_RenderUNICODE_Blended(data->font[size],str,COMMENT_COLOR[color]);
+       SDL_SetAlpha(tmp,SDL_SRCALPHA | SDL_RLEACCEL,0xff);
+       SDL_Surface* surf = SDL_ConvertSurface(tmp,fmt->format,SDL_SRCALPHA | SDL_HWSURFACE);
+       SDL_FreeSurface(tmp);
+       SDL_FreeSurface(fmt);
+       */
+       SDL_Surface* surf = TTF_RenderUNICODE_Blended(data->common->font[size],str,COMMENT_COLOR[color]);
+       return surf;
+}