Skip to content

Commit

Permalink
Fix font routines and add gfx_ScaleSprite
Browse files Browse the repository at this point in the history
  • Loading branch information
mateoconlechuga committed Mar 12, 2017
1 parent 53eba20 commit 7618598
Show file tree
Hide file tree
Showing 8 changed files with 230 additions and 34 deletions.
4 changes: 3 additions & 1 deletion CEdev/examples/library_examples/graphics/demo_0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
/* Shared libraries */
#include <lib/ce/graphx.h>

#define FONT_WIDTH 8

/* Put function prototypes here */
void print_string_centered(const char *str);

Expand Down Expand Up @@ -45,5 +47,5 @@ void main(void) {

/* Prints a screen centered string */
void print_string_centered(const char *str) {
gfx_PrintStringXY(str, (LCD_WIDTH-gfx_GetStringWidth(str)) / 2, (LCD_HEIGHT-gfx_FontHeight()) / 2);
gfx_PrintStringXY(str, (LCD_WIDTH-gfx_GetStringWidth(str)) / 2, (LCD_HEIGHT-FONT_WIDTH) / 2);
}
3 changes: 2 additions & 1 deletion CEdev/examples/library_examples/graphics/demo_10/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/* Use some random color as the transparent one */
#define TRANSPARENT_COLOR 10
#define FONT_WIDTH 8
#define FONT_HEIGHT 8

/* Put function prototypes here */

Expand All @@ -38,7 +39,7 @@ void main(void) {
gfx_SetMonospaceFont( FONT_WIDTH );

/* Print some upside down text */
printu(my_str, (LCD_WIDTH - gfx_GetStringWidth(my_str)) / 2, (LCD_HEIGHT - gfx_FontHeight()) / 2);
printu(my_str, (LCD_WIDTH - gfx_GetStringWidth(my_str)) / 2, (LCD_HEIGHT - FONT_HEIGHT) / 2);

/* Wait for key */
while(!os_GetCSC());
Expand Down
4 changes: 1 addition & 3 deletions CEdev/examples/library_examples/graphics/demo_8/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

/* Put all your code here */
void main(void) {
unsigned x_offset = 0, y_offset = 0;

/* Initialize the 8bpp graphics */
gfx_Begin( gfx_8bpp );

Expand All @@ -34,7 +32,7 @@ void main(void) {

/* Draw a line on the buffer */
//gfx_FillScreen( gfx_black );
gfx_Line( 0, 0, 319, 239 );
gfx_Line( 0, 0, LCD_WIDTH-1, LCD_HEIGHT-1 );

/* Wait for a key */
while( !os_GetCSC() );
Expand Down
3 changes: 2 additions & 1 deletion CEdev/examples/library_examples/graphics/demo_9/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
/* Use some random color as the transparent one */
#define TRANSPARENT_COLOR 10
#define FONT_WIDTH 8
#define FONT_HEIGHT 8

/* Put function prototypes here */

Expand Down Expand Up @@ -50,7 +51,7 @@ void main(void) {

/* Configure the font to normal size, clipped, and monospaced */
gfx_SetTextScale(1,1);
gfx_SetTextConfig( GFX_TEXT_CLIP );
gfx_SetTextConfig( gfx_text_clip );
gfx_SetMonospaceFont( FONT_WIDTH );

/* Graphics routines draw to the back buffer */
Expand Down
32 changes: 21 additions & 11 deletions CEdev/include/lib/ce/graphx.h
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ typedef enum {
gfx_tile_16_pixel, /**< Set when using 16 pixel tiles */
gfx_tile_32_pixel, /**< Set when using 32 pixel tiles */
gfx_tile_64_pixel, /**< Set when using 64 pixel tiles */
gfx_tile_128_pixel, /**< Set when using 128 pixel tiles */
gfx_tile_128_pixel /**< Set when using 128 pixel tiles */
} gfx_tilemap_type_t;

/**
Expand Down Expand Up @@ -906,6 +906,16 @@ gfx_image_t *gfx_RotateSpriteCC(gfx_image_t *sprite_in, gfx_image_t *sprite_out)
*/
gfx_image_t *gfx_RotateSpriteHalf(gfx_image_t *sprite_in, gfx_image_t *sprite_out);

/**
* Resizes a sprite to new dimensions
*
* Place new image dimensions in sprite_out; i.e. sprite_out->width = 80; sprite_out->height = 20.
* @param sprite_in Input sprite to scale
* @param sprite_out Pointer to where scaled sprite will be stored
* @returns A pointer to sprite_out
*/
gfx_image_t *gfx_ScaleSprite(gfx_image_t *sprite_in, gfx_image_t *sprite_out);

/**
* Creates a temporary character sprite
*
Expand All @@ -930,11 +940,20 @@ void gfx_SetFontData(uint8_t *data);
*/
void gfx_SetFontSpacing(uint8_t *spacing);

/**
* Sets the height in pixels of each character
*
* The default value is 8 pixels
* @param height New font height in pixels
* @returns Previous height of font in pixels
*/
uint8_t gfx_SetFontHeight(uint8_t height);

/**
* Sets monospaced font
*
* @param spacing Distance between characters
* @note To disable monospaced font set to 0
* @note To disable monospaced font, set to 0
*/
void gfx_SetMonospaceFont(uint8_t spacing);

Expand All @@ -955,15 +974,6 @@ unsigned int gfx_GetStringWidth(const char *string);
*/
unsigned int gfx_GetCharWidth(const char c);

/**
* Gets pixel height of a character
*
* @param c Character to get height of
* @returns Height in pixels of character
*/
#define gfx_GetCharHeight(c) \
8

/**
* Sets the clipping window
*
Expand Down
10 changes: 5 additions & 5 deletions CEdev/include/lib/ce/tice.h
Original file line number Diff line number Diff line change
Expand Up @@ -650,6 +650,11 @@ void os_ResetFlagBits(int16_t offset_pattern);
*/
uint16_t os_GetKey(void);

/**
* @brief Scan code type
*/
typedef uint8_t sk_key_t;

/**
* Performs an OS call to get the keypad scan code
*
Expand All @@ -658,11 +663,6 @@ uint16_t os_GetKey(void);
*/
sk_key_t os_GetCSC(void);

/**
* @brief Scan code type
*/
typedef uint8_t sk_key_t;

/**
* Runs the calulator at 6 MHz
*/
Expand Down
8 changes: 4 additions & 4 deletions CEdev/lib/src/buildexamples.bat
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ REM ----------------------------------------------------

echo -- Cleaning examples...
cd /D %CEDEV%\examples
for /D %%a in (demo*) do cd %%a && make && cd ..
for /D %%a in (demo*) do cd %%a && make -B && cd ..
cd /D %CEDEV%\examples\library_examples\fileio
for /D %%a in (demo*) do cd %%a && make && cd ..
for /D %%a in (demo*) do cd %%a && make -B && cd ..
cd /D %CEDEV%\examples\library_examples\graphics
for /D %%a in (demo*) do cd %%a && make && cd ..
for /D %%a in (demo*) do cd %%a && make -B && cd ..
cd /D %CEDEV%\examples\library_examples\keypad
for /D %%a in (demo*) do cd %%a && make && cd ..
for /D %%a in (demo*) do cd %%a && make -B && cd ..
cd %CEDEV%\lib\src
Loading

0 comments on commit 7618598

Please sign in to comment.