Re: 128 Slider/Faders Include Crossplatform - Redesigned
Posted: Thu Mar 07, 2013 8:56 pm
Remarkable!
and a lesson in OOP to boot
I haven't a clue...
and a lesson in OOP to boot

I haven't a clue...
http://www.purebasic.com
https://www.purebasic.fr/english/
The "redesigned" code works fine now also on my MacOS 10.5.8netmaestro wrote:Event testing is updated to include leftclick and you're right, it's quite useful. Now the only unanswered question is whether or not it's still working properly on Mac and Linux.
Code: Select all
*this.FADER = AllocateMemory(SizeOf(FADER))
InitializeStructure(*this, FADER)
*this\vTable = ?FADER_Methods
DataSection
FADER_Methods:
Data.i @Fader_Canvas(),
@Fader_SetColumn(),
@Fader_GetColumn(),
@Fader_RedrawColumn(),
@Fader_ProcessEvents(),
@Fader_Move(),
@Fader_Free()
EndDataSection
It reflects the Interface. *vTable simply points to the start of a 'vector Table' which holds the addresses for all of the methods (in the same order) that were defined in the Interface.Joris wrote:Netmaestro or whoever is able, do you wont to enlighten this magic code part a bit more ?
How does one field of a structure (vTable) get multiple proc-adresses ?
It's just one pointer and so how can it receive multiple proc-adresses ? That's what's happening there I believe.
InitializeStructure has probably something to do with these I suppose, but...I suppose, I can imitate this setup, but understanding what is going on, how much elements (proc-adresses) can be added and so on, that's another thingCode: Select all
*this.FADER = AllocateMemory(SizeOf(FADER)) InitializeStructure(*this, FADER) *this\vTable = ?FADER_Methods DataSection FADER_Methods: Data.i @Fader_Canvas(), @Fader_SetColumn(), @Fader_GetColumn(), @Fader_RedrawColumn(), @Fader_ProcessEvents(), @Fader_Move(), @Fader_Free() EndDataSection
Code: Select all
Interface iFADER
canvas()
SetColumn(column, level)
GetColumn(column)
RedrawColumn(column)
ProcessFaderEvents(*fader.iFADER)
Move(x, y)
Free()
EndInterface
Code: Select all
Procedure New_Fader(x, y)
fg_iCol = CreateImage(#PB_Any, 6, 128)
...
For i=0 To 127
temp = GrabImage(fg_iCol, #PB_Any, 0, 127-i, 6, i+1)
*this\iLevel(i) = CreateImage(#PB_Any, 6, 128)
StartDrawing(ImageOutput(*this\iLevel(i)))
Box(0,0,6,128,$D1D1D1)
Box(1,0,4,128,$EFD6AD)
DrawImage(ImageID(temp), 0, 128-i)
FreeImage(temp)
For j=3 To 123 Step 4
Line(0,j,4,1,$EF1010)
Next
StopDrawing()
Next
FreeImage(fg_iCol)
...
Wooops, I didn't noticed that quit well.netmaestro wrote:There is one image built and stored for each possible level.
...
Just to be clear, what do you mean by 'non-crossplatform BitBlt' ? PB DrawImage() uses BitBlt() on Windows, so did I miss something ?Joris wrote:Wooops, I didn't noticed that quit well.netmaestro wrote:There is one image built and stored for each possible level.
...
I was already trying to do partly redrawing of the fader image, but no go, as the complete image is just drawn in a smaller size. Then it make sense to have an image for every value : SPEED, as the drawings commands are many for a bit nice picture. Yet, quit sad, there isn't a way to fast redraw a part, except a non-crossplatform BitBlt. I'm thinking of that other source where you could do it, inside the same output... we need also into another output.
Has this never been a requested ?
@Fred: He means that he thinks BitBlt() is the only way to accomplish the task but that it is non-crossplatform. He is looking for a way to draw a clipped image that would also be cross-platform.Fred wrote:Just to be clear, what do you mean by 'non-crossplatform BitBlt' ? PB DrawImage() uses BitBlt() on Windows, so did I miss something ?
Indeed, but also speed is quit important herein.Demivec wrote:@Fred: He means that he thinks BitBit() is the only way to accomplish the task but that it is non-crossplatform. He is looking for a way to draw a clipped image that would also be cross-platform.
It would be great to have a convenient method of clipping a drawing. Still, I don't think it is too much of a speed hit to simply draw the portion again. This is what I did in the first code sample that I posted in your original thread requesting a solution to this need. The code did all of the things that you demonstrated you needed and seemed to function just fine. Refining it to add more customization or converting it to use an interface (as netmaestro did) would not be too difficult.Joris wrote:Wooops, I didn't noticed that quit well.netmaestro wrote:There is one image built and stored for each possible level.
...
I was already trying to do partly redrawing of the fader image, but no go, as the complete image is just drawn in a smaller size. Then it make sense to have an image for every value : SPEED, as the drawings commands are many for a bit nice picture. Yet, quit sad, there isn't a way to fast redraw a part, except a non-crossplatform BitBlt. I'm thinking of that other source where you could do it, inside the same output... we need also into another output.
Has this never been a requested ?
Demivec, I have no comment on the code of Netmaestro or yours, but what I didn't tell...Demivec wrote:It would be great to have a convenient method of clipping a drawing. Still, I don't think it is too much of a speed hit to simply draw the portion again. This is what I did in the first code sample that I posted in your original thread requesting a solution to this need. The code did all of the things that you demonstrated you needed and seemed to function just fine.
@Joris: You have made things clearer.Joris wrote:Demivec, I have no comment on the code of Netmaestro or yours, but what I didn't tell...
All is based on this one example of fader image which was shown, while I also use more complex fader images and in more or less numbers, sizes and spaces between them.
These become moved while there is also a timer calling a proc (1/1000s), which may absolutely not become interrupted.
So, speed is very important in the first place, the timer-thing in PB is a later concern. I hope this makes a bit more clear. And, thanks again for the help, also on the interface explanation.
I was a bit scared for that and I don't wont that too.Demivec wrote:My intention wasn't to muddy the waters.
Now that I understand his code for 99% I know it is the best solution in any way : nice image, speed, redrawings, etc. But doing a research is part of learning and that sometimes ends up in 'silly questions' (beside the need to translate my words and thoughts). Me, I'm used to BitBlt for this kind of things and find it still hard to believe it isn't included for a crossplatform way. I got to accept that, but sorry to say, it feels a bit like going backwards having no other solution. Maybe an elucidation : think about a nice audio volume meter...Demivec wrote:Netmaestro's code is a great demonstration of one way to accomplish the things you originally requested but has some challenges with speed of redrawing as it is currently implemented. All one has to do is move the trackbar up or down to notice this.