ImageCombo to select colors: Problems and Questions

Started by roy_043, July 14, 2011, 05:05:03 AM

Previous topic - Next topic

roy_043

ImageCombo to select colors: Problems and Questions

Hello,

This is a continuation of
http://www.opendcl.com/forum/index.php?topic=1654.0

The program has been renamed to ComboTest and now uses an ImageCombo to select colors which is my reason for starting this new topic.

System:
Bricscad 11.4.2
Windows XP
OpenDCL 6.0.2.4

Files:
ComboTest.lsp
ComboTest.odcl
ComboTest_Images.zip

1.
After starting the program two problems are immediately apparent. The first one is that the ImageCombo shows the correct image but not the correct text.

2
The second obvious problem is that the text in the TextBox has been selected. This seems a different manifestation of the problem described here:
http://www.opendcl.com/forum/index.php?topic=1647.msg8218#msg8218
It would seem that the first control in the tab order is somehow triggered in Bricscad.

3.
After selecting 'Red' two new problems appear:
Both the image and the text in the ImageCombo are marked with a blue background/'overlay' (this may depend on the current theme). This obscures the color swatch. If you click behind the text its blue background disappears but the blue 'overlay' remains for the image portion. Clicking outside the dialog will clear the image. Is there a way to clear this automatically?

4.
The other new problem:
The OnSelChanged event always returns -1 for ItemIndexOrCount.

5.
Selecting one of the true colors shows that Bricscad displays true colors incorrectly in ODCL dialogs. The Red and Blue values are reversed:
RGB:247,186,011 displays as RGB:011,186,247 and vice versa.

6.
And finally a very strange one:
- Open ComboTest.odcl
- Change ListImages for ImageCombo1 to: 0|1|2|3|4|5|6|7|8|9|10|11
- Restart the program
- Select 'Red'
Result:
The top left pixel of the image is not displayed. This seems to be related to the use of png images and the image index. Not using the zero-index png image or changing that image to a bmp will solve this. The missing pixel is also visible if you open the Control Property Wizard on the Image List tab. If you delete the zero-index image you have to reopen the wizard to see the effect.

Regards, Roy.

roy_043

One obvious solution for problem 3:
Change the focus to another control on the dialog:
(dcl_Control_SetFocus ComboTest_Form1_textbox1)
This may be confusing for the user however.

Fred Tomke

roy_043,

it is necessary to set the imagecombobox style value to 2 for DropDown. Then it works very fine. I'd recommend you not to use an imagecombo as an editable combobox.

Furthermore the function to get rgb value need to be inverted: AutoCAD is computing it differently:

Code (autolisp) Select

(defun kg_ColorRgbToOle (rgbLst)
  (+
    (lsh (caddr rgbLst) 16)
    (lsh (cadr rgbLst) 8)
    (car rgbLst)
  )
)


After changing both your project works fine.

Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

owenwengerd

The -1 for ItemIndexOrCount was a bug, now fixed for the next build. Fred is correct that your color bytes are reversed, but that is a Windows thing (AutoCAD in fact uses BGR color representation internally, not RGB as Windows does).

It would be less confusing if you passed your RGB color as a list of RGB bytes, but while testing this I noticed another bug: an (R G B) list is not accepted for the ForeColor or BackColor properties. I'll see if I can't address that as well.

In any case, you can use the built-in (dcl_GetOLEColorValue) function to do the dirty work -- but you'll want to avoid the DXF code bug by ensuring that the first element is not an integer:
Code (autolisp) Select
(dcl_GetOLEColorValue (mapcar 'float (read (strcat "(" (vl-string-translate "," " "  (substr Value 5)) ")"))))
Owen Wengerd (Outside The Box) / ManuSoft

roy_043

#4
Fred and Owen thank you very much for your answers.

Setting the ImageCombo style to '2 - Drop Down' as advised by Fred solves problem #1.

Problem #3 remains see image ComboTest_after_selecting_red.png.

Confronted with problem #5 I was of course surprised. To make sure that my function kg_ColorRgbToOle was correct I created a layer "Orange" with color RGB:247,186,011 and checked its entity list:

(
 (-1 . <Entity name: ...>)
 (0 . "LAYER")
 ...
 (2 . "Orange")
 (70 . 0)
 (62 . 40)
 (420 . 16235019)
 ...
)

And I compared group code 420 with the result of my function:
(kg_ColorRgbToOle '(247 186 11)) ; => 16235019
This convinced me that my function was OK. But judging from your comments this is not the case.
For my understanding:
If you create a layer following the above steps in AutoCAD, what is the group code 420 value?

Thanks again for your time and patience.

Regard, Roy.

Edit: dwg attachment removed.

owenwengerd

AutoCAD and Bricscad both use BGR for true colors, so yes, AutoCAD reports the same color value as Bricscad. Windows, however, uses an RGB color format.

As for Problem #3, from your description I would say this is behaving as designed when the control has focus. Have you considered turning off Keep Focus?
Owen Wengerd (Outside The Box) / ManuSoft

roy_043

Quote from: owenwengerd on July 15, 2011, 07:37:55 AM
AutoCAD and Bricscad both use BGR for true colors, so yes, AutoCAD reports the same color value as Bricscad. Windows, however, uses an RGB color format.
Finally I understand my confusion. Up to now I have been reading a group code 420 color value from left to right. This, of course, makes no sense. An integer is 'filled' from right to left.

Quote from: owenwengerd on July 15, 2011, 07:37:55 AM
As for Problem #3, from your description I would say this is behaving as designed when the control has focus. Have you considered turning off Keep Focus?
The form has Keep Focus turned off. I can't find this setting for a control.

Attached updated files.

Fred Tomke

Hi, roy,

a non-modal form (modeless, dockable and palette) has the property KeepFocus and the property EventInvoke. A control has only the property EventInvoke which you can switch between KeepFocus and AllowCommand.

Regards, Fred
Fred Tomke
Dipl.-Ing. (FH) Landespflege

[ landscaper - landscape developer - digital landscape and urban design]

roy_043

I have switched EventInvoke to '1 - Asynchronous' (which I think is meant by 'AllowCommand') for the ImageCombo. But problem #3 remains.

Additionally switching EventInvoke to 1 for the form also has no effect on problem #3. KeepFocus was already 'False' for the form.

owenwengerd

FWIW, problem #3 does not occur in AutoCAD, only Bricscad.
Owen Wengerd (Outside The Box) / ManuSoft