//
//  libs.h
//  汎用関数
//
//  Created by 今井 彰彦 on 10/12/21.
//  Copyright 2010 AIG-Soft. All rights reserved.
//

#import <UIKit/UIKit.h>
#include <stdlib.h>	// abs()

typedef enum { // デバイス種類
	DEVICE_UNKNOWN=0,
	DEVICE_IPAD,
	DEVICE_IPODTOUCH,
	DEVICE_IPHONE,
	// シミュレーター
	DEVIDE_IPHONE_SIMURATOR,
	DEVICE_IPAD_SIMULATOR
} DEVICE_TYPE;
#define DEVICE_SIMULATOR	DEVIDE_IPHONE_SIMURATOR

// プロトタイプ宣言
void SetViewBelowStatusBar(UIView *view);
void SetViewSize(UIView *view,CGFloat wx,CGFloat wy);
NSString *strInterfaceOrientation(UIInterfaceOrientation Orientation);
NSString *strDeviceOrientation(UIDeviceOrientation Orientation);
BOOL checkDeviceOrientation(UIDeviceOrientation *deviceOrientation);
BOOL checkDeviceOrientationOK(void);
NSString *mesONOFF(BOOL onoff);
NSString *mesONOFF2(BOOL onoff,NSString *onmes,NSString *offmes);
void understandOrientation(UIInterfaceOrientation Orientation);
DEVICE_TYPE getDeviceType(void);
BOOL isDeviceIpad(DEVICE_TYPE devtype);
BOOL isDeviceIpadAndPortrait(DEVICE_TYPE devtype);
NSUInteger getHourMinSec(NSDate *date,NSUInteger *hour,NSUInteger *sec);
void centeringActivityIndicator(UIActivityIndicatorView *indicator,UIView *view);
UIActivityIndicatorView *displayActivityIndicator(UIView *view,UIActivityIndicatorViewStyle style);
void changeActivityIndicator(UIActivityIndicatorView *indicator,UIView *view);
void eraseActivityIndicator(UIActivityIndicatorView *indicator);
NSString *dateStringWithoutGMT(NSDate *date);
void setActionSheetResize(UIActionSheet *asheet);
void setAlertViewResize(UIAlertView *aview);
void Alert1(NSString *title,NSString *message,id delegate);
NSString *dateFormatJtoE(NSString *date);
BOOL cmpRegularExpression(NSString *str,NSString *expression);
BOOL isMailAddress(NSString *adrs);
BOOL isServerAddress(NSString *adrs);
NSString *localKeyName(NSString *defaultName);
UIColor *colorByNo(NSInteger no);
float getSystemVersion(void);
BOOL isPointInRect(CGPoint point,CGRect rect);
NSInteger strArray2No(NSString *str,NSArray *array);
NSInteger pathArray2No(NSString *fname,NSArray *pathes);
NSString *makeNowDateStr(void);
CGSize getFontSize(UIFont *font);

typedef struct {
	NSUInteger	b;
	NSUInteger	r;
	NSUInteger	g;
} RGB_TABLE;

#ifndef RGB
#define RGB(R,G,B) [UIColor colorWithRed:R/255.0f green:G/255.0f blue:B/255.0f alpha:1.0f]
#endif

enum {
	PENCIL_COLOR_BLACK=0,
	PENCIL_COLOR_BLUE,
	PENCIL_COLOR_RED,
	PENCIL_COLOR_MAGENTA,
	PENCIL_COLOR_GREEN,
	PENCIL_COLOR_CYAN,
	PENCIL_COLOR_YELLOW,
	PENCIL_COLOR_WHITE
};


// #define関数
// 実行ループにタイマーを追加する
#define AddTimerToRunLoop(timer)	[[NSRunLoop currentRunLoop] addTimer:timer forMode:NSDefaultRunLoopMode]

// 指定時間後に実行ループに入る:tm=0.0で直後
#define EnterRunLoop(tm)	[[NSRunLoop currentRunLoop]runUntilDate:[NSDate dateWithTimeIntervalSinceNow:tm]]

// 浮動小数点(<1.0,>=0.1)比較:浮動小数点では==は使えないので
#define	EquFloat(f1,f2)	(abs(f1-f2)<0.1)

// 分→秒変換
#define	tMin(m)	((NSTimeInterval)(m)*60.0)

// カメラが有効かどうか
#define	isCameraEnable()	([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
// アルバムが有効かどうか
#define	isAlbumEnable()		([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum])

// センタリング
#define CenteringX(lbl,view)	{CGPoint center=lbl.center; center.x=view.center.x; lbl.center=center;}

// iOS5かどうか
#define isiOS5over()	(getSystemVersion()>=5.0)


// デバッグ用関数
#ifdef DEBUG
void printFrame(NSString *mes,CGRect frame);
#define	isJIKKI()		(getDeviceType()<DEVICE_SIMULATOR)
#define	isSIMULATOR()	(getDeviceType()>=DEVICE_SIMULATOR)
#else // 本番
#define	printFrame(...)
#define	isJIKKI()		(1)	/* 本番は常に実機とみなす */
#define	isSIMULATOR()	(0)	/* 同上 */
#endif
