OBJ_BITMAP_LABEL

位图对象标签。

ObjBitmapLabel

注意

相对于标签的定位点位置可以从 ENUM_ANCHOR_POINT 枚举选择。定位点坐标用像素设置。

您也可以从 ENUM_BASE_CORNER 枚举选择位图定位角。

针对位图标签,您可以选择图像的 可视范围

示例

下面的脚本创建图表上的多个位图。已开发的特别函数用于创建和改变图形对象的属性。您可以在您的个人应用中使用这些函数"as is" 。

//--- 描述
#property description "Script creates \"Bitmap Label\" object."
//--- 启动脚本期间显示输入参数的窗口
#property script_show_inputs
//--- 脚本的输入参数
input string            InpName="BmpLabel";               // 标签名称
input string            InpFileOn="\\Images\\dollar.bmp"// On 模式的文件名称
input string            InpFileOff="\\Images\\euro.bmp";  // Off 模式的文件名称
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,               // 图表 ID
                       const string            name="BmpLabel",          // 标签名称
                       const int               sub_window=0,             // 子窗口指数
                       const int               x=0,                      // X 坐标
                       const int               y=0,                      // Y 坐标
                       const string            file_on="",               // On 模式的图像
                       const string            file_off="",              // 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);
     }
//--- 设置On 和 Off 模式的图形
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,0,file_on))
     {
      Print(__FUNCTION__,
            ": failed to download the image for On mode! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,1,file_off))
     {
      Print(__FUNCTION__,
            ": failed to download 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,      // 图表 ID
                         const string name="BmpLabel"// 标签名称
                         const int    on_off=0,        // 修饰符 (On 或 Off)
                         const string file="")         // 文件路径
  {
//--- 重置错误的值
   ResetLastError();
//--- 设置图像文件路径
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,on_off,file))
     {
      Print(__FUNCTION__,
            ": failed to download the image! Error code = ",GetLastError());
      return(false);
     }
//--- 成功执行
   return(true);
  }
//+------------------------------------------------------------------+
//| 移动位图标签对象                                                   |
//+------------------------------------------------------------------+
bool BitmapLabelMove(const long   chart_ID=0,      // 图表 ID
                     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,      // 图表 ID
                           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);
  }
//+--------------------------------------------------------------------+
//| 改变可见范围左上角的坐标                                              |
//+--------------------------------------------------------------------+
bool BitmapLabelMoveVisibleArea(const long   chart_ID=0,      // 图表 ID
                                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,      // 图表 ID
                       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);
//---
  }