260 lines
6.4 KiB
Plaintext
260 lines
6.4 KiB
Plaintext
///////////////////////////////////////////////////////
|
|
//
|
|
// SaherElm IT Center MQL5 Class Library
|
|
// --------------------------------------
|
|
// Name: XCRectangleLabel
|
|
// Description: provides all based classes for use ...
|
|
//
|
|
//
|
|
// Maintainer:
|
|
// ------------
|
|
// Hadi Khazaee Asl (hadi_khazaee_asl@yahoo.com)
|
|
//
|
|
//////////////////////////////////////////////////////
|
|
//
|
|
// Global Properties ...
|
|
#property library
|
|
#property copyright "Copyright 2023, SaherElm IT Center"
|
|
#property link "https://www.saherelm.ir"
|
|
#property version "1.00"
|
|
#property strict
|
|
|
|
//
|
|
#include "../XCObjects/x-saherelm.xcobject.class.mq5"
|
|
|
|
//
|
|
// Definitions ...
|
|
|
|
//
|
|
// Implementation ...
|
|
|
|
//
|
|
// a Rectangle Label Creation Class ...
|
|
class XCRectangleLabel : public XCObject
|
|
{
|
|
//
|
|
// Public ...
|
|
public:
|
|
//
|
|
// Constructor(s) ...
|
|
void XCRectangleLabel()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Deconstructor ...
|
|
void ~XCRectangleLabel()
|
|
{
|
|
}
|
|
|
|
//
|
|
// Actions ...
|
|
|
|
/**
|
|
* Create an Instance of Class Object ...
|
|
*
|
|
* @param name: Object Name
|
|
* @param xDis: X Distance
|
|
* @param yDis: Y Distance
|
|
* @param xSize: X Size
|
|
* @param ySize: Y Size
|
|
*/
|
|
bool Create(
|
|
string name,
|
|
int xDis,
|
|
int yDis,
|
|
int xSize,
|
|
int ySize,
|
|
long chartID = 0 //
|
|
)
|
|
{
|
|
//
|
|
// Object creation and property settings
|
|
bool result = false;
|
|
|
|
//
|
|
result = ObjectCreate(chartID, name, OBJ_RECTANGLE_LABEL, 0, 0, 0);
|
|
if (!result)
|
|
{
|
|
return result;
|
|
}
|
|
|
|
//
|
|
ObjectSetInteger(chartID, name, OBJPROP_XDISTANCE, xDis);
|
|
ObjectSetInteger(chartID, name, OBJPROP_YDISTANCE, yDis);
|
|
ObjectSetInteger(chartID, name, OBJPROP_XSIZE, xSize);
|
|
ObjectSetInteger(chartID, name, OBJPROP_YSIZE, ySize);
|
|
|
|
//
|
|
mName = name;
|
|
mChartID = chartID;
|
|
|
|
//
|
|
return result;
|
|
}
|
|
|
|
/**
|
|
* Add a Name to Object
|
|
* @param name: name
|
|
*/
|
|
void Add(string name)
|
|
{
|
|
//
|
|
// Add a new object by name to the rectangle label and track distances
|
|
ArrayResize(mAddedNames, ArraySize(mAddedNames) + 1);
|
|
ArrayResize(mAddedXDisDiffrence, ArraySize(mAddedXDisDiffrence) + 1);
|
|
ArrayResize(mAddedYDisDiffrence, ArraySize(mAddedYDisDiffrence) + 1);
|
|
|
|
//
|
|
mAddedNames[ArraySize(mAddedNames) - 1] = name;
|
|
mAddedXDisDiffrence[ArraySize(mAddedXDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_XDISTANCE) - ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
|
|
mAddedYDisDiffrence[ArraySize(mAddedYDisDiffrence) - 1] = ObjectGetInteger(0, mName, OBJPROP_YDISTANCE) - ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
|
|
}
|
|
|
|
//
|
|
// Handlers ...
|
|
|
|
/**
|
|
* Event Handling for Mouse Movement ...
|
|
* @param id: Event ID
|
|
* @param lparam: Event parameter of long type
|
|
* @param dparam: Event parameter of double type
|
|
* @param sparam: Event parameter of string type
|
|
*/
|
|
void OnEvent(
|
|
int id,
|
|
long lparam,
|
|
double dparam,
|
|
string sparam //
|
|
)
|
|
{
|
|
//
|
|
// Handle mouse movement events for dragging the rectangle label
|
|
if (id == CHARTEVENT_MOUSE_MOVE)
|
|
{
|
|
//
|
|
int X = (int)lparam;
|
|
int Y = (int)dparam;
|
|
int MouseState = (int)sparam;
|
|
|
|
//
|
|
string name = mName;
|
|
int XSize = (int)ObjectGetInteger(0, name, OBJPROP_XSIZE);
|
|
int YSize = (int)ObjectGetInteger(0, name, OBJPROP_YSIZE);
|
|
int XDistance = (int)ObjectGetInteger(0, name, OBJPROP_XDISTANCE);
|
|
int YDistance = (int)ObjectGetInteger(0, name, OBJPROP_YDISTANCE);
|
|
|
|
//
|
|
if (MouseState == 1 &&
|
|
mPreviousMouseState == 0)
|
|
{
|
|
//
|
|
mlbDownX = X;
|
|
mlbDownY = Y;
|
|
mlbDownXDistance = XDistance;
|
|
mlbDownYDistance = YDistance;
|
|
|
|
//
|
|
if (X >= XDistance &&
|
|
Y >= YDistance &&
|
|
X <= XDistance + XSize &&
|
|
Y <= YDistance + YSize)
|
|
{
|
|
mMovingState = true;
|
|
}
|
|
}
|
|
|
|
//
|
|
if (mMovingState)
|
|
{
|
|
//
|
|
ChartSetInteger(0, CHART_MOUSE_SCROLL, false);
|
|
ObjectSetInteger(0, name, OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX);
|
|
ObjectSetInteger(0, name, OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY);
|
|
|
|
//
|
|
for (int i = 0; i < ArraySize(mAddedNames); i++)
|
|
{
|
|
//
|
|
ObjectSetInteger(0, mAddedNames[i], OBJPROP_XDISTANCE, mlbDownXDistance + X - mlbDownX - mAddedXDisDiffrence[i]);
|
|
ObjectSetInteger(0, mAddedNames[i], OBJPROP_YDISTANCE, mlbDownYDistance + Y - mlbDownY - mAddedYDisDiffrence[i]);
|
|
}
|
|
|
|
//
|
|
ChartRedraw(0);
|
|
}
|
|
|
|
//
|
|
if (MouseState == 0)
|
|
{
|
|
//
|
|
mMovingState = false;
|
|
ChartSetInteger(0, CHART_MOUSE_SCROLL, true);
|
|
}
|
|
|
|
//
|
|
mPreviousMouseState = MouseState;
|
|
}
|
|
}
|
|
|
|
//
|
|
// Getter(s) / Setter(s) ...
|
|
|
|
/**
|
|
* Set Object Border Type ...
|
|
*
|
|
* @param borderType: Specified border type
|
|
*/
|
|
void BorderType(ENUM_BORDER_TYPE borderType)
|
|
{
|
|
//
|
|
ObjectSetInteger(
|
|
mChartID,
|
|
mName,
|
|
OBJPROP_BORDER_TYPE,
|
|
borderType //
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Set Object Background Color
|
|
*
|
|
* @param value: color
|
|
*/
|
|
void BGColor(color value)
|
|
{
|
|
//
|
|
ObjectSetInteger(
|
|
mChartID,
|
|
mName,
|
|
OBJPROP_BGCOLOR,
|
|
value //
|
|
);
|
|
}
|
|
|
|
//
|
|
// Protected ...
|
|
protected:
|
|
//
|
|
// Private ...
|
|
private:
|
|
//
|
|
// Props ...
|
|
|
|
//
|
|
// Mouse state tracking variables ...
|
|
int mlbDownX;
|
|
int mlbDownY;
|
|
int mlbDownXDistance;
|
|
int mlbDownYDistance;
|
|
int mPreviousMouseState;
|
|
|
|
//
|
|
bool mMovingState; // State for whether the object is moving
|
|
|
|
//
|
|
string mAddedNames[]; // Array of added names
|
|
long mAddedXDisDiffrence[]; // Arrays to store added distance differences
|
|
long mAddedYDisDiffrence[]; // Arrays to store added distance differences
|
|
};
|