[GTK3] Implement sprite viewer
This commit is contained in:
parent
d75a261663
commit
5020be359e
49
gtk3/main.c
49
gtk3/main.c
@ -37,6 +37,10 @@ static uint32_t tileset_buffer[tileset_buffer_length] = {0};
|
||||
#define tilemap_buffer_length 256 * 256 * 4
|
||||
static uint32_t tilemap_buffer[tilemap_buffer_length] = {0};
|
||||
|
||||
static GB_oam_info_t oamInfo[40];
|
||||
static uint16_t oamCount;
|
||||
static uint8_t oamHeight;
|
||||
|
||||
static uint8_t pressed_buttons;
|
||||
|
||||
// List of GActions for the `app` prefix
|
||||
@ -1064,7 +1068,52 @@ static void vblank(GB_gameboy_t *gb) {
|
||||
};
|
||||
}
|
||||
else if (g_strcmp0("vram_viewer_sprites", active) == 0) {
|
||||
GtkListStore *store = builder_get(GTK_LIST_STORE, "sprite_list_store");
|
||||
GtkTreeIter iter;
|
||||
|
||||
gtk_list_store_clear(store);
|
||||
gtk_tree_model_get_iter_first(GTK_TREE_MODEL(store), &iter);
|
||||
|
||||
oamCount = GB_get_oam_info(gb, oamInfo, &oamHeight);
|
||||
|
||||
for (unsigned row = 0; row < oamCount; ++row) {
|
||||
GdkPixbuf *pixbuf = gdk_pixbuf_new_from_bytes(
|
||||
g_bytes_new(oamInfo[row].image, 128 * sizeof(uint32_t)),
|
||||
GDK_COLORSPACE_RGB, true, 8, 8, oamHeight, 8 * sizeof(uint32_t)
|
||||
);
|
||||
|
||||
GdkPixbuf *dest = gdk_pixbuf_new(GDK_COLORSPACE_RGB, true, 8, 8 * 2, oamHeight * 2);
|
||||
|
||||
gdk_pixbuf_scale(pixbuf, dest,
|
||||
0, 0, 8 * 2, oamHeight * 2,
|
||||
0, 0, 2.0, 2.0,
|
||||
GDK_INTERP_NEAREST
|
||||
);
|
||||
|
||||
g_object_unref(pixbuf);
|
||||
|
||||
gtk_list_store_insert_with_values(store, &iter, -1,
|
||||
0, dest,
|
||||
1, itoa(oamInfo[row].x - 8),
|
||||
2, itoa(oamInfo[row].y - 16),
|
||||
3, g_strdup_printf("$%02x", oamInfo[row].tile),
|
||||
4, g_strdup_printf("$%04x", 0x8000 + oamInfo[row].tile * 0x10),
|
||||
5, g_strdup_printf("$%04x", oamInfo[row].oam_addr),
|
||||
6, GB_is_cgb(gb)
|
||||
? g_strdup_printf("%c%c%c%d%d",
|
||||
oamInfo[row].flags & 0x80? 'P' : '-',
|
||||
oamInfo[row].flags & 0x40? 'Y' : '-',
|
||||
oamInfo[row].flags & 0x20? 'X' : '-',
|
||||
oamInfo[row].flags & 0x08? 1 : 0,
|
||||
oamInfo[row].flags & 0x07)
|
||||
: g_strdup_printf("%c%c%c%d",
|
||||
oamInfo[row].flags & 0x80? 'P' : '-',
|
||||
oamInfo[row].flags & 0x40? 'Y' : '-',
|
||||
oamInfo[row].flags & 0x20? 'X' : '-',
|
||||
oamInfo[row].flags & 0x10? 1 : 0),
|
||||
-1
|
||||
);
|
||||
}
|
||||
}
|
||||
else if (g_strcmp0("vram_viewer_palettes", active) == 0) {
|
||||
|
||||
|
@ -1441,7 +1441,10 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
<object class="GtkTreeViewColumn">
|
||||
<property name="min_width">32</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<object class="GtkCellRendererPixbuf"/>
|
||||
<attributes>
|
||||
<attribute name="pixbuf">0</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
@ -1495,7 +1498,7 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">4</attribute>
|
||||
<attribute name="text">5</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
@ -1506,7 +1509,7 @@ Maximilian Mader https://github.com/max-m</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">5</attribute>
|
||||
<attribute name="text">6</attribute>
|
||||
</attributes>
|
||||
</child>
|
||||
</object>
|
||||
|
Loading…
Reference in New Issue
Block a user