OBJ_BITMAP_LABEL

비트맵 레이블 개체.

ObjBitmapLabel

참조

레이블에 상대적인 고정점 위치는 ENUM_ANCHOR_POINT 열거에서 선택할 수 있습니다. 고정점 좌표는 픽셀 단위로 설정됩니다.

비트맵 고정 모서리를 ENUM_BASE_CORNER 열거에서 선택할 수도 있습니다.

비트맵 레이블의 경우 이미지의 가시 범위를 선택할 수 있습니다.

다음 스크립트는 차트에서 여러 비트맵을 생성합니다. 그래픽 개체의 속성을 만들고 변경할 수 있는 특수 기능이 개발되었습니다. 이러한 기능은 자체 애플리케이션에서 "있는 대로" 사용할 수 있습니다.

//--- 설명
#property description "스크립트는 \"비트맵 레이블\" 개체를 생성합니다."
//--- 스크립트 실행 중 입력 매개변수의 표시 창
#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__,
            ": \"비트맵 레이블\" 개체 생성 실패! Error code = ",GetLastError());
      return(false);
     }
//--- On 및 Off 모드에 대한 이미지 설정
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,0,file_on))
     {
      Print(__FUNCTION__,
            ": On 모드 이미지 불러오기 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetString(chart_ID,name,OBJPROP_BMPFILE,1,file_off))
     {
      Print(__FUNCTION__,
            ": Off 모드 이미지 불러오기 실패! 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__,
            ": 이미지 불러오기 실패! 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__,
            ": 개체의 X 좌표 이동 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YDISTANCE,y))
     {
      Print(__FUNCTION__,
            ": 개체의 Y 좌표 이동 실패! 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__,
            ": 개체 너비 변경 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YSIZE,height))
     {
      Print(__FUNCTION__,
            ": 개체 높이 변경 실패! 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__,
            ": 가시 범위의 X 좌표 변경 실패! Error code = ",GetLastError());
      return(false);
     }
   if(!ObjectSetInteger(chart_ID,name,OBJPROP_YOFFSET,y_offset))
     {
      Print(__FUNCTION__,
            ": 가시 범위의 Y 좌표 변경 실패! 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__,
            ": \"비트맵 레이블\" 개체 삭제 실패! 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("차트 너비 가져오기 실패! Error code = ",GetLastError());
      return;
     }
   if(!ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0,y_distance))
     {
      Print("차트 높이 가져오기 실패! 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);
//---
  }