Using DrawArea - Simplified
Posted
#1
(In Topic #832)
Regular

I created a simple form (600x600) with only two objects.
- DrawingArea1
- Button1
Super simple… the idea is that if I click the button, it draws a line. Should be eazy-peasy… but I just don't understand what Gambas wants from me.
Code (gambas)
- ' Gambas class file
- ' Variables
- mytask = 1
- x1 = 100
- y1 = 100
- x2 = 150
- y2 = 150
- DrawingArea1_Draw
When run, the routine sees that mytask = 0 and it draws a small line… Apparently the Public Sub DrawingArea1_Draw() runs automatically when the form opens. Ok… I get that.
When I click the button, I reset the variables and tell it to run the routine again… <COLOR color="#FF0000">crash and burn</COLOR>.
I was like… Ok… maybe I thought that I needed to put the Draw.Begin(DrawingArea1) in the Public Sub Form_Open() and the Draw.End in the Public Sub Form_Close()… nope… <COLOR color="#BF0000">CRASH </COLOR>again.
If I can get Gambas to do something graphical when I press a button… then there is hope that I can do stuff on a slider change, or a timer activation… can someone help me please???
Posted
Regular

1) the instruction "DrawingArea1_Draw" in Button1_Click() routine makes no sense, as it conforms to an Event.
However, in your case you have to use the "DrawingArea.Refresh" Method.
2) The instruction: "Draw.Begin (DrawingArea1)" is not necessary within the "DrawingArea" Event, in which you have to draw.
3) I would avoid using the "Draw" Class, as it has long been considered obsolete/deprecated. You should use the "Paint" Class.
So… I suggest:
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

That worked perfectly, and I see now the DrawingArea1.Refresh causes the drawing area to clear, and the subroutine DrawingArea1_Draw() is where all the graphics command must reside. Now I have a handle on it… I can make an array of points for a gauge arrow, then read a sensor in a timer function, update the coordinates with rotation, and send the focus to the DrawingArea1_Draw() routine where it will be updated.
I'll look into circle and fill commands, should be pretty simple now that I understand the process.
Reference: /comp/gb.qt4/paint - Gambas Documentation
<COLOR color="#008000">Thanks again!</COLOR>
Jerry
I will update when I have something interesting to show.
Posted
Regular

Am I using the .COLOR command wrong?? (Well obviously… but why?) :roll:
The screen consist of only 3 items…
<LIST>
- <LI>Drawarea1 (500,500 pixels)
Textbox1 (Shows Slider value)
Slider1 (Min=0 Max=220)</LI>
Help! (Thanks)
Code (gambas)
- ' Gambas class file
- ' Variables
- Slider1_Change ' <---- Paint initial slider state.
- With Paint
- x1 = 250
- y1 = 250
- .MoveTo(x1, y1)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x1, y1)
- '.Stroke <---------- REM this out to only fill the shape, not draw lines.
- .Color(&H00CC0000)
- .Fill
- .End
- TextBox1.Text = Slider1.value
- DrawingArea1.Refresh
Posted
Regular

Code (gambas)
Now I can do any color i want… and what is really cool… I can use this to pick my exact colors.
https://www.w3schools.com/colors/colors_picker.asp
It also looks like I can outline things too… pretty cool… I'm sure there is a way to specify an outlined and filled line with a simpler command… but at least this is working for me.
Code (gambas)
- With Paint
- ' Make a filled shape for a pointer.
- .Brush = Paint.Color(&H00FFCC00)
- .MoveTo(x1, y1)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x1, y1)
- '.Stroke <---------- REM this out to only fill the shape, not draw lines.
- .Fill
- ' Trace lines around the pointer we just made.
- .Brush = Paint.Color(&H000000FF)
- .MoveTo(x1, y1)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x2, y2)
- .LineTo(x1, y1)
- .Stroke
- '.Fill < - - - - - - - - - - REM this out To only draw the shape, lines not fill.
- .End
So yeah… I can load SVG backgrounds, make programmable components… very exciting to be able to build NICE graphic panels now!!! Finally… so now if I can only learn to read the ADS1115 Chip with piGPIO… I'll have everything sorted out. Well… pretty much.
Posted
Regular

Attached:
Feedback Welcome
Posted
Regular

<IMG src="%5Battachment=0%5DControl%20Panel%20Demo.png%5B/attachment%5D">
Posted
Guru

Minor point regarding using the Quit command see here.
Posted
Regular

Once I get this thing running… it will be for school events, robotics meetings, etc.
there won't… or shouldn't be much starting/stopping once we begin the event.
Ever since starting with the Raspberry Pi I've been looking for a way to make eye-catching programs… once I paired PIGPIO with GAMBAS3… I was home.
Jerry
Posted
Regular

Are your controls available under open source? I would love to use them for my work. Thank you.
PS: Is there a web repo of all available controls, made by community? Thank you
Posted
Guru

seany said
Hi
PS: Is there a web repo of all available controls, made by community? Thank you
We have been discussing on the gambas mailing list about expanding the Farm to include modules/classes/components/controls/etc as well as whole gambas applications (Benoit included).
Benoit has a million things to do though so it may take a while but something is happening towards gambas having it's own list of community based custom things
This forum has a Component Showcase section but there is currently not a lot on it: Gambas One - Gambas ONE
Posted
Regular

If you know someone who has figured out the ADS1115 chip in Gambas… that would be incredibly helpful :-)
If you need me to zip up some files I can do that too.
Jerry
Posted
Regular

I suggest you also search the currently existing international forums of Gambas programmers.seany said
Is there a web repo of all available controls, made by community?
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

<LIST>
- <LI>
- Picture</LI>
<LI> - Image</LI>
<LI> - DrawingArea</LI>
<LI> - Printer</LI>
<LI> - SvgImage</LI>
DRAWINGAREA works great… I make a PICTUREBOX and load in the SVG image… then I create a DRAWINGAREA and place it over the PICTUREBOX… think a sheet of glass laid on top of an image… then I can draw on it. But if I just create a PICTUREBOX and try to PAINT directly on it… I get errors.
Any ideas?
I mean for now… I'll keep dropping a DRAWINGAREA over the PICTUREBOX(s). I could have an array of them, with a single DRAWINGAREA over them all… then just adjust my math to draw where I like. I was just curious if someone got code working to do it without two separate layers.
Posted
Regular

Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

If I create a PICTUREBOX, then paste the exact same code… fails.
Posted
Regular

So, you will need to use Paint with an Object of type "Image" or "Picture" (by using Paint.Begin() Method), and then load this Object into the PictureBox.
Europaeus sum !
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
<COLOR color="#FF8000">Amare memorentes atque deflentes ad mortem silenter labimur.</COLOR>
Posted
Regular

Thanks,
Jerry
Posted
Guru

This will operate on a PictureBox.
it loads huge/color icon then superimposes the gambas icon on it.
then makes it the picturebox picture
Posted
Regular

Thank you!
1 guest and 0 members have just viewed this.


