comparison scn2k/scn2k_text.h @ 56:c7bcc0ec2267

* replaced Grp and Text classes by the TextImpl and GrpImpl ones * splitted scn2k.h into smaller header files * moved some definitions from scn2k_*.cc to the header files * moved opcode implementation to scn2k_*impl.cc
author thib
date Thu, 30 Apr 2009 19:05:09 +0000
parents
children 6d9146f56ccf
comparison
equal deleted inserted replaced
55:f1a27ee7e03c 56:c7bcc0ec2267
1 /*
2 * Copyright (c) 2009 Thibaut GIRKA
3 * Copyright (c) 2004-2006 Kazunori "jagarl" Ueno
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #ifndef __SCN2K_TEXT_H__
30 #define __SCN2K_TEXT_H__
31
32 #include <vector>
33 #include <map>
34 #include <list>
35
36 #include "scn2k_cmd.h"
37
38 #include "window/event.h"
39 #include "window/picture.h"
40 #include "window/widget.h"
41
42 #include "font/text.h"
43
44 #include "system/system_config.h"
45
46 using namespace std;
47
48 void dprintf(const char* fmt, ...); //FIXME
49 void eprintf(const char* fmt, ...); //FIXME
50
51 // kanji conv : デバッグ表示用
52 void kconv(const unsigned char* src, unsigned char* dest);
53 void kconv_rev(const unsigned char* src, unsigned char* dest);
54 string kconv(const string& s);
55 string kconv_rev(const string& s);
56
57 /**************************************************************::
58 **
59 ** TimerAtom
60 */
61
62 struct TimerAtom {
63 int from;
64 int to;
65 unsigned int start_time;
66 unsigned int total_time;
67 };
68
69
70 /**************************************************************::
71 **
72 ** BacklogItem
73 */
74
75 struct BacklogItem {
76 enum {SaveSelect = -2};
77 int scn, pos;
78 int koe;
79 std::string face;
80 struct TextStream text;
81 BacklogItem(void);
82 void Clear(void);
83 void AddTextPos(Cmd&);
84 void DeleteTextPos();
85 void SetSavepos(int pos);
86 BacklogItem& operator =(const BacklogItem&);
87 };
88
89 /**************************************************************::
90 **
91 ** TextWindow
92 */
93
94 struct TextWindow {
95 /* @@@ : SetWindowColor での surface 再設定に注意 */
96 WidText* wid;
97 bool name_visible;
98 WidLabel* name;
99 PicContainer* name_container;
100 PicBase* face;
101 PicBase* face_pics[8];
102 TextWindow(PicContainer& parent, Event::Container& event, int window_no, void* callback);
103 ~TextWindow();
104 Rect WakuSize(PicContainer& pic, int waku_no);
105 void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, void* callback);
106 void show(void);
107 void hide(void);
108 void ShowFace(const char* path);
109 void ResetFace(void);
110 void StartText(const TextStream& _stream);
111 void SetName(const char* n);
112 };
113
114 /**************************************************************::
115 **
116 ** SaveFaceHash
117 */
118
119 struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う
120 map<string, int> facetonum;
121 typedef pair<string,int> Node;
122 typedef list<Node> List;
123 List container;
124 int id_max;
125 static int size_max;
126 SaveFaceHash() : id_max(0) {}
127 void NewNode(string face, int face_id);
128 int Add(string face);
129 string Get(int num);
130 };
131
132
133 /**************************************************************::
134 **
135 ** Text
136 */
137
138 class Text : public CommandHandler {
139 public:
140 Text(Event::Container& _event, PicContainer& _parent);
141 ~Text();
142 void InitWindow(void);
143 void Exec(Cmd& cmd);
144 bool Wait(unsigned int current_time, Cmd& cmd);
145 void SetSkipMode(SkipMode _mode);
146 void hide(void);
147 void show(void) { show(text_window_number); }
148 void show(int num);
149 void Save(std::string& str, bool select_save);
150 void Load(const char* str);
151 void DrawBacklog(BacklogItem& item, Cmd& cmd);
152
153 static void PressFuncSkip(void* pointer, WidButton* from);
154 static void PressFuncLoad(void* pointer, WidButton* from);
155 static void PressFuncSave(void* pointer, WidButton* from);
156 static void PressFuncBacklog(void* pointer, WidButton* from);
157 static void PressFuncBacklogFwd(void* pointer, WidButton* from);
158
159 private:
160 void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
161 void SetTextSpeed(int new_speed);
162 void SetTextWait(int new_wait);
163
164 void CreateSelect(Cmd& cmd);
165 void CreateSelBG(void);
166
167 void AddText(const char* str);
168
169 static void PressFuncButton(void* pointer, WidButton* from);
170 static bool PressFunc(int x, int y, void* pointer);
171
172 void SetCursor(int num);
173
174 public:
175 vector<BacklogItem> backlog;
176 BacklogItem backlog_item;
177 TextWindow* text;
178 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
179 WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
180 WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
181 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
182 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
183 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
184 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
185 BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
186 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK |
187 LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD |
188 BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK |
189 CLEARSCR_WAIT_MASK | SKIPEND_MASK)
190 } Status;
191 Status status, status_saved, status_mask;
192
193 private:
194 std::string ruby_text;
195 bool ruby_text_flag;
196 unsigned int wait_time;
197 unsigned int old_time;
198 unsigned int base_time;
199 int text_window_number;
200 bool text_parsing;
201 TextStream text_stream;
202 SkipMode skip_mode;
203 int save_selectcount;
204
205 std::map<int, TimerAtom> timer_var;
206 std::vector<WidTextButton*> selects;
207 std::vector<int> sel_backlog_pos;
208 string replace_name[26];
209 string replace_name2[26];
210 PicContainer* sel_widget;
211 PicWidget* backlog_widget;
212
213 BacklogItem cur_backlog_item;
214 BacklogItem drawn_backlog_item;
215
216 TextWindow* widgets[32];
217 WidTimeCursor* kcursor;
218 Surface* sel_bg1;
219 Surface* sel_bg2;
220 Rect sel_bg_rect;
221
222 VarInfo wait_savedvar[2];
223
224 AyuSysConfig *config;
225
226 Event::Container& event;
227 PicContainer& parent;
228
229 //Opcode handling
230 void impl_txtClear(Cmd& cmd);
231 void impl_logKoe(Cmd& cmd);
232 void impl_pause(Cmd& cmd);
233 void impl_br(Cmd& cmd);
234 void impl_FaceOpen(Cmd& cmd);
235 void impl_FaceClear(Cmd& cmd);
236 void impl_doRuby(Cmd& cmd);
237 void impl_TextWindow(Cmd& cmd);
238 void impl_msgClear(Cmd& cmd);
239 void impl_FastText(Cmd& cmd);
240 void impl_createSelect(Cmd& cmd);
241 void impl_ShowBackground(Cmd& cmd);
242 void impl_SetSkipMode(Cmd& cmd);
243 void impl_Wait(Cmd& cmd);
244 };
245
246 #endif