(RGUI) refactor font code

This commit is contained in:
Toad King 2012-08-27 14:48:00 -04:00
parent 0f3c3ff06c
commit fdd4adf76c
4 changed files with 42 additions and 14 deletions

27
console/font.h Normal file
View File

@ -0,0 +1,27 @@
/* RetroArch - A frontend for libretro.
* Copyright (C) 2010-2012 - Hans-Kristian Arntzen
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _CONSOLE_FONT_H
#define _CONSOLE_FONT_H
#define FONT_WIDTH 5
#define FONT_HEIGHT 10
#define FONT_OFFSET(x) ((x) * ((FONT_HEIGHT * FONT_WIDTH + 7) / 8))
//extern uint8_t _binary_console_font_bmp_start[];
extern uint8_t _binary_console_font_bin_start[];
#endif

View File

@ -16,6 +16,7 @@
#include "rgui.h"
#include "list.h"
#include "../rarch_console_video.h"
#include "../font.h"
#include "../../screenshot.h"
#include <stdlib.h>
#include <stddef.h>
@ -23,8 +24,6 @@
#include <string.h>
#include <limits.h>
#define FONT_WIDTH 5
#define FONT_HEIGHT 10
#define FONT_WIDTH_STRIDE (FONT_WIDTH + 1)
#define FONT_HEIGHT_STRIDE (FONT_HEIGHT + 1)
@ -55,7 +54,8 @@ struct rgui_handle
char path_buf[PATH_MAX];
uint8_t font[256][(FONT_HEIGHT * FONT_WIDTH + 7) / 8];
uint8_t *font;
bool alloc_font;
};
static const char *rgui_device_labels[] = {
@ -94,8 +94,7 @@ static inline bool rgui_is_viewport_menu(rgui_file_type_t menu_type)
return (menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT || menu_type == RGUI_SETTINGS_CUSTOM_VIEWPORT_2);
}
static void copy_glyph(uint8_t glyph[(FONT_HEIGHT * FONT_WIDTH + 7) / 8],
const uint8_t *buf)
static void copy_glyph(uint8_t *glyph, const uint8_t *buf)
{
for (int y = 0; y < FONT_HEIGHT; y++)
{
@ -117,18 +116,20 @@ static void copy_glyph(uint8_t glyph[(FONT_HEIGHT * FONT_WIDTH + 7) / 8],
static void init_font(rgui_handle_t *rgui, const uint8_t *font_bmp_buf)
{
rgui->font = (uint8_t *) calloc(1, FONT_OFFSET(256));
rgui->alloc_font = true;
for (unsigned i = 0; i < 256; i++)
{
unsigned y = i / 16;
unsigned x = i % 16;
copy_glyph(rgui->font[i],
copy_glyph(&rgui->font[FONT_OFFSET(i)],
font_bmp_buf + 54 + 3 * (256 * (255 - 16 * y) + 16 * x));
}
}
rgui_handle_t *rgui_init(const char *base_path,
uint16_t *framebuf, size_t framebuf_pitch,
const uint8_t *font_bmp_buf, const uint8_t *font_bin_buf,
const uint8_t *font_bmp_buf, uint8_t *font_bin_buf,
rgui_folder_enum_cb_t folder_cb, void *userdata)
{
rgui_handle_t *rgui = (rgui_handle_t*)calloc(1, sizeof(*rgui));
@ -146,7 +147,7 @@ rgui_handle_t *rgui_init(const char *base_path,
if (font_bmp_buf)
init_font(rgui, font_bmp_buf);
else if (font_bin_buf)
memcpy(rgui->font, font_bin_buf, sizeof(rgui->font));
rgui->font = font_bin_buf;
else
{
RARCH_ERR("no font bmp or bin, abort");
@ -160,6 +161,8 @@ void rgui_free(rgui_handle_t *rgui)
{
rgui_list_free(rgui->path_stack);
rgui_list_free(rgui->folder_buf);
if (rgui->alloc_font)
free(rgui->font);
free(rgui);
}
@ -200,7 +203,7 @@ static void blit_line(rgui_handle_t *rgui,
{
uint8_t rem = 1 << ((i + j * FONT_WIDTH) & 7);
unsigned offset = (i + j * FONT_WIDTH) >> 3;
bool col = (rgui->font[(unsigned char)*message][offset] & rem);
bool col = (rgui->font[FONT_OFFSET((unsigned char)*message) + offset] & rem);
if (col)
rgui->frame_buf[(y + j) * (rgui->frame_buf_pitch >> 2) + (x + i)] = green ?

View File

@ -104,7 +104,7 @@ typedef bool (*rgui_folder_enum_cb_t)(const char *directory,
rgui_handle_t *rgui_init(const char *base_path,
uint16_t *framebuf, size_t framebuf_pitch,
const uint8_t *font_bmp_buf, const uint8_t *font_bin_buf,
const uint8_t *font_bmp_buf, uint8_t *font_bin_buf,
rgui_folder_enum_cb_t folder_cb, void *userdata);
void rgui_iterate(rgui_handle_t *rgui, rgui_action_t action);

View File

@ -22,6 +22,7 @@
#include "../../libretro.h"
#include "../../console/rgui/rgui.h"
#include "../../console/font.h"
#include "../../console/rarch_console_exec.h"
#include "../../console/rarch_console_input.h"
@ -130,9 +131,6 @@ enum
GX_DEVICE_NAV_LAST
};
//extern uint8_t _binary_console_font_bmp_start[];
extern uint8_t _binary_console_font_bin_start[];
static bool folder_cb(const char *directory, rgui_file_enum_cb_t file_cb,
void *userdata, void *ctx)
{
@ -322,7 +320,7 @@ static void menu_init(void)
{
rgui = rgui_init("",
menu_framebuf, RGUI_WIDTH * sizeof(uint32_t),
NULL, _binary_console_font_bin_start, folder_cb, NULL);
NULL /* _binary_console_font_bmp_start */, _binary_console_font_bin_start, folder_cb, NULL);
rgui_iterate(rgui, RGUI_ACTION_REFRESH);
g_console.mode_switch = MODE_MENU;