-
Notifications
You must be signed in to change notification settings - Fork 24
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
gdi32 palette functions #49
base: main
Are you sure you want to change the base?
Conversation
@@ -134,7 +136,8 @@ pub fn GetDeviceCaps( | |||
GetDeviceCapsArg::NUMCOLORS => -1i32 as u32, // true color | |||
GetDeviceCapsArg::HORZRES => 640, | |||
GetDeviceCapsArg::VERTRES => 480, | |||
_ => unimplemented!(), | |||
GetDeviceCapsArg::RASTERCAPS => 0x100, // RC_PALETTE |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this need to depend on the underlying device? I think this is making this function say that all our DCs support palettes, when I think in practice none (?) of them do.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not 100% sure here, but what I assumed when I wrote it was that the palettes would be handled by some code that I will write soon. But with that said, I'm not really sure what these paletts do, and how they are used at the moment 😅
Maybe it's better to hold of on this one until I have gotten more of it to work...
@@ -98,6 +99,7 @@ pub fn SelectObject(machine: &mut Machine, hdc: HDC, hGdiObj: HGDIOBJ) -> HGDIOB | |||
DCTarget::DirectDrawSurface(_) => todo!(), | |||
}, | |||
Object::Brush(_) => std::mem::replace(&mut dc.brush, hGdiObj), | |||
Object::Palette(_) => panic!("SelectObject called with a palette (use SelectPalette)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess the author of the exe is unlikely to see this recommendation :)
(The panic is fine, but if a program ends up going down this codepath we'll need to eventually figure out what behavior they expected)
|
||
#[win32_derive::dllexport] | ||
pub fn CreatePalette(machine: &mut Machine, plpal: u32) -> HGDIOBJ { | ||
let header = machine.mem().view::<LOGPALETTE_HEADER>(plpal).clone(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better as:
let header = machine.mem().get_pod::<LOGPALETTE_HEADER>(plpal);
(Ultimately I think I might need to remove the .view() methods, because Rust is unhappy if the underlying pointers aren't aligned)
let header = machine.mem().view::<LOGPALETTE_HEADER>(plpal).clone(); | ||
|
||
let entries = plpal + size_of::<LOGPALETTE_HEADER>() as u32; | ||
let entries = machine.mem().view_n::<PALETTEENTRY>(entries, header.palNumEntries as u32).to_vec(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(...but don't worry about changing view_n, I will need to revisit this API...)
Object::Bitmap(_) => panic!("SelectPalette called with a bitmap (use SelectObject)"), | ||
Object::Brush(_) => panic!("SelectPalette called with a brush (use SelectObject)"), | ||
Object::Palette(_) => std::mem::replace(&mut dc.palette, hpal), | ||
Object::Pen(_) => panic!("SelectPalette called with a pen (use SelectObject)"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have the same comment here about the panic!()s, they might be better expressed as todo()s given that if they're ever called we will need to figure what to do
#[win32_derive::dllexport] | ||
pub fn RealizePalette(machine: &mut Machine, hdc: HDC) -> u32 { | ||
let dc = match machine.state.gdi32.dcs.get_mut(hdc) { | ||
None => return !0, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...oh interesting, I think this is basically saying the palette supports 2^32 entries?
Could you put a module-level comment about how you are thinking about this? I guess returning RC_PALETTE above is correct if this is a legal value here (?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that the value of GDI_ERROR
is !0
, my intention was to return GDI_ERROR
. I should have made it a constant though 😅
Object::Bitmap(_) => panic!("RealizePalette called with a bitmap"), | ||
Object::Brush(_) => panic!("RealizePalette called with a brush"), | ||
Object::Palette(palette) => palette.1.len() as u32, | ||
Object::Pen(_) => panic!("RealizePalette called with a pen"), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could perhaps just handle the Palette case and add a _ => todo!
branch otherwise, unless you think it's common
No description provided.