1 /*---------------------------------------------------------------------------*
2 Project: Horizon
3 File: kbd.cpp
4
5 Copyright (C)2009-2012 Nintendo Co., Ltd. All rights reserved.
6
7 These coded instructions, statements, and computer programs contain
8 proprietary information of Nintendo of America Inc. and/or Nintendo
9 Company Ltd., and are protected by Federal copyright law. They may
10 not be disclosed to third parties or copied or duplicated in any form,
11 in whole or in part, without the prior written consent of Nintendo.
12
13 $Rev: 46365 $
14 *---------------------------------------------------------------------------*/
15
16 #include <nn/os.h>
17 #include <nn/swkbd.h>
18 #include <string.h>
19 #include <wchar.h>
20 #include "kbd.h"
21
22 u8 SwkbdDemo::m_KeyboardBuffer[KEYBOARD_BUFFER_SIZE] NN_ATTRIBUTE_ALIGN(4096);
23
Initialize(demo::RenderSystemDrawing * p_RenderSystem)24 void SwkbdDemo::Initialize(demo::RenderSystemDrawing* p_RenderSystem)
25 {
26 Device::Initialize(p_RenderSystem);
27 mp_RenderSystem = p_RenderSystem;
28
29 memset( m_TextBuffer, 0, sizeof( m_TextBuffer ) );
30
31 // Initialize config
32 nn::swkbd::InitializeConfig(&m_Param.config);
33 m_Param.config.keyboardType = nn::swkbd::KEYBOARD_TYPE_QWERTY;
34 m_Param.config.textLengthMax = 10;
35 m_Param.config.lineFeed = false;
36 m_Size = nn::swkbd::GetSharedMemorySize(&m_Param.config, NULL, NULL);
37
38 NN_ASSERT( KEYBOARD_BUFFER_SIZE > m_Size );
39 }
40
DrawFrame(void)41 void SwkbdDemo::DrawFrame(void)
42 {
43 mp_RenderSystem->SetColor(1.0f, 1.0f, 1.0f, 1.0f);
44
45 for(int i = 0; i < 10 ; i++)
46 {
47 mp_RenderSystem->DrawText(200 + 8 * i, 220, "%s", &m_TextBuffer[i]);
48 }
49 }
50
Exec(void)51 bool SwkbdDemo::Exec(void)
52 {
53 wcsncpy( m_Param.config.guideText, m_TextBuffer, 11 );
54
55 // Start the software keyboard
56 nn::swkbd::StartKeyboardApplet(&m_WakeupState, &m_Param, m_KeyboardBuffer, KEYBOARD_BUFFER_SIZE, NULL, NULL, NULL, NULL, NULL);
57
58 // End determination
59 if ( nn::applet::IsExpectedToCloseApplication() )
60 {
61 return 1;
62 }
63
64 // Recover the GPU register settings
65 nngxUpdateState(NN_GX_STATE_ALL);
66 nngxValidateState(NN_GX_STATE_ALL,GL_TRUE);
67
68 // Get the input string
69 if( m_Param.config.inputText != -1 && !nn::applet::IsExpectedToProcessHomeButton() )
70 {
71 u8* buf = m_KeyboardBuffer;
72 memset( m_TextBuffer, 0, sizeof( m_TextBuffer ) );
73 memcpy( m_TextBuffer, &buf[m_Param.config.inputText], m_Param.config.inputTextLength * sizeof( wchar_t ) );
74 }
75
76 return 0;
77 }
78
79 /*---------------------------------------------------------------------------*
80 End of file
81 *---------------------------------------------------------------------------*/
82