view window/event.h @ 48:ed6c21dde840

* use correct format (%p) for pointers
author thib
date Wed, 15 Apr 2009 20:28:19 +0000
parents 5ae5533b3a9a
children 15a18fbe6f21
line wrap: on
line source

/*
 * 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 __EVENT__
#define __EVENT__

#include"rect.h"
#include"SDL.h"

namespace Event {

class Video;
class Time;
class Container;

/*
** マウスの press, ドラッグ、in/out を検出できる
** focus がある時の left/right/space(==press) のキーを判別できる
*/
struct Video {
	virtual void Press(void) {}
	virtual void Release(void) {}
	virtual void Drag(int x_from, int y_from, int x_to, int y_to) {}
	virtual void Motion(int x, int y) {}
	virtual void In(void) {}
	virtual void Out(void) {}
	virtual void KeyLeft(void) {}
	virtual void KeyRight(void) {}

	int point_in(int x, int y); /* z or -1 を返す。大きいほど高いところにある */

	Video(Container& container);
	Video(Container& container, const Rect& init_rect);
	Video(Container& container, const Rect& init_rect, int z);
	void SetRegion(const Rect& new_rect);
	void SetZ(int new_z);
	void activate(void);
	void deactivate(void);
	virtual ~Video();

	Rect Region(void) const { return region;}
private:
	Rect region;
	int z;
	Container& parent;
	bool activated;
	friend bool operator <(const Video& position1, const Video& position2);
};

struct Time {
	enum { NEVER_WAKE = 0xffffffff, FRAME_UPDATE = 0xfffffffe};
	virtual void Elapsed(unsigned int current_time) {wakeup_time = NEVER_WAKE; }; /* next: never elapsed */
	void SetWakeup(unsigned int new_wakeup_time) { wakeup_time = new_wakeup_time; }
	unsigned  Wakeup(void) const { return wakeup_time; }

	Time(Container& container);
	~Time();
private:
	unsigned int wakeup_time;
	Container& parent;
};

struct Container {
#define MOUSE_LEFT 0
#define MOUSE_MIDDLE 1
#define MOUSE_RIGHT 2
#define MOUSE_UP 3
#define MOUSE_DOWN 4
#define KEY_SHIFT 10
#define BUTTON_MAX 32
	int button_pressed;
	int button_presscount[BUTTON_MAX];
	int current_time;

	void MousePos(int& x, int& y);
	bool Exec(unsigned int current_time);

	void Add(Video* item);
	void Delete(Video* item);

	void Add(Time* item);
	void Delete(Time* item);

	typedef bool (*motionfunc)(int x, int y, void* pointer);
	void RegisterGlobalMotionFunc(motionfunc, void* pointer); // マウスの移動のたびに呼び出される関数を登録する
	void DeleteGlobalMotionFunc(motionfunc, void* pointer);
	void RegisterGlobalPressFunc(motionfunc, void* pointer); // マウスのクリックのたびに呼び出される関数を登録する
	void DeleteGlobalPressFunc(motionfunc, void* pointer);

	Container(void);
	~Container(void);
	bool pressed(int mask);
	bool presscount(int mask);
private:
	class ContainerImplVideo* pimpl_video;
	class ContainerImplTime* pimpl_time;
};

}; /* end of namespace Event */


#endif