root/scn2k/scn2k_text.h

Revision 59:36d92d21300f, 8.2 KB (checked in by Thibaut GIRKA <thib@…>, 2 years ago)
Implemented sin opcode
Line 
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
46using namespace std;
47
48void dprintf(const char* fmt, ...); //FIXME
49void eprintf(const char* fmt, ...); //FIXME
50
51// kanji conv : デバッグ衚瀺甚
52void kconv(const unsigned char* src, unsigned char* dest);
53void kconv_rev(const unsigned char* src, unsigned char* dest);
54string kconv(const string& s);
55string kconv_rev(const string& s);
56
57/**************************************************************::
58**
59** TimerAtom
60*/
61
62struct TimerAtom {
63        unsigned int start_time;
64};
65
66struct FrameTimerAtom : TimerAtom {
67        int from;
68        int to;
69        unsigned int total_time;
70};
71
72
73/**************************************************************::
74**
75** BacklogItem
76*/
77
78struct BacklogItem {
79        enum {SaveSelect = -2};
80        int scn, pos;
81        int koe;
82        std::string face;
83        struct TextStream text;
84        BacklogItem(void);
85        void Clear(void);
86        void AddTextPos(Cmd&);
87        void DeleteTextPos();
88        void SetSavepos(int pos);
89        BacklogItem& operator =(const BacklogItem&);
90};
91
92/**************************************************************::
93**
94** TextWindow
95*/
96
97struct TextWindow {
98/* @@@ : SetWindowColor での surface 再蚭定に泚意 */
99        WidText* wid;
100        bool name_visible;
101        WidLabel* name;
102        PicContainer* name_container;
103        PicBase* face;
104        PicBase* face_pics[8];
105        TextWindow(PicContainer& parent, Event::Container& event, int window_no, void* callback);
106        ~TextWindow();
107        Rect WakuSize(PicContainer& pic, int waku_no);
108        void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, void* callback);
109        void show(void);
110        void hide(void);
111        void ShowFace(const char* path);
112        void ResetFace(void);
113        void StartText(const TextStream& _stream);
114        void SetName(const char* n);
115};
116
117/**************************************************************::
118**
119** SaveFaceHash
120*/
121
122struct SaveFaceHash { // バックログセヌブ時の顔画像管理を行う
123        map<string, int> facetonum;
124        typedef pair<string,int> Node;
125        typedef list<Node> List;
126        List container;
127        int id_max;
128        static int size_max;
129        SaveFaceHash() : id_max(0) {}
130        void NewNode(string face, int face_id);
131        int Add(string face);
132        string Get(int num);
133};
134
135
136/**************************************************************::
137**
138** Text
139*/
140
141class Text : public CommandHandler {
142        public:
143                Text(Event::Container& _event, PicContainer& _parent);
144                ~Text();
145                void InitWindow(void);
146                void Exec(Cmd& cmd);
147                bool Wait(unsigned int current_time, Cmd& cmd);
148                void SetSkipMode(SkipMode _mode);
149                void hide(void);
150                void show(void) { show(text_window_number); }
151                void show(int num);
152                void Save(std::string& str, bool select_save);
153                void Load(const char* str);
154                void DrawBacklog(BacklogItem& item, Cmd& cmd);
155
156                static void PressFuncSkip(void* pointer, WidButton* from);
157                static void PressFuncLoad(void* pointer, WidButton* from);
158                static void PressFuncSave(void* pointer, WidButton* from);
159                static void PressFuncBacklog(void* pointer, WidButton* from);
160                static void PressFuncBacklogFwd(void* pointer, WidButton* from);
161
162        private:
163                void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
164                void SetTextSpeed(int new_speed);
165                void SetTextWait(int new_wait);
166
167                void CreateSelect(Cmd& cmd);
168                void CreateSelBG(void);
169
170                void AddText(const char* str);
171
172                static void PressFuncButton(void* pointer, WidButton* from);
173                static bool PressFunc(int x, int y, void* pointer);
174
175                void SetCursor(int num);
176
177        public:
178                vector<BacklogItem> backlog;
179                BacklogItem backlog_item;
180                TextWindow* text;
181                typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
182                        WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
183                        WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
184                        WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
185                        WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
186                        CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
187                        SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
188                        BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
189                        ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK |
190                                                LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD |
191                                                BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK |
192                                                CLEARSCR_WAIT_MASK | SKIPEND_MASK)
193                } Status;
194                Status status, status_saved, status_mask;
195
196        private:
197                std::string ruby_text;
198                bool ruby_text_flag;
199                unsigned int wait_time;
200                unsigned int old_time;
201                int text_window_number;
202                bool text_parsing;
203                TextStream text_stream;
204                SkipMode skip_mode;
205                int save_selectcount;
206
207                std::map<int, TimerAtom> timer_var;
208                //TODO: Handle EX Timer set
209                std::map<int, TimerAtom> timer_var_ex;
210                //TODO: Handle Frame Timers
211                std::map<int, FrameTimerAtom> frame_var;
212                std::map<int, FrameTimerAtom> frame_var_ex;
213
214                std::vector<WidTextButton*> selects;
215                std::vector<int> sel_backlog_pos;
216                string replace_name[26];
217                string replace_name2[26];
218                PicContainer* sel_widget;
219                PicWidget* backlog_widget;
220
221                BacklogItem cur_backlog_item;
222                BacklogItem drawn_backlog_item;
223
224                TextWindow* widgets[32];
225                WidTimeCursor* kcursor;
226                Surface* sel_bg1;
227                Surface* sel_bg2;
228                Rect sel_bg_rect;
229
230                VarInfo wait_savedvar[2];
231
232                AyuSysConfig *config;
233
234                Event::Container& event;
235                PicContainer& parent;
236
237                //Opcode handling
238                // Text
239                void impl_txtClear(Cmd& cmd);
240                void impl_logKoe(Cmd& cmd);
241                void impl_pause(Cmd& cmd);
242                void impl_br(Cmd& cmd);
243                void impl_FaceOpen(Cmd& cmd);
244                void impl_FaceClear(Cmd& cmd);
245                void impl_doRuby(Cmd& cmd);
246                void impl_TextWindow(Cmd& cmd);
247                void impl_msgClear(Cmd& cmd);
248                void impl_FastText(Cmd& cmd);
249                void impl_createSelect(Cmd& cmd);
250                void impl_SetSkipMode(Cmd& cmd);
251                void impl_Wait(Cmd& cmd);
252                void impl_PauseCursor(Cmd& cmd);
253                void impl_SetWindowAttr(Cmd& cmd);
254                void impl_GetWindowAttr(Cmd& cmd);
255                void impl_GetName(Cmd& cmd);
256                void impl_SetName(Cmd& cmd);
257                void impl_GetLocalName(Cmd& cmd);
258                void impl_SetLocalName(Cmd& cmd);
259                // Misc (related with text)
260                void impl_ShowBackground(Cmd& cmd);
261                void impl_GetDefConfig(Cmd& cmd);
262                void impl_GetConfig(Cmd& cmd);
263                void impl_SetConfig(Cmd& cmd);
264                // Misc
265                void impl_index_series(Cmd& cmd);
266                void impl_load(Cmd& cmd);
267                void impl_GetClick(Cmd& cmd);
268                // Time/Frame
269                void impl_InitFrame(Cmd& cmd);
270                void impl_ReadFrame(Cmd& cmd);
271                void impl_InitFrames(Cmd& cmd);
272                void impl_ReadFrames(Cmd& cmd);
273                void impl_ResetTimer(Cmd& cmd);
274                void impl_Timer(Cmd& cmd);
275                // Maths
276                void impl_rnd(Cmd& cmd);
277                void impl_pcnt(Cmd& cmd);
278                void impl_abs(Cmd& cmd);
279                void impl_power(Cmd& cmd);
280                void impl_sin(Cmd& cmd);
281                void impl_min(Cmd& cmd);
282                void impl_max(Cmd& cmd);
283                void impl_constrain(Cmd& cmd);
284};
285
286#endif
Note: See TracBrowser for help on using the browser.