xenia icon indicating copy to clipboard operation
xenia copied to clipboard

Implement screenshot feature

Open SirQuartz opened this issue 2 years ago • 9 comments

This pull request adds the ability to take screenshots from within the emulator.

It will save the screenshot and name the file using this format: "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in nanoseconds since epoch].png". The menu button is found under Display > Take Screenshot and can also be activated by pressing F12.

Screenshots are saved to Documents\Xenia\Screenshots\{Game Title or Game ID} by default.

https://user-images.githubusercontent.com/62965063/194796537-5a8910c2-d2c5-42f6-b224-e5b62cc99a86.mp4

Take Screenshot

Resolves: #2049, #2039

SirQuartz avatar Oct 09 '22 05:10 SirQuartz

nice work! I'm kinda surprised how easy this was to implement. Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)? Also I'd change the output filename to something like {title or title ID} - {date}.png

Razzile avatar Oct 09 '22 11:10 Razzile

nice work! I'm kinda surprised how easy this was to implement. Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)? Also I'd change the output filename to something like {title or title ID} - {date}.png

Thanks! I was honestly surprised too. It helped that the project already included a third-party library that would save image files and that there was already a method to capture the raw render output. Also, GitHub Copilot sleuthed about half of the solution, and I deduced the rest to get it working. Otherwise, I wouldn't have even known about the stbi_write_to_func() method.

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png". The time since the epoch in milliseconds will look like a long random number, but also never be the same, it can only ever increase. That way, it can give a unique file name.

And yeah, I can add a message box with imgui to say "Screenshot saved to [screenshot path]".

SirQuartz avatar Oct 10 '22 03:10 SirQuartz

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png"

Maybe something like ISO 8601? So the date format is something like %Y%m%dT%H%M%S which maps to time-strings such as 20221011T102845 which is sortable alphabetically in a file-browser and pretty human-readable.

Wunkolo avatar Oct 11 '22 17:10 Wunkolo

nice work! I'm kinda surprised how easy this was to implement. Do we have a way of notifying users that the screenshot has been saved (maybe imgui has some kind of notification functionality)? Also I'd change the output filename to something like {title or title ID} - {date}.png

Thanks! I was honestly surprised too. It helped that the project already included a third-party library that would save image files and that there was already a method to capture the raw render output. Also, GitHub Copilot sleuthed about half of the solution, and I deduced the rest to get it working. Otherwise, I wouldn't have even known about the stbi_write_to_func() method.

I'll see about making the filename more descriptive, probably something like "Screenshot - [Title_Name or Title_ID] - [Datetime] - [Time in milliseconds since epoch].png". The time since the epoch in milliseconds will look like a long random number, but also never be the same, it can only ever increase. That way, it can give a unique file name.

And yeah, I can add a message box with imgui to say "Screenshot saved to [screenshot path]".

You used github copilot for this? How did that process work?

A message box might be too intrusive. maybe if imgui has no notification widget (that doesn't get in the way/steal context) you could add <SCREENSHOT SAVED> to the window title for a second or two

Razzile avatar Oct 12 '22 13:10 Razzile

Yeah, GitHub Copilot is surprisingly helpful in finding the missing pieces to a solution at times. Especially in this case where the answer was just sitting right in front of me but I hadn't noticed it yet. In this case, I didn't know the project had a save-to-PNG method, but GitHub Copilot did, which saved me a lot of time. The only way I would have known about that would have been by searching through every file in the project until I randomly stumbled upon it.

https://user-images.githubusercontent.com/62965063/195423727-616e4354-608a-416a-a89a-fea95082c459.mp4

GitHub Copilot will use the context of the rest of your project to help find what you're looking for, and it does it remarkably quickly. It doesn't always work perfectly, and won't always give you what you're looking for. Most of the time you still need to fill in the rest or make changes. Overall, it's still very useful and I'd recommend it.

I'll see about changing the title instead of showing a message box when a screenshot is saved.

SirQuartz avatar Oct 12 '22 19:10 SirQuartz

Yeah, GitHub Copilot is surprisingly helpful in finding the missing pieces to a solution at times. Especially in this case where the answer was just sitting right in front of me but I hadn't noticed it yet. In this case, I didn't know the project had a save-to-PNG method, but GitHub Copilot did, which saved me a lot of time. The only way I would have known about that would have been by searching through every file in the project until I randomly stumbled upon it. Github.Copilot.mp4

GitHub Copilot will use the context of the rest of your project to help find what you're looking for, and it does it remarkably quickly. It doesn't always work perfectly, and won't always give you what you're looking for. Most of the time you still need to fill in the rest or make changes. Overall, it's still very useful and I'd recommend it.

I'll see about changing the title instead of showing a message box when a screenshot is saved.

Wow that's actually pretty insane. This is the first time I've seen github copilot be used for anything other than hello world or basic algorithms

Razzile avatar Oct 13 '22 07:10 Razzile

Wow that's actually pretty insane. This is the first time I've seen github copilot be used for anything other than hello world or basic algorithms

I've seen it construct some really advanced functions that would've taken me hours or days to figure out. This is actually a pretty decent example of a practical use for it in the real world.

SirQuartz avatar Oct 13 '22 08:10 SirQuartz

Does it still have the issue of randomly spitting out chunks of other people's code? Or has it been trained enough for it to be genericized

Masamune3210 avatar Oct 13 '22 20:10 Masamune3210

Does it still have the issue of randomly spitting out chunks of other people's code? Or has it been trained enough for it to be genericized

I've personally never seen that happen, but I have the "suggestions matching public code" option disabled so maybe that's why? Either way, it's pretty good at coming up with original solutions, as is the case in this example. As I said, it favors using the context of your project and what it already has for methods to come up with a solution over just randomly yoinking one from the internet.

For the most part, it just constructs a generic method based on the prompt or context of the current and previous lines.

Copilot

SirQuartz avatar Oct 13 '22 20:10 SirQuartz