| //+------------------------------------------------------------------+
|
| //| TituloSimpel.mqh |
|
| //| Copyright 2025, Niquel Mendoza. |
|
| //| https://www.mql5.com/es/users/nique_372/news |
|
| //+------------------------------------------------------------------+
|
| #property copyright "Copyright 2025, Niquel Mendoza."
|
| #property link "https://www.mql5.com/es/users/nique_372/news"
|
| #property strict
|
|
|
| #ifndef GENERAL_TEXTO_CANVAS_BY_LEO_MQH
|
| #define GENERAL_TEXTO_CANVAS_BY_LEO_MQH
|
|
|
|
|
| #include "..\\General\\Canvas.mqh"
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| class CTextCanvas
|
| {
|
| protected:
|
| CCanvasCustom* m_canvas; // Canvas
|
| bool m_init; // Iniciado?
|
| uint m_clr; // Color
|
| string m_text; // Texto
|
| string m_font; // Fuente
|
| int m_font_size; // Tamaño de fuente
|
| uint m_alingement; // Bandera de alineación
|
| uint m_posicion; // Ángulo
|
| uint m_flags_text; // Banderas de texto
|
| int m_x; // X
|
| int m_y; // Y
|
| uint m_clr_clean; // Color de limpieza
|
|
|
| public:
|
| CTextCanvas();
|
|
|
| //--- Creación
|
| void Create(CCanvasCustom *c, int x, int y, const string& txt
|
| , uint clr, uint align, int fontsize = 0, string font = NULL, uint flagtext = UINT_MAX, uint textpos = UINT_MAX);
|
|
|
| //--- Update (solo pixeles)
|
| void UpdateTextPx();
|
|
|
| //--- Limpia el texto
|
| void CleanText();
|
|
|
| //--- Setea la fuente
|
| void SetFont(); // Gloabal (canvas no ve los cambios)
|
| void SetFontInCanvas(); // Canvas (varialbes internas + global)
|
|
|
| //--- Setters y Getters
|
| //- Color de limpieza
|
| __forceinline uint CleanColor() const { return m_clr_clean; }
|
| void CleanColor(uint new_value) { m_clr_clean = new_value; }
|
|
|
| //- X
|
| __forceinline int X() const { return m_x; }
|
| void X(int new_value);
|
| inline void XSetValue(int new_value) { m_x = new_value; }
|
| __forceinline void XSetFast(int new_value);
|
|
|
| //- Y
|
| __forceinline int Y() const { return m_y; }
|
| void Y(int new_value);
|
| inline void YSetValue(int new_value) { m_y = new_value; }
|
| __forceinline void YSetFast(int new_value);
|
|
|
| //-
|
| void ChangeYAndX(int x, int y);
|
| __forceinline void ChangeYAndXFast(int x, int y);
|
|
|
| //- Font
|
| __forceinline string Font() const { return m_font; }
|
| void Font(const string& new_value);
|
| inline void FontSetValue(const string& new_value) { m_font = new_value; }
|
| void FontSetFast(const string& new_value);
|
|
|
| //- Font Size
|
| __forceinline int FontSize() const { return m_font_size; }
|
| void FontSize(int new_value);
|
| inline void FontSizeSetValue(int new_value) { m_font_size = new_value;}
|
| __forceinline void FontSizeSetFast(int new_value);
|
|
|
|
|
| //- Alineamiento
|
| __forceinline uint TextAlingement() const { return m_alingement; }
|
| void TextAlingement(uint new_value);
|
| inline void TextAlingementSetValue(uint new_value) { m_alingement = new_value; }
|
| __forceinline void TextAlingementSetFast(uint new_value);
|
|
|
| //- Flags text
|
| __forceinline uint TextFlags() const { return m_flags_text; }
|
| void TextFlags(uint new_value);
|
| inline void TextFlagsSetValue(uint new_value) { m_flags_text = new_value;}
|
| __forceinline void TextFlagsSetFast(uint new_value);
|
|
|
| //- Color
|
| __forceinline uint Color() const { return m_clr; }
|
| void Color(uint new_value);
|
| inline void ColorSetValue(uint new_value) { m_clr = new_value; }
|
| __forceinline void ColorSetFast(uint new_value);
|
|
|
| //- Texto
|
| __forceinline string Text() const { return m_text; }
|
| void Text(const string& new_value);
|
| inline void TextSetValue(const string& new_value) { m_text = new_value; }
|
| void TextSetFast(const string& new_value);
|
|
|
| //- Posición (ángulo)
|
| __forceinline uint TextPosition() const { return m_posicion; }
|
| void TextPosition(uint new_value);
|
| inline void TextPositionSetValue(uint new_value) { m_posicion = new_value; }
|
| __forceinline void TextPositionSetFast(uint new_value);
|
|
|
|
|
|
|
| //- Init
|
| __forceinline bool IsInit() const { return m_init; }
|
| };
|
|
|
| //+------------------------------------------------------------------+
|
| //| Constructor |
|
| //+------------------------------------------------------------------+
|
| CTextCanvas::CTextCanvas(void)
|
| : m_canvas(NULL), m_init(false)/*, m_clr(0xFFFFFFFF), m_text(""),
|
| m_font("Arial"), m_font_size(10), m_alingement(0), m_posicion(0),
|
| m_flags_text(0), m_x(0), m_y(0), m_clr_clean(0xFFFFFFFF)*/
|
| {
|
| }
|
|
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| // Notas:
|
| // Si al menos uno de los 4 parametros pro defecto es valido, entoces se setera el font
|
| // Al momenot de setear los valores "Font" los valores si el valor corespondinete es valido, entonces se usara dicho valor, de lo contrario el valor ultimo de canvas
|
| // Por esto mismo se recoeminda al usuario usar el .FontSet de canvas... de lo contraio se guradan valores invalidos
|
| // Ls valores invalidos que vinene por defecto dan la opcion al usuario a usar el ultimo font conocido de canvas
|
|
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::Create(CCanvasCustom *c, int x, int y, const string& txt
|
| , uint clr, uint align, int fontsize = 0, string font = NULL, uint flagtext = UINT_MAX, uint textpos = UINT_MAX)
|
| {
|
| if(m_init)
|
| return;
|
|
|
| //---
|
| const bool valid_font = font != NULL;
|
| const bool valid_font_size = fontsize > 0;
|
| const bool valid_flags_text = flagtext < UINT_MAX;
|
| const bool valid_text_pos = textpos < UINT_MAX;
|
| const bool set_font = (valid_flags_text || valid_font || valid_font_size || valid_text_pos);
|
|
|
| //---
|
| m_canvas = c;
|
| m_x = x;
|
| m_y = y;
|
| m_text = txt;
|
| m_alingement = align;
|
| m_clr = clr;
|
| m_init = true;
|
|
|
| //---
|
| m_font_size = valid_font_size ? fontsize : c.FontSizeGet();
|
| m_font = valid_font ? font : c.FontNameGet();
|
| m_posicion = valid_text_pos ? textpos : c.FontAngleGet();
|
| m_flags_text = valid_flags_text ? flagtext : c.FontFlagsGet();
|
|
|
| //--- Dibujar texto inicial
|
| if(set_font)
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
|
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::UpdateTextPx(void)
|
| {
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::CleanText()
|
| {
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::SetFont(void)
|
| {
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::SetFontInCanvas(void)
|
| {
|
| m_canvas.FontSet(m_font, m_font_size, m_flags_text, m_posicion);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::X(int new_value)
|
| {
|
| //--- Limpiar texto en posición anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar
|
| m_x = new_value;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::XSetFast(int new_value)
|
| {
|
| // Limpiamos el texto anteior, asumirmo que el fontse se puso al valor adecuado
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_canvas.TextOuTF((m_x = new_value), m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::Y(int new_value)
|
| {
|
| //--- Limpiar texto en posición anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar
|
| m_y = new_value;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::YSetFast(int new_value)
|
| {
|
| // Limpiamos el texto anteior, asumirmo que el fontse se puso al valor adecuado
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_canvas.TextOuTF(m_x, (m_y = new_value), m_text, m_clr, m_alingement); // Nuevo valor
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::ChangeYAndX(int x, int y)
|
| {
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_y = y;
|
| m_x = x;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::ChangeYAndXFast(int x, int y)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_canvas.TextOuTF((m_x = x), (m_y = y), m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::Font(const string &new_value)
|
| {
|
| //--- Limpiar con font anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevo font
|
| m_font = new_value;
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::FontSetFast(const string &new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_font = new_value;
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::FontSize(int new_value)
|
| {
|
| //--- Limpiar con tamaño anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevo tamaño
|
| m_font_size = new_value;
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::FontSizeSetFast(int new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| ::TextSetFont(m_font, (m_font_size = new_value), m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::TextAlingement(uint new_value)
|
| {
|
| //--- Limpiar con alineamiento anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevo alineamiento
|
| m_alingement = new_value;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::TextAlingementSetFast(uint new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, (m_alingement = new_value));
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::TextFlags(uint new_value)
|
| {
|
| //--- Limpiar con flags anteriores
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevas flags
|
| m_flags_text = new_value;
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::TextFlagsSetFast(uint new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| ::TextSetFont(m_font, m_font_size, (m_flags_text = new_value), m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::Color(uint new_value)
|
| {
|
| //--- Establecer el fontset correcto
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_clr = new_value;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::ColorSetFast(uint new_value)
|
| {
|
| // Asumo que el TextSetFont es el correcto
|
| // Ademas solo se cambia el color (no posiocn ni tanñao, asi que no es necesito limpiar)
|
| m_canvas.TextOuTF(m_x, m_y, m_text, (m_clr = new_value), m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::Text(const string &new_value)
|
| {
|
| //--- Limpiar texto anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevo texto
|
| m_text = new_value;
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::TextSetFast(const string &new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| m_text = new_value; // como es string mejor inline
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| //| |
|
| //+------------------------------------------------------------------+
|
| void CTextCanvas::TextPosition(uint new_value)
|
| {
|
| //--- Limpiar con ángulo anterior
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
|
|
| //--- Actualizar y redibujar con nuevo ángulo
|
| m_posicion = new_value;
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, m_posicion);
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| __forceinline void CTextCanvas::TextPositionSetFast(uint new_value)
|
| {
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr_clean, m_alingement);
|
| ::TextSetFont(m_font, m_font_size, m_flags_text, (m_posicion = new_value));
|
| m_canvas.TextOuTF(m_x, m_y, m_text, m_clr, m_alingement);
|
| }
|
|
|
| //+------------------------------------------------------------------+
|
| #endif
|
| //+------------------------------------------------------------------+
|