Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define DEFAULT_SYSUTIL_CALLBACK_SLOT 0
- struct _Callback
- {
- int id;
- CellSysutilCallback cb;
- void* userdata;
- };
- std::list<_Callback> SysCallback::m_sys_callbacks;
- static std::list<_Callback>::iterator _cb_it;
- class SysCallback
- {
- public:
- static int reg_cb(const CellSysutilCallback& cb, void* userdata)
- {
- static int _id = 1;
- int ret;
- if (m_sys_callbacks.empty())
- {
- ret = cellSysutilRegisterCallback(DEFAULT_SYSUTIL_CALLBACK_SLOT, SysCallback::sysutil_callback, NULL);
- if (ret < 0)
- return ret;
- }
- _Callback _cb;
- _cb.id = _id;
- _cb.cb = cb;
- _cb.userdata = userdata;
- m_sys_callbacks.push_back(_cb);
- ret = _id;
- ++_id;
- return ret;
- }
- static int SysCallback::unreg_cb(int id)
- {
- for (_cb_it = m_sys_callbacks.begin(); _cb_it != m_sys_callbacks.end(); ++_cb_it)
- {
- if (_cb_it->id == id)
- {
- m_sys_callbacks.erase(_cb_it);
- if (m_sys_callbacks.empty())
- {
- cellSysutilUnregisterCallback(DEFAULT_SYSUTIL_CALLBACK_SLOT);
- }
- return 0;
- }
- }
- return -1;
- }
- private:
- static void sysutil_callback(uint64_t status, uint64_t param, void* userdata)
- {
- (void)userdata;
- for (_cb_it = m_sys_callbacks.begin(); _cb_it != m_sys_callbacks.end(); ++_cb_it)
- {
- _cb_it->cb(status, param, _cb_it->userdata);
- }
- }
- static std::list<_Callback> m_sys_callbacks;
- };
- #include <cell/pad.h>
- #define GAMEPAD_ENTER_BUTTON_ASSIGN_CIRCLE 0
- #define GAMEPAD_ENTER_BUTTON_ASSIGN_CROSS 1
- #define GAMEPAD_CONTROLLER_1 0
- #define GAMEPAD_CONTROLLER_2 1
- #define GAMEPAD_CELL_MAX_CONNECTION 7 // Recommended by libpad reference
- #define GAMEPAD_CELL_STATUS_CONNECTED 1
- #define GAMEPAD_CELL_STATUS_DISCONNECTED 0
- #define GAMEPAD_UNINITIALIZED 0xFFFF
- class Gamepad
- {
- public:
- Gamepad() :
- m_main_pad_port(GAMEPAD_UNINITIALIZED),
- m_enter_button_assign(0),
- CELL_CIRCLE_BUTTON_MASK(0),
- CELL_CROSS_BUTTON_MASK(0),
- CELL_SQUARE_BUTTON_MASK(0),
- CELL_TRIANGLE_BUTTON_MASK(0),
- CELL_UP_BUTTON_MASK(0),
- CELL_DOWN_BUTTON_MASK(0),
- CELL_LEFT_BUTTON_MASK(0),
- CELL_RIGHT_BUTTON_MASK(0),
- CELL_R1_BUTTON_MASK(0),
- CELL_L1_BUTTON_MASK(0),
- CELL_R2_BUTTON_MASK(0),
- CELL_L2_BUTTON_MASK(0),
- CELL_SELECT_BUTTON_MASK(0)
- {
- }
- ~Gamepad()
- {
- }
- bool init()
- {
- int ret;
- ret = cellPadInit(GAMEPAD_CELL_MAX_CONNECTION);
- if (ret != CELL_PAD_OK)
- {
- printf("cellPadInit() failed. error: 0x%x\n", ret);
- return false;
- }
- //-------------------------------------------------------------------------------
- //Get Enter Button settings (CROSS or CIRCLE)
- //-------------------------------------------------------------------------------
- if (cellSysutilGetSystemParamInt(CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN,
- &m_enter_button_assign) != CELL_OK)
- {
- printf("cellSysutilGetSystemParamInt() CELL_SYSUTIL_SYSTEMPARAM_ID_ENTER_BUTTON_ASSIGN error\n");
- return false;
- }
- //If Enter button is assigned to circle
- if (m_enter_button_assign == GAMEPAD_ENTER_BUTTON_ASSIGN_CIRCLE)
- {
- m_enter_button_symbol = "O";
- m_cancel_button_symbol = "X";
- }
- else //If Enter button is assigned to cross
- {
- m_enter_button_symbol = "X";
- m_cancel_button_symbol = "O";
- }
- //--------------------------------------------------------------
- //Bind gamepad button bit masks
- //--------------------------------------------------------------
- if (m_enter_button_assign == GAMEPAD_ENTER_BUTTON_ASSIGN_CIRCLE)
- {
- CELL_CIRCLE_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_CIRCLE;
- CELL_CROSS_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_CROSS;
- }
- else
- {
- CELL_CIRCLE_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_CROSS;
- CELL_CROSS_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_CIRCLE;
- }
- CELL_SQUARE_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_SQUARE;
- CELL_TRIANGLE_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_TRIANGLE;
- CELL_UP_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_UP;
- CELL_DOWN_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_DOWN;
- CELL_LEFT_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_LEFT;
- CELL_RIGHT_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_RIGHT;
- CELL_R1_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_R1;
- CELL_L1_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_L1;
- CELL_R2_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_R2;
- CELL_L2_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_L2;
- CELL_SELECT_BUTTON_MASK = 0X00FF & CELL_PAD_CTRL_SELECT;
- GAMEPAD_CIRCLE_BUTTON = CELL_CIRCLE_BUTTON_MASK;
- GAMEPAD_CIRCLE_BUTTON = GAMEPAD_CIRCLE_BUTTON << 16;
- GAMEPAD_CROSS_BUTTON = CELL_CROSS_BUTTON_MASK;
- GAMEPAD_CROSS_BUTTON = GAMEPAD_CROSS_BUTTON << 16;
- GAMEPAD_SQUARE_BUTTON = CELL_SQUARE_BUTTON_MASK;
- GAMEPAD_SQUARE_BUTTON = GAMEPAD_SQUARE_BUTTON << 16;
- GAMEPAD_TRIANGLE_BUTTON = CELL_TRIANGLE_BUTTON_MASK;
- GAMEPAD_TRIANGLE_BUTTON = GAMEPAD_TRIANGLE_BUTTON << 16;
- GAMEPAD_UP_BUTTON = CELL_UP_BUTTON_MASK;
- GAMEPAD_DOWN_BUTTON = CELL_DOWN_BUTTON_MASK;
- GAMEPAD_LEFT_BUTTON = CELL_LEFT_BUTTON_MASK;
- GAMEPAD_RIGHT_BUTTON = CELL_RIGHT_BUTTON_MASK;
- GAMEPAD_R1_BUTTON = CELL_R1_BUTTON_MASK;
- GAMEPAD_R1_BUTTON = GAMEPAD_R1_BUTTON << 16;
- GAMEPAD_L1_BUTTON = CELL_L1_BUTTON_MASK;
- GAMEPAD_L1_BUTTON = GAMEPAD_L1_BUTTON << 16;
- GAMEPAD_R2_BUTTON = CELL_R2_BUTTON_MASK;
- GAMEPAD_R2_BUTTON = GAMEPAD_R2_BUTTON << 16;
- GAMEPAD_L2_BUTTON = CELL_L2_BUTTON_MASK;
- GAMEPAD_L2_BUTTON = GAMEPAD_L2_BUTTON << 16;
- GAMEPAD_SELECT_BUTTON = CELL_SELECT_BUTTON_MASK;
- //------------------------------------------------------------
- //End button binding
- //------------------------------------------------------------
- return true;
- }
- //*********************************************************
- // Class: Gamepad
- // Member function: update
- // Description: This function is used for reading and
- // processing the gamepad input.
- //*********************************************************
- void update()
- {
- m_monitor_gamepad();
- if (m_main_pad_port == GAMEPAD_UNINITIALIZED)
- return;
- int ret = cellPadGetData(m_main_pad_port, &m_pad_data);
- if (ret != CELL_PAD_OK)
- printf("Error cellPadGetData() failed. error: 0x%x\n", ret);
- }
- //*********************************************************
- // Class: Gamepad
- // Member function: shutdown
- // Description: Call this to clear up input devices,
- // normally called at program shutdown.
- //*********************************************************
- bool shutdown()
- {
- int ret;
- ret = cellPadEnd();
- if (ret != CELL_PAD_OK)
- {
- printf("cellPadEnd() failed. error: 0x%x\n", ret);
- return false;
- }
- return true;
- }
- bool circle_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_CIRCLE_BUTTON_MASK) == CELL_CIRCLE_BUTTON_MASK)
- return true;
- return false;
- }
- bool cross_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_CROSS_BUTTON_MASK) == CELL_CROSS_BUTTON_MASK)
- return true;
- return false;
- }
- bool square_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_SQUARE_BUTTON_MASK) == CELL_SQUARE_BUTTON_MASK)
- return true;
- return false;
- }
- bool triangle_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_TRIANGLE_BUTTON_MASK) == CELL_TRIANGLE_BUTTON_MASK)
- return true;
- return false;
- }
- bool up_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_UP_BUTTON_MASK) == CELL_UP_BUTTON_MASK)
- return true;
- return false;
- }
- bool down_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_DOWN_BUTTON_MASK) == CELL_DOWN_BUTTON_MASK)
- return true;
- return false;
- }
- bool left_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_LEFT_BUTTON_MASK) == CELL_LEFT_BUTTON_MASK)
- return true;
- return false;
- }
- bool right_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_RIGHT_BUTTON_MASK) == CELL_RIGHT_BUTTON_MASK)
- return true;
- return false;
- }
- bool r1_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_R1_BUTTON_MASK) == CELL_R1_BUTTON_MASK)
- return true;
- return false;
- }
- bool l1_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_L1_BUTTON_MASK) == CELL_L1_BUTTON_MASK)
- return true;
- return false;
- }
- bool r2_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_R2_BUTTON_MASK) == CELL_R2_BUTTON_MASK)
- return true;
- return false;
- }
- bool l2_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & CELL_L2_BUTTON_MASK) == CELL_L2_BUTTON_MASK)
- return true;
- return false;
- }
- bool select_pressed() const
- {
- if (m_pad_data.len == 0)
- return false;
- if ((m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & CELL_SELECT_BUTTON_MASK) == CELL_SELECT_BUTTON_MASK)
- return true;
- return false;
- }
- static uint32_t GAMEPAD_CIRCLE_BUTTON;
- static uint32_t GAMEPAD_CROSS_BUTTON;
- static uint32_t GAMEPAD_SQUARE_BUTTON;
- static uint32_t GAMEPAD_TRIANGLE_BUTTON;
- static uint32_t GAMEPAD_UP_BUTTON;
- static uint32_t GAMEPAD_DOWN_BUTTON;
- static uint32_t GAMEPAD_LEFT_BUTTON;
- static uint32_t GAMEPAD_RIGHT_BUTTON;
- static uint32_t GAMEPAD_R1_BUTTON;
- static uint32_t GAMEPAD_L1_BUTTON;
- static uint32_t GAMEPAD_R2_BUTTON;
- static uint32_t GAMEPAD_L2_BUTTON;
- static uint32_t GAMEPAD_SELECT_BUTTON;
- uint32_t button_pressed() const
- {
- if (m_pad_data.len == 0)
- return 0;
- uint32_t buttons_bit_field;
- buttons_bit_field = 0;
- buttons_bit_field = m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL2] & 0X00FF;
- buttons_bit_field = buttons_bit_field << 16;
- buttons_bit_field = buttons_bit_field | (m_pad_data.button[CELL_PAD_BTN_OFFSET_DIGITAL1] & 0X00FF);
- return buttons_bit_field;
- }
- int enter_button_assign() const { return m_enter_button_assign; }
- std::string enter_button_symbol() const { return m_enter_button_symbol; }
- std::string cancel_button_symbol() const { return m_cancel_button_symbol; }
- private:
- void m_monitor_gamepad()
- {
- int ret = cellPadGetInfo2(&m_pad_info);
- if (ret != CELL_PAD_OK)
- {
- printf("cellPadGetInfo2() failed. error: 0x%x\n", ret);
- return;
- }
- static bool print_no_pad_error = true;
- if (m_pad_info.now_connect == 0)
- {
- if (print_no_pad_error)
- {
- printf("No Pad detected\n");
- cellMsgDialogOpen2(CELL_MSGDIALOG_TYPE_SE_TYPE_ERROR,
- "Error:\nNo Gamepad detected\nPlease press the PS button if the gamepad is connected",
- NULL, NULL, NULL);
- print_no_pad_error = false;
- }
- return;
- }
- //Reaching this point means at least one pad is connected
- if (print_no_pad_error == false) //Do this only if the error dialog was opened
- {
- cellMsgDialogClose(0); //Close message dialog
- print_no_pad_error = true; //Reset print error flag
- }
- if (m_main_pad_port != GAMEPAD_UNINITIALIZED)
- {
- if ((m_pad_info.port_status[m_main_pad_port] & GAMEPAD_CELL_STATUS_CONNECTED) == 0)
- {
- printf("Gamepad got disconnected\n");
- m_main_pad_port = GAMEPAD_UNINITIALIZED;
- }
- }
- else
- {
- for (uint32_t i = 0; i<m_pad_info.max_connect; ++i)
- {
- if ((m_pad_info.port_status[i] & GAMEPAD_CELL_STATUS_CONNECTED) != 0)
- {
- m_main_pad_port = i;
- cellPadClearBuf(i);
- break;
- }
- }
- }
- }
- CellPadInfo2 m_pad_info;
- CellPadData m_pad_data;
- uint32_t m_main_pad_port;
- int m_enter_button_assign;
- std::string m_enter_button_symbol;
- std::string m_cancel_button_symbol;
- uint16_t CELL_CIRCLE_BUTTON_MASK;
- uint16_t CELL_CROSS_BUTTON_MASK;
- uint16_t CELL_SQUARE_BUTTON_MASK;
- uint16_t CELL_TRIANGLE_BUTTON_MASK;
- uint16_t CELL_UP_BUTTON_MASK;
- uint16_t CELL_DOWN_BUTTON_MASK;
- uint16_t CELL_LEFT_BUTTON_MASK;
- uint16_t CELL_RIGHT_BUTTON_MASK;
- uint16_t CELL_R1_BUTTON_MASK;
- uint16_t CELL_L1_BUTTON_MASK;
- uint16_t CELL_R2_BUTTON_MASK;
- uint16_t CELL_L2_BUTTON_MASK;
- uint16_t CELL_SELECT_BUTTON_MASK;
- };
- uint32_t Gamepad::GAMEPAD_CIRCLE_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_CROSS_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_SQUARE_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_TRIANGLE_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_UP_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_DOWN_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_LEFT_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_RIGHT_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_R1_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_L1_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_R2_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_L2_BUTTON = 0;
- uint32_t Gamepad::GAMEPAD_SELECT_BUTTON = 0;
- enum InputStatus
- {
- STATUS_INPUT_FAILED,
- STATUS_INPUT_OK,
- };
- // Memory container size for the OskDialogInput panels
- #define OSK_DIALOG_MEMORY_CONTAINER_SIZE_7 ( 7 * 1024 * 1024 )
- #define OSK_DIALOG_MEMORY_CONTAINER_SIZE_5 ( 5 * 1024 * 1024 )
- #define OSK_DIALOG_MEMORY_CONTAINER_SIZE_3 ( 3 * 1024 * 1024 )
- #define OSK_DIALOG_MEMORY_CONTAINER_SIZE_2 ( 2 * 1024 * 1024 )
- #define OSK_DIALOG_DEFAULT_X 0.1
- #define OSK_DIALOG_DEFAULT_Y 0.1
- enum TextInputStatus
- {
- TEXT_INPUT_STATUS_OSK_UNLOADED,
- TEXT_INPUT_STATUS_WAITING,
- TEXT_INPUT_STATUS_CANCELED,
- TEXT_INPUT_STATUS_OK,
- TEXT_INPUT_STATUS_ABORTED,
- TEXT_INPUT_STATUS_NO_INPUT
- };
- struct Text_Input_Info
- {
- CellOskDialogCallbackReturnParam OutputInfo;
- uint16_t Result_Text_Buffer[CELL_OSKDIALOG_STRING_SIZE + 1];
- sys_memory_container_t container_id;
- CellOskDialogInputFieldInfo inputFieldInfo;
- CellOskDialogParam dialogParam;
- TextInputStatus status;
- };
- class Input
- {
- public:
- static bool init()
- {
- int ret;
- ret = 0; // cellSysmoduleLoadModule(CELL_SYSMODULE_IO); we dont need this since the game already loads it
- if (ret != CELL_OK)
- {
- printf("cellSysmoduleLoadModule( CELL_SYSMODULE_IO ) failed: 0x%x\n", ret);
- m_status = STATUS_INPUT_FAILED;
- return false;
- }
- if (m_gamepad.init() == false)
- {
- m_status = STATUS_INPUT_FAILED;
- return false;
- }
- if (m_init_osk() == false)
- {
- m_status = STATUS_INPUT_FAILED;
- return false;
- }
- m_status = STATUS_INPUT_OK;
- return true;
- }
- static bool shutdown()
- {
- m_gamepad.shutdown();
- m_shutdown_osk();
- int ret;
- ret = 0; // cellSysmoduleUnloadModule(CELL_SYSMODULE_IO); we dont need this since the game already loads it
- if (ret != CELL_OK)
- {
- //printf("cellSysmoduleLoadModule( CELL_SYSMODULE_IO ) failed: 0x%x\n", ret);
- return false;
- }
- return true;
- }
- static void update()
- {
- m_gamepad.update();
- }
- static InputStatus status() { return m_status; }
- static const Gamepad* gamepad() { return &m_gamepad; }
- static bool open_text_input(size_t length, const wchar_t* dialog_message, wchar_t* init_text = NULL)
- {
- if (m_osk_inited == false)
- return false;
- if (length > CELL_OSKDIALOG_STRING_SIZE)
- length = CELL_OSKDIALOG_STRING_SIZE;
- m_text_input_info.OutputInfo.numCharsResultString = length;
- memset(m_text_input_info.Result_Text_Buffer, 0,
- sizeof(m_text_input_info.Result_Text_Buffer));
- if (init_text == NULL)
- m_text_input_info.inputFieldInfo.init_text = (uint16_t*)L"";
- else
- m_text_input_info.inputFieldInfo.init_text = (uint16_t*)init_text;
- m_text_input_info.inputFieldInfo.limit_length = length;
- m_text_input_info.inputFieldInfo.message = (uint16_t*)dialog_message;
- int ret = cellOskDialogLoadAsync(m_text_input_info.container_id,
- &m_text_input_info.dialogParam,
- &m_text_input_info.inputFieldInfo);
- if (ret < 0)
- {
- printf("cellOskDialogLoadAsync() = 0x%x \n", ret);
- return false;
- }
- m_text_input_info.status = TEXT_INPUT_STATUS_WAITING;
- return true;
- }
- static void abort_text_input()
- {
- if (m_osk_inited == false)
- return;
- int ret = cellOskDialogAbort();
- if (ret < 0)
- printf("cellOskDialog failed. ret = %#x\n", ret);
- }
- static void abort_text_input_wait()
- {
- if (m_osk_inited == false)
- return;
- int ret = cellOskDialogAbort();
- if (ret < 0)
- {
- printf("cellOskDialogAbort failed. ret = %#x\n", ret);
- return;
- }
- while (m_text_input_info.status != TEXT_INPUT_STATUS_ABORTED)
- cellSysutilCheckCallback();
- }
- static bool set_osk_pos(float x, float y)
- {
- m_text_input_info.dialogParam.controlPoint.x = x;
- m_text_input_info.dialogParam.controlPoint.y = y;
- return true;
- }
- static bool text_input_set_flags_default()
- {
- memset(&m_text_input_info.dialogParam, 0, sizeof(CellOskDialogParam));
- return true;
- }
- static bool text_input_set_flags_alpha_only()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- m_text_input_info.dialogParam.prohibitFlgs = 0;
- return true;
- }
- static bool text_input_set_flags_alpha_nospace()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ALPHABET;
- m_text_input_info.dialogParam.prohibitFlgs = CELL_OSKDIALOG_NO_SPACE;
- return true;
- }
- static bool text_input_set_flags_num_only()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_NUMERAL;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_NUMERAL;
- m_text_input_info.dialogParam.prohibitFlgs = 0;
- return true;
- }
- static bool text_input_set_flags_num_nospace()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_NUMERAL;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_NUMERAL;
- m_text_input_info.dialogParam.prohibitFlgs = CELL_OSKDIALOG_NO_SPACE;
- return true;
- }
- static bool text_input_set_flags_alphanum()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_ENGLISH;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ENGLISH;
- m_text_input_info.dialogParam.prohibitFlgs = 0;
- return true;
- }
- static bool text_input_set_flags_alphanum_nospace()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_ENGLISH;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_ENGLISH;
- m_text_input_info.dialogParam.prohibitFlgs = CELL_OSKDIALOG_NO_SPACE;
- return true;
- }
- static bool text_input_set_flags_password()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_PASSWORD;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_PASSWORD;
- m_text_input_info.dialogParam.prohibitFlgs = 0;
- return true;
- }
- static bool text_input_set_flags_url()
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = CELL_OSKDIALOG_PANELMODE_URL;
- m_text_input_info.dialogParam.firstViewPanel = CELL_OSKDIALOG_PANELMODE_URL;
- m_text_input_info.dialogParam.prohibitFlgs = 0;
- return true;
- }
- static bool text_input_set_flags(unsigned int allowOskPanelFlg,
- unsigned int firstViewPanel,
- int prohibitFlgs)
- {
- m_text_input_info.dialogParam.allowOskPanelFlg = allowOskPanelFlg;
- m_text_input_info.dialogParam.firstViewPanel = firstViewPanel;
- m_text_input_info.dialogParam.prohibitFlgs = prohibitFlgs;
- return true;
- }
- static TextInputStatus text_input_status() { return m_text_input_info.status; }
- static const uint16_t* text_input_result_str() { return m_text_input_info.Result_Text_Buffer; }
- private:
- static Gamepad m_gamepad;
- static InputStatus m_status;
- Input() {}
- static bool m_osk_inited;
- static bool m_init_osk()
- {
- //--------------------------------------------------------------------------------
- // Initialize on-screen keyboard resources
- //--------------------------------------------------------------------------------
- int ret = sys_memory_container_create(&m_text_input_info.container_id, OSK_DIALOG_MEMORY_CONTAINER_SIZE_7);
- if (ret != CELL_OK)
- {
- switch (ret)
- {
- case ENOMEM:
- printf("Cannot allocate memory of the specified size from the default memory container\n");
- break;
- case EAGAIN:
- printf("Kernel memory shortage\n");
- break;
- case EFAULT:
- printf("An invalid address is specified\n");
- break;
- default:
- break;
- }
- cellMsgDialogOpenErrorCode(ret, NULL, NULL, NULL);
- return false;
- }
- CellOskDialogPoint pos;
- pos.x = OSK_DIALOG_DEFAULT_X;
- pos.y = OSK_DIALOG_DEFAULT_Y;
- m_text_input_info.dialogParam.controlPoint = pos;
- m_text_input_info.OutputInfo.pResultString = m_text_input_info.Result_Text_Buffer;
- m_text_input_info.status = TEXT_INPUT_STATUS_OSK_UNLOADED;
- m_sys_cb_id = SysCallback::reg_cb(osk_sysutil_callback, NULL);
- if (m_sys_cb_id < 0)
- return false;
- //--------------------------------------------------------------------------------
- // End on-screen keyboard resources initialization
- //--------------------------------------------------------------------------------
- m_osk_inited = true;
- return true;
- }
- static void m_shutdown_osk()
- {
- if (!m_osk_inited)
- return;
- sys_memory_container_destroy(m_text_input_info.container_id);
- SysCallback::unreg_cb(m_sys_cb_id);
- m_osk_inited = false;
- }
- static int m_sys_cb_id;
- static void osk_sysutil_callback(uint64_t status, uint64_t param, void * userdata)
- {
- (void)param;
- (void)userdata;
- switch (status)
- {
- case CELL_SYSUTIL_OSKDIALOG_LOADED:
- break;
- case CELL_SYSUTIL_OSKDIALOG_FINISHED:
- if (cellOskDialogUnloadAsync(&m_text_input_info.OutputInfo) != 0)
- printf("cellOskDialogUnloadAsync() failed\n");
- m_text_input_info.status = TEXT_INPUT_STATUS_OK;
- if (m_text_input_info.OutputInfo.result != CELL_OSKDIALOG_INPUT_FIELD_RESULT_OK)
- {
- if (m_text_input_info.OutputInfo.result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_CANCELED)
- {
- m_text_input_info.status = TEXT_INPUT_STATUS_CANCELED;
- printf("User canceled input\n");
- }
- else if (m_text_input_info.OutputInfo.result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_NO_INPUT_TEXT)
- {
- m_text_input_info.status = TEXT_INPUT_STATUS_NO_INPUT;
- printf("No text inputed\n");
- }
- else if (m_text_input_info.OutputInfo.result == CELL_OSKDIALOG_INPUT_FIELD_RESULT_ABORT)
- {
- m_text_input_info.status = TEXT_INPUT_STATUS_ABORTED;
- printf("User aborted input\n");
- }
- else
- {
- m_text_input_info.status = TEXT_INPUT_STATUS_ABORTED;
- printf("OutputInfo.result not OK. Uknown result\n");
- }
- break;
- }
- printf("%ls\n", (wchar_t*)m_text_input_info.OutputInfo.pResultString);
- break;
- case CELL_SYSUTIL_OSKDIALOG_UNLOADED:
- m_text_input_info.status = TEXT_INPUT_STATUS_OSK_UNLOADED;
- break;
- case CELL_SYSUTIL_OSKDIALOG_INPUT_ENTERED:
- if (cellOskDialogGetInputText(&m_text_input_info.OutputInfo) != 0)
- printf("cellOskDialogGetInputText() failed\n");;
- printf("%ls\n", (wchar_t*)m_text_input_info.OutputInfo.pResultString);
- break;
- case CELL_SYSUTIL_OSKDIALOG_INPUT_CANCELED:
- cellOskDialogAbort();
- break;
- default: break;
- }
- }
- static Text_Input_Info m_text_input_info;
- };
- Gamepad Input::m_gamepad;
- InputStatus Input::m_status;
- Text_Input_Info Input::m_text_input_info;
- int Input::m_sys_cb_id;
- bool Input::m_osk_inited = false;
- static void RetrieveInputLoop(
- char *str_buf,
- size_t size,
- bool *canceled = NULL)
- {
- while (1) {
- switch (Input::text_input_status())
- {
- //E When the On Screen Keyboard is being used the Input status should be Waiting
- case TEXT_INPUT_STATUS_WAITING:
- break;
- //E When the status is no longer Waiting
- //E Get input if the status is OK
- case TEXT_INPUT_STATUS_OK:
- snprintf(str_buf, size, "%ls", (wchar_t*)Input::text_input_result_str());
- break;
- case TEXT_INPUT_STATUS_CANCELED:
- if (canceled != NULL) {
- *canceled = true;
- }
- break;
- case TEXT_INPUT_STATUS_ABORTED:
- case TEXT_INPUT_STATUS_NO_INPUT:
- break;
- //E Go back to normal state for any case when we are no longer waiting for the OSK to finish
- default:
- printf("state = %d\n", Input::text_input_status());
- break;
- case TEXT_INPUT_STATUS_OSK_UNLOADED:
- /* OSK has been safely unloaded */
- return;
- }
- sys_timer_usleep(100);
- }
- //return; /* end of function */
- }
- void RetrieveInputForText(
- char *str_buf,
- int char_len,
- size_t buf_byte_size,
- const char *initialText,
- bool *canceled)
- {
- if (char_len > CELL_OSKDIALOG_STRING_SIZE) char_len = CELL_OSKDIALOG_STRING_SIZE;
- memset(str_buf, 0x00, buf_byte_size);
- size_t length = strlen(initialText);
- wchar_t *wc = (wchar_t*)malloc(sizeof(wchar_t) * (length + 1));
- memset(wc, 0x00, sizeof(wchar_t) * (length + 1));
- mbstowcs(wc, initialText, length + 1);
- Input::text_input_set_flags(CELL_OSKDIALOG_PANELMODE_ALPHABET,
- CELL_OSKDIALOG_PANELMODE_ALPHABET,
- CELL_OSKDIALOG_NO_RETURN);
- Input::open_text_input(char_len, L"Input text", wc);
- RetrieveInputLoop(str_buf, buf_byte_size, canceled);
- free(wc);
- }
- void RetrieveInputForUrl(
- char *str_buf,
- int char_len,
- size_t buf_byte_size,
- const char *initialText,
- bool *canceled)
- {
- if (char_len > CELL_OSKDIALOG_STRING_SIZE) char_len = CELL_OSKDIALOG_STRING_SIZE;
- memset(str_buf, 0x00, buf_byte_size);
- size_t length = strlen(initialText);
- wchar_t *wc = (wchar_t*)malloc(sizeof(wchar_t) * (length + 1));
- memset(wc, 0x00, sizeof(wchar_t) * (length + 1));
- mbstowcs(wc, initialText, length + 1);
- Input::text_input_set_flags(CELL_OSKDIALOG_PANELMODE_URL,
- CELL_OSKDIALOG_PANELMODE_URL,
- 0);
- Input::open_text_input(char_len, L"Input text", wc);
- RetrieveInputLoop(str_buf, buf_byte_size, canceled);
- free(wc);
- }
- // useage
- // Input::gamepad()->l2_pressed()
Add Comment
Please, Sign In to add comment