implementing text input on osx
This commit is contained in:
@@ -265,6 +265,8 @@ static CVReturn MyDisplayLinkCallback(CVDisplayLinkRef displayLink, const CVTime
|
||||
auto keyCode = [theEvent keyCode];
|
||||
auto chars = [theEvent characters];
|
||||
App::I.key_down(convert_key(keyCode));
|
||||
if (const char* cstr = [chars cStringUsingEncoding:NSASCIIStringEncoding])
|
||||
App::I.key_char(cstr[0]);
|
||||
CGLUnlockContext([[self openGLContext] CGLContextObj]);
|
||||
}
|
||||
- (void)keyUp:(NSEvent *)theEvent
|
||||
|
||||
@@ -175,6 +175,7 @@
|
||||
<border width="400" color="0 0 0 .9" pad="10" dir="col">
|
||||
<image-texture id="thumb-tex" width="64" height="64"/>
|
||||
<text text="Longer description for the error or the message." font-face="arial" font-size="11"></text>
|
||||
<text-input width="100" height="100" color=".3"/>
|
||||
<node height="40" grow="1" dir="row" align="flex-end" justify="flex-end">
|
||||
<button id="btn-ok" text="Open Project" width="100" height="30" margin="0 10 0 0"/>
|
||||
<button id="btn-cancel" text="Cancel" width="60" height="30" pad="10"/>
|
||||
@@ -394,11 +395,13 @@
|
||||
</scroll>
|
||||
</node>
|
||||
<!-- timeline -->
|
||||
<!--
|
||||
<node height="100%" width="1" grow="1" dir="col" justify="flex-end">
|
||||
<border color=".3 .3 .3 .4" height="50" width="100%" pad="10">
|
||||
<slider-h id="frames-slider"></slider-h>
|
||||
</border>
|
||||
</node>
|
||||
-->
|
||||
</node>
|
||||
<!-- status bar -->
|
||||
<!--<border height="30" width="100%" color=".15" border-color=".3" dir="row" pad="0 0 0 10" align="center">
|
||||
|
||||
@@ -7,6 +7,18 @@ Node* NodeTextInput::clone_instantiate() const
|
||||
return new NodeTextInput();
|
||||
}
|
||||
|
||||
void NodeTextInput::clone_finalize(Node* dest) const
|
||||
{
|
||||
NodeBorder::clone_copy(dest);
|
||||
NodeTextInput* n = static_cast<NodeTextInput*>(dest);
|
||||
if (n->m_children.size())
|
||||
{
|
||||
auto t = n->m_children[0];
|
||||
n->m_text = (NodeText*)t.get();
|
||||
}
|
||||
n->m_string = m_string;
|
||||
}
|
||||
|
||||
void NodeTextInput::init()
|
||||
{
|
||||
init_controls();
|
||||
@@ -20,6 +32,7 @@ void NodeTextInput::init_controls()
|
||||
m_text->m_font_size = 11;
|
||||
m_text->m_text = "TextInput";
|
||||
m_text->create();
|
||||
m_string = "TextInput";
|
||||
}
|
||||
|
||||
kEventResult NodeTextInput::handle_event(Event* e)
|
||||
@@ -46,7 +59,13 @@ kEventResult NodeTextInput::handle_event(Event* e)
|
||||
case kEventType::KeyChar:
|
||||
if (ke->m_char >= 32 && ke->m_char < (32 + 96))
|
||||
{
|
||||
m_string += (char)ke->m_key;
|
||||
if (ke->m_char == 0x7f)
|
||||
{
|
||||
if (!m_string.empty())
|
||||
m_string.erase(m_string.end() - 1);
|
||||
}
|
||||
else
|
||||
m_string += (char)ke->m_char;
|
||||
m_text->set_text(m_string.c_str());
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -8,6 +8,7 @@ public:
|
||||
NodeText* m_text;
|
||||
std::string m_string;
|
||||
virtual Node* clone_instantiate() const override;
|
||||
virtual void clone_finalize(Node* dest) const override;
|
||||
virtual void init() override;
|
||||
void init_controls();
|
||||
virtual kEventResult handle_event(Event* e) override;
|
||||
|
||||
Reference in New Issue
Block a user