Problem with CanvasDrawDrag Example

actually in programming an example is just that an example of how something MIGHT be done, but does not purport to be the “proper” way, as the “proper” way is dependent on other factors in your design which the example is not meant to cover.

If you have use Picture.RGBSurface.pixel, then you must take scale into account. What you describe indeed looks like it was the case. Picture.Graphics.Pixel reports points.

At the risk of getting lyrical, computer languages, like human languages are made of words that can be arranged in an infinite manner. Hence poetry for human languages, and so many approaches to the same problem, depending on the programmer background, education, and creativity.

“Proper” literature is dull, unimaginative, and generally uninspired. Scholarly.

“Proper” programming is often the same way. It works, but it has no zing. It does not sing.

As a matter of fact, I think what makes some programmers great and other average is precisely the level of creativity. The very subject of CanvasDrawDrag is an interesting case study. There are probable dozen of possible ways to implement it, some clever, some more laborious. In a way, precisely examples are not perfect, they engage the user to perfect them, innovate, and in doing so, learn more than by applying “proper” recipes.

Actually, this discussion itself is a good inspiration.

“Proper” literature has elegance, be it poetry or prose. It can be the art of expressing complex problems in simple and easy to follow terms (prose), or the masterful and evokativ use of language in poetry (Rostand’s “Cyrano de Bergerac” comes to mind).

[quote=295032:@Michel Bujardet]If you have use Picture.RGBSurface.pixel, then you must take scale into account. What you describe indeed looks like it was the case. Picture.Graphics.Pixel reports points.
[/quote]
No. This is the code:

    If inPicture Then
      // So we're in the picture, but is this pixel opaque?
      Dim pixel As Color = pic.Image.Graphics.Pixel(picX*pic.Image.Graphics.ScaleX,_
       picY*pic.Image.Graphics.ScaleY)    '****** added scale factor
      PixAlpha=pixel.Alpha
      PixColor=pixel 'sets a public property that's used to display last clicked pixel
      If pixel.Alpha < 255 and pixel <> &c00000000 Then Return pic
    End If
  Next

As you can see it uses pic.Image.Graphics.Pixel, and without adding the scale factors it wouldn’t work correctly when run with the HiDPI option. Could this be a platform specific issue?

[quote=295052:@Robert Weaver]No. This is the code:
…//
As you can see it uses pic.Image.Graphics.Pixel, and without adding the scale factors it wouldn’t work correctly when run with the HiDPI option. Could this be a platform specific issue?[/quote]

Well, I just ran the original project with HiDPI active on a Retina screen, and I don’t see this.

At any rate, indeed, I would switch to RGBSurface with your code. That way you are sure it addresses pixels, not points.

While on the topic of CanvasDrawDrag example.
I am in the school that these examples should be correct or, when incorrect, corrected. It seems strange to me to expect people who are just learning the language, and need to use the provided examples in the first place, to be savvy enough to realize that this or that part of the project is logically wrong. So I greatly appreciated the discussion above.

Anyway…

In the CanvasDrawDrag example in the Paint event we see the following code.

For Each pic As DragPic In mPics g.DrawPicture(pic.Image, pic.x, pic.y) Next

All the pictures in the mPics array are drawn onto the canvas. As I understand the logic of this project, the various pictures are “stacked” so that the lower index pictures are “behind” the higher index pictures.

So when you would draw them in the Paint event, it would seem to me that the lower index pictures should be draw first so that they would be behind the higher index pictures.

But using For Each does not seem to me to guarantee that. In the Xojo documentation – [quote]For Each: The loop processes each value in array, but the specific order is not guaranteed[/quote]

It might be wiser to explicitly draw the pictures in the order of their index.

For i As Integer = 0 To UBound(Self.mPics) g.DrawPicture(Self.mPics(i).Image, Self.mPics(i).x, Self.mPics(i).y) Next
If I am wrong about this (entirely possible) I would appreciate being informed.

In practice, For Each works sequentially. So it ends up being the same as a For Next.

About examples, like most here, they have been an excellent way for me to see how to do things. As a matter of fact, I use an iOS version I made of CanvasDrawDrag in my latest iOS app to enable the user to change the layout. That version will accompany Xojo soon.

Examples should work. That is for me the basic requirement. And indeed if they don’t, they should be corrected.

But most are the result of users voluntary efforts. Requiring them to be perfect in all aspects is probably the best way to definitely sterilize production. Heck, even our beloved Xojo itself still has quirks, after going through months of vetting by Alpha and Beta testers, plus the entire Xojo team of engineers.

Perfection is not of this world.

On the other hand, I have the examples that Microsoft produced for Windows Store apps. Back in 2013, I tried to understand their “Print sample”. The thing is so complex, with calls upon calls to intricate subroutines, I could never make heads and tails from that ball of spaghetti. I finally gave up altogether.

A sensible example should remain simple enough to help the user grasp the workings of the program. Adding bells and whistles would only blur the educative value IMHO.

That is how I came to computer development using AppleSoft BASIC with the fantastic Apple Books (Reference).

Then, with time, I saw user’s manuals number of page slowing down to totally disappears. In fact, with time, you’d better lear CSI at school (university) instead been autodidact. As noted above, Language Reference, Examples, etc. are not really your friends. I am quite sure that I can find a 15 or 20 y/o example.

Even w3school.com tutorials that are absolutely counter inuitive, not understandable. I get what I was searching in a Real Studio 2012 release (in the Language Reference) / and in a printing tutorial I wrote (for my own use) in 2001 or 2002 (the electronic version with example was not found, probably in a CD Archive somewhere).

Beforeupgrading to Xojo 1.0 (2013), I maintained an rtfd file with everything that was bad, old, too old, wrong, misleading, etc. I lost it in a (wrong) hard disk formating (last year ?) and it was good. I get very bad feeling each tima I added something to that file.

One that I still suffer from (in Xojo 2015r1, I do not checked in 2016r3) is… “Where is the Focus in the IDED after a run - application checkings - quit to go back to Xojo ? Or… why when I open back a project, the two or six or… opened entities in the Navigator are now closed ?

Emile: nice weather today in “France Grand Est” today ! Remember: you saw the Sun today and feel its warm on your head