• Welcome to PlanetSquires Forums.
 

Help with a Color Picker?

Started by chjmartin2, December 05, 2023, 07:21:07 PM

Previous topic - Next topic

chjmartin2

Hi,

I have an application that converts images to be able to be displayed on a Bally Astrocade.  The original code just used Screenres but I have always wanted to make a real GUI application.  I have used WinFBE for quite some time and have given Visual Designer a go.  I have gotten really far.  I'm not a great coder to begin with, I never use pointers or subroutines and I love goto.  I have made it through.  Anyway, I want to create a color picker form.  I have an image that has a matrix of 16x16 boxes with 256 unique colors.  I want to an event when the user clicks on the image where I can tell what color they clicked on.  I have used e.x and e.y and tried to use form.top and form.left but none of those numbers make sense to figure out the relative position of the mouse during the click.  I would appreciate help because the absolute x,y values on the screen seem to be not directly useful.  Open to any suggestions on how I could do this?


Thanks,

Chris

Paul Squires

Hi Chris, I will take a look at this later today and see if I can gather together some code that will help you.

What code did you use to create the 16x16 matrix of "boxes". Are those boxes Labels? Buttons?

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

Paul Squires

Depending on how you created your 16x16 matrix, you could respond to "click" events from a Label/Button. However, if these boxes are drawn on the form (which is what I think you are doing) then you are on the right track of using e.x and e.y to determining where your mouse clicked. I am thinking that you might be getting caught in the problem that the e.x and e.y values are SCREEN coordinates whereas your 16x16 matrix are in CLIENT coordinates relative to the Form.

The following code should help:

''
''
Function frmMain_MouseUp( ByRef sender As wfxForm, ByRef e As EventArgs ) As LRESULT
   
    '//  The following is based on Window Screen coordinates.
    print e.x, e.y
   
    '//  We want to convert from Screen coordinates to Client coordinates.
    '//  The Client coordinates are the for the Form with 0,0 being the upper left corner.
   
    '//  Need to copy the e.pt point because we can not directly modify e.pt
    dim as POINT pt

    '//  You can use MapWindowPoints *OR* ScreenToClient to do the conversion.

    '// MapWindowPoints method
    pt = e.pt
    MapWindowPoints( HWND_DESKTOP, sender.hWindow, cast(LPPOINT, @pt), 1)
    print pt.x, pt.y

    '// ScreenToClient method
    pt = e.pt
    ScreenToClient( sender.hWindow, @pt)
    print pt.x, pt.y
   
    Function = 0
End Function
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

chjmartin2

Wow this works great!  Exactly what I needed.  Now I just have to map the pixels and boom I can have my color picker!


chjmartin2

Quote from: Paul Squires on December 06, 2023, 02:29:56 PMDepending on how you created your 16x16 matrix, you could respond to "click" events from a Label/Button. However, if these boxes are drawn on the form (which is what I think you are doing) then you are on the right track of using e.x and e.y to determining where your mouse clicked. I am thinking that you might be getting caught in the problem that the e.x and e.y values are SCREEN coordinates whereas your 16x16 matrix are in CLIENT coordinates relative to the Form.


Are the coordinates always going to be the same.  Oddly I am getting coordinates that feel double what they should be based on the size of the image.  It is working, but nervous it might work differently on another system.

chjmartin2

I am using the below code on a picture to open up the Color Picker form.  When I try to use Application.Run to open up my color picker it works the first time, but then when I click again it crashes.  When I use frmPicker.Show the program continues to execute.  pickedcolor is a shared variable and so is PickedColorOne.  What I want to do is halt execution, open the color picker, pick the color, send the value back somehow and then call code to run to update with the color in the destination image.  I just can't figure out how to open the form and then have the code wait for the click.  Would appreciate any ideas. 

Function frmMain_ColPic1_Click( ByRef sender As wfxPictureBox, ByRef e As EventArgs ) As LRESULT
   Function = 0
   Pickedcolor=256
   'Application.Run(frmPicker)
   frmPicker.show
   while pickedcolor=256
   wend
   PickedColorOne = pickedcolor
   PickedColor=256 
End Function




Paul Squires

What you are looking to do is open a modal style popup form. You do that with the ShowDialog method of your form. You pass that method the handle of the form that you want to be the parent.

frmPicker.ShowDialog(frmMain.hWindow)

When you have chosen the color, then you call the Close method on your popup form.

frmPicker.Close
Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer

chjmartin2

Thank you for the help.  As expected, it works perfectly.  I promise I won't ask the same question twice.  I really do love the visual designer capability, it has made my dream of a Windows GUI app come true!

chjmartin2

I can't thank you enough Paul for helping me with this and making this amazing tool.  Finally I can create true Windows GUI applications.  I have learned so much from this process.  I still do not write well formatted and well commented code.  I also am not using pointers and I am sure my immediate DIMs are a mess - BUT - it works!  The tool I wrote really is just for me and a really small crowd but here it is anyway.

https://forums.atariage.com/topic/358652-bally-astrocade-image-works-version-10-release/

I am happy to share the source/project file to anybody who may be interested.  I don't have a great GITHUB (on the to do list) but will send along if anybody asks.

Paul Squires

That's a mighty fine looking application! Congratulations! It makes me happy that my little WinFBE has helped you achieve your goal of a Windows GUI. That's awesome!

Paul Squires
PlanetSquires Software
WinFBE Editor and Visual Designer