Author Topic: Button drawing fix  (Read 1835 times)

0 Members and 1 Guest are viewing this topic.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Button drawing fix
« 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:


Also attached the fixed images for the standard theme.
« Last Edit: March 07, 2016, 03:14:36 AM by An_dz »

Offline Max-Max

Re: Button drawing fix
« Reply #1 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.
« Last Edit: May 18, 2014, 04:32:32 PM by Max-Max »
- My code doesn't have bugs. It develops random features...

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Button drawing fix
« Reply #2 on: May 18, 2014, 05:49:52 PM »
The only patch I have from you doesn't have this part of the code. :(

Offline prissi

  • Developer
  • Administrator
  • *
  • Posts: 8752
  • Total likes: 305
  • Helpful: 229
  • Languages: De,EN,JP
Re: Button drawing fix
« Reply #3 on: May 21, 2014, 10:01:14 PM »
Sorry for the late comment.

Code: [Select]
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
Code: [Select]
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.

Offline An_dz

  • Web Admin
  • Administrator
  • *
  • Posts: 2593
  • Total likes: 289
  • Helpful: 89
  • D'oh
    • by An_dz
  • Languages: PT, EN, (it, de)
Re: Button drawing fix
« Reply #4 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.