Discussion of article "Studying the CCanvas Class. How to Draw Transparent Objects" - page 3

 
Vladimir, I'm not good at canvas....
Here's a question.
I draw different shapes in the canvas and overlay them on each other. How to make the colours remain original without blending?

I set COLOR_FORMAT_XRGB_NOALPHA, but mixing takes place :-(((.

However, I have this variant. There is a picture of CPicture type attached to a dialogue of CDialog type. It is linked to a resource of CCanvas type. The latter is created without binding to a window.

 
Dennis Kirichenko:
Vladimir, I'm not good at canvas....
Here's a question.
I draw different shapes in the canvas and overlay them on each other. How to make the colours remain original without blending?

I set COLOR_FORMAT_XRGB_NOALPHA, but blending takes place :-(((

...

Knavas

The colour drawn in the canvas (let's call it "top" or last) replaces the colour drawn in the canvas earlier.

//+------------------------------------------------------------------+
//|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 colour transparency
//--- variable width and height of the chart.
int            ChartWidth=-1;
int            ChartHeight=-1;
//+------------------------------------------------------------------+
//| Script programme 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 seconds
   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 seconds
   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);
  }
//+------------------------------------------------------------------+
Files:
 

Vladimir, thank you very much!

I just overlooked the ColorToARGB() conversion.

 
Dennis Kirichenko:

Vladimir, thank you very much!

I just overlooked the ColorToARGB() conversion.

You're welcome :) .
 
Hi, i think this article is excellent. I have a question how can I make a rectangle on the screen with coordinates x1, x2, y1, y2. where:

x1 = Time[1]

x2 = Time[0]

y1 = Open[1]

y2 = Close[1]
 
Jorge Fernando De Los Ríos De Los Ríos:
Hi, i think this article is excellent. I have a question how can I make a rectangle on the screen with coordinates x1, x2, y1, y2. where:

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 datetimetime, // time
const doubleprice, // price
constintwidth, // 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 Canvas. But width and height, all the same, will be set in pixels.

 

Let's do an excercise more easily. 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 an excercise more easily. 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 an excercise more easily. 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 ;)