//--- 설명
#property description "스크립트는 \"직사각형 레이블\" 그래픽 개체를 생성합니다."
//--- 스크립트 실행 중 입력 매개변수의 표시 창
#property script_show_inputs
//--- 스크립트의 입력 매개변수
input string InpName="RectLabel"; // 레이블 이름
input color InpBackColor=clrSkyBlue; // 배경 색상
input ENUM_BORDER_TYPE InpBorder=BORDER_FLAT; // 테두리 유형
input ENUM_BASE_CORNER InpCorner=CORNER_LEFT_UPPER; // 고정하기 위한 차트 모서리
input color InpColor=clrDarkBlue; // 평면 테두리 색상(평면)
input ENUM_LINE_STYLE InpStyle=STYLE_SOLID; // 평면 테두리 스타일(평면)
input int InpLineWidth=3; // 평면 테두리 너비(평면)
input bool InpBack=false; // 배경 개체
input bool InpSelection=true; // 이동하려면 강조 표시
input bool InpHidden=true; // 개체 목록에 숨겨짐
input long InpZOrder=0; // 마우스 클릭 우선 순위
//+------------------------------------------------------------------+
//| 직사각형 레이블 생성 label |
//+------------------------------------------------------------------+
bool RectLabelCreate(const long chart_ID=0, // 차트의 ID
const string name="RectLabel", // 레이블 이름
const int sub_window=0, // 하위 창 인덱스
const int x=0, // X 좌표
const int y=0, // Y 좌표
const int width=50, // 너비
const int height=18, // 높이
const color back_clr=C'236,233,216', // 배경 색상
const ENUM_BORDER_TYPE border=BORDER_SUNKEN, // 테두리 유형
const ENUM_BASE_CORNER corner=CORNER_LEFT_UPPER, // 고정을 위한 차트 모서리
const color clr=clrRed, // 평면 테두리 색상(평면)
const ENUM_LINE_STYLE style=STYLE_SOLID, // 평면 테두리 스타일
const int line_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_RECTANGLE_LABEL,sub_window,0,0))
{
Print(__FUNCTION__,
": 직사각형 레이블 생성 실패! 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_BGCOLOR,back_clr);
//--- 테두리 유형 설정
ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border);
//--- 지정된 점 좌표를 기준으로 차트 모서리 설정
ObjectSetInteger(chart_ID,name,OBJPROP_CORNER,corner);
//--- 평면 테두리 색상 설정(평면 모드에서)
ObjectSetInteger(chart_ID,name,OBJPROP_COLOR,clr);
//--- 평면 테두리선 스타일 설정
ObjectSetInteger(chart_ID,name,OBJPROP_STYLE,style);
//--- 평면 테두리 너비 설정
ObjectSetInteger(chart_ID,name,OBJPROP_WIDTH,line_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 RectLabelMove(const long chart_ID=0, // 차트의 ID
const string name="RectLabel", // 레이블 이름
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 RectLabelChangeSize(const long chart_ID=0, // 차트의 ID
const string name="RectLabel", // 레이블 이름
const int width=50, // 레이블 너비
const int height=18) // 레이블 높이
{
//--- 오류 값 재설정
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 RectLabelChangeBorderType(const long chart_ID=0, // 차트의 ID
const string name="RectLabel", // label name
const ENUM_BORDER_TYPE border=BORDER_SUNKEN) // 테두리 유형
{
//--- 오류 값 재설정
ResetLastError();
//--- 테두리 유형 변경
if(!ObjectSetInteger(chart_ID,name,OBJPROP_BORDER_TYPE,border))
{
Print(__FUNCTION__,
": 테두리 유형 변경 실패! Error code = ",GetLastError());
return(false);
}
//--- 실행 성공
return(true);
}
//+------------------------------------------------------------------+
//| 직사각형 레이블 삭제 |
//+------------------------------------------------------------------+
bool RectLabelDelete(const long chart_ID=0, // 차트의 ID
const string name="RectLabel") // 레이블 이름
{
//--- 오류 값 재설정
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/4;
int y=(int)y_distance/4;
//--- 레이블 크기 설정
int width=(int)x_distance/4;
int height=(int)y_distance/4;
//--- 직사각형 레이블 생성
if(!RectLabelCreate(0,InpName,0,x,y,width,height,InpBackColor,InpBorder,InpCorner,
InpColor,InpStyle,InpLineWidth,InpBack,InpSelection,InpHidden,InpZOrder))
{
return;
}
//--- 차트를 다시 그리고 1초 대기
ChartRedraw();
Sleep(1000);
//--- 직사각형 레이블 크기 변경
int steps=(int)MathMin(x_distance/4,y_distance/4);
for(int i=0;i<steps;i++)
{
//--- 크기 조정
width+=1;
height+=1;
if(!RectLabelChangeSize(0,InpName,width,height))
return;
//--- 스크립트 작업이 강제로 비활성화 되었는지 확인
if(IsStopped())
return;
//--- 차트를 다시 그리고 0.01 초 대기
ChartRedraw();
Sleep(10);
}
//--- 1초 지연
Sleep(1000);
//--- 테두리 유형 변경
if(!RectLabelChangeBorderType(0,InpName,BORDER_RAISED))
return;
//--- 차트를 다시 그리고 1초 동안 대기
ChartRedraw();
Sleep(1000);
//--- 테두리 유형 변경
if(!RectLabelChangeBorderType(0,InpName,BORDER_SUNKEN))
return;
//--- 차트를 다시 그리고 1초 동안 대기
ChartRedraw();
Sleep(1000);
//--- 레이블 삭제
RectLabelDelete(0,InpName);
ChartRedraw();
//--- 1초 동안 대기
Sleep(1000);
//---
}
|