Creating a responsive text box
In this recipe we will learn how to create a text box that responds to the user's keystrokes. It will be active when pressed over by the mouse and inactive when the mouse is released outside the box.
Getting ready
Grab the following files from the recipe Creating an interactive object that responds to the mouse and add them to your project:
InteractiveObject.h
InteractiveObject.cpp
Create and add the following files to your project:
InteractiveTextBox.h
InteractiveTextBox.cpp
How to do it…
We will create an InteractiveTextBox
class that inherits from InteractiveObject
and adds text functionality.
Go to the file
InteractiveTextBox.h
and add the#pragma once
macro and include the necessary files.#pragma once #include "InteractiveObject.h" #include "cinder/Text.h" #include "cinder/gl/Texture.h" #include "cinder/app/KeyEvent.h" #include "cinder/app/AppBasic.h"
Now declare the
InteractiveTextBox
class, making it a subclass ofInteractiveObject
with the following members and...