-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
457 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
#include "danzeff.h" | ||
|
||
#include <malloc.h> | ||
#include <vita2d.h> | ||
#include <psp2/ctrl.h> | ||
|
||
#define false 0 | ||
#define true 1 | ||
|
||
/*bool*/ int holding = false; //user is holding a button | ||
/*bool*/ int dirty = true; //keyboard needs redrawing | ||
/*bool*/ int shifted = false; //user is holding shift | ||
int mode = 0; //charset selected. (0 - letters or 1 - numbers) | ||
/*bool*/ int initialized = false; //keyboard is initialized | ||
|
||
//Position on the 3-3 grid the user has selected (range 0-2) | ||
int selected_x = 1; | ||
int selected_y = 1; | ||
|
||
float moved_x = 0, moved_y = 0; // location that we are moved to | ||
|
||
//Variable describing where each of the images is | ||
#define guiStringsSize 12 /* size of guistrings array */ | ||
#define PICS_BASEDIR "app0:graphics/" | ||
char *guiStrings[] = | ||
{ | ||
PICS_BASEDIR "keys.png", PICS_BASEDIR "keys_t.png", PICS_BASEDIR "keys_s.png", | ||
PICS_BASEDIR "keys_c.png", PICS_BASEDIR "keys_c_t.png", PICS_BASEDIR "keys_s_c.png", | ||
PICS_BASEDIR "nums.png", PICS_BASEDIR "nums_t.png", PICS_BASEDIR "nums_s.png", | ||
PICS_BASEDIR "nums_c.png", PICS_BASEDIR "nums_c_t.png", PICS_BASEDIR "nums_s_c.png" | ||
}; | ||
|
||
vita2d_texture* keyTextures[guiStringsSize]; | ||
|
||
//amount of modes (non shifted), each of these should have a corresponding shifted mode. | ||
#define MODE_COUNT 2 | ||
//this is the layout of the keyboard | ||
char modeChar[MODE_COUNT*2][3][3][5] = | ||
{ | ||
{ //standard letters | ||
{ ",abc", ".def","!ghi" }, | ||
{ "-jkl","\010m n", "?opq" }, | ||
{ "(rst", ":uvw",")xyz" } | ||
}, | ||
|
||
{ //capital letters | ||
{ "^ABC", "@DEF","*GHI" }, | ||
{ "_JKL","\010M N", "\"OPQ" }, | ||
{ "=RST", ";UVW","/XYZ" } | ||
}, | ||
|
||
{ //numbers | ||
{ "\0\0\0001","\0\0\0002","\0\0\0003" }, | ||
{ "\0\0\0004", "\010\0 5","\0\0\0006" }, | ||
{ "\0\0\0007","\0\0\0008", "\0\00009" } | ||
}, | ||
|
||
{ //special characters | ||
{ "'(.)", "\"<'>","-[_]" }, | ||
{ "!{?}","\010\0 \0", "+\\=/" }, | ||
{ ":@;#", "~$`%","*^|&" } | ||
} | ||
}; | ||
|
||
/*bool*/ int danzeff_isinitialized() | ||
{ | ||
return initialized; | ||
} | ||
|
||
/*bool*/ int danzeff_dirty() | ||
{ | ||
return dirty; | ||
} | ||
|
||
/** Attempts to read a character from the controller | ||
* If no character is pressed then we return 0 | ||
* Other special values: 1 = move left, 2 = move right, 3 = select, 4 = start | ||
* Every other value should be a standard ascii value. | ||
* An unsigned int is returned so in the future we can support unicode input | ||
*/ | ||
unsigned int danzeff_readInput(SceCtrlData pad) | ||
{ | ||
//Work out where the analog stick is selecting | ||
int x = 1; | ||
int y = 1; | ||
if (pad.lx < 85) x -= 1; | ||
else if (pad.lx > 170) x += 1; | ||
|
||
if (pad.ly < 85) y -= 1; | ||
else if (pad.ly > 170) y += 1; | ||
|
||
if (selected_x != x || selected_y != y) //If they've moved, update dirty | ||
{ | ||
dirty = true; | ||
selected_x = x; | ||
selected_y = y; | ||
} | ||
//if they are changing shift then that makes it dirty too | ||
if ((!shifted && (pad.buttons & SCE_CTRL_RTRIGGER)) || (shifted && !(pad.buttons & SCE_CTRL_RTRIGGER))) | ||
dirty = true; | ||
|
||
unsigned int pressed = 0; //character they have entered, 0 as that means 'nothing' | ||
shifted = (pad.buttons & SCE_CTRL_RTRIGGER)?true:false; | ||
|
||
if (!holding) | ||
{ | ||
if (pad.buttons& (SCE_CTRL_CROSS|SCE_CTRL_CIRCLE|SCE_CTRL_TRIANGLE|SCE_CTRL_SQUARE)) //pressing a char select button | ||
{ | ||
int innerChoice = 0; | ||
if (pad.buttons & SCE_CTRL_TRIANGLE) | ||
innerChoice = 0; | ||
else if (pad.buttons & SCE_CTRL_SQUARE) | ||
innerChoice = 1; | ||
else if (pad.buttons & SCE_CTRL_CROSS) | ||
innerChoice = 2; | ||
else //if (pad.buttons & SCE_CTRL_CIRCLE) | ||
innerChoice = 3; | ||
|
||
//Now grab the value out of the array | ||
pressed = modeChar[ mode*2 + shifted][y][x][innerChoice]; | ||
} | ||
else if (pad.buttons& SCE_CTRL_LTRIGGER) //toggle mode | ||
{ | ||
dirty = true; | ||
mode++; | ||
mode %= MODE_COUNT; | ||
} | ||
else if (pad.buttons& SCE_CTRL_DOWN) | ||
{ | ||
pressed = '\n'; | ||
} | ||
else if (pad.buttons& SCE_CTRL_UP) | ||
{ | ||
pressed = 8; //backspace | ||
} | ||
else if (pad.buttons& SCE_CTRL_LEFT) | ||
{ | ||
pressed = DANZEFF_LEFT; //LEFT | ||
} | ||
else if (pad.buttons& SCE_CTRL_RIGHT) | ||
{ | ||
pressed = DANZEFF_RIGHT; //RIGHT | ||
} | ||
else if (pad.buttons& SCE_CTRL_SELECT) | ||
{ | ||
pressed = DANZEFF_SELECT; //SELECT | ||
} | ||
else if (pad.buttons& SCE_CTRL_START) | ||
{ | ||
pressed = DANZEFF_START; //START | ||
} | ||
} | ||
|
||
holding = pad.buttons & ~SCE_CTRL_RTRIGGER; //RTRIGGER doesn't set holding | ||
|
||
return pressed; | ||
} | ||
|
||
/* load all the guibits that make up the OSK */ | ||
void danzeff_load() | ||
{ | ||
if (initialized) return; | ||
|
||
int a; | ||
for (a = 0; a < guiStringsSize; a++) | ||
{ | ||
SceUInt32 height, width; | ||
|
||
keyTextures[a] = vita2d_load_PNG_file(guiStrings[a]); | ||
} | ||
initialized = true; | ||
} | ||
|
||
/* remove all the guibits from memory */ | ||
void danzeff_free() | ||
{ | ||
if (!initialized) return; | ||
|
||
int a; | ||
for (a = 0; a < guiStringsSize; a++) | ||
{ | ||
vita2d_free_texture(keyTextures[a]); | ||
} | ||
initialized = false; | ||
} | ||
|
||
/* move the position the keyboard is currently drawn at */ | ||
void danzeff_moveTo(float newX, float newY) | ||
{ | ||
moved_x = newX; | ||
moved_y = newY; | ||
} | ||
|
||
/* draw the keyboard at the current position */ | ||
void danzeff_render() | ||
{ | ||
dirty = false; | ||
|
||
///Draw the background for the selected keyboard either transparent or opaque | ||
///this is the whole background image, not including the special highlighted area | ||
//if center is selected then draw the whole thing opaque | ||
if (selected_x == 1 && selected_y == 1) | ||
vita2d_draw_texture(keyTextures[6*mode + shifted*3], moved_x, moved_y); | ||
else | ||
vita2d_draw_texture(keyTextures[6*mode + shifted*3 + 1], moved_x, moved_y); | ||
|
||
///Draw the current Highlighted Selector (orange bit) | ||
vita2d_draw_texture_part(keyTextures[6*mode + shifted*3 + 2], | ||
//Offset from the current draw position to render at | ||
moved_x + selected_x*43, moved_y + selected_y*43, | ||
//internal offset of the image | ||
selected_x*64,selected_y*64, | ||
64, | ||
64); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#ifndef INCLUDED_KEYBOARDS_DANZEFF_H | ||
#define INCLUDED_KEYBOARDS_DANZEFF_H | ||
|
||
//danzeff is BSD licensed, if you do make a new renderer then please share it back and I can add it | ||
//to the original distribution. | ||
|
||
#include <psp2/ctrl.h> | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
//Initialization and de-init of the keyboard, provided as the keyboard uses alot of images, so if you aren't going to use it for a while, I'd recommend unloading it. | ||
void danzeff_load(); | ||
void danzeff_free(); | ||
|
||
//returns true if the keyboard is initialized | ||
/*bool*/ int danzeff_isinitialized(); | ||
|
||
/** Attempts to read a character from the controller | ||
* If no character is pressed then we return 0 | ||
* Other special values: 1 = move left, 2 = move right, 3 = select, 4 = start | ||
* Every other value should be a standard ascii value. | ||
* An unsigned int is returned so in the future we can support unicode input | ||
*/ | ||
unsigned int danzeff_readInput(SceCtrlData pad); | ||
#define DANZEFF_LEFT 1 | ||
#define DANZEFF_RIGHT 2 | ||
#define DANZEFF_SELECT 3 | ||
#define DANZEFF_START 4 | ||
|
||
//Move the area the keyboard is rendered at to here | ||
void danzeff_moveTo(float newX, float newY); | ||
|
||
//Returns true if the keyboard that would be rendered now is different to the last time | ||
//that the keyboard was drawn, this is altered by readInput/render. | ||
/*bool*/ int danzeff_dirty(); | ||
|
||
//draw the keyboard to the screen | ||
void danzeff_render(); | ||
|
||
|
||
///Functions only for particular renderers: | ||
|
||
#ifdef DANZEFF_SDL ///Functions only for SDL Renderer | ||
#include <SDL/SDL.h> | ||
#include <SDL/SDL_image.h> | ||
//set the screen surface for rendering on. | ||
void danzef_set_screen(SDL_Surface* screen); | ||
#endif //DANZEFF_SDL | ||
|
||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif //INCLUDED_KEYBOARDS_DANZEFF_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
----- Dev Stuff | ||
All included files are licensed under the BSD license, see LICENSE in PSPSDK root for details. | ||
|
||
|
||
danzeff is an OSK, as such it has alot of code dependant on what your current rendering system is. | ||
|
||
I have tryed my best to seperate the rendering code out from the thinking code, so that additionally rendering targets can be added. | ||
Currently there is only an implementation for SDL, but if you make an implementation for another renderer then please send it to me (danzelatlocalhostdotgeekdotnz) and I'll add it. | ||
|
||
The pspctrl_emu files are for the SDL implementation. | ||
If you are using SDL to take input (SDL_Joystick) then you can use the function provided in pspctrl_emu to convert the SDL_Joystick to a SceCtrlData for use with the OSK functions (I have also used it for psprint and it worked fine). | ||
|
||
|
||
Code Usage: | ||
Call danzeff_load(); to load up the keyboard (loads images from the memory stick) | ||
Check that it managed to load the images with danzeff_isinitialized(); If it failed then either: There's not enough memory or the images aren't there. | ||
You can now move it to where on the screen you want it to be using danzeff_moveTo(X,Y); | ||
|
||
The 3 functions you can now use are: | ||
int danzeff_dirty(); // <- returns true if the OSK would render differently to the last time it was rendered. | ||
unsigned int danzeff_readInput(SceCtrlData pspctrl); // <- returns a character if one is pressed | ||
void danzeff_render(); // <- draws the OSK | ||
|
||
|
||
And the keyboard usage instructions from AFKIM: | ||
|
||
----- USAGE | ||
The danzeff keyboard is an OSK, mainly controlled by the analog stick. | ||
|
||
Use the analog stick to select which square to chose from, and then press the button (X O [] /\) in the direction of the letter you want to input. | ||
|
||
To switch into numbers mode Tap the L Shoulder. | ||
To get capital Letters hold the R shoulder while in letters input. | ||
To get a complete set of extra characters, hold down R shoulder while in numbers mode. | ||
|
||
Other special keys: | ||
Digital down -> enter | ||
Digital up -> delete | ||
Digital left -> move left | ||
Digital right -> move right | ||
Select -> ??? | ||
Start -> ??? |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.