Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android: Allow non-square overlay control images #9944

Merged
merged 1 commit into from Dec 11, 2022

Conversation

JosJuice
Copy link
Member

This removes an assumption in the code which made every overlay control image be scaled to a square even if the actual image was rectangular.

This removes an assumption in the code which made every overlay control
image be scaled to a square even if the actual image was rectangular.
@dolphin-emu-bot
Copy link
Contributor

FifoCI detected that this change impacts graphical rendering. Here are the behavior differences detected by the system:

  • soniccolors-mm on uberogl-lin-radeon: diff

automated-fifoci-reporter

@blakbin
Copy link

blakbin commented Aug 4, 2021

im tested it but it seem no change. the classic L & R button still has Rectangle Bound, in my phone width and height still 259x259

@JosJuice
Copy link
Member Author

JosJuice commented Aug 4, 2021

That's because I didn't change any of the image files. I was thinking that could be done in a separate PR if desired.

@blakbin
Copy link

blakbin commented Aug 4, 2021

im using crop before scaled, everything looked fine and now if any button gotten hit on transparent area it will be not get pressed state, but my code look like dirty

public static Bitmap resizeBitmap(Context context, Bitmap bitmap, float scale)
  {
    // Determine the button size based on the smaller screen dimension.
    // This makes sure the buttons are the same size in both portrait and landscape.
    DisplayMetrics dm = context.getResources().getDisplayMetrics();
    int minScreenDimension = Math.min(dm.widthPixels, dm.heightPixels);

    int minX = bitmap.getWidth();
    int minY = bitmap.getHeight();
    int maxX = -1;
    int maxY = -1;
    for(int y = 0; y < bitmap.getHeight(); y++)
    {
      for(int x = 0; x < bitmap.getWidth(); x++)
      {
        int alpha = (bitmap.getPixel(x, y) >> 24) & 255;
        if(alpha > 0) 
        {
          if(x < minX)
            minX = x;
          if(x > maxX)
            maxX = x;
          if(y < minY)
            minY = y;
          if(y > maxY)
            maxY = y;
        }
      }
    }
    Bitmap croppedBitmap = Bitmap.createBitmap(bitmap, minX, minY, (maxX - minX) + 1, (maxY - minY) + 1);

    int maxBitmapDimension = Math.max(croppedBitmap.getWidth(), croppedBitmap.getHeight());
    float bitmapScale = scale * minScreenDimension / maxBitmapDimension;

    return Bitmap.createScaledBitmap(croppedBitmap,
      (int) (croppedBitmap.getWidth() * bitmapScale),
      (int) (croppedBitmap.getHeight() * bitmapScale),
      true);
  }

@ghost
Copy link

ghost commented Nov 3, 2021

Any news about this?

@JosJuice
Copy link
Member Author

JosJuice commented Nov 3, 2021

As far as I'm concerned, this is ready to go.

@t895
Copy link
Contributor

t895 commented Dec 10, 2022

I don't have a good way of testing rectangular images at the moment but LGTM

@JosJuice JosJuice merged commit 82e87cf into dolphin-emu:master Dec 11, 2022
11 checks passed
@JosJuice JosJuice deleted the android-nonsquare-buttons branch December 11, 2022 11:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
4 participants