Home
JAQForum Ver 20.06
Log In or Join  
Active Topics
Local Time 00:14 30 Mar 2024 Privacy Policy
Jump to

Notice. New forum software under development. It's going to miss a few functions and look a bit ugly for a while, but I'm working on it full time now as the old forum was too unstable. Couple days, all good. If you notice any issues, please contact me.

Forum Index : Microcontroller and PC projects : Inverse 'bargraph' (trackbar?)

Author Message
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 05:08pm 13 Dec 2019
Copy link to clipboard 
Print this post

Hi,
I was wondering if anyone has implemented a "reverse bargraph"...
Normally a bargraph would only display a value, using a bar, between a minimum and maximum value.
What I'm looking for is a way to still display a bargraph, but have the bar active so I can touch or point somewhere in that region and have the touched point become the setpoint. The bar would ideally show the current value in one colour and the targeted value overlayed in another.
Some background control algorithm would then push the value towards the setpoint.

Has anyone done this?

Cheers,
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 639
Posted: 10:29pm 13 Dec 2019
Copy link to clipboard 
Print this post

G'Day Mustard

I just draw two long skinny boxes to make one long graph with the join between the two determined by touch.

I hope this helps

Peter
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 01:32pm 14 Dec 2019
Copy link to clipboard 
Print this post

I did something similar (if I understand you right) for a customer where I provided a slider that could set a value similar.

I did it by drawing as PeterB suggested and simply processing touches in a given area.

I made a vid for you: https://youtu.be/EJ3nozmU0wE

if this is what you are after - or close enough to tweak, I can post the code for it.
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 08:33pm 14 Dec 2019
Copy link to clipboard 
Print this post

Thanks Peter, sort of like what I had in mind for drawing (much easier to draw two bargraphs of different colour rather than one multi-colour.

But how do I detect where on the screen an area has been touched, especially when other 'buttons' are present (eg: cancel, accept, etc)? ... and still have those buttons respond normally? MMbasic is pretty good (very good actually) for just simple buttons.

Sorry, it is probably quite simple to do. I'm just starting to get into this GUI stuff.

Cheers,
 
MustardMan

Senior Member

Joined: 30/08/2019
Location: Australia
Posts: 175
Posted: 08:40pm 14 Dec 2019
Copy link to clipboard 
Print this post

@CaptainBoing

That is very similar to what I visualised. The only difference is the background: rather than being a line, I visualised a bar (a line with width?)
I would certainly be interested in the code!

Cheers,
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 10:21pm 14 Dec 2019
Copy link to clipboard 
Print this post

OK, then it is easy enough... I have a line with a box on it, you can change this to be a long box with a bar in it easy enough.

Here's the code - it should be enough to get you going:


'master brightness slider, just draw it on the screen as part of the init
Colour 0 ' black
Move 208,100:DrawR 108,0 ' move to the start and draw a line 108px long
ButtonUp 208+MBright,90,16,20,Str$(MBright,2) 'draw the slider button

DrawSlider
Native 222,88
Text Gx,Gy,"Master Brightness",,8



then in the main loop you detect touches and deal accordingly - note I continually poll the touch values, I don't use interrupts on touches at all. I find this is a stumbling block to many on this. Far easy to check for touches when it is convenient than get interrupted when you have no control.

tx=Touch(x):ty=Touch(y)
If tx<>-1 And ty<>-1 Then


If tx>207 And tx<309 And ty>135 And ty<150 Then 'master brightness rectangle
FlagSet 12'master change flag
If otx<>tx Then ' only if the position changed
otx=tx
MBright=Constrain(tx-208,1,99) ' calculate the master brightness setting from the screen touch position
DrawSlider
EndIf
EndIf


EndIf



Sub DrawSlider ' draws the slider
Native 199,111
Box Gx,Gy,120,23,,cGy,cGy
Colour 0
Move 203,100:DrawR 104,0
ButtonUp 204+MBright,90,16,20,Str$(MBright,2) ' show the value box as a button in the "up" position
End Sub


hth

h
Edited 2019-12-15 08:31 by CaptainBoing
 
PeterB
Guru

Joined: 05/02/2015
Location: Australia
Posts: 639
Posted: 10:34pm 14 Dec 2019
Copy link to clipboard 
Print this post

If you look at CB's code

tx = Touch(x) etc
defines which part of the screen has been touched

The other significant bit is
if otx <> tx Then etc
means the drawing will be updated only if it has changed. This prevents flicker.

You will have a lot of fun with GUI.

Peter
 
CaptainBoing

Guru

Joined: 07/09/2016
Location: United Kingdom
Posts: 1983
Posted: 06:25am 26 Dec 2019
Copy link to clipboard 
Print this post

Morning MM...

is there any update on this? did you get it working ok?
 
Print this page


To reply to this topic, you need to log in.

© JAQ Software 2024