comparison scn2k/scn2k_text.cc @ 52:15a18fbe6f21

* Known bugs added to the README * Code cleaning (0 -> NULL when needed, indentation, spaces, ...)
author thib
date Sat, 18 Apr 2009 18:35:39 +0000
parents 35ce1a30f3f9
children ddbcbd000206
comparison
equal deleted inserted replaced
51:cbb301016a4e 52:15a18fbe6f21
53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 53 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 54 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 55 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 */ 56 */
57 57
58 #include"window/event.h" 58 #include "window/event.h"
59 #include"window/picture.h" 59 #include "window/picture.h"
60 #include"window/widget.h" 60 #include "window/widget.h"
61 #include"system/file.h" 61 #include "system/file.h"
62 #include"system/system_config.h" 62 #include "system/system_config.h"
63 #include"scn2k.h" 63 #include "scn2k.h"
64 64
65 #include<string> 65 #include <string>
66 using namespace std; 66 using namespace std;
67 67
68 // kanji conv : デバッグ表示用 68 // kanji conv : デバッグ表示用
69 void kconv(const unsigned char* src, unsigned char* dest); 69 void kconv(const unsigned char* src, unsigned char* dest);
70 void kconv_rev(const unsigned char* src, unsigned char* dest); 70 void kconv_rev(const unsigned char* src, unsigned char* dest);
93 PicContainer* name_container; 93 PicContainer* name_container;
94 PicBase* face; 94 PicBase* face;
95 PicBase* face_pics[8]; 95 PicBase* face_pics[8];
96 TextWindow(PicContainer& parent, Event::Container& event, int window_no, const AyuSysConfig& config, void* callback); 96 TextWindow(PicContainer& parent, Event::Container& event, int window_no, const AyuSysConfig& config, void* callback);
97 ~TextWindow() { 97 ~TextWindow() {
98 if (name_container) delete name_container; 98 if (name_container != NULL) {
99 int i; for (i=0; i<8; i++) { 99 delete name_container;
100 if (face_pics[i]) delete face_pics[i]; 100 name_container = NULL;
101 } 101 }
102 if (wid) delete wid; 102 int i;
103 for (i=0; i<8; i++) {
104 if (face_pics[i] != NULL) {
105 delete face_pics[i];
106 face_pics[i] = NULL;
107 }
108 }
109 if (wid != NULL) {
110 delete wid;
111 wid = NULL;
112 }
103 } 113 }
104 Rect WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config); 114 Rect WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config);
105 void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, const AyuSysConfig& config, void* callback); 115 void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, const AyuSysConfig& config, void* callback);
106 void show(void) { 116 void show(void) {
107 wid->show(); 117 wid->show();
152 } 162 }
153 } 163 }
154 }; 164 };
155 165
156 class TextImpl { 166 class TextImpl {
157 private: 167 public:
158 public: 168 TextWindow* text;
159 TextWindow* text; 169 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2,
160 typedef enum {NORMAL=0, WAIT_TEXT=1, WAIT=2, WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5, WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7, 170 WAIT_CLICK=3, WAIT_ABORT=4, WAIT_CLICK_MOUSEPOS = 5,
161 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12, 171 WAIT_CLICK_MOUSEPOSEND_L = 6, WAIT_CLICK_MOUSEPOSEND_R = 7,
162 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512, 172 WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
163 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12), 173 WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
164 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15), BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17), 174 CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
165 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK) 175 SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
166 } Status; 176 BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
167 Status status, status_saved, status_mask; 177 ALLMASK = (CLEARSCR_MASK | WAIT_EXTRN_MASK | SAVEMASK | LOADMASK | SKIPMASK | BACKLOG_MASK | BACKLOG_MASK_FWD | BACKLOG_MASK_KOE | BACKLOG_WAIT_MASK | STATSAVE_MASK | CLEARSCR_WAIT_MASK | SKIPEND_MASK)
168 private: 178 } Status;
169 std::string ruby_text; 179 Status status, status_saved, status_mask;
170 bool ruby_text_flag; 180 private:
171 unsigned int wait_time; 181 std::string ruby_text;
172 unsigned int old_time; 182 bool ruby_text_flag;
173 unsigned int base_time; 183 unsigned int wait_time;
174 int text_window_number; 184 unsigned int old_time;
175 bool text_parsing; 185 unsigned int base_time;
176 TextStream text_stream; 186 int text_window_number;
177 SkipMode skip_mode; 187 bool text_parsing;
178 int save_selectcount; 188 TextStream text_stream;
179 189 SkipMode skip_mode;
180 std::map<int, TimerAtom> timer_var; 190 int save_selectcount;
181 std::vector<WidTextButton*> selects; 191
182 std::vector<int> sel_backlog_pos; 192 std::map<int, TimerAtom> timer_var;
183 string replace_name[26]; 193 std::vector<WidTextButton*> selects;
184 string replace_name2[26]; 194 std::vector<int> sel_backlog_pos;
185 PicContainer* sel_widget; 195 string replace_name[26];
186 PicWidget* backlog_widget; 196 string replace_name2[26];
187 197 PicContainer* sel_widget;
188 vector<BacklogItem>& backlog; 198 PicWidget* backlog_widget;
189 BacklogItem& backlog_item; 199
190 BacklogItem cur_backlog_item; 200 vector<BacklogItem>& backlog;
191 BacklogItem drawn_backlog_item; 201 BacklogItem& backlog_item;
192 202 BacklogItem cur_backlog_item;
193 public: 203 BacklogItem drawn_backlog_item;
194 PicContainer& parent; 204
195 Event::Container& event; 205 public:
196 AyuSysConfig& config; 206 PicContainer& parent;
197 private: 207 Event::Container& event;
198 TextWindow* widgets[32]; 208 AyuSysConfig& config;
199 WidTimeCursor* kcursor; 209 private:
200 Surface* sel_bg1; 210 TextWindow* widgets[32];
201 Surface* sel_bg2; 211 WidTimeCursor* kcursor;
202 Rect sel_bg_rect; 212 Surface* sel_bg1;
203 213 Surface* sel_bg2;
204 void SetCursor(int num); 214 Rect sel_bg_rect;
205 VarInfo wait_savedvar[2]; 215
206 216 void SetCursor(int num);
207 public: 217 VarInfo wait_savedvar[2];
208 void AddText(const char* str); 218
209 219 public:
210 static void PressFuncSkip(void* pointer, WidButton* from); 220 void AddText(const char* str);
211 static void PressFuncLoad(void* pointer, WidButton* from); 221
212 static void PressFuncSave(void* pointer, WidButton* from); 222 static void PressFuncSkip(void* pointer, WidButton* from);
213 static void PressFuncBacklog(void* pointer, WidButton* from); 223 static void PressFuncLoad(void* pointer, WidButton* from);
214 static void PressFuncBacklogFwd(void* pointer, WidButton* from); 224 static void PressFuncSave(void* pointer, WidButton* from);
215 private: 225 static void PressFuncBacklog(void* pointer, WidButton* from);
216 static void PressFuncButton(void* pointer, WidButton* from); 226 static void PressFuncBacklogFwd(void* pointer, WidButton* from);
217 static bool PressFunc(int x, int y, void* pointer); 227 private:
218 228 static void PressFuncButton(void* pointer, WidButton* from);
219 public: 229 static bool PressFunc(int x, int y, void* pointer);
220 TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item); 230
221 ~TextImpl(); 231 public:
222 void InitWindow(void); 232 TextImpl(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config, vector<BacklogItem>& parent_backlog, BacklogItem& parent_backlog_item);
223 void SetWindowColor(int r, int g, int b, int a, bool is_transparent); 233 ~TextImpl();
224 void SetTextSpeed(int new_speed); 234 void InitWindow(void);
225 void SetTextWait(int new_wait); 235 void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
226 void CreateSelect(Cmd& cmd); 236 void SetTextSpeed(int new_speed);
227 void Exec(Cmd& cmd); 237 void SetTextWait(int new_wait);
228 bool Wait(unsigned int current_time, Cmd& cmd); 238 void CreateSelect(Cmd& cmd);
229 void hide(void); 239 void Exec(Cmd& cmd);
230 void show(void) { show(text_window_number); } 240 bool Wait(unsigned int current_time, Cmd& cmd);
231 void show(int num); 241 void hide(void);
232 void DrawBacklog(BacklogItem& item, Cmd& cmd); 242 void show(void) { show(text_window_number); }
233 void Save(std::string& str, bool select_save); 243 void show(int num);
234 void Load(const char* str); 244 void DrawBacklog(BacklogItem& item, Cmd& cmd);
235 void SetSkipMode(SkipMode _mode); 245 void Save(std::string& str, bool select_save);
236 void CreateSelBG(void); 246 void Load(const char* str);
247 void SetSkipMode(SkipMode _mode);
248 void CreateSelBG(void);
237 }; 249 };
238 250
239 /**************************************************************:: 251 /**************************************************************::
240 ** 252 **
241 ** TextImpl(implementation) 253 ** TextImpl(implementation)
308 void TextImpl::SetSkipMode(SkipMode _mode) { 320 void TextImpl::SetSkipMode(SkipMode _mode) {
309 if ( (skip_mode & SKIP_IN_MENU) && (_mode & SKIP_IN_MENU) == 0) { 321 if ( (skip_mode & SKIP_IN_MENU) && (_mode & SKIP_IN_MENU) == 0) {
310 if (status_mask & BACKLOG_WAIT_MASK) { // backlog mode から復帰 322 if (status_mask & BACKLOG_WAIT_MASK) { // backlog mode から復帰
311 status_mask = Status(status_mask & (~(BACKLOG_MASK|BACKLOG_MASK_FWD|BACKLOG_MASK_KOE|BACKLOG_WAIT_MASK))); 323 status_mask = Status(status_mask & (~(BACKLOG_MASK|BACKLOG_MASK_FWD|BACKLOG_MASK_KOE|BACKLOG_WAIT_MASK)));
312 text->wid->Clear(); 324 text->wid->Clear();
313 if (status == WAIT_TEXT && text != 0) { 325 if (status == WAIT_TEXT && text != NULL) {
314 text->StartText(text_stream); 326 text->StartText(text_stream);
315 text->ShowFace(backlog_item.face.c_str()); 327 text->ShowFace(backlog_item.face.c_str());
316 text->wid->Flush(); 328 text->wid->Flush();
317 if (kcursor) kcursor->show(); 329 if (kcursor) kcursor->show();
318 } 330 }
335 } 347 }
336 skip_mode = _mode; 348 skip_mode = _mode;
337 } 349 }
338 350
339 /* hash_map が欲しい……*/ 351 /* hash_map が欲しい……*/
340 #include<map> 352 #include <map>
341 #include<list> 353 #include <list>
342 struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う 354 struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う
343 map<string, int> facetonum; 355 map<string, int> facetonum;
344 typedef pair<string,int> Node; 356 typedef pair<string,int> Node;
345 typedef list<Node> List; 357 typedef list<Node> List;
346 List container; 358 List container;
387 num--; 399 num--;
388 } 400 }
389 return ""; 401 return "";
390 } 402 }
391 }; 403 };
404
392 int SaveFaceHash::size_max = 20; 405 int SaveFaceHash::size_max = 20;
393 406
394 void TextImpl::Save(string& str, bool rollback_save) { 407 void TextImpl::Save(string& str, bool rollback_save) {
395 char buf[1024]; 408 char buf[1024];
396 str = "\n"; 409 str = "\n";
461 str += "\n"; 474 str += "\n";
462 } while(it != backlog.end()); 475 } while(it != backlog.end());
463 } 476 }
464 return; 477 return;
465 } 478 }
479
466 void TextImpl::Load(const char* str) { 480 void TextImpl::Load(const char* str) {
467 if (text) text->wid->Clear(); 481 if (text) text->wid->Clear();
468 hide(); 482 hide();
469 text_window_number = 0; 483 text_window_number = 0;
470 save_selectcount = 0; 484 save_selectcount = 0;
471 if (sel_widget) { 485 if (sel_widget != NULL) {
472 selects.clear(); 486 selects.clear();
473 sel_backlog_pos.clear(); 487 sel_backlog_pos.clear();
474 delete sel_widget; 488 delete sel_widget;
475 sel_widget = 0; 489 sel_widget = NULL;
476 } 490 }
477 if (backlog_widget) { 491 if (backlog_widget != NULL) {
478 delete backlog_widget; 492 delete backlog_widget;
479 backlog_widget = 0; 493 backlog_widget = NULL;
480 } 494 }
481 status = NORMAL; 495 status = NORMAL;
482 status_mask = NORMAL; 496 status_mask = NORMAL;
483 status_saved = NORMAL; 497 status_saved = NORMAL;
484 text_parsing = false; 498 text_parsing = false;
497 const char* strend = str; 511 const char* strend = str;
498 do { 512 do {
499 str = strend; 513 str = strend;
500 514
501 strend = strchr(str, '\n'); 515 strend = strchr(str, '\n');
502 if (strend == 0) strend = str + strlen(str); 516 if (strend == NULL) strend = str + strlen(str);
503 else strend++; 517 else strend++;
504 518
505 if (str[0] == '[') break; // next section 519 if (str[0] == '[') break; // next section
506 if (strncmp(str, "TextImplWindow=",15) == 0) { 520 if (strncmp(str, "TextImplWindow=",15) == 0) {
507 str += 15; 521 str += 15;
522 } else if (strncmp(str, "Backlog.", 8) == 0) { 536 } else if (strncmp(str, "Backlog.", 8) == 0) {
523 int cur_scn = -1; 537 int cur_scn = -1;
524 int n = -1; 538 int n = -1;
525 sscanf(str+8, "%d", &n); /* not used */ 539 sscanf(str+8, "%d", &n); /* not used */
526 const char* next_str = strchr(str, ';'); 540 const char* next_str = strchr(str, ';');
527 while(next_str != 0 && next_str < strend) { 541 while(next_str != NULL && next_str < strend) {
528 str = next_str + 1; 542 str = next_str + 1;
529 next_str = strchr(str, ';'); 543 next_str = strchr(str, ';');
530 if (next_str == 0) next_str = strend; 544 if (next_str == NULL) next_str = strend;
531 545
532 BacklogItem item; 546 BacklogItem item;
533 if (str[0] == '"') { 547 if (str[0] == '"') {
534 const char* send = strchr(str+1, '"'); 548 const char* send = strchr(str+1, '"');
535 if (send == 0 || send > next_str) continue; 549 if (send == NULL || send > next_str) continue;
536 string tmp_str; tmp_str.assign(str+1, send-str-1); 550 string tmp_str; tmp_str.assign(str+1, send-str-1);
537 item.DeleteTextPos(); 551 item.DeleteTextPos();
538 item.text.Load(tmp_str); 552 item.text.Load(tmp_str);
539 str = send + 1; 553 str = send + 1;
540 } 554 }
548 } else { 562 } else {
549 item.scn = cur_scn; 563 item.scn = cur_scn;
550 sscanf(str, "%d", &item.pos); 564 sscanf(str, "%d", &item.pos);
551 } 565 }
552 str = strchr(str, ','); 566 str = strchr(str, ',');
553 if (str == 0 || str > next_str) goto backlog_store; 567 if (str == NULL || str > next_str) goto backlog_store;
554 str++; 568 str++;
555 if (str[0] == ';' || str[0] == ',') 569 if (str[0] == ';' || str[0] == ',')
556 item.koe = -1; 570 item.koe = -1;
557 else 571 else
558 sscanf(str, "%d", &item.koe); 572 sscanf(str, "%d", &item.koe);
559 str = strchr(str, ','); 573 str = strchr(str, ',');
560 if (str == 0 || str > next_str) goto backlog_store; 574 if (str == NULL || str > next_str) goto backlog_store;
561 str++; 575 str++;
562 if (*str == '"') { 576 if (*str == '"') {
563 const char* send = strchr(str+1, '"'); 577 const char* send = strchr(str+1, '"');
564 if (send) { 578 if (send) {
565 item.face.assign(str+1, send-str-1); 579 item.face.assign(str+1, send-str-1);
587 --save_selectcount; 601 --save_selectcount;
588 } else { 602 } else {
589 backlog.swap(new_backlog); 603 backlog.swap(new_backlog);
590 } 604 }
591 // backlog.clear(); 605 // backlog.clear();
592 return;
593 } 606 }
594 607
595 void TextImpl::hide(void) { 608 void TextImpl::hide(void) {
596 if (text) text->hide(); 609 if (text) text->hide();
597 if (kcursor) kcursor->hide(); 610 if (kcursor) kcursor->hide();
598 text = 0; 611 text = NULL;
599 } 612 }
600 void TextImpl::show(int num) { 613 void TextImpl::show(int num) {
601 if (num != text_window_number) { 614 if (num != text_window_number) {
602 hide(); 615 hide();
603 if (num >= 0 && num < 32 && widgets[num] != 0) { 616 if (num >= 0 && num < 32 && widgets[num] != 0) {
617 // 微妙に下にする 630 // 微妙に下にする
618 ky += 8; 631 ky += 8;
619 kcursor->Pic()->Move(kx, ky); 632 kcursor->Pic()->Move(kx, ky);
620 } 633 }
621 } 634 }
635
622 void TextImpl::DrawBacklog(BacklogItem& item, Cmd& cmd) { 636 void TextImpl::DrawBacklog(BacklogItem& item, Cmd& cmd) {
623 show(); 637 show();
624 text->wid->deactivate(); 638 text->wid->deactivate();
625 status_mask = Status(status_mask | BACKLOG_WAIT_MASK); 639 status_mask = Status(status_mask | BACKLOG_WAIT_MASK);
626 drawn_backlog_item = item; 640 drawn_backlog_item = item;
639 else text->ShowFace(item.face.c_str()); 653 else text->ShowFace(item.face.c_str());
640 if (kcursor) kcursor->hide(); 654 if (kcursor) kcursor->hide();
641 } 655 }
642 656
643 void TextImpl::CreateSelBG(void) { 657 void TextImpl::CreateSelBG(void) {
644 if (sel_bg1 != 0 || sel_bg2 != 0) return; 658 if (sel_bg1 != NULL || sel_bg2 != NULL) return;
645 659
646 const char* btnfile1 = config.GetParaStr("#SELBTN.000.NAME"); 660 const char* btnfile1 = config.GetParaStr("#SELBTN.000.NAME");
647 const char* btnfile2 = config.GetParaStr("#SELBTN.000.BACK"); 661 const char* btnfile2 = config.GetParaStr("#SELBTN.000.BACK");
648 char path[1024]; 662 char path[1024];
649 strcpy(path, btnfile1); 663 strcpy(path, btnfile1);
650 sel_bg1 = parent.Root().NewSurface(path); 664 sel_bg1 = parent.Root().NewSurface(path);
651 if (sel_bg1 == 0) { 665 if (sel_bg1 == NULL) {
652 sprintf(path,"%s.g00",btnfile1); 666 sprintf(path,"%s.g00",btnfile1);
653 sel_bg1 = parent.Root().NewSurface(path); 667 sel_bg1 = parent.Root().NewSurface(path);
654 } 668 }
655 strcpy(path, btnfile2); 669 strcpy(path, btnfile2);
656 sel_bg2 = parent.Root().NewSurface(path); 670 sel_bg2 = parent.Root().NewSurface(path);
657 if (sel_bg2 == 0) { 671 if (sel_bg2 == NULL) {
658 sprintf(path,"%s.g00",btnfile2); 672 sprintf(path,"%s.g00",btnfile2);
659 sel_bg2 = parent.Root().NewSurface(path); 673 sel_bg2 = parent.Root().NewSurface(path);
660 } 674 }
661 sel_bg_rect = Rect(0,0,0,0); 675 sel_bg_rect = Rect(0,0,0,0);
662 if (sel_bg1) sel_bg_rect.join(Rect(*sel_bg1)); 676 if (sel_bg1) sel_bg_rect.join(Rect(*sel_bg1));
663 if (sel_bg2) sel_bg_rect.join(Rect(*sel_bg2)); 677 if (sel_bg2) sel_bg_rect.join(Rect(*sel_bg2));
664 return;
665 } 678 }
666 679
667 void TextImpl::CreateSelect(Cmd& cmd) { 680 void TextImpl::CreateSelect(Cmd& cmd) {
668 char key[1024]; 681 char key[1024];
669 sprintf(key, "#WINDOW.%03d.SELCOM_USE",text_window_number); 682 sprintf(key, "#WINDOW.%03d.SELCOM_USE",text_window_number);
753 config.GetParam("#SELBTN.000.MOJISIZE", 1, &mojisize); 766 config.GetParam("#SELBTN.000.MOJISIZE", 1, &mojisize);
754 Color fore(0xff,0xff,0xff); 767 Color fore(0xff,0xff,0xff);
755 Color seled(0xff,0xff,0xff); 768 Color seled(0xff,0xff,0xff);
756 769
757 show(); 770 show();
758 if (text == 0) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする 771 if (text == NULL) goto External_select; // テキスト・ウィンドウを表示できなければ外部選択肢にする
759 text->wid->Clear(); 772 text->wid->Clear();
760 if (kcursor) kcursor->hide(); 773 if (kcursor) kcursor->hide();
761 /* ウィジット作成 : テキスト表示範囲と同じ*/ 774 /* ウィジット作成 : テキスト表示範囲と同じ*/
762 int posx = text->wid->pictext->PosX(); 775 int posx = text->wid->pictext->PosX();
763 int posy = text->wid->pictext->PosY(); 776 int posy = text->wid->pictext->PosY();
785 } 798 }
786 } 799 }
787 800
788 void TextImpl::AddText(const char* str_o) { 801 void TextImpl::AddText(const char* str_o) {
789 char str[10001]; 802 char str[10001];
790 if (text == 0) return; 803 if (text == NULL) return;
791 /* まず、replace string を変換 */ 804 /* まず、replace string を変換 */
792 int i; 805 int i;
793 int cnt = 0; 806 int cnt = 0;
794 /* * = 81 96 A-Z = 0x82 [0x60-0x79] */ 807 /* * = 81 96 A-Z = 0x82 [0x60-0x79] */
795 /* % = 81 93 A-Z = 0x82 [0x60-0x79] */ 808 /* % = 81 93 A-Z = 0x82 [0x60-0x79] */
846 text_stream.AddReturn(); 859 text_stream.AddReturn();
847 str_top = s; 860 str_top = s;
848 } else if (*s < 0 && s[1] != 0) s++; 861 } else if (*s < 0 && s[1] != 0) s++;
849 } 862 }
850 text_stream.Add(str_top); 863 text_stream.Add(str_top);
851 return;
852 } 864 }
853 865
854 void TextImpl::Exec(Cmd& cmd) { 866 void TextImpl::Exec(Cmd& cmd) {
855 if (cmd.cmd_type == CMD_TEXT) { 867 if (cmd.cmd_type == CMD_TEXT) {
856 if (text == 0) { 868 if (text == NULL) {
857 show(); 869 show();
858 } 870 }
859 if (cmd.args.size() != 1) return; 871 if (cmd.args.size() != 1) return;
860 if (ruby_text_flag) { 872 if (ruby_text_flag) {
861 ruby_text = cmd.Str(cmd.args[0]); 873 ruby_text = cmd.Str(cmd.args[0]);
918 } else if (cmd.cmd3 == 3 || cmd.cmd3 == 0xc9) { // リターン挿入 930 } else if (cmd.cmd3 == 3 || cmd.cmd3 == 0xc9) { // リターン挿入
919 text_stream.AddReturn(); 931 text_stream.AddReturn();
920 cur_backlog_item.DeleteTextPos(); 932 cur_backlog_item.DeleteTextPos();
921 cmd.clear(); 933 cmd.clear();
922 } else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更 934 } else if (cmd.cmd3 == 0x3e8 || cmd.cmd3 == 0x3e9) { // 顔グラフィック変更
923 if (text == 0) { 935 if (text == NULL) {
924 show(); 936 show();
925 } 937 }
926 if (cmd.cmd3 == 0x3e8) { 938 if (cmd.cmd3 == 0x3e8) {
927 string s = cmd.Str(cmd.args[0]); 939 string s = cmd.Str(cmd.args[0]);
928 s += ".g00"; 940 s += ".g00";
933 if (text) text->ResetFace(); 945 if (text) text->ResetFace();
934 cur_backlog_item.face = ""; 946 cur_backlog_item.face = "";
935 cmd.cmd_type = CMD_SAVECMD_ONCE; 947 cmd.cmd_type = CMD_SAVECMD_ONCE;
936 } 948 }
937 } else if (cmd.cmd3 == 0x78) { // ルビ関連 949 } else if (cmd.cmd3 == 0x78) { // ルビ関連
938 if (text == 0) { 950 if (text == NULL) {
939 show(); 951 show();
940 } 952 }
941 if (cmd.cmd4 == 1) { 953 if (cmd.cmd4 == 1) {
942 ruby_text_flag = true; 954 ruby_text_flag = true;
943 eprintf("SetRubyTextImpl."); 955 eprintf("SetRubyTextImpl.");
1323 } else { 1335 } else {
1324 cmd.SetStrvar(cmd.args[1], ""); 1336 cmd.SetStrvar(cmd.args[1], "");
1325 } 1337 }
1326 } 1338 }
1327 } 1339 }
1328 1340 }
1329 return; 1341
1330 }
1331 extern int print_blit; 1342 extern int print_blit;
1332 bool TextImpl::Wait(unsigned int current_time, Cmd& cmd) { 1343 bool TextImpl::Wait(unsigned int current_time, Cmd& cmd) {
1333 if (current_time != 0xffffffffUL) old_time = current_time; 1344 if (current_time != Event::Time::NEVER_WAKE) old_time = current_time;
1334 /* 1345 /*
1335 if (event.presscount(MOUSE_UP)) { 1346 if (event.presscount(MOUSE_UP)) {
1336 if (text) text->Pic()->ReBlit(); 1347 if (text) text->Pic()->ReBlit();
1337 } 1348 }
1338 if (event.presscount(MOUSE_DOWN)) { 1349 if (event.presscount(MOUSE_DOWN)) {
1339 print_blit^=1; 1350 print_blit^=1;
1340 } 1351 }
1341 */ 1352 */
1342 1353
1343 if (status == NORMAL && status_mask == NORMAL) return false; 1354 if (status == NORMAL && status_mask == NORMAL) return false;
1344 1355
1345 if (status_mask & WAIT_EXTRN_MASK) return true; 1356 if (status_mask & WAIT_EXTRN_MASK) return true;
1346 if (status_mask & (BACKLOG_MASK|BACKLOG_MASK_FWD) ) { 1357 if (status_mask & (BACKLOG_MASK|BACKLOG_MASK_FWD) ) {
1347 if (status_mask & BACKLOG_WAIT_MASK) ; 1358 if (status_mask & BACKLOG_WAIT_MASK) ;
1348 else { 1359 else {
1349 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { 1360 if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
1350 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { 1361 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
1351 text->wid->Flush(); // 表示を最後の状態にする 1362 text->wid->Flush(); // 表示を最後の状態にする
1352 } 1363 }
1353 if (status == WAIT_TEXT && text != 0 && kcursor) kcursor->show(); 1364 if (status == WAIT_TEXT && text != NULL && kcursor != NULL) kcursor->show();
1354 } 1365 }
1355 } 1366 }
1356 if (status_mask & BACKLOG_MASK) { 1367 if (status_mask & BACKLOG_MASK) {
1357 cmd.cmd_type = CMD_BACKLOGREQ; 1368 cmd.cmd_type = CMD_BACKLOGREQ;
1358 } else { 1369 } else {
1407 } 1418 }
1408 status_mask = Status(status_mask & ~SKIPMASK); 1419 status_mask = Status(status_mask & ~SKIPMASK);
1409 return false; 1420 return false;
1410 } 1421 }
1411 if (event.presscount(MOUSE_RIGHT)) { 1422 if (event.presscount(MOUSE_RIGHT)) {
1412 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { 1423 if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
1413 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { 1424 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
1414 text->wid->Flush(); // 表示を最後の状態にする 1425 text->wid->Flush(); // 表示を最後の状態にする
1415 } 1426 }
1416 cmd.cmd_type = CMD_MENUREQ; 1427 cmd.cmd_type = CMD_MENUREQ;
1417 if (!(status_mask & STATSAVE_MASK)) { 1428 if (!(status_mask & STATSAVE_MASK)) {
1422 } else if (status == WAIT_CLICK_MOUSEPOS) { 1433 } else if (status == WAIT_CLICK_MOUSEPOS) {
1423 status = WAIT_CLICK_MOUSEPOSEND_R; 1434 status = WAIT_CLICK_MOUSEPOSEND_R;
1424 } 1435 }
1425 } 1436 }
1426 if (event.presscount(MOUSE_UP)) { 1437 if (event.presscount(MOUSE_UP)) {
1427 if ( (status == WAIT_TEXT && text != 0) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { 1438 if ( (status == WAIT_TEXT && text != NULL) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
1428 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { 1439 if(text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
1429 text->wid->Flush(); // 表示を最後の状態にする 1440 text->wid->Flush(); // 表示を最後の状態にする
1430 } 1441 }
1431 cmd.cmd_type = CMD_BACKLOGREQ; 1442 cmd.cmd_type = CMD_BACKLOGREQ;
1432 if (!(status_mask & STATSAVE_MASK)) { 1443 if (!(status_mask & STATSAVE_MASK)) {
1435 } 1446 }
1436 return false; 1447 return false;
1437 } 1448 }
1438 } 1449 }
1439 if (status_mask & CLEARSCR_MASK) { 1450 if (status_mask & CLEARSCR_MASK) {
1440 if ( (status == WAIT_TEXT && text != 0 ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) { 1451 if ( (status == WAIT_TEXT && text != NULL ) || status == WAIT_SELECT_INBOX || status == WAIT_SELECT_OUTBOX) {
1441 if (skip_mode) skip_mode = SKIP_NO; 1452 if (skip_mode) skip_mode = SKIP_NO;
1442 if (text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) { 1453 if (text && text->wid->status != WidText::PREPARE && text->wid->status != WidText::WAIT && text->wid->status != WidText::WAIT2) {
1443 text->wid->Flush(); // 表示を最後の状態にする 1454 text->wid->Flush(); // 表示を最後の状態にする
1444 return true; 1455 return true;
1445 } 1456 }
1446 status_mask = Status(status_mask & (~CLEARSCR_MASK) | CLEARSCR_WAIT_MASK); 1457 status_mask = Status(status_mask & (~CLEARSCR_MASK) | CLEARSCR_WAIT_MASK);
1447 if (text) text->hide(); 1458 if (text != NULL) text->hide();
1448 if (kcursor) kcursor->hide(); 1459 if (kcursor != NULL) kcursor->hide();
1449 if (sel_widget) sel_widget->hide(); 1460 if (sel_widget != NULL) sel_widget->hide();
1450 if (backlog_widget) backlog_widget->hide(); 1461 if (backlog_widget != NULL) backlog_widget->hide();
1451 return true; 1462 return true;
1452 } 1463 }
1453 status_mask = Status(status_mask & (~CLEARSCR_MASK)); 1464 status_mask = Status(status_mask & (~CLEARSCR_MASK));
1454 return false; 1465 return false;
1455 } 1466 }
1456 if (status_mask & CLEARSCR_WAIT_MASK) { 1467 if (status_mask & CLEARSCR_WAIT_MASK) {
1457 return true; 1468 return true;
1458 } 1469 }
1459 if (status == WAIT_TEXT) { 1470 if (status == WAIT_TEXT) {
1460 if (text == 0) { status = NORMAL; return false;} 1471 if (text == NULL) {
1472 status = NORMAL;
1473 return false;
1474 }
1461 if (skip_mode & SKIP_TEXT) { 1475 if (skip_mode & SKIP_TEXT) {
1462 } else if (text->wid->status != WidText::PREPARE) { 1476 } else if (text->wid->status != WidText::PREPARE) {
1463 return true; 1477 return true;
1464 } 1478 }
1465 if (kcursor) kcursor->hide(); 1479 if (kcursor != NULL) kcursor->hide();
1466 text_stream.Clear(); 1480 text_stream.Clear();
1467 status = NORMAL; 1481 status = NORMAL;
1468 cmd.cmd_type = CMD_TEXTEND; 1482 cmd.cmd_type = CMD_TEXTEND;
1469 return false; 1483 return false;
1470 } 1484 }
1498 } else if ( int(status) >= WAIT_SELECT_VALUE) { 1512 } else if ( int(status) >= WAIT_SELECT_VALUE) {
1499 int sel_val = int(status) - WAIT_SELECT_VALUE; 1513 int sel_val = int(status) - WAIT_SELECT_VALUE;
1500 cmd.SetSysvar(sel_val); 1514 cmd.SetSysvar(sel_val);
1501 selects.clear(); 1515 selects.clear();
1502 delete sel_widget; 1516 delete sel_widget;
1503 sel_widget = 0; 1517 sel_widget = NULL;
1504 status = NORMAL; 1518 status = NORMAL;
1505 // CreateSelect() で作成された cur_backlog_item を backlog_item へ反映させる 1519 // CreateSelect() で作成された cur_backlog_item を backlog_item へ反映させる
1506 cur_backlog_item.text.InsertColor(sel_backlog_pos[sel_val], sel_backlog_pos[sel_val+1], 0xff, 0, 0); 1520 cur_backlog_item.text.InsertColor(sel_backlog_pos[sel_val], sel_backlog_pos[sel_val+1], 0xff, 0, 0);
1507 backlog_item = cur_backlog_item; 1521 backlog_item = cur_backlog_item;
1508 cur_backlog_item.Clear(); 1522 cur_backlog_item.Clear();
1509 } 1523 }
1510 return false; 1524 return false;
1511 } 1525 }
1512 1526
1513 void clearbtn_press(void* pointer, WidButton* button) { 1527 void clearbtn_press(void* pointer, WidButton* button) {
1514 if (pointer == 0) return; 1528 if (pointer == NULL) return;
1515 TextImpl* t = (TextImpl*)pointer; 1529 TextImpl* t = (TextImpl*)pointer;
1516 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::CLEARSCR_MASK); 1530 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::CLEARSCR_MASK);
1517 return; 1531 return;
1518 } 1532 }
1519 void TextImpl::PressFuncSkip(void* pointer, WidButton* from) { 1533 void TextImpl::PressFuncSkip(void* pointer, WidButton* from) {
1520 if (pointer == 0) return; 1534 if (pointer == NULL) return;
1521 TextImpl* t = (TextImpl*)pointer; 1535 TextImpl* t = (TextImpl*)pointer;
1522 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SKIPMASK); 1536 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SKIPMASK);
1523 return; 1537 return;
1524 } 1538 }
1525 void TextImpl::PressFuncLoad(void* pointer, WidButton* from) { 1539 void TextImpl::PressFuncLoad(void* pointer, WidButton* from) {
1526 if (pointer == 0) return; 1540 if (pointer == NULL) return;
1527 TextImpl* t = (TextImpl*)pointer; 1541 TextImpl* t = (TextImpl*)pointer;
1528 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::LOADMASK); 1542 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::LOADMASK);
1529 return; 1543 return;
1530 } 1544 }
1531 void TextImpl::PressFuncSave(void* pointer, WidButton* from) { 1545 void TextImpl::PressFuncSave(void* pointer, WidButton* from) {
1532 if (pointer == 0) return; 1546 if (pointer == NULL) return;
1533 TextImpl* t = (TextImpl*)pointer; 1547 TextImpl* t = (TextImpl*)pointer;
1534 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SAVEMASK); 1548 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::SAVEMASK);
1535 return; 1549 return;
1536 } 1550 }
1537 void TextImpl::PressFuncBacklog(void* pointer, WidButton* from) { 1551 void TextImpl::PressFuncBacklog(void* pointer, WidButton* from) {
1538 if (pointer == 0) return; 1552 if (pointer == NULL) return;
1539 TextImpl* t = (TextImpl*)pointer; 1553 TextImpl* t = (TextImpl*)pointer;
1540 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK); 1554 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK);
1541 return; 1555 return;
1542 } 1556 }
1543 void TextImpl::PressFuncBacklogFwd(void* pointer, WidButton* from) { 1557 void TextImpl::PressFuncBacklogFwd(void* pointer, WidButton* from) {
1544 if (pointer == 0) return; 1558 if (pointer == NULL) return;
1545 TextImpl* t = (TextImpl*)pointer; 1559 TextImpl* t = (TextImpl*)pointer;
1546 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK_FWD); 1560 t->status_mask = TextImpl::Status(t->status_mask | TextImpl::BACKLOG_MASK_FWD);
1547 return; 1561 return;
1548 } 1562 }
1549 void movebtn_drag(int from_x, int from_y, int x, int y, void* pointer, WidButton* button) { 1563 void movebtn_drag(int from_x, int from_y, int x, int y, void* pointer, WidButton* button) {
1550 if (pointer == 0) return; 1564 if (pointer == NULL) return;
1551 fprintf(stderr,"drag.\n"); 1565 fprintf(stderr,"drag.\n");
1552 } 1566 }
1567
1553 #define BTNCNT 10 1568 #define BTNCNT 10
1554 static const char* btnname[BTNCNT] = { 1569 static const char* btnname[BTNCNT] = {
1555 "MOVE", 1570 "MOVE",
1556 "CLEAR", 1571 "CLEAR",
1557 "READJUMP", 1572 "READJUMP",
1561 "MSGBKRIGHT", 1576 "MSGBKRIGHT",
1562 "EXBTN_000", 1577 "EXBTN_000",
1563 "EXBTN_001", 1578 "EXBTN_001",
1564 "EXBTN_002" 1579 "EXBTN_002"
1565 }; 1580 };
1581
1566 static int btnpos[BTNCNT] = { // g00 ファイル内のボタン情報の位置 1582 static int btnpos[BTNCNT] = { // g00 ファイル内のボタン情報の位置
1567 // 0, 1, 13, 12, 2, 3, 4, 5, 6, 7 // princess bride? 1583 // 0, 1, 13, 12, 2, 3, 4, 5, 6, 7 // princess bride?
1568 0, 1, 13, 14, 2, 3, 4, 5, 6, 7 // tomoyo after? 1584 0, 1, 13, 14, 2, 3, 4, 5, 6, 7 // tomoyo after?
1569 }; 1585 };
1586
1570 static WidButton::PressFunc btnpress[BTNCNT] = { 1587 static WidButton::PressFunc btnpress[BTNCNT] = {
1571 0, clearbtn_press, &TextImpl::PressFuncSkip,0,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncBacklog,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncSave,&TextImpl::PressFuncLoad,0 1588 0, clearbtn_press, &TextImpl::PressFuncSkip,0,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncBacklog,&TextImpl::PressFuncBacklogFwd,&TextImpl::PressFuncSave,&TextImpl::PressFuncLoad,0
1572 }; 1589 };
1590
1573 static WidButton::DragFunc btndrag[BTNCNT] = { 1591 static WidButton::DragFunc btndrag[BTNCNT] = {
1574 movebtn_drag, 0,0,0,0, 0,0,0,0, 0 1592 movebtn_drag, 0,0,0,0, 0,0,0,0, 0
1575 }; 1593 };
1576 1594
1577 void TextImpl::SetTextSpeed(int speed) { 1595 void TextImpl::SetTextSpeed(int speed) {
1583 else speed = 1000 / speed; 1601 else speed = 1000 / speed;
1584 int i; 1602 int i;
1585 for (i=0; i<32; i++) 1603 for (i=0; i<32; i++)
1586 if (widgets[i]) widgets[i]->wid->SetSpeed(speed); 1604 if (widgets[i]) widgets[i]->wid->SetSpeed(speed);
1587 } 1605 }
1606
1588 void TextImpl::SetTextWait(int wait) { 1607 void TextImpl::SetTextWait(int wait) {
1589 int i; 1608 int i;
1590 for (i=0; i<32; i++) 1609 for (i=0; i<32; i++)
1591 if (widgets[i]) widgets[i]->wid->SetWait(wait); 1610 if (widgets[i]) widgets[i]->wid->SetWait(wait);
1592 } 1611 }
1594 void TextImpl::SetWindowColor(int r, int g, int b, int a, bool is_transparent) { 1613 void TextImpl::SetWindowColor(int r, int g, int b, int a, bool is_transparent) {
1595 char key[1024]; 1614 char key[1024];
1596 int w; 1615 int w;
1597 1616
1598 for (w=0; w<32; w++) { 1617 for (w=0; w<32; w++) {
1599 if (widgets[w] == 0) continue; 1618 if (widgets[w] == NULL) continue;
1600 sprintf(key, "#WAKU.%03d.000.BACK", w); 1619 sprintf(key, "#WAKU.%03d.000.BACK", w);
1601 const char* back = config.GetParaStr(key); 1620 const char* back = config.GetParaStr(key);
1602 if (back == 0 || back[0] == 0) continue; 1621 if (back == NULL || back[0] == 0) continue;
1603 sprintf(key, "%s.g00", back); 1622 sprintf(key, "%s.g00", back);
1604 Surface* back_s = parent.Root().NewSurface(key); 1623 Surface* back_s = parent.Root().NewSurface(key);
1605 if (back_s == 0) continue; 1624 if (back_s == NULL) continue;
1606 Rect rect(*back_s); 1625 Rect rect(*back_s);
1607 Surface* new_s = parent.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); 1626 Surface* new_s = parent.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK);
1608 DSurfaceMove(back_s, rect, new_s, rect); 1627 DSurfaceMove(back_s, rect, new_s, rect);
1609 DSurfaceFillA(new_s, rect, r, g, b, a); 1628 DSurfaceFillA(new_s, rect, r, g, b, a);
1610 widgets[w]->wid->Pic()->SetSurface(new_s, 0, 0); 1629 widgets[w]->wid->Pic()->SetSurface(new_s, 0, 0);
1611 widgets[w]->wid->Pic()->SetSurfaceFreeFlag(1); 1630 widgets[w]->wid->Pic()->SetSurfaceFreeFlag(1);
1612 if (!is_transparent) 1631 if (!is_transparent)
1613 widgets[w]->wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY); 1632 widgets[w]->wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY);
1614 parent.Root().DeleteSurface(back_s); 1633 parent.Root().DeleteSurface(back_s);
1615 } 1634 }
1616 return;
1617 } 1635 }
1618 1636
1619 void TextImpl::SetCursor(int cursor_no) { 1637 void TextImpl::SetCursor(int cursor_no) {
1620 char key[1024]; 1638 char key[1024];
1621 sprintf(key, "#CURSOR.%03d.NAME", cursor_no); 1639 sprintf(key, "#CURSOR.%03d.NAME", cursor_no);
1629 config.GetParam(key, 1, &cont); 1647 config.GetParam(key, 1, &cont);
1630 sprintf(key, "#CURSOR.%03d.SPEED", cursor_no); 1648 sprintf(key, "#CURSOR.%03d.SPEED", cursor_no);
1631 config.GetParam(key, 1, &speed); 1649 config.GetParam(key, 1, &speed);
1632 1650
1633 // speed で1周、cont 回変化 1651 // speed で1周、cont 回変化
1634 if (kcursor) delete kcursor; 1652 if (kcursor != NULL) delete kcursor;
1635 1653
1636 kcursor = new WidTimeCursor(event, speed/cont, &parent, path.c_str(), 0, 0, w, 0, cont, Rect(0,0,w,h)); 1654 kcursor = new WidTimeCursor(event, speed/cont, &parent, path.c_str(), 0, 0, w, 0, cont, Rect(0,0,w,h));
1637 int i; 1655 int i;
1638 for (i=0; i<32; i++) { 1656 for (i=0; i<32; i++) {
1639 if (widgets[i]) widgets[i]->wid->SetCursor(kcursor); 1657 if (widgets[i]) widgets[i]->wid->SetCursor(kcursor);
1640 } 1658 }
1641 } 1659 }
1642 1660
1643 void kconv(const unsigned char* src, unsigned char* dest) { 1661 void kconv(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication?
1644 /* input : sjis output: euc */ 1662 /* input : sjis output: euc */
1645 while(*src) { 1663 while(*src) {
1646 unsigned int high = *src++; 1664 unsigned int high = *src++;
1647 if (high < 0x80) { 1665 if (high < 0x80) {
1648 /* ASCII */ 1666 /* ASCII */
1671 } 1689 }
1672 *dest++ = high | 0x80; *dest++ = low | 0x80; 1690 *dest++ = high | 0x80; *dest++ = low | 0x80;
1673 } 1691 }
1674 *dest = 0; 1692 *dest = 0;
1675 } 1693 }
1676 void kconv_rev(const unsigned char* src, unsigned char* dest) { 1694
1695 void kconv_rev(const unsigned char* src, unsigned char* dest) { //FIXME: code duplication?
1677 /* input : euc output: sjis */ 1696 /* input : euc output: sjis */
1678 while(*src) { 1697 while(*src) {
1679 unsigned int high = *src++; 1698 unsigned int high = *src++;
1680 if (high < 0x80) { 1699 if (high < 0x80) {
1681 /* ASCII */ 1700 /* ASCII */
1699 *dest++ = low; 1718 *dest++ = low;
1700 } 1719 }
1701 } 1720 }
1702 *dest = 0; 1721 *dest = 0;
1703 } 1722 }
1723
1704 string kconv(const string& s) { 1724 string kconv(const string& s) {
1705 char* out = new char[s.length()*2+100]; 1725 char* out = new char[s.length()*2+100];
1706 kconv((const unsigned char*)s.c_str(), (unsigned char*)out); 1726 kconv((const unsigned char*)s.c_str(), (unsigned char*)out);
1707 string ret = out; 1727 string ret = out;
1708 delete[] out; 1728 delete[] out;
1709 return ret; 1729 return ret;
1710 } 1730 }
1731
1711 string kconv_rev(const string& s) { 1732 string kconv_rev(const string& s) {
1712 char* out = new char[s.length()*2+100]; 1733 char* out = new char[s.length()*2+100];
1713 kconv_rev((const unsigned char*)s.c_str(), (unsigned char*)out); 1734 kconv_rev((const unsigned char*)s.c_str(), (unsigned char*)out);
1714 string ret = out; 1735 string ret = out;
1715 delete[] out; 1736 delete[] out;
1721 ** Text 1742 ** Text
1722 */ 1743 */
1723 Text::Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config) { 1744 Text::Text(Event::Container& _event, PicContainer& _parent, AyuSysConfig& config) {
1724 pimpl = new TextImpl(_event, _parent, config, backlog, backlog_item); 1745 pimpl = new TextImpl(_event, _parent, config, backlog, backlog_item);
1725 } 1746 }
1747
1726 Text::~Text() { 1748 Text::~Text() {
1727 delete pimpl; 1749 delete pimpl;
1728 } 1750 pimpl = NULL;
1751 }
1752
1729 void Text::InitWindow(void) { 1753 void Text::InitWindow(void) {
1730 pimpl->InitWindow(); 1754 pimpl->InitWindow();
1731 } 1755 }
1756
1732 void Text::Exec(Cmd& cmd) { 1757 void Text::Exec(Cmd& cmd) {
1733 pimpl->Exec(cmd); 1758 pimpl->Exec(cmd);
1734 } 1759 }
1760
1735 bool Text::Wait(unsigned int current_time, Cmd& cmd) { 1761 bool Text::Wait(unsigned int current_time, Cmd& cmd) {
1736 return pimpl->Wait(current_time, cmd); 1762 return pimpl->Wait(current_time, cmd);
1737 } 1763 }
1764
1738 void Text::SetSkipMode(SkipMode mode) { 1765 void Text::SetSkipMode(SkipMode mode) {
1739 pimpl->SetSkipMode(mode); 1766 pimpl->SetSkipMode(mode);
1740 } 1767 }
1768
1741 void Text::Save(std::string& str, bool select_save) { 1769 void Text::Save(std::string& str, bool select_save) {
1742 pimpl->Save(str, select_save); 1770 pimpl->Save(str, select_save);
1743 } 1771 }
1772
1744 void Text::Load(const char* str) { 1773 void Text::Load(const char* str) {
1745 pimpl->Load(str); 1774 pimpl->Load(str);
1746 } 1775 }
1747 1776
1748 void Text::hide(void) { 1777 void Text::hide(void) {
1749 pimpl->hide(); 1778 pimpl->hide();
1750 } 1779 }
1780
1751 void Text::show(void) { 1781 void Text::show(void) {
1752 pimpl->show(); 1782 pimpl->show();
1753 } 1783 }
1784
1754 void Text::show(int num) { 1785 void Text::show(int num) {
1755 pimpl->show(num); 1786 pimpl->show(num);
1756 } 1787 }
1788
1757 void Text::DrawBacklog(BacklogItem& item, Cmd& cmd) { 1789 void Text::DrawBacklog(BacklogItem& item, Cmd& cmd) {
1758 pimpl->DrawBacklog(item, cmd); 1790 pimpl->DrawBacklog(item, cmd);
1759 } 1791 }
1792
1760 /**************************************************************:: 1793 /**************************************************************::
1761 ** 1794 **
1762 ** BacklogItem 1795 ** BacklogItem
1763 */ 1796 */
1764 1797
1767 pos = -1; 1800 pos = -1;
1768 koe = -1; 1801 koe = -1;
1769 face = ""; 1802 face = "";
1770 text.kanji_type = TextStream::sjis; 1803 text.kanji_type = TextStream::sjis;
1771 } 1804 }
1805
1772 void BacklogItem::Clear(void) { 1806 void BacklogItem::Clear(void) {
1773 scn = -1; 1807 scn = -1;
1774 pos = -1; 1808 pos = -1;
1775 koe = -1; 1809 koe = -1;
1776 text.Clear(); 1810 text.Clear();
1777 } 1811 }
1812
1778 void BacklogItem::AddTextPos(Cmd& cmd) { 1813 void BacklogItem::AddTextPos(Cmd& cmd) {
1779 if (scn == -1 && pos == -1) { 1814 if (scn == -1 && pos == -1) {
1780 scn = cmd.scn; 1815 scn = cmd.scn;
1781 pos = cmd.pos; 1816 pos = cmd.pos;
1782 return; 1817 return;
1783 } 1818 }
1784 DeleteTextPos(); 1819 DeleteTextPos();
1785 } 1820 }
1821
1786 void BacklogItem::DeleteTextPos(void) { 1822 void BacklogItem::DeleteTextPos(void) {
1787 scn = 0; 1823 scn = 0;
1788 pos = -1; 1824 pos = -1;
1789 } 1825 }
1826
1790 BacklogItem& BacklogItem::operator =(const BacklogItem& p) { 1827 BacklogItem& BacklogItem::operator =(const BacklogItem& p) {
1791 scn = p.scn; 1828 scn = p.scn;
1792 pos = p.pos; 1829 pos = p.pos;
1793 koe = p.koe; 1830 koe = p.koe;
1794 face = p.face; 1831 face = p.face;
1795 text = p.text; 1832 text = p.text;
1796 } 1833 }
1834
1797 void BacklogItem::SetSavepos(int p) { 1835 void BacklogItem::SetSavepos(int p) {
1798 Clear(); 1836 Clear();
1799 scn = SaveSelect; 1837 scn = SaveSelect;
1800 pos = p; 1838 pos = p;
1801 } 1839 }
1802 1840
1803 Rect TextWindow::WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config) { 1841 Rect TextWindow::WakuSize(PicContainer& pic, int waku_no, const AyuSysConfig& config) {
1804 char key[1024]; 1842 char key[1024];
1805 sprintf(key, "#WAKU.%03d.000.NAME", waku_no); 1843 sprintf(key, "#WAKU.%03d.000.NAME", waku_no);
1806 const char* name = config.GetParaStr(key); 1844 const char* name = config.GetParaStr(key);
1807 if (!name) return Rect(0,0,0,0); 1845 if (name == NULL) return Rect(0,0,0,0);
1808 std::string str = name; str += ".g00"; 1846 std::string str = name; str += ".g00";
1809 Surface* s = pic.Root().NewSurface(str.c_str()); 1847 Surface* s = pic.Root().NewSurface(str.c_str());
1810 if (!s) return Rect(0,0,0,0); 1848 if (s == NULL) return Rect(0,0,0,0);
1811 Rect r(*s); 1849 Rect r(*s);
1812 pic.Root().DeleteSurface(s); 1850 pic.Root().DeleteSurface(s);
1813 return r; 1851 return r;
1814 } 1852 }
1853
1815 void TextWindow::MakeWaku(PicContainer& pic, Event::Container& event, int waku_no, int window_no, bool* use_btn, const AyuSysConfig& config, void* callback) { 1854 void TextWindow::MakeWaku(PicContainer& pic, Event::Container& event, int waku_no, int window_no, bool* use_btn, const AyuSysConfig& config, void* callback) {
1816 char key[1024]; 1855 char key[1024];
1817 std::string str; 1856 std::string str;
1818 /* 枠を作成 */ 1857 /* 枠を作成 */
1819 sprintf(key, "#WAKU.%03d.000.NAME", waku_no); 1858 sprintf(key, "#WAKU.%03d.000.NAME", waku_no);
1820 const char* name = config.GetParaStr(key); 1859 const char* name = config.GetParaStr(key);
1821 if (name && name[0] == 0) name = 0; 1860 if (name != NULL && name[0] == 0) name = NULL;
1822 sprintf(key, "#WAKU.%03d.000.BACK", waku_no); 1861 sprintf(key, "#WAKU.%03d.000.BACK", waku_no);
1823 const char* back = config.GetParaStr(key); 1862 const char* back = config.GetParaStr(key);
1824 if (back && back[0] == 0) back = 0; 1863 if (back != NULL && back[0] == 0) back = NULL;
1825 sprintf(key, "#WAKU.%03d.000.BTN", waku_no); 1864 sprintf(key, "#WAKU.%03d.000.BTN", waku_no);
1826 const char* btn = config.GetParaStr(key); 1865 const char* btn = config.GetParaStr(key);
1827 if (btn && btn[0] == 0) btn = 0; 1866 if (btn != NULL && btn[0] == 0) btn = NULL;
1828 1867
1829 if (name == 0 && back == 0 && btn == 0) return; 1868 if (name == NULL && back == NULL && btn == NULL) return;
1830 1869
1831 /* まず、テキスト背景を設定 */ 1870 /* まず、テキスト背景を設定 */
1832 if (back) { 1871 if (back != NULL) {
1833 str = back; str += ".g00"; 1872 str = back; str += ".g00";
1834 int rc,gc,bc,ac, flag; 1873 int rc, gc, bc, ac, flag;
1835 char key[1024]; 1874 char key[1024];
1836 sprintf(key, "#WINDOW.%03d.ATTR", window_no); 1875 sprintf(key, "#WINDOW.%03d.ATTR", window_no);
1837 if (config.GetParam(key, 5, &rc, &gc, &bc, &ac, &flag) == -1) { 1876 if (config.GetParam(key, 5, &rc, &gc, &bc, &ac, &flag) == -1) {
1838 config.GetParam("#WINDOW_ATTR", 5, &rc, &gc, &bc, &ac, &flag); 1877 config.GetParam("#WINDOW_ATTR", 5, &rc, &gc, &bc, &ac, &flag);
1839 } 1878 }
1840 Surface* back_s = pic.Root().NewSurface(str.c_str()); 1879 Surface* back_s = pic.Root().NewSurface(str.c_str());
1841 if (back_s) { 1880 if (back_s != NULL) {
1842 Rect rect(*back_s); 1881 Rect rect(*back_s);
1843 Surface* s = pic.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK); 1882 Surface* s = pic.Root().NewSurface(rect.width(), rect.height(), ALPHA_MASK);
1844 DSurfaceMove(back_s, rect, s, rect); 1883 DSurfaceMove(back_s, rect, s, rect);
1845 DSurfaceFillA(s, rect, rc, gc, bc, ac); // 透明度設定 1884 DSurfaceFillA(s, rect, rc, gc, bc, ac); // 透明度設定
1846 pic.SetSurface(s, 0, 0); 1885 pic.SetSurface(s, 0, 0);
1848 if (flag == 0) wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY); 1887 if (flag == 0) wid->Pic()->SetSurfaceAttribute(PicBase::BLIT_MULTIPLY);
1849 pic.Root().DeleteSurface(back_s); 1888 pic.Root().DeleteSurface(back_s);
1850 } 1889 }
1851 } 1890 }
1852 /* その前に枠飾りを設定 */ 1891 /* その前に枠飾りを設定 */
1853 if (name) { 1892 if (name != NULL) {
1854 str = name; str += ".g00"; 1893 str = name; str += ".g00";
1855 Surface* s = pic.Root().NewSurface(str.c_str()); 1894 Surface* s = pic.Root().NewSurface(str.c_str());
1856 if (s) { 1895 if (s) {
1857 Rect rect(*s); 1896 Rect rect(*s);
1858 pic.Root().DeleteSurface(s); 1897 pic.Root().DeleteSurface(s);
1860 p->SetSurface(str.c_str(), 0, 0); 1899 p->SetSurface(str.c_str(), 0, 0);
1861 p->ZMove(ZMOVE_BOTTOM); 1900 p->ZMove(ZMOVE_BOTTOM);
1862 p->show(); 1901 p->show();
1863 } 1902 }
1864 } 1903 }
1865 if (btn == 0) return; 1904 if (btn == NULL) return;
1866 if (use_btn == 0) return; 1905 if (use_btn == NULL) return;
1867 // ボタンの作成 1906 // ボタンの作成
1868 // 使用するボタンについては、必要に応じて show() すること 1907 // 使用するボタンについては、必要に応じて show() すること
1869 1908
1870 /* ボタンの位置情報を求める */ 1909 /* ボタンの位置情報を求める */
1871 str = btn; str += ".g00"; 1910 str = btn; str += ".g00";
1872 ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, str.c_str(), "g00"); 1911 ARCINFO* info = file_searcher.Find(FILESEARCH::PDT, str.c_str(), "g00");
1873 if (info == 0) return; // cannot find file 1912 if (info == NULL) return; // cannot find file
1874 const char* data = info->Read(); 1913 const char* data = info->Read();
1875 /* g00 ファイルのヘッダ部分に位置情報は入っている */ 1914 /* g00 ファイルのヘッダ部分に位置情報は入っている */
1876 /* 存在しなければボタン画像ではない */ 1915 /* 存在しなければボタン画像ではない */
1877 if (data == 0 || *data != 2) { 1916 if (data == NULL || *data != 2) {
1878 delete info; 1917 delete info;
1879 return; 1918 return;
1880 } 1919 }
1881 int index_count = read_little_endian_int(data+5); // 0x70 == 112 ( 8 個ずつグループなので、14個のボタン ) が標準 1920 int index_count = read_little_endian_int(data+5); // 0x70 == 112 ( 8 個ずつグループなので、14個のボタン ) が標準
1882 int i; 1921 int i;
1899 WidButton* wid = new WidButton(event, &pic, str.c_str(), sx, sy, sdx, sdy, cnt, Rect(x, y, x+w, y+h), 1); 1938 WidButton* wid = new WidButton(event, &pic, str.c_str(), sx, sy, sdx, sdy, cnt, Rect(x, y, x+w, y+h), 1);
1900 if (btnpress[i]) { wid->press_func = btnpress[i]; wid->press_pointer = callback;} 1939 if (btnpress[i]) { wid->press_func = btnpress[i]; wid->press_pointer = callback;}
1901 if (btndrag[i]) { wid->drag_func = btndrag[i]; wid->drag_pointer = callback;} 1940 if (btndrag[i]) { wid->drag_func = btndrag[i]; wid->drag_pointer = callback;}
1902 } 1941 }
1903 delete info; 1942 delete info;
1904 return;
1905 } 1943 }
1906 1944
1907 TextWindow::TextWindow(PicContainer& parent, Event::Container& event, int win_no, const AyuSysConfig& config, void* callback) : 1945 TextWindow::TextWindow(PicContainer& parent, Event::Container& event, int win_no, const AyuSysConfig& config, void* callback) :
1908 wid(0), name_visible(true),name(0),name_container(0), face(0) { 1946 wid(0), name_visible(true),name(0),name_container(0), face(0) {
1909 int i; for (i=0; i<8; i++) face_pics[i]=0; 1947 int i; for (i=0; i<8; i++) face_pics[i]=0;
1985 } else { // 名前専用枠なし 2023 } else { // 名前専用枠なし
1986 Rect name_r(0, 0, w, h); 2024 Rect name_r(0, 0, w, h);
1987 name_r.rmove(r.lx, r.ty); 2025 name_r.rmove(r.lx, r.ty);
1988 name_r.rmove(name_posx, name_posy-name_size); 2026 name_r.rmove(name_posx, name_posy-name_size);
1989 name_container = parent.create_node(name_r, 0); 2027 name_container = parent.create_node(name_r, 0);
1990 name = new WidLabel(name_container, Rect(0,0,w,h), true, 0, name_size); 2028 name = new WidLabel(name_container, Rect(0, 0, w, h), true, 0, name_size);
1991 name->show(); 2029 name->show();
1992 name_container->show(); 2030 name_container->show();
1993 } 2031 }
1994 } else { // name_mod == 2 or 3 2032 } else { // name_mod == 2 or 3
1995 name_container = parent.create_node( Rect(0,0,1,1), 0); 2033 name_container = parent.create_node( Rect(0, 0, 1, 1), 0);
1996 } 2034 }
1997 } 2035 }
1998 MakeWaku(*wid->PicNode(), event,waku_no, win_no, use_btn, config, callback); 2036 MakeWaku(*wid->PicNode(), event,waku_no, win_no, use_btn, config, callback);
1999 } 2037 }
2038
2000 void TextImpl::InitWindow(void) { 2039 void TextImpl::InitWindow(void) {
2001 int i; 2040 int i;
2002 int w; 2041 int w;
2003 std::string str; 2042 std::string str;
2004 2043
2005 for (w=0; w<32; w++) { 2044 for (w=0; w<32; w++) {
2006 widgets[w] = new TextWindow(parent, event, w, config, (void*)this); 2045 widgets[w] = new TextWindow(parent, event, w, config, (void*)this);
2007 if (widgets[w]->wid == 0) { 2046 if (widgets[w]->wid == 0) {
2008 delete widgets[w]; 2047 delete widgets[w];
2009 widgets[w] = 0; 2048 widgets[w] = NULL;
2010 } 2049 }
2011 } 2050 }
2012 SetCursor(0); 2051 SetCursor(0);
2013 for (i=0; i<26; i++) { 2052 for (i=0; i<26; i++) {
2014 char buf[1024]; 2053 char buf[1024];
2015 sprintf(buf, "#NAME.%c", i+'A'); 2054 sprintf(buf, "#NAME.%c", i+'A');
2016 const char* s = config.GetParaStr(buf); 2055 const char* s = config.GetParaStr(buf);
2017 if (s) replace_name[i] = s; 2056 if (s != NULL) replace_name[i] = s;
2018 } 2057 }
2019 // replace_name2 : 初期設定 2058 // replace_name2 : 初期設定
2020 // 渚、秋生、渚 (CLANNAD) 2059 // 渚、秋生、渚 (CLANNAD)
2021 char name_nagisa[3] = {0x8f,0x8d,0}; 2060 char name_nagisa[3] = {'\x8f', '\x8d', '\0'};
2022 char name_akio[5] = {0x8f, 0x48, 0x90, 0xb6, 0}; 2061 char name_akio[5] = {'\x8f', '\x48', '\x90', '\xb6', '\0'};
2023 replace_name2[0] = name_nagisa; 2062 replace_name2[0] = name_nagisa;
2024 replace_name2[1] = name_akio; 2063 replace_name2[1] = name_akio;
2025 replace_name2[2] = name_nagisa; 2064 replace_name2[2] = name_nagisa;
2026 text = 0; 2065 text = NULL;
2027 /* テキスト速度の設定 */ 2066 /* テキスト速度の設定 */
2028 int speed, mod, wait, auto_mod; 2067 int speed, mod, wait, auto_mod;
2029 config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed); 2068 config.GetParam("#INIT_MESSAGE_SPEED", 1, &speed);
2030 config.GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &mod); 2069 config.GetParam("#INIT_MESSAGE_SPEED_MOD", 1, &mod);
2031 config.GetParam("#MESSAGE_KEY_WAIT_USE", 1, &auto_mod); 2070 config.GetParam("#MESSAGE_KEY_WAIT_USE", 1, &auto_mod);