using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
namespace MarimoDX
{
public class Graph:IDisposable
{
public bool IsDisposed { get; private set; }
public int Width { get; private set; }
public int Height { get; private set; }
public int GHandle { get; private set; }
public Graph(string filename)
{
if (!File.Exists(filename)) { throw new FileNotFoundException("画像データが見つかりませんでした"); }
int i = DX.FileRead_size(filename);
if ((GHandle = DX.LoadGraph(filename)) == (int)(-1)) { throw new GraphException("画像読み込みで異常がおきました"); }
int w, h;
DX.GetGraphSize(GHandle, out w, out h);
Width = w; Height = h;
}
public Graph(int GHandle)
{
this.GHandle = GHandle;
int w, h;
DX.GetGraphSize(GHandle, out w, out h);
Width = w; Height = h;
}
///
/// 画像を描画します
///
/// 左上x座標
/// 左上y座標
public void Draw(int x, int y)
{
DX.DrawGraph(x, y, GHandle, 1);
}
///
/// 画像を描画します
///
/// 左上の座標
public void Draw(Point p) { Draw(p.X, p.Y); }
///
/// 画像を指定の大きさに拡大or縮小して描画します
///
/// 左上x座標
/// 左上y座標
/// 描画横幅
/// 描画縦幅
public void Draw(int x, int y, int width, int height)
{
DX.DrawExtendGraph(x, y, x + width, y + height, GHandle, 1);
}
///
/// 画像を指定の大きさに拡大or縮小して描画します
///
/// 左上座標
/// 描画横幅
/// 描画縦幅
public void Draw(Point p, int width, int height)
{
Draw(p.X, p.Y, width, height);
}
#region 回転描画系
///
/// 拡大、回転して描画
///
/// 左上x座標
/// 左上y座標
/// 拡大率
/// 回転角度
public void Draw(int x,int y, double ExtRate, double Angle)
{
DX.DrawRotaGraph(x, y, ExtRate, Angle, GHandle, 1);
}
///
/// 拡大、回転して描画
///
/// 描画点、回転軸
/// 拡大率
/// 回転角度
public void Draw(Point p, double ExtRate, double Angle)
{
DX.DrawRotaGraph(p.X, p.Y, ExtRate, Angle, GHandle, 1);
}
///
/// 拡大、回転して描画
///
/// 左上x座標
/// 左上y座標
/// 回転軸x座標
/// 回転軸y座標
/// 拡大率
/// 回転角度
public void Draw(int x, int y, int cx, int cy, double ExtRate, double Angle)
{
DX.DrawRotaGraph2(x, y, cx, cy, ExtRate, Angle, GHandle, 1);
}
///
/// 拡大、回転して描画
///
/// 左上座標
/// 回転軸x座標
/// 回転軸y座標
/// 拡大率
/// 回転角度
public void Draw(Point p, int cx, int cy, double ExtRate, double Angle)
{
DX.DrawRotaGraph2(p.X, p.Y, cx, cy, ExtRate, Angle, GHandle, 1);
}
///
/// 拡大、回転して描画
///
/// 左上座標
/// 回転軸座標
/// 拡大率
/// 回転角度
public void Draw(Point p, Point c, double ExtRate, double Angle)
{
DX.DrawRotaGraph2(p.X, p.Y, c.X, c.Y, ExtRate, Angle, GHandle, 1);
}
///
/// 回転して描画
///
/// 左上x座標
/// 左上y座標
/// 回転角度
public void Draw(int x, int y, double Angle)
{
DX.DrawRotaGraph(x, y, 1, Angle, GHandle, 1);
}
///
/// 回転して描画
///
/// 描画点、回転軸
/// 回転角度
public void Draw(Point p, double Angle)
{
DX.DrawRotaGraph(p.X, p.Y, 1, Angle, GHandle, 1);
}
///
/// 回転して描画
///
/// 左上x座標
/// 左上y座標
/// 回転軸x座標
/// 回転軸y座標
/// 回転角度
public void Draw(int x, int y, int cx, int cy, double Angle)
{
DX.DrawRotaGraph2(x, y, cx, cy, 1, Angle, GHandle, 1);
}
///
/// 回転して描画
///
/// 左上座標
/// 回転軸x座標
/// 回転軸y座標
/// 回転角度
public void Draw(Point p, int cx, int cy, double Angle)
{
DX.DrawRotaGraph2(p.X, p.Y, cx, cy, 1, Angle, GHandle, 1);
}
///
/// 回転して描画
///
/// 左上座標
/// 回転軸座標
/// 回転角度
public void Draw(Point p, Point c, double Angle)
{
DX.DrawRotaGraph2(p.X, p.Y, c.X, c.Y, 1, Angle, GHandle, 1);
}
#endregion
#region IDisposable メンバ
public void Dispose()
{
if (IsDisposed) return;
IsDisposed = true;
DX.DeleteGraph(GHandle);
GC.SuppressFinalize(this);
}
~Graph()
{
Dispose();
}
#endregion
///
/// 画像の分割読み込み
///
/// ファイル名
/// 読み込み数
/// 横の画像数
///
public static Graph[] DivGraph(string filename, int allnum, int xnum)
{
int[] handles = new int[allnum];
using (Bitmap bmp = new Bitmap(filename))
{
int h = (int)Math.Ceiling((double)(allnum / xnum));
DX.LoadDivGraph(filename, allnum, xnum, h, (int)(bmp.Width / xnum), (int)(bmp.Height / h),out handles[0]);
}
Graph[] ret = new Graph[allnum];
for (int i = 0; i < ret.Length; i++)
{
ret[i] = new Graph(handles[i]);
}
return ret;
}
}
public class GraphException : Exception
{
public GraphException(string message)
: base(message)
{
}
public GraphException() : base() { }
}
}