view scn2k/scn2k_text.h @ 62:3b1593186f12

fix pointers used to get strchr result
author Thibaut GIRKA <thib@sitedethib.com>
date Sat, 06 Feb 2010 17:03:47 +0100
parents 36d92d21300f
children
line wrap: on
line source

/*
 * Copyright (c) 2009 Thibaut GIRKA
 * Copyright (c) 2004-2006  Kazunori "jagarl" Ueno
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

#ifndef __SCN2K_TEXT_H__
#define __SCN2K_TEXT_H__

#include <vector>
#include <map>
#include <list>

#include "scn2k_cmd.h"

#include "window/event.h"
#include "window/picture.h"
#include "window/widget.h"

#include "font/text.h"

#include "system/system_config.h"

using namespace std;

void dprintf(const char* fmt, ...); //FIXME
void eprintf(const char* fmt, ...); //FIXME

// kanji conv : デバッグ表示用
void kconv(const unsigned char* src, unsigned char* dest);
void kconv_rev(const unsigned char* src, unsigned char* dest);
string kconv(const string& s);
string kconv_rev(const string& s);

/**************************************************************::
**
** TimerAtom
*/

struct TimerAtom {
	unsigned int start_time;
};

struct FrameTimerAtom : TimerAtom {
	int from;
	int to;
	unsigned int total_time;
};


/**************************************************************::
**
** BacklogItem
*/

struct BacklogItem {
	enum {SaveSelect = -2};
	int scn, pos;
	int koe;
	std::string face;
	struct TextStream text;
	BacklogItem(void);
	void Clear(void);
	void AddTextPos(Cmd&);
	void DeleteTextPos();
	void SetSavepos(int pos);
	BacklogItem& operator =(const BacklogItem&);
};

/**************************************************************::
**
** TextWindow
*/

struct TextWindow {
/* @@@ : SetWindowColor での surface 再設定に注意 */
	WidText* wid;
	bool name_visible;
	WidLabel* name;
	PicContainer* name_container;
	PicBase* face;
	PicBase* face_pics[8];
	TextWindow(PicContainer& parent, Event::Container& event, int window_no, void* callback);
	~TextWindow();
	Rect WakuSize(PicContainer& pic, int waku_no);
	void MakeWaku(PicContainer& pic, Event::Container& event, int waku_no,int window_no, bool* use_btn, void* callback);
	void show(void);
	void hide(void);
	void ShowFace(const char* path);
	void ResetFace(void);
	void StartText(const TextStream& _stream);
	void SetName(const char* n);
};

/**************************************************************::
**
** SaveFaceHash
*/

struct SaveFaceHash { // バックログセーブ時の顔画像管理を行う
	map<string, int> facetonum;
	typedef pair<string,int> Node;
	typedef list<Node> List;
	List container;
	int id_max;
	static int size_max;
	SaveFaceHash() : id_max(0) {}
	void NewNode(string face, int face_id);
	int Add(string face);
	string Get(int num);
};


/**************************************************************::
**
** Text
*/

class Text : public CommandHandler {
	public:
		Text(Event::Container& _event, PicContainer& _parent);
		~Text();
		void InitWindow(void);
		void Exec(Cmd& cmd);
		bool Wait(unsigned int current_time, Cmd& cmd);
		void SetSkipMode(SkipMode _mode);
		void hide(void);
		void show(void) { show(text_window_number); }
		void show(int num);
		void Save(std::string& str, bool select_save);
		void Load(const char* str);
		void DrawBacklog(BacklogItem& item, Cmd& cmd);

		static void PressFuncSkip(void* pointer, WidButton* from);
		static void PressFuncLoad(void* pointer, WidButton* from);
		static void PressFuncSave(void* pointer, WidButton* from);
		static void PressFuncBacklog(void* pointer, WidButton* from);
		static void PressFuncBacklogFwd(void* pointer, WidButton* from);

	private:
		void SetWindowColor(int r, int g, int b, int a, bool is_transparent);
		void SetTextSpeed(int new_speed);
		void SetTextWait(int new_wait);

		void CreateSelect(Cmd& cmd);
		void CreateSelBG(void);

		void AddText(const char* str);

		static void PressFuncButton(void* pointer, WidButton* from);
		static bool PressFunc(int x, int y, void* pointer);

		void SetCursor(int num);

	public:
		vector<BacklogItem> backlog;
		BacklogItem backlog_item;
		TextWindow* text;
		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,
			WAIT_SELECT_INBOX = 10, WAIT_SELECT_OUTBOX=11, WAIT_SELECT_VALUE = 12,
			WAIT_EXTRN_MASK = 64, SAVEMASK = 128, LOADMASK = 256, SKIPMASK = 512,
			CLEARSCR_MASK = 1024, STATSAVE_MASK = 2048, CLEARSCR_WAIT_MASK=(1<<12),
			SKIPEND_MASK = (1<<13), BACKLOG_MASK=(1<<14), BACKLOG_MASK_FWD=(1<<15),
			BACKLOG_MASK_KOE=(1<<16), BACKLOG_WAIT_MASK=(1<<17),
			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)
		} Status;
		Status status, status_saved, status_mask;

	private:
		std::string ruby_text;
		bool ruby_text_flag;
		unsigned int wait_time;
		unsigned int old_time;
		int text_window_number;
		bool text_parsing;
		TextStream text_stream;
		SkipMode skip_mode;
		int save_selectcount;

		std::map<int, TimerAtom> timer_var;
		//TODO: Handle EX Timer set
		std::map<int, TimerAtom> timer_var_ex;
		//TODO: Handle Frame Timers
		std::map<int, FrameTimerAtom> frame_var;
		std::map<int, FrameTimerAtom> frame_var_ex;

		std::vector<WidTextButton*> selects;
		std::vector<int> sel_backlog_pos;
		string replace_name[26];
		string replace_name2[26];
		PicContainer* sel_widget;
		PicWidget* backlog_widget;

		BacklogItem cur_backlog_item;
		BacklogItem drawn_backlog_item;

		TextWindow* widgets[32];
		WidTimeCursor* kcursor;
		Surface* sel_bg1;
		Surface* sel_bg2;
		Rect sel_bg_rect;

		VarInfo wait_savedvar[2];

		AyuSysConfig *config;

		Event::Container& event;
		PicContainer& parent;

		//Opcode handling
		// Text
		void impl_txtClear(Cmd& cmd);
		void impl_logKoe(Cmd& cmd);
		void impl_pause(Cmd& cmd);
		void impl_br(Cmd& cmd);
		void impl_FaceOpen(Cmd& cmd);
		void impl_FaceClear(Cmd& cmd);
		void impl_doRuby(Cmd& cmd);
		void impl_TextWindow(Cmd& cmd);
		void impl_msgClear(Cmd& cmd);
		void impl_FastText(Cmd& cmd);
		void impl_createSelect(Cmd& cmd);
		void impl_SetSkipMode(Cmd& cmd);
		void impl_Wait(Cmd& cmd);
		void impl_PauseCursor(Cmd& cmd);
		void impl_SetWindowAttr(Cmd& cmd);
		void impl_GetWindowAttr(Cmd& cmd);
		void impl_GetName(Cmd& cmd);
		void impl_SetName(Cmd& cmd);
		void impl_GetLocalName(Cmd& cmd);
		void impl_SetLocalName(Cmd& cmd);
		// Misc (related with text)
		void impl_ShowBackground(Cmd& cmd);
		void impl_GetDefConfig(Cmd& cmd);
		void impl_GetConfig(Cmd& cmd);
		void impl_SetConfig(Cmd& cmd);
		// Misc
		void impl_index_series(Cmd& cmd);
		void impl_load(Cmd& cmd);
		void impl_GetClick(Cmd& cmd);
		// Time/Frame
		void impl_InitFrame(Cmd& cmd);
		void impl_ReadFrame(Cmd& cmd);
		void impl_InitFrames(Cmd& cmd);
		void impl_ReadFrames(Cmd& cmd);
		void impl_ResetTimer(Cmd& cmd);
		void impl_Timer(Cmd& cmd);
		// Maths
		void impl_rnd(Cmd& cmd);
		void impl_pcnt(Cmd& cmd);
		void impl_abs(Cmd& cmd);
		void impl_power(Cmd& cmd);
		void impl_sin(Cmd& cmd);
		void impl_min(Cmd& cmd);
		void impl_max(Cmd& cmd);
		void impl_constrain(Cmd& cmd);
};

#endif