Recent

Author Topic: menu item bitmap visible? laz v2.0  (Read 1687 times)

OH1KH

  • New Member
  • *
  • Posts: 28
menu item bitmap visible? laz v2.0
« on: March 18, 2019, 06:27:44 pm »
Hi!
I upgraded from laz 1.84 to 2.0.0 (Fedora 28) and now one menu of my program does not show any more bitmaps.
Source code is same as with 1.8.4 when it worked.

It is a popup color menu with main item "Set Color of" and 5 sub items that have had small color spot 10x10 bitmap in front of selection text showing current color.

I do not paste code yet, first I would like to know has there been any change with menu handling from 1.8.4 -> 2.0.0 ?

Few hours of Googling did not give any help.
--
Saku

Blaazen

  • Hero Member
  • *****
  • Posts: 2782
  • POKE 54296,15
    • Eye-Candy Controls
Re: menu item bitmap visible? laz v2.0
« Reply #1 on: March 18, 2019, 06:43:45 pm »
Give us more info. It is Qt or GTK2? The menu is main menu or popmenu? Images are from ImageList?

EDIT: The screenshot looks like something custom-drawn.
Lazarus 2.1.0 r61214:62238 FPC 3.3.1 r40507 x86_64-linux-qt Chakra, Qt 4.8.7/5.13.2, Plasma 5.17.3
Lazarus 1.8.2 r57369 FPC 3.0.4 i386-win32-win32/win64 Wine 3.21

Try Eye-Candy Controls: https://sourceforge.net/projects/eccontrols/files/

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #2 on: March 18, 2019, 06:59:13 pm »
Hi!
It is GTK2.

And more mysterious now. This PC x86_64  (Fedora 28 just full updated) it does not work, but i have server an old i386 running Ubuntu 18.04.2 LTS  and I can access it via vnc.
There I have same source and also upgraded laz 2.0.0 and when I compile and start program there it shows color spots ok.

Maybe something with 64-gtk2 ?
--
Saku

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #3 on: March 19, 2019, 07:57:47 am »
Got info also from 64 bit ubuntu 18.04. user.
Colors do not show up  with version compiled by laz 2.0.0.   Older binary, compiled with 1.8.4 works also there.

So it seems to be related to 64bits and Laz 2.0.0
--
Saku

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #4 on: March 19, 2019, 08:50:21 am »
Here is simplified program that is made by partially copying from original.

--
Saku

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #5 on: March 22, 2019, 05:21:15 pm »
Hi again, myself!

Modified source a bit, but no help. Then compiled it with old laptop  Lazarus 1.8.2 (Fedora28 x64).
AND IT WORKS !! 
So there is a bug in 2.0.0. or the component handling has totally changed.
--
Saku

wp

  • Hero Member
  • *****
  • Posts: 6334
Re: menu item bitmap visible? laz v2.0
« Reply #6 on: March 22, 2019, 06:11:13 pm »
What was changed in Laz 2.0 is the imagelist which supports images at several sizes for various screen resolutions now. It is possible that handling of the bitmaps directly assigned to menu items has been affected this way on gtk2. I can confirm the issue on a VM with Lubuntu/gtk2 (32 bit). The issue does not appear on Windows.

I cannot give you a direct solution of the issue since I lack knowledge in low-level gtk2 programming. But why, after all, do you assign bitmaps to menu items directly without using an ImageList? I am always using ImageLists and have never seen issues with it, and in fact, before your post, I did not even know that direct assignment of bitmaps is possible.

The attached demo extends your program with an ImageList and works also on Lubuntu/gtk2. It is a bit simplified because it does not take advantage of the new high-dpi features of the ImageList.

I am aware that my code requires you to change your code at a few places. But you will be rewarded by being prepared for high-dpi icons in the menu.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #7 on: March 22, 2019, 07:13:06 pm »
HI !

Thanks! Seems to work "as in old days".

Why I assign bitmap directly. It is the easiest way!  My code even had too many lines as I first create bitmap and fill it and then assign it to menuitem's bitmap. Same can be done directly to menutem's bitmap. (My last post's unit1.txt)

It just happened to stop working on ver 2.0.0. but works with ver 1.8.x OK

Where I do need the imageList for? I just need one image (or plain bitmap) to get different colors and drop that to menuitems (or access them directly...unfortunately not any more)

Actually I was quite near to start testing something like your demo, but as I never have used image list for any purpose I tried to survive first without.
I even tested with one single image and tried to drop it to menu.bitmap. Same result.Nul.

Thank you.
Saved lot of my time.

Spent already 2 evenings with testing all variations. Noticed that sizing menuitem's bitmap does affect the size of item so it somehow reads bitmap and reacts to it but does not make it visible.


--
Saku

wp

  • Hero Member
  • *****
  • Posts: 6334
Re: menu item bitmap visible? laz v2.0
« Reply #8 on: March 22, 2019, 07:20:54 pm »
After playing with your issue I found a less disruptive solution: It seems that the bitmap painted by a uniform color out to its very edge is interpreted as being transparent - you remember that the left-bottom-most pixel is the transparent color? I don't know why switching Bitmap.Transparent to false does not help here, but you can work around by filling the bitmap with the Rectangle function instead of FillRect - you only must take care of the Pen.Color being different from the Brush.Color. The border of the rectangle will now be taken as transparent, but the inner fill will appear. The color box is smaller by 1 pixel on each side, but you can compensate it by incrementing the bitmap width and height accordingly by 2.

This code works for me on Lubuntu/gtk2:
Code: Pascal  [Select]
  1. procedure TForm1.Setbitmap(bm: TBitmap; col: Tcolor);
  2. begin
  3.  with bm do
  4.   Begin
  5.     Width  := bmW + 2;
  6.     Height := bmH + 2;
  7.     with Canvas do
  8.      Begin
  9.         Brush.Style := bsSolid;
  10.         if col = clBlack then Pen.Color := clFuchsia else Brush.Color := clBlack;
  11.         Brush.Color := col;
  12.         Rectangle(0, 0, bmW, bmH);
  13.      end;
  14.   end;
  15. end;
« Last Edit: March 22, 2019, 07:25:16 pm by wp »
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

wp

  • Hero Member
  • *****
  • Posts: 6334
Re: menu item bitmap visible? laz v2.0
« Reply #9 on: March 22, 2019, 07:52:02 pm »
Where I do need the imageList for? I just need one image (or plain bitmap) to get different colors and drop that to menuitems (or access them directly...unfortunately not any more)
Yes, an ImageList is probably overkill here for just providing a single user-drawn bitmap.

But in general, imagelists provide a generalized container for all images used by an application. You just add the images to the list (by double-clicking on its icon on the form and using the image list editor dialog), and then any image-aware component refers to its image by the index on the image list, the ImageIndex property. Suppose you have a menu and a toolbar and somewhere a speedbutton - all three are for saving a file and look good if you assign the well-known floppy icon to them. Using your method with the direct bitmap property means that your form must contain three copies of the same image - in the image list, however, it is stored only once.

The other advantage is that, since Laz 2.0, image lists can scale the images according to the resolution of the system on which your program runs. In the old days, a screen usually had 96 pixels per inch, and a 16x16 pixel bitmap had a usable size. Today high-dpi screens are popular and have resolutions of 192 dpi or more. When the size of the monitor is appoximately the same as before the size of the 16x16 bitmap now appears to be only half of the old size or less. It is very difficult to hit such tiny icons with the mouse. And an application with huge letters and tiny icons looks terrible. The new imagelist can help to overcome these issues along with the LCL form scaling.

Read the wiki to learn about the ImageList. It's worth the effort.
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #10 on: March 23, 2019, 09:33:19 am »
Hi!

This morning I did convert your sample to my program. Result NIL.

Then I forgot the color change procedure and just tried to get the initial view. Tried in  both formCreate and FormShow.
Does not matter nothing shows up.

I have to try your Rectangle next.

--
Saku

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0
« Reply #11 on: March 23, 2019, 10:03:30 am »
Yes !

Rectangle solution is lot more simpler and this time it also works.
I even dropped  away extra bitmaps and initialize menuitem.bitmap right away at formCreate and then do the SetBitmap directly to it.
 It is funny that your first example worked when I tried it alone, but wthe transferred the FrormCreate part to my program it did not work there, although I checked the code to be similar many times.

This one I do not understand right away:
Code: Pascal  [Select]
  1.  if col = clBlack then Pen.Color := clFuchsia else Brush.Color := clBlack;
  2.         Brush.Color := col;

If "col" is NOT  black we set brush black and right away set it again as "col"

Do you mean:
Code: Pascal  [Select]
  1. if col =clBlack then Pen.Color:=clFuchsia else Pen.color := clBlack;

?
I think that would make sense.

--
Saku

wp

  • Hero Member
  • *****
  • Posts: 6334
Re: menu item bitmap visible? laz v2.0
« Reply #12 on: March 23, 2019, 10:22:06 am »
Sorry for the typo... It should be "Pen" in the "if". The line has the purpose to make sure that the border of the rectangle has a different color than the interior fill because in this case the bitmap would have a uniform color again.
Code: Pascal  [Select]
  1.     procedure TForm1.Setbitmap(bm: TBitmap; col: Tcolor);
  2.     begin
  3.      with bm do
  4.       Begin
  5.         Width  := bmW + 2;
  6.         Height := bmH + 2;
  7.         with Canvas do
  8.          Begin
  9.             Brush.Style := bsSolid;
  10.             if col = clBlack then Pen.Color := clFuchsia else Pen.Color := clBlack;
  11.             Brush.Color := col;
  12.             Rectangle(0, 0, bmW, bmH);
  13.          end;
  14.       end;
  15.     end;
Lazarus trunk / fpc 3.0.4 / all 32-bit on Win-10

OH1KH

  • New Member
  • *
  • Posts: 28
Re: menu item bitmap visible? laz v2.0 [solved]
« Reply #13 on: March 23, 2019, 11:25:19 am »
So I was thinking.

Many thanks.
Now this is solved.
--
Saku