Making a crowdsourced project on Canvas - page 22

 
Nikolai Semko:
Almost finished the GButton class example, but have to run away. I'll finish it tomorrow and present it.
Great. Very interesting. )
 
Реter Konow:
Great. Very interesting. )


Here's what you get.


The button can be displayed in the background or in the foreground, with or without a latching function.

In the example file CanvasButton.mq5 it is possible to drag the button with the mouse. To do this, simply press Ctrl to move the blue button, and Shift to move the red button.

Because the GButton class is a descendant of the CCanvas class, the example demonstrates the ability to use functions of the CCanvas class on the CircleWu example (This is implemented in OnInit). So, it is possible to write text on the button using functions of the CCanvas class.

This class, of course, does not pretend to be clean. The graphics does not shine with perfection and 3D is very conventional; the shadows are not implemented, the execution speed is not optimized. And most likely there are a lot of rough edges and lack of various checks. So do not judge severely.

If you spend a little more time, of course it can be done:


I was just trying to... you could say - set the direction.


Canvas.mqh file differs from the original one only in that m_pixels array is defined as public.

Files:
GButton.mqh  20 kb
Canvas.mqh  152 kb
 
Nikolai Semko:


Here is what we have got.


The button can be displayed in the background or in the foreground and can be clicked or non-locked.

In the example file CanvasButton.mq5 it is possible to drag the button with the mouse. To do this, simply press Ctrl to move the blue button, and Shift to move the red button.

Because the GButton class is a descendant of the CCanvas class, the example demonstrates the ability to use functions of the CCanvas class on the CircleWu example (This is implemented in OnInit). So, it is possible to write text on the button using functions of the CCanvas class.

This class, of course, does not pretend to be clean. The graphics does not shine with perfection and 3D is very conventional; the shadows are not implemented, the execution speed is not optimized. And most likely there are a lot of rough edges and lack of various checks. So do not judge too harshly.

If you spend a little more time, of course, you can do this:


I was just trying to... you could say - set the direction.


Canvas.mqh file differs from the original one only in that m_pixels array is defined as public.

Nikolay, in my opinion, it turned out pretty good. We have made a good start and can go further. I would call this type of button a key. If you have 4 clear frame lines: - top, left light and right, the bottom - dark for pressed state and vice versa, it will be even better (only need to add a light background, otherwise the dark lines on a black background chart will not be visible). And then you can set text and picture.

Anyway, nice try. )

 
Реter Konow:

. If you divide the frame's 4 clear lines along the edges: - top, left light and right, bottom dark for pressed state and vice versa for pressed state, it will be even better (you just need to add a light background, otherwise the dark lines will not be visible against the black graphics).

Yes, it's clear that you can draw as you want. In this case, I did not set out to achieve a masterpiece. But the first thing I would like to improve, is to generate all arrays of button image (two arrays in this case) and then copy them only through ArrayCopy, so that we don't have to create an image every time. This will greatly reduce the work, but at the cost of additional consumption of RAM, but because it is now commonplace on computers 16 GB of RAM, and if there are even a lot of buttons, the additional memory consumption is unlikely to exceed 1-2 MB, especially if the same buttons will use the same arrays. So, I don't think it's a problem. The main thing is the speed.
 
Nikolai Semko:
Yes, it's clear that you can draw as you like. In this case, I did not set a goal to achieve a masterpiece. But the first thing I would like to improve, is to generate all arrays of button image (two arrays in this case) and then copy them only through ArrayCopy, so that we don't have to create an image every time. This will greatly reduce the work, but at the cost of additional consumption of RAM, but because it is now commonplace on computers 16 GB of RAM, and if there are even a lot of buttons, the additional memory consumption is unlikely to exceed 1-2 MB, especially if the same buttons will use the same arrays. So, I don't think it's a problem. The main thing is the speed.

I see. When I posed the question about the button, I wanted to find out if it was possible to do this with a canvas:


Pressed:

Pressed:

In this example, each side of the frame consists of several lines. There are a total of 4 gradient lines on each side of the frame. Each line has a different shade that depends on the state of the button and the given shape of the frame. If CCanvas has the ability to set the colour to specific gradient lines of the frame, then making the above example is easy. That's exactly what I wanted to find out.

 
Реter Konow:

I see. When I posed the question about the button, I wanted to find out if it was possible to do this with a canvas:


Pressed:

Pressed:

In this example, each side of the frame consists of several lines. There are a total of 4 gradient lines on each side of the frame. Each line has a different shade, which depends on the state of the button and the given shape of the frame. If CCanvas has the ability to set the colour to specific gradient lines of the frame, then making the above example is easy. That's exactly what I wanted to find out.

I do not understand you, Peter. You're talking about meat and I'm talking about the skeleton. If you had bones, you could grow meat. Doesn't my example have the states Pressed, Pressed? Have you even looked inside the GButton class? Peter, my advice: leave everything and urgently study OOP. You just hit a ceiling in your project, which is called bloated code. It is easily overcome by OOP.
And with CCanvas you can do everything, even write Windows inside of MT5 window, in full visual emulation mode of course :), because there is no access to hardware

 
Nikolai Semko:
I do not understand you, Peter. You are talking about meat and I am talking about skeleton. If you had bones, you could add meat. Doesn't my example have the states Pressed, Pressed? Have you even looked inside the GButton class? Peter, my advice: leave everything and urgently study OOP. It's just that in your project you've hit a ceiling, which is called bloated code, it's easily overcome with the help of OOP.
And with Canvas you can do everything, even Windows can be written inside MT5 window.

))) So why did I start this topic? ) I will be studying OOP now.

Your example has buttons, click events and states of those buttons. Everything is ok. But Nikolai, I still don't understand what I was asking - is there an option in CCcanvas class to set a specific colour to the gradient lines of the frame? Looking at your example, you may think there is... If so, can you draw something similar to my example? I'm interested in the ease and possibilities of drawing as such using the functionality of this class, and you're talking about speed and improvements to the functionality of the class. That's a slightly different topic.

 
Реter Konow:

))) So why did I start this topic? ) I'm going to study OOP now.

It's better to start learning OOP with something easier, not with Canvas.
 
Vasiliy Sokolov:
It's better to start learning OOP with something simpler than Canvas.
You are right. Maybe I'd better start with a textbook. Really, OOP is a complicated thing. It's confusing...
 
Nikolai Semko:
Have you even looked inside the GButton class?


I've looked inside the class. It looks cool, but I don't understand the whole mechanism of CCanvas class. That's why I didn't see the answer to my question there.
Reason: