Recent

Author Topic: [SOLVED]Cannot center image in tSpeedButton  (Read 3676 times)

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
[SOLVED]Cannot center image in tSpeedButton
« on: April 25, 2018, 01:18:50 pm »

I have a speed button (W=24; H=24 px), placed in a toolbar.

My code is

  if stQuickTransOn
    then imagelist1.GetBitmap(0,SpeedButton1.Glyph)
    else imagelist1.GetBitmap(1,SpeedButton1.Glyph);

Images are stored in imglImagesOnOff, all images in it are 24x24 pixels. imglImagesOnOff is itself 24 pixels wide.

When I have not touched default values of the speed button image is drawn OUTSIDE(above) the button.
I tried various settings, but could not center the image on both axises.
I have also tried Center of the images in imagelist1, but they got garbled, scrambled... etc.

Should I use some other control instead of TSpeedButton?

(a sample is attached)
« Last Edit: April 25, 2018, 08:44:08 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

ASerge

  • Hero Member
  • *****
  • Posts: 2223
Re: Cannot center image in tSpeedButton
« Reply #1 on: April 25, 2018, 01:56:49 pm »
The image is centered, but the arrow in the image is not centered. Correct the image.

RayoGlauco

  • Full Member
  • ***
  • Posts: 176
  • Beers: 1567
Re: Cannot center image in tSpeedButton
« Reply #2 on: April 25, 2018, 02:00:37 pm »
I usually use  tBitBtn and I like it. I have no problem, and the images are placed in the center.
Anyway, I think your button must be greater than 24x24 if you want it to contain 24x24 images, because there has to be some margin.
To err is human, but to really mess things up, you need a computer.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Cannot center image in tSpeedButton
« Reply #3 on: April 25, 2018, 02:09:04 pm »
The image is centered, but the arrow in the image is not centered. Correct the image.
It is offset one pixel to the left and is vertically centered. And even if it was not so, I except it should not be drawn oustside (above) the button, as it happens.


Anyway, I think your button must be greater than 24x24 if you want it to contain 24x24 images, because there has to be some margin.

I increased it to 28x28, and still image is alligned top-left.
« Last Edit: April 25, 2018, 02:15:04 pm by CM630 »
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

RayoGlauco

  • Full Member
  • ***
  • Posts: 176
  • Beers: 1567
Re: Cannot center image in tSpeedButton
« Reply #4 on: April 25, 2018, 02:35:40 pm »
Maybe this is a kind of bug?  Using your code, image is placed top-left. If I manually put an image on the button, the result is different, as the attached image shows.

If you place on your button some image (same size: 24x24) in design time, I think then the images placed by code may be ok.
« Last Edit: April 25, 2018, 02:51:07 pm by RayoGlauco »
To err is human, but to really mess things up, you need a computer.

balazsszekely

  • Guest
Re: Cannot center image in tSpeedButton
« Reply #5 on: April 25, 2018, 02:51:28 pm »
Did you take into account ShowCaption, Caption Layout properties? More over the arrow is not in the center of your image. Set ShowCaption to false and LayOut to glyphRight + move the arrow to the middle and you should be good to go.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Cannot center image in tSpeedButton
« Reply #6 on: April 25, 2018, 02:55:24 pm »

Maybe this is a kind of bug?  Using your code, image is placed top-left. If I manually put an image on the button, the result is different, as the attached image shows.

If you place on your button some image (same size: 24x24) in design time, I think then the images placed by code may be ok.


Yes, it is centered when I put the image at design time.


Did you take into account ShowCaption, Caption Layout properties? More over the arrow is not in the center of your image. Set ShowCaption to false and LayOut to glyphRight + move the arrow to the middle and you should be good to go.

I have already tried ShowCaption=false  and LayOut=Everything possible.

How am I to move the arrow to the middle?
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Cannot center image in tSpeedButton
« Reply #7 on: April 25, 2018, 02:59:28 pm »
Your image originally looks like 16x16, but your image list is 24x24. If I use an image from which I know for sure that it is 24x24 it works correctly.

And if I put the 16x16 image into a 16x16 imagelist, everything works fine as well.

Probably when you put the 16x16 into the 24x24 image list the imagelist has its own ideas of how to handle this cas.
« Last Edit: April 25, 2018, 03:01:04 pm by wp »

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Cannot center image in tSpeedButton
« Reply #8 on: April 25, 2018, 03:19:12 pm »
Yes @wp, that should be it.
And imagelist cannot center properly. It has sucha property, results are desastrous.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Cannot center image in tSpeedButton
« Reply #9 on: April 25, 2018, 03:21:40 pm »
Yes @wp, that should be it.
And imagelist cannot center properly. It has sucha property, results are desastrous.
change the transparent color to something else than default before centering
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Cannot center image in tSpeedButton
« Reply #10 on: April 25, 2018, 03:36:48 pm »

There is sth. wrong with ImageList.
1. When I set transparency to something else (i.e. Fucscia) I get purle artefacts aroud the image. If I used the default colour I get the image on a black background./
2. When adding an image 16x16 with red stripes in an image list 24x24 they are displayed as yellow stripes.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

wp

  • Hero Member
  • *****
  • Posts: 11857
Re: Cannot center image in tSpeedButton
« Reply #11 on: April 25, 2018, 03:56:50 pm »
No nothing wrong with the image list. You're just not using it correctly. When the image is smaller than the size assumed by the imagelist then the pixels outside the image are undefined. BTW, this might have changed with the new image list of Laz trunk which can scale the images to the required size.

CM630

  • Hero Member
  • *****
  • Posts: 1082
  • Не съм сигурен, че те разбирам.
    • http://sourceforge.net/u/cm630/profile/
Re: Cannot center image in tSpeedButton
« Reply #12 on: April 25, 2018, 06:12:19 pm »

...the pixels outside the image are undefined...

Could this explain that
Quote from: СМ630
2. When adding an image 16x16 with red stripes in an image list 24x24 they are displayed as yellow stripes.

These stripes are inside the image.
Лазар 3,2 32 bit (sometimes 64 bit); FPC3,2,2; rev: Lazarus_3_0 on Win10 64bit.

 

TinyPortal © 2005-2018