mirror of
https://github.com/italicsjenga/agb.git
synced 2024-12-23 00:01:34 +11:00
Nicer test logo (#707)
With the new examples page on the website, I thought it was probably time to update the logo we use there to a nicer one. I've also added a basic one to make the background colour change example nicer, and sometimes you might want the less busy one. - [x] Changelog updated ![image](https://github.com/agbrs/agb/assets/460842/062bb473-1b2f-4db0-a712-6d264240be9a)
This commit is contained in:
commit
a243bf4078
|
@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
|
||||
- Added `find_colour_index_16` and `find_colour_index_256` to the `VRamManager` to find where a colour is in a palette.
|
||||
|
||||
## [0.20.2] - 2024/05/25
|
||||
|
||||
### Fixed
|
||||
|
|
|
@ -25,24 +25,25 @@ fn main(mut gba: agb::Gba) -> ! {
|
|||
|
||||
let dma = gba.dma.dma().dma0;
|
||||
|
||||
example_logo::display_logo(&mut map, &mut vram);
|
||||
example_logo::display_logo_basic(&mut map, &mut vram);
|
||||
|
||||
let vblank = VBlank::get();
|
||||
|
||||
let colours: Box<[_]> = (0..160).map(|i| ((i * 0xffff) / 160) as u16).collect();
|
||||
|
||||
let mut frame = 0;
|
||||
let background_colour = 0x732b; // generated using `https://agbrs.dev/colour`
|
||||
let background_colour_index = vram
|
||||
.find_colour_index_16(0, background_colour)
|
||||
.expect("Should contain colour 0x732b");
|
||||
|
||||
loop {
|
||||
// hardcoding palette index 2 here which you wouldn't want to do in a real example (instead, look for
|
||||
// the colour you want to replace)
|
||||
let _background_color_transfer =
|
||||
unsafe { dma.hblank_transfer(&vram.background_palette_colour_dma(0, 2), &colours) };
|
||||
let _background_color_transfer = unsafe {
|
||||
dma.hblank_transfer(
|
||||
&vram.background_palette_colour_dma(0, background_colour_index),
|
||||
&colours,
|
||||
)
|
||||
};
|
||||
|
||||
vblank.wait_for_vblank();
|
||||
frame += 1;
|
||||
if frame > 160 {
|
||||
frame = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
BIN
agb/gfx/test_logo.aseprite
Normal file
BIN
agb/gfx/test_logo.aseprite
Normal file
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB After Width: | Height: | Size: 2.9 KiB |
BIN
agb/gfx/test_logo_basic.png
Normal file
BIN
agb/gfx/test_logo_basic.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
|
@ -1,6 +1,7 @@
|
|||
use super::tiled::{RegularMap, TiledMap, VRamManager};
|
||||
|
||||
crate::include_background_gfx!(crate, agb_logo, test_logo => deduplicate "gfx/test_logo.png");
|
||||
crate::include_background_gfx!(crate, agb_logo_basic, test_logo => deduplicate "gfx/test_logo_basic.png");
|
||||
|
||||
pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
||||
vram.set_background_palettes(agb_logo::PALETTES);
|
||||
|
@ -11,6 +12,15 @@ pub fn display_logo(map: &mut RegularMap, vram: &mut VRamManager) {
|
|||
map.set_visible(true);
|
||||
}
|
||||
|
||||
pub fn display_logo_basic(map: &mut RegularMap, vram: &mut VRamManager) {
|
||||
vram.set_background_palettes(agb_logo_basic::PALETTES);
|
||||
|
||||
map.fill_with(vram, &agb_logo_basic::test_logo);
|
||||
|
||||
map.commit(vram);
|
||||
map.set_visible(true);
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::display::{tiled::RegularBackgroundSize, Priority};
|
||||
|
|
|
@ -461,4 +461,18 @@ impl VRamManager {
|
|||
self.set_background_palette(palette_index as u8, entry);
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the index of the colour for a given background palette, or None if it doesn't exist
|
||||
#[must_use]
|
||||
pub fn find_colour_index_16(&self, palette_index: usize, colour: u16) -> Option<usize> {
|
||||
assert!(palette_index < 16);
|
||||
|
||||
(0..16).find(|i| PALETTE_BACKGROUND.get(palette_index * 16 + i) == colour)
|
||||
}
|
||||
|
||||
/// Gets the index of the colour in the entire background palette, or None if it doesn't exist
|
||||
#[must_use]
|
||||
pub fn find_colour_index_256(&self, colour: u16) -> Option<usize> {
|
||||
(0..256).find(|&i| PALETTE_BACKGROUND.get(i) == colour)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue