forums.silverfrost.com Forum Index forums.silverfrost.com
Welcome to the Silverfrost forums
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Lots of small color "swatches"
Goto page 1, 2  Next
 
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+
View previous topic :: View next topic  
Author Message
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Wed Nov 04, 2020 6:10 pm    Post subject: Lots of small color "swatches" Reply with quote

I have been trying to noodle out a method for doing the following:

I have 254 color choices (0 and 255 are fixed, unchangeable). I wish to display the number of the color with a small sample of the color. If the user wishes to change the color, they merely click the color swatch to invoke a callback that allows them to set a new RGB value.

I have toyed with using a text box (%rs) and setting the background color, changing it dynamically as needed. I have also thought about creating a graphic object (16x16 or 32x32) of the appropriate color and detecting when the user clicks on that swatch coordinate. This seems to be a more complex solution, but perhaps it is not. It is something I've never tried.

I had looked at using the make_icon or make_bitmap functions, but I cannot replicate the precise RGB values that should be represented. Am I missing some other function that might be useful?

There may be other options I have not considered. And that's why I'm asking you!

Thanks in advance,
Bill

P.S. As an aside: This function is linked to AutoCAD and how it operates.
Back to top
View user's profile Send private message Visit poster's website
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Wed Nov 04, 2020 6:33 pm    Post subject: Reply with quote

If in doubt, I usually resort to a %gr area and in the callback, determine the mouse coordinates and then figure back what that means.

The problem with 254 is that it factorizes to 2 and 127, and 127 is prime.. so it's 2 rows and 127 columns or vice versa. 250 is a better number of swatches as that can be 10x25.

It is possible to use 2 %gr areas, one for 'primary' colours and one for the rest, which with judicious arrangements (say a square and a column) could look quite nice.

What I have found by experience is that saturated colours look good on screen, but more pastel shade are better on a print. Saturated colours on a print sometimes lead to incomplete toner fusing (laser) or wet and stretched paper (inkjet).

Eddie
Back to top
View user's profile Send private message
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Wed Nov 04, 2020 8:22 pm    Post subject: Reply with quote

One approach is to access the "Color Dialog Box" and then get the nearest colour to the one selected by the user.

I can find some details if this is of interest.

https://docs.microsoft.com/en-us/windows/win32/dlgbox/color-dialog-box
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Wed Nov 04, 2020 11:49 pm    Post subject: Reply with quote

Eddie, I was thinking more of a 16x16 array of swatches., and I would ignore trying to change 0 and 255.

Paul, I'll also look at the color chooser; thanks for the link. It is definitely of interest to me, perhaps others. And, it is something my users have likely run across in the past!

Bill
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Thu Nov 05, 2020 8:41 am    Post subject: Reply with quote

See CHOOSE_COLOUR@.

GET_NEAREST_COLOUR@ and GET_MATCHED_COLOUR@ are probably not relevant to your needs.
Back to top
View user's profile Send private message AIM Address
LitusSaxonicum



Joined: 23 Aug 2005
Posts: 2388
Location: Yateley, Hants, UK

PostPosted: Thu Nov 05, 2020 11:12 am    Post subject: Reply with quote

Bill,

I'd still use %gr.

Eddie
Back to top
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Thu Nov 05, 2020 3:14 pm    Post subject: Reply with quote

Paul, thanks for the hint! I'd missed that one! I'll use that to allow the colour selection.

Eddie, I'll give the %gr a shot!

Bill
Back to top
View user's profile Send private message Visit poster's website
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Fri Nov 06, 2020 2:18 am    Post subject: Reply with quote

I've done some %gr testing and have some really good outcomes!

First the %gr will work great, and using a %ud along with it give me great flexibility. I can write a handler that is "swatch independent" by passing along the uid parameter (%`gr) with each drawn entity.

I can also "link" the choose_colour@() routine to the swatch in this way. Because I'll have the uid parameter, I can directly re-draw the swatch with a new color when the user changes it as well as use the uid as an index into the array that saves the color information. I couldn't see any other way to change a %gr color, so if someone wants to weigh in on other methods of changing the color of a %gr object, feel free.

I do have a question, maybe for Paul? If I have multiple %gr in different child windows, but they share a parent window, do the uid's need to be unique? I'm thinking that they do need to be.
Back to top
View user's profile Send private message Visit poster's website
DanRRight



Joined: 10 Mar 2008
Posts: 2813
Location: South Pole, Antarctica

PostPosted: Fri Nov 06, 2020 4:23 am    Post subject: Reply with quote

Bill, Looks like your GUI is pretty advanced, would be nice if you post how it looks to potentially learn something too. Also this will lure new users to Clearwin. The more users the more features and faster fixes.
Back to top
View user's profile Send private message
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Fri Nov 06, 2020 4:30 am    Post subject: Reply with quote

Thanks for the accolade, we'll see how the implementation works!

I'll let you know!
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Nov 06, 2020 8:37 am    Post subject: Reply with quote

Bill

I am not clear about what your uid's are for. I would have to see some code to work it out. If they are needed then I guess it won't work without them.
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Fri Nov 06, 2020 3:19 pm    Post subject: Reply with quote

Paul, each swatch is assigned a uid, and there is a common callback handler. I'm not trying to process coordinates; I have user data attached to each swatch as well, and as the cursor moves across them, the user data is sampled and that shows the user what color is "rolled over".

So, each swatch is created thusly:
Code:
               ii = winio@('%`^gr[colour=#'//initial_color//',FULL_MOUSE_INPUT]%ud&',24,24,1000+k,track_mouse_autocad,k)

Quote:
I didn't see that I could supply an initial color any other way. If there is one, I'm open to change!


and the callback that populates other controls is:

Code:
   integer function track_mouse_autocad()
   USE MSWIN
   INCLUDE 'CONFIG_AUTOCAD_COMMON.INS'
   INTEGER:: I,J,K,RR,GG,BB
   CHARACTER*20:: REASON
   INTEGER:: USER_DATA,HANDLE
   HANDLE = CLEARWIN_INFO@('CALL_BACK_WINDOW')
   REASON = CLEARWIN_STRING@("CALLBACK_REASON")
   SELECT CASE (REASON)
      CASE ('MOUSE_MOVE')
         USER_DATA = CLEARWIN_INFO@('USER_DATA')
         USER_DATA = MOD(USER_DATA,1000)
         IF(LAST_COLOR.NE.USER_DATA) THEN
! PICK UP THE INFO REGARDING THE COLOR
            PRINT *,USER_DATA
            call retrieve_color(USER_DATA,   RR,  GG,  BB) ! to verify
            AUTOCAD_COLOR(1) = RR ; AUTOCAD_COLOR(2) = GG ; AUTOCAD_COLOR(3) = BB
            CALL WINDOW_UPDATE@(AUTOCAD_COLOR(1))
            CALL WINDOW_UPDATE@(AUTOCAD_COLOR(2))
            CALL WINDOW_UPDATE@(AUTOCAD_COLOR(3))
            AUTOCAD_INDEX = USER_DATA
            CALL WINDOW_UPDATE@(AUTOCAD_INDEX)
            LAST_COLOR = USER_DATA
         ENDIF
      CASE ('MOUSE_LEFT_CLICK')
         CALL SET_MOUSE_CURSOR_POSITION@(HANDLE,0,0)
         I = SETFOCUS(FOCUS_CONTROL)
   END SELECT
   track_mouse_autocad = 1
   return
   end


One of the problems with this was I wanted the user to be able to see the color choices as they scanned the cursor over the swatch area. This causes a problem if the user moves the cursor over the swatches to select other controls, the selection changes. So, I have some additional work to do to make the user interface a bit more seamless (like taking the mouse_left_click and making that the selection criteria, not just scanning over the colors).

Ultimately, when the user chooses to change the color, I will use the UID to draw the new color over the old one, thus showing the change. I've already tried that out in some test code, works great! But for that, I have to have the UID to select the color to be updated.

Code:
        k=select_graphics_object@(clearwin_info@('USER_DATA')+1000)
        call draw_filled_rectangle@(0,0,24,24,color(i))
        call perform_graphics_update@()


Being able to use the system dialog for color is great. I was also wondering if (somehow) the initial RGB color setting can be applied to that dialog so the user is at the appropriate starting point for doing a color change. That would increase its usability immensely, especially for my application!
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Fri Nov 06, 2020 5:22 pm    Post subject: Reply with quote

Bill

I don't have time to analyse your code right now but I will look at it when I can.

As I recall, the colours in the Choose Color dialog can in theory be preset but not at the moment via ClearWin+. However, they are saved between one call and another within a given session.

It should be fairly easy to add something to ClearWin+ that allows you to preset the custom colours.
Back to top
View user's profile Send private message AIM Address
wahorger



Joined: 13 Oct 2014
Posts: 1217
Location: Morrison, CO, USA

PostPosted: Fri Nov 06, 2020 6:44 pm    Post subject: Reply with quote

Paul, the Choose Color addition of setting the original would be fantastic! I look forward to that capability.

As far as my %gr code, what you see is pretty complete, but not 100%. I can envision a few ways to get the same results without having the UID specifically, but it sure does make life easy!

Perhaps even a %lc would work......
Back to top
View user's profile Send private message Visit poster's website
PaulLaidler
Site Admin


Joined: 21 Feb 2005
Posts: 7916
Location: Salford, UK

PostPosted: Sat Nov 07, 2020 1:06 pm    Post subject: Reply with quote

Bill

I have had a look at your code but I am not able to deduce anything from it.

Just to clarify, the colours that can be preset (by my adding a routine to ClearWin+) are the 16 "Custom colors" and not the "Basic colors".
Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    forums.silverfrost.com Forum Index -> ClearWin+ All times are GMT + 1 Hour
Goto page 1, 2  Next
Page 1 of 2

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group