Обсуждение статьи "Изучаем класс CCanvas. Реализация прозрачности графических объектов" - страница 3

 
Владимир, не силён в канвасе...
Вопрос такой.
Рисуются различные фигуры в канвасе, и идёт наложение их друг на друга. Как сделать так, чтобы цвета оставались первоначальными без смешивания?

Поставил COLOR_FORMAT_XRGB_NOALPHA, но смешивание имеет место :-((

Правда у меня такой вариант. К диалогу типа CDialog прикреплена картинка типа CPicture. Она залинкована с ресурсом типа CCanvas. Последний создан без привязки к окну.

 
Dennis Kirichenko:
Владимир, не силён в канвасе...
Вопрос такой.
Рисуются различные фигуры в канвасе, и идёт наложение их друг на друга. Как сделать так, чтобы цвета оставались первоначальными без смешивания?

Поставил COLOR_FORMAT_XRGB_NOALPHA, но смешивание имеет место :-((

...

Кнавас

Нарисованный в канвасе цвет (назовём его "верхний" или последний) замещает цвет нарисованный в канвасе ранее.

//+------------------------------------------------------------------+
//|                                                   canvas+xor.mq5 |
//|                              Copyright © 2015, Vladimir Karputov |
//|                                           http://wmua.ru/slesar/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2015, Vladimir Karputov"
#property link      "http://wmua.ru/slesar/"
#property version   "1.00"
#property description "The script draws overlapping areas on canvas"
//--- show the window of input parameters when launching the script
#property script_show_inputs
#include <Canvas\Canvas.mqh>
//--- input
input uchar alfa=150;         // alpha channel managing color transparency
//--- variable width and height of the chart.
int            ChartWidth=-1;
int            ChartHeight=-1;
//+------------------------------------------------------------------+
//| Script program start function                                    |
//+------------------------------------------------------------------+
void OnStart()
  {
//--- width and height of the chart
   ChartWidth=ChartWidthInPixels();
   ChartHeight=ChartHeightInPixelsGet()-50;

//--- create canvas COLOR_FORMAT_XRGB_NOALPHA
   CCanvas canvas_XARGB_NORMALIZE;
   if(!canvas_XARGB_NORMALIZE.CreateBitmapLabel("canvas_XARGB_NORMALIZE",0,0,
      ChartWidth,ChartHeight,COLOR_FORMAT_ARGB_NORMALIZE))
     {
      Print("Error creating canvas: ",GetLastError());
      return;
     }
   canvas_XARGB_NORMALIZE.Erase(ColorToARGB(clrAqua,255));
//--- create a rectangle №1
   canvas_XARGB_NORMALIZE.FillRectangle(ChartWidth/20,ChartHeight/20,
                                        10*ChartWidth/20,10*ChartHeight/20,
                                        ColorToARGB(clrBlue,alfa));
   canvas_XARGB_NORMALIZE.Update();
//--- wait for 3 second
   Sleep(3000);
//--- create a rectangle №2
   canvas_XARGB_NORMALIZE.FillRectangle(7*ChartWidth/20,7*ChartHeight/20,
                                        16*ChartWidth/20,16*ChartHeight/20,
                                        ColorToARGB(clrGreen,alfa));
   canvas_XARGB_NORMALIZE.Update();
//--- wait for 3 second
   Sleep(3000);
  }
//+------------------------------------------------------------------+
//| Chart property width                                             |
//+------------------------------------------------------------------+
int ChartWidthInPixels(const long chart_ID=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_WIDTH_IN_PIXELS,0,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+
//| Chart property height                                            |
//+------------------------------------------------------------------+
int ChartHeightInPixelsGet(const long chart_ID=0,const int sub_window=0)
  {
//--- prepare the variable to get the property value
   long result=-1;
//--- reset the error value
   ResetLastError();
//--- receive the property value
   if(!ChartGetInteger(chart_ID,CHART_HEIGHT_IN_PIXELS,sub_window,result))
     {
      //--- display the error message in Experts journal
      Print(__FUNCTION__+", Error Code = ",GetLastError());
     }
//--- return the value of the chart property
   return((int)result);
  }
//+------------------------------------------------------------------+
Файлы:
 

Владимир, огромное спасибо!

Я просто упустил из виду  преобразование ColorToARGB().

 
Dennis Kirichenko:

Владимир, огромное спасибо!

Я просто упустил из виду  преобразование ColorToARGB().

Пожалуйста :) .
 
привет, я думаю, что эта статья является превосходным. У меня есть вопрос, как я могу сделать прямоугольник на экране с координатами x1, x2, y1, y2. где:

x1 = Time[1]

 x2 = Time[0]

y1 = Open[1]

y2 = Close[1] 
 
Jorge Fernando De Los Ríos De Los Ríos:
привет, я думаю, что эта статья является превосходным. У меня есть вопрос, как я могу сделать прямоугольник на экране с координатами x1, x2, y1, y2. где:

x1 = Time[1]

 x2 = Time[0]

y1 = Open[1]

y2 = Close[1] 

By means of the class CCanvas? 

 

P.S. Use CCanvas.CreateBitmap:

Creates a graphical resource bound to a chart object.

1. Creates a graphical resource in the main window of the current chart.

bool  CreateBitmap( 
   const string       name,                                 // name 
   const datetime     time,                                 // time 
   const double       price,                                // price 
   const int          width,                                // width 
   const int          height,                               // height 
   ENUM_COLOR_FORMAT  clrfmt=COLOR_FORMAT_XRGB_NOALPHA      // format 
   );

 

Thus you will be able to bind one corner of a Сanvas. But width and height, all the same, will be set in pixels. 

 

Let's do a excercise more easy. I go to put a circle moves with the price; but, why does not it move in axis Y?

 

That is the code 

void OnStart()
  {
   int ChartWidth=ChartWidthInPixels();
   int ChartHeight=ChartHeightInPixelsGet();

   CCanvas pepe;

   int t1,t0,p1,p0;
   ChartTimePriceToXY(0,0,Time[1],Open[1],t1,p1);
   ChartTimePriceToXY(0,0,Time[0],Close[1],t0,p0);

   pepe.CreateBitmapLabel("canvas_XRGB_NOALPHA",0,0,ChartWidth,ChartHeight,COLOR_FORMAT_ARGB_RAW);
   pepe.Erase(0);
   pepe.FillCircle(t0,p0,25,ColorToARGB(clrBlue,255));
   pepe.Update();
   return(rates_total);
  } 
 
Jorge Fernando De Los Ríos De Los Ríos:

Let's do a excercise more easy. I go to put a circle moves with the price; but, why does not it move in axis Y?

 

That is the code 

This script isn't compiled. In him a heap of mistakes.
 
Jorge Fernando De Los Ríos De Los Ríos:

Let's do a excercise more easy. I go to put a circle moves with the price; but, why does not it move in axis Y?

 

That is the code 

"Time[]", "Close[]" - mistake. There are no such variables in MQL5!
 
Karputov Vladimir:
"Time[]", "Close[]" - mistake. There are no such variables in MQL5!
MQL4 ;)