OSDN Git Service

文字コード、改行コード修正
[coroid/inqubus.git] / vhook / chat / process_chat.c
1 #include <SDL/SDL.h>
2 #include "chat.h"
3 #include "chat_slot.h"
4 #include "process_chat.h"
5 #include "../main.h"
6 #include "../mydef.h"
7
8 //このソース内でしか使わないメソッド
9 void drawComment(SDL_Surface* surf,CHAT_SLOT* slot,int now_vpos);
10
11 /**
12  * コメントを描画する。
13  */
14 int chat_process(COMMDATA* data,SDL_Surface* surf,const int now_vpos){
15         CHAT* chat = &data->chat;
16         CHAT_SLOT* slot = &data->slot;
17         FILE* log = data->common->log;
18         /*見せないものを削除*/
19         CHAT_SLOT_ITEM* slot_item;
20         CHAT_ITEM* chat_item;
21         resetChatSlotIterator(slot);
22         while((slot_item = getChatSlotErased(slot,now_vpos)) != NULL){
23                 chat_item = slot_item->chat_item;
24                 fprintf(log,"[process-chat/process]<vpos:%6d>com%4d<color:%2d loc:%2d size:%2d %6d-%6d(%6d)> erased. \n",now_vpos,chat_item->no,chat_item->color,chat_item->location,chat_item->size,chat_item->vstart,chat_item->vend,chat_item->vpos);
25                 fflush(log);
26                 deleteChatSlot(slot,slot_item);
27         }
28         /*見せるものをセット*/
29         resetChatIterator(chat);
30         while((chat_item = getChatShowed(chat,now_vpos)) != NULL){
31                 fprintf(log,"[process-chat/process]<vpos:%6d>com%4d<color:%2d loc:%2d size:%2d %6d-%6d(%6d)> added. \n",now_vpos,chat_item->no,chat_item->color,chat_item->location,chat_item->size,chat_item->vstart,chat_item->vend,chat_item->vpos);
32                 fflush(log);
33                 addChatSlot(data,slot,chat_item,surf->w,surf->h);
34         }
35         drawComment(surf,slot,now_vpos);
36         return TRUE;
37 }
38
39 /*
40  * レイヤ順にそって描画する
41  */
42
43 void drawComment(SDL_Surface* surf,CHAT_SLOT* slot,int now_vpos){
44         int i;
45         SDL_Rect rect;
46         int max_item = slot->max_item;
47         CHAT_SLOT_ITEM* item;
48         for(i=0;i<max_item;i++){
49                 item = &slot->item[i];
50                 if(item->used){
51                         rect.x = getX(now_vpos,item,surf->w);
52                         rect.y = item->y;
53                         SDL_BlitSurface(item->surf,NULL,surf,&rect);
54                 }
55         }
56 }
57
58 /*
59  * 位置を求める
60  */
61 int getX(int now_vpos,const CHAT_SLOT_ITEM* item,int video_width){
62         int text_width = item->surf->w;
63         int width = video_width;
64         if(item->chat_item->location != CMD_LOC_DEF){
65                 return (width - text_width) >>1;
66         }else{
67                 int tmp = now_vpos - item->chat_item->vpos + TEXT_AHEAD_SEC;
68                 return width - ((tmp * (width + text_width)) / TEXT_SHOW_SEC);
69         }
70         return -1;
71 }