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

API to get device scale for handling high-DPI mode manually #395

Closed
hajimehoshi opened this issue Jul 27, 2017 · 14 comments
Closed

API to get device scale for handling high-DPI mode manually #395

hajimehoshi opened this issue Jul 27, 2017 · 14 comments
Labels
Milestone

Comments

@hajimehoshi
Copy link
Owner

No description provided.

@joeblew99
Copy link

Detecting DPi is something i need, so that i can then scale everything properly and do constraint based layout.

Is there anything in Ebiten yet for detection of DPI ?

@hajimehoshi
Copy link
Owner Author

Is there anything in Ebiten yet for detection of DPI ?

Not so far, and let me think if I should make the API. This is risky because this might break assumptions of Ebiten's graphics system.

@joeblew99
Copy link

I can see what you mean about risky as you presume a fixed X and Y screen space.
If its really not something you want to put in yet thats OK. I can always try out some ideas in a fork..

@hajimehoshi hajimehoshi modified the milestones: v2.0.0, v1.6.0 Jan 2, 2018
@hajimehoshi hajimehoshi changed the title High-DPI mode Option to disable auto-scaling for handling high-DPI mode manually Jan 2, 2018
@ffigiel
Copy link
Sponsor

ffigiel commented Jan 2, 2018

In #469 @hajimehoshi said

Thanks, but let me think a little more about how the new API would be. My concern is to pass 0 to Run might be confusing.

Another API I can think if is ebiten.RunWithoutDpiScaling(update, 800, 600, "My app") but that seems too verbose 😕

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Jan 2, 2018

My concern is not only making Run counterintuitive, but also making SetScreenScale and ScreenScale counterintuitive.

My current idea is to add IsScreenAutoScaled() bool and SetScreenAutoScaled(value bool). When SetScreenAutoScaled(false) is called, the set scale in Run is just ignored. This 'ignoring-scale' behavior is similar to current SetFullscreen and IsFullscreen.

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Jan 2, 2018

Now I have implemented on desktops and not on browsers and mobiles. (not pushed yet)

I found another concern: if auto-scaling is disabled, what if fullscreen scaling? Probably making the game fullscreen without scaling would be the answer, but this would be the first case that SetFullscreen affects the actual screen (*ebiten.Image instance) width and height.

@hajimehoshi
Copy link
Owner Author

Yet another concern: As MacBook (Pro) or iPhone can't render pixel-perfect way, this option might not be useful for 'perfectly-crisp' rendering.

@hajimehoshi
Copy link
Owner Author

hajimehoshi commented Jan 2, 2018

Oh, I came up with much more elegant solution! Assuming we have DeviceScale(),

  • Pass the invert of device scale (1 / DeviceScale()) to Run
  • Multiply screen width and height by DeviceScale() if necessary and pass them to Run

As a result, auto scaling by device scale would be invalidated without introducing a new state to Ebiten. What I have to do is add DeviceScale().

@megapctr, do you think this would work in your case?

@ffigiel
Copy link
Sponsor

ffigiel commented Jan 2, 2018

Wouldn't that stretch the image back and forth? If not then it's great :) I'll try this in a moment

@hajimehoshi
Copy link
Owner Author

Wouldn't that stretch the image back and forth? If not then it's great :) I'll try this in a moment

It's not. Actually the number of scaling is not changed and the final scale (1/devicescale * devicescale = 1 in this case) is just adopted.

@ffigiel
Copy link
Sponsor

ffigiel commented Jan 2, 2018

I just tried this, works perfectly 👏 Thank you very much!
I'll just hardcode 1 / 1.25 until the new API is shipped :)

@hajimehoshi
Copy link
Owner Author

d18fc36 Added DeviceScale() function experimentally. There is no doc, but I'll add this later.

I just tried this, works perfectly 👏 Thank you very much!
I'll just hardcode 1 / 1.25 until the new API is shipped :)

Oh, I'm glad to hear that!

@ffigiel
Copy link
Sponsor

ffigiel commented Jan 2, 2018

As for the fullscreen issue, I think we'd need to know the screen resolution. Knowing this, if user wants to toggle fullscreen, the update func could return a specific error which tells our main function to re-run Ebiten with updated dimensions and toggle ebiten.SetFullscreen.

Perhaps this code will better explain the idea:

var enableFullscreen = errors.New('enableFullscreen')
var width, height = 800, 600

func main() {
  while true {
    err := ebiten.Run(update, width, height, 1 / ebiten.GetDeviceScale(), "My app")
    if err == enableFullscreen {
      width, height = ebiten.GetScreenResolution() /* new api? */
      ebiten.SetFullscreen(true)
    } else if err != nil {
      panic(err)
    }
  }
}

func update(screen *ebiten.Image) error {
  return enableFullscreen
}

By the way, is it even possible for ebiten.Run to return nil?

@hajimehoshi
Copy link
Owner Author

Yeah I agree we need to have a new API for screen resolution. I think we should have another ticket.

By the way, is it even possible for ebiten.Run to return nil?

This returns nil when the window is closed. IIUC there are not other cases. If you want to terminate the game without errors, you can define an error value, return this in update func, and detect this at Run's return.

@hajimehoshi hajimehoshi changed the title Option to disable auto-scaling for handling high-DPI mode manually API to get device scale for handling high-DPI mode manually Jan 3, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants