//--- 説明
#property description "Script creates \"Bitmap Label\" object."
//--- スクリプトの起動時に入力パラメータのウィンドウを表示する
#property script_show_inputs
//--- スクリプト入力パラメータ
input string InpName="BmpLabel"; // ラベル名
input string InpFileOn="\\Images\\dollar.bmp"; // オンモードでのファイル名
input string InpFileOff="\\Images\\euro.bmp"; // オフモードでのファイル名
input bool InpState=false; // ラベルが押される/解放される
input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // アンカーに使用されるチャートのコーナー
input ENUM_ANCHOR_POINT InpAnchor=ANCHOR_CENTER; // アンカーの種類
input color InpColor=clrRed; // 強調表示時の境界線の色
input ENUM_LINE_STYLE InpStyle=STYLE_SOLID; // 強調表示時の線のスタイル
input int InpPointWidth=1; // 移動のポイントサイズ
input bool InpBack=false; // 背景オブジェクト
input bool InpSelection=false; // 強調表示して移動
input bool InpHidden=true; // オブジェクトリストに隠す
input long InpZOrder=0; // マウスクリックの優先順位
//+------------------------------------------------------------------+
//| ビットマップラベルオブジェクトを作成する |
//+------------------------------------------------------------------+
bool BitmapLabelCreate(const long chart_ID=0, // チャート識別子
const string name="BmpLabel", // ラベル名
const int sub_window=0, // サブウィンドウ番号
const int x=0, // X 座標
const int y=0, // Y 座標
const string file_on="", // オンモードでの画像
const string file_off="", // オフモードでの画像
const int width=0, // 表示範囲の X 座標
const int height=0, // 表示範囲の Y 座標
const int x_offset=10, // 表示範囲を X 軸に沿ってシフト
const int y_offset=10, // 表示範囲を Y 軸に沿ってシフト
const bool state=false, // 押される/解放される
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // アンカーに使用されるチャートのコーナー
const ENUM_ANCHOR_POINT anchor=ANCHOR_LEFT_UPPER, // アンカーの種類
const color clr=clrRed, // 強調表示時の境界線の色
const ENUM_LINE_STYLE style=STYLE_SOLID, // 強調表示時の線のスタイル
const int point_width=1, // 移動ポイントサイズ
const bool back=false, // 背景で表示する
const bool selection=false, // 強調表示して移動
const bool hidden=true, // オブジェクトリストに隠す
const long z_order=0) // マウスクリックの優先順位
{
//--- エラー値をリセットする
ResetLastError();
//--- ビットマップラベルを作成する
if(!ObjectCreate(chart_ID,name,OBJ_BITMAP_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": failed to create \"Bitmap Label\" object! Error code = ",GetLastError());
return(false);
}
//--- オンとオフモードでの画像を設定する
if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,0,file_on))
{
Print(__FUNCTION__,
": failed to load the image for On mode! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,1,file_off))
{
Print(__FUNCTION__,
": failed to load the image for Off mode! Error code = ",GetLastError());
return(false);
}
//--- ラベル座標を設定する
ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x);
ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y);
//--- 画像の表示範囲を設定する。もし幅または高さの値が
//--- それぞれソース画像の幅と高さを超えた場合、
//--- 描画されない。反対の場合
//--- これらの値に対応する部分が描画される。
ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width);
ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height);
//--- 表示範囲に表示される画像の部分を設定する
//--- デフォルトの部分は、画像の左上の領域
//--- 値は、この領域からのシフトして画像の別の部分の表示を可能にする
ObjectSetInteger(chart_ID,name,OBJPROP_XOFFSET,x_offset);
ObjectSetInteger(chart_ID,name,OBJPROP_YOFFSET,y_offset);
//--- ラベルの状態(キーの押または離し)を定義する
ObjectSetInteger(chart_ID,name,OBJPROP_STATE,state);
//--- ポイント座標が相対的に定義されているチャートのコーナーを設定
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- アンカーの種類を設定
ObjectSetInteger(chart_ID,name,OBJPROP_ANCHOR,anchor);
//--- オブジェクトのハイライト表示モードが有効になっている際の境界線の色を設定する
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- オブジェクトのハイライト表示モードが有効になっている際の境界線のスタイルを設定する
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- オブジェクトを移動するためのアンカーポイントのサイズを設定する
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,point_width);
//--- 前景(false)または背景(true)に表示
ObjectSetInteger(chart_ID,name,OBJPROP_BACK,back);
//--- マウスでラベルを移動させるモードを有効(true)か無効(false)にする
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTABLE,selection);
ObjectSetInteger(chart_ID,name,OBJPROP_SELECTED,selection);
//--- オブジェクトリストのグラフィックオブジェクトを非表示(true)か表示(false)にする
ObjectSetInteger(chart_ID,name,OBJPROP_HIDDEN,hidden);
//--- チャートのマウスクリックのイベントを受信するための優先順位を設定する
ObjectSetInteger(chart_ID,name,OBJPROP_ZORDER,z_order);
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| ビットマップラベルオブジェクトに新しい画像を設定する |
//+------------------------------------------------------------------+
bool BitmapLabelSetImage(const long chart_ID=0, // チャート識別子
const string name="BmpLabel", // ラベル名e
const int on_off=0, // 修飾子(オンまたはオフ)
const string file="") // ファイルパス
{
//--- エラー値をリセットする
ResetLastError();
//--- 画像へのパスを設定する
if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,on_off,file))
{
Print(__FUNCTION__,
": failed to load the image! Error code = ",GetLastError());
return(false);
}
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| ビットマップラベルオブジェクトを移動する |
//+------------------------------------------------------------------+
bool BitmapLabelMove(const long chart_ID=0, // チャート識別子
const string name="BmpLabel", // ラベル名
const int x=0, // X 座標
const int y=0) // Y 座標
{
//--- エラー値をリセットする
ResetLastError();
//--- オブジェクトを移動する
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XDISTANCE,x))
{
Print(__FUNCTION__,
": failed to move X coordinate of the object! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
{
Print(__FUNCTION__,
": failed to move Y coordinate of the object! Error code = ",GetLastError());
return(false);
}
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| ビットマップの表示範囲のサイズを変更する |
//+------------------------------------------------------------------+
bool BitmapLabelChangeSize(const long chart_ID=0, // チャート識別子
const string name="BmpLabel", // ラベル名
const int width=0, // ラベル幅
const int height=0) // ラベルの高さ
{
//--- エラー値をリセットする
ResetLastError();
//--- オブジェクトサイズを変更する
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XSIZE,width))
{
Print(__FUNCTION__,
": failed to change the object width! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
{
Print(__FUNCTION__,
": failed to change the object height! Error code = ",GetLastError());
return(false);
}
//--- 実行成功
return(true);
}
//+--------------------------------------------------------------------+
//| 表示範囲の左上隅のy座標を変更する |
//+--------------------------------------------------------------------+
bool BitmapLabelMoveVisibleArea(const long chart_ID=0, // チャート識別子
const string name="BmpLabel", // ラベル名
const int x_offset=0, // 表示範囲の X 座標
const int y_offset=0) //表示範囲の Y 座標
{
//--- エラー値をリセットする
ResetLastError();
//--- オブジェクトの表示範囲の座標を変更する
if(!ObjectSetInteger(chart_ID,name,OBJPROP_XOFFSET,x_offset))
{
Print(__FUNCTION__,
": failed to change X coordinate of the visibility scope! Error code = ",GetLastError());
return(false);
}
if(!ObjectSetInteger(chart_ID,name,OBJPROP_YOFFSET,y_offset))
{
Print(__FUNCTION__,
": failed to change Y coordinate of the visibility scope! Error code = ",GetLastError());
return(false);
}
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| ビットマップラベルオブジェクトを削除する |
//+------------------------------------------------------------------+
bool BitmapLabelDelete(const long chart_ID=0, // チャート識別子
const string name="BmpLabel") // ラベル名
{
//--- エラー値をリセットする
ResetLastError();
//--- ラベルを削除する
if(!ObjectDelete(chart_ID,name))
{
Print(__FUNCTION__,
": failed to delete \"Bitmap label\" object! Error code = ",GetLastError());
return(false);
}
//--- 実行成功
return(true);
}
//+------------------------------------------------------------------+
//| スクリプトプログラムを開始する関数 |
//+------------------------------------------------------------------+
void OnStart()
{
//--- チャートウィンドウサイズ
long x_distance;
long y_distance;
//--- ウィンドウサイズを設定する
if(!ChartGetInteger(0,CHART_WIDTH_IN_PIXELS,0,x_distance))
{
Print("Failed to get the chart width! Error code = ",GetLastError());
return;
}
if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
{
Print("Failed to get the chart height! Error code = ",GetLastError());
return;
}
//--- ビットマップラベル座標を定義する
int x=(int)x_distance/2;
int y=(int)y_distance/2;
//--- ラベルのサイズと表示範囲座標を設定する
int width=32;
int height=32;
int x_offset=0;
int y_offset=0;
//--- ビットマップラベルをウィンドウの中央に配置する
if(!BitmapLabelCreate(0,InpName,0,x,y,InpFileOn,InpFileOff,width,height,x_offset,y_offset,InpState,
InpCorner,InpAnchor,InpColor,InpStyle,InpPointWidth,InpBack,InpSelection,InpHidden,InpZOrder))
{
return;
}
//--- チャートを再描画して1 秒待つ
ChartRedraw();
Sleep(1000);
//--- ループ内でラベルの表示範囲サイズを変更する
for(int i=0;i<6;i++)
{
//--- 表示範囲サイズを変更する
width--;
height--;
if(!BitmapLabelChangeSize(0,InpName,width,height))
return;
//--- スクリプトの動作が強制的に無効にされているかどうかをチェックする
if(IsStopped())
return;
//--- チャートを再描画する
ChartRedraw();
// 0.3 秒の遅れ
Sleep(300);
}
//--- 1 秒の遅れ
Sleep(1000);
//--- ループ内でラベルの表示範囲座標を変更する
for(int i=0;i<2;i++)
{
//--- 表示範囲座標を変更する
x_offset++;
y_offset++;
if(!BitmapLabelMoveVisibleArea(0,InpName,x_offset,y_offset))
return;
//--- スクリプトの動作が強制的に無効にされているかどうかをチェックする
if(IsStopped())
return;
//--- チャートを再描画する
ChartRedraw();
// 0.3 秒の遅れ
Sleep(300);
}
//--- 1 秒の遅れ
Sleep(1000);
//--- ラベルを削除する
BitmapLabelDelete(0,InpName);
ChartRedraw();
//--- 1 秒の遅れ
Sleep(1000);
//---
}
|