The International Simutrans Forum

Development => Patches & Projects => Topic started by: An_dz on May 18, 2014, 04:32:00 AM

Title: Button drawing fix
Post by: An_dz on May 18, 2014, 04:32:00 AM
Here's a patch to fix how buttons are drawn, the main objective of this patch is correct the colored buttons mask.

Basically now every row will use the highest image as the height for all, and when building the colour mask we use the sizes for the actual state, this way the colour mask stays where the artist meant to be.

Here's what the patch allows:
(http://i.imgur.com/B7LbOtx.png)

Also attached the fixed images for the standard theme.
Title: Re: Button drawing fix
Post by: Max-Max on May 18, 2014, 04:18:14 PM
Great job, but this wasn't an issue in my original code. In my original code, I was looking for the highest element and even left out the side elements (left/top/right/bottom) if the sum of corner elements was larger, clipping them as well to get the right size.

I feel like the current implementation makes me look bad, because you guys are fixing so much stuff related to my work. A lot of the fixes was already taken care of in my original implementation, that Prissi rewrote almost completely.

For some reason Prissi thought this was't necessarily code and removed it. Maybe if you have a look at my original source, a lot of work can be saved by just reimplementing it.
I will again state that the current implementation is mostly Prissi's rework of my code. Most of it was rewritten to Prissi's liking and broke a lot of functionalities. I was just to tired of bother since it felt pointless to put any efforts into the project.

I also included a new theme and modified the current default themes, with source included, to show how it worked, but that was never included in the trunk. Instead Prissi reworked his current themes to fit his implementation.
Title: Re: Button drawing fix
Post by: An_dz on May 18, 2014, 05:49:52 PM
The only patch I have from you doesn't have this part of the code. :(
Title: Re: Button drawing fix
Post by: prissi on May 21, 2014, 10:01:14 PM
Sorry for the late comment.


void display_img_stretch( const stretch_map_t &imag, scr_rect area )
{
+ // This prevents Simutrans from crashing
+ imd img[3][3];
+ for(  int i = 0; i < 9; ++i  ) {
+ if(  imag[i%3][i/3] != IMG_LEER  ) {
+ img[i%3][i/3] = images[ imag[i%3][i/3] ];
+ }
+ }


At which part will it crash? It may be still be uninitialized when images are no available by

if(  imag[0][2]!=IMG_LEER  ) {
- h_bottom = images[ imag[0][2] ].h;
+ h_bottom = max( img[0][2].h, max(img[1][2].h, img[2][2].h) );
}


Either img needs to be and array of coord and set to zero or you will just get the max of wrong images in case those are not present. Given how often coord are accessed, it may make sense to use the coors instead and only dereference the imgs when needed.
Title: Re: Button drawing fix
Post by: An_dz on May 23, 2014, 01:25:12 AM
Then that's why it was crashing. :D I need to get better on seeing when things may be uninitialised.

I used scr_size for img as it makes more sense, and removed the first if's as they were redundant. Try the new patch.