ManaPlus
Public Member Functions | Protected Attributes
Key Class Reference

#include <key.h>

Public Member Functions

 Key (const int value)
 
bool isCharacter () const
 
bool isNumber () const
 
bool isLetter () const
 
int getValue () const
 
bool operator== (const Key &key) const
 
bool operator!= (const Key &key) const
 

Protected Attributes

int mValue
 

Detailed Description

Represents a key or a character.

Definition at line 80 of file key.h.

Constructor & Destructor Documentation

◆ Key()

Key::Key ( const int  value)
explicit

Constructor.

Parameters
valueThe ascii or enum value for the key.

Definition at line 73 of file key.cpp.

73  :
74  mValue(value)
75 {
76 }
int mValue
Definition: key.h:145

Member Function Documentation

◆ getValue()

int Key::getValue ( ) const

Gets the value of the key. If an ascii value exists it will be returned. Otherwise an enum value will be returned.

Returns
the value of the key.

Definition at line 99 of file key.cpp.

100 {
101  return mValue;
102 }

References mValue.

Referenced by TextBox::keyPressed(), and ChatWindow::keyPressed().

◆ isCharacter()

bool Key::isCharacter ( ) const

Checks if a key is a character.

Returns
True if the key is a letter, number or whitespace, false otherwise.

Definition at line 78 of file key.cpp.

79 {
80  return (mValue >= 32 && mValue <= 126)
81  || (mValue >= 162 && mValue <= 255)
82  || (mValue == 9);
83 }

References mValue.

Referenced by TextBox::keyPressed().

◆ isLetter()

bool Key::isLetter ( ) const

Checks if a key is a letter.

Returns
True if the key is a letter (a-z,A-Z), false otherwise.

Definition at line 90 of file key.cpp.

91 {
92  return ((mValue >= 65 && mValue <= 90) ||
93  (mValue >= 97 && mValue <= 122) ||
94  (mValue >= 192 && mValue <= 255)) &&
95  mValue != 215 &&
96  mValue != 247;
97 }

References mValue.

◆ isNumber()

bool Key::isNumber ( ) const

Checks if a key is a number.

Returns
True if the key is a number (0-9), false otherwise.

Definition at line 85 of file key.cpp.

86 {
87  return mValue >= 48 && mValue <= 57;
88 }

References mValue.

Referenced by IntTextField::keyPressed().

◆ operator!=()

bool Key::operator!= ( const Key key) const

Compares two keys.

Parameters
keyThe key to compare this key with.
Returns
True if the keys are not equal, false otherwise.

Definition at line 109 of file key.cpp.

110 {
111  return mValue != key.mValue;
112 }

References mValue.

◆ operator==()

bool Key::operator== ( const Key key) const

Compares two keys.

Parameters
keyThe key to compare this key with.
Returns
True if the keys are equal, false otherwise.

Definition at line 104 of file key.cpp.

105 {
106  return mValue == key.mValue;
107 }

References mValue.

Field Documentation

◆ mValue

int Key::mValue
protected

Holds the value of the key. It may be an ascii value or an enum value.

Definition at line 145 of file key.h.

Referenced by getValue(), isCharacter(), isLetter(), isNumber(), operator!=(), and operator==().


The documentation for this class was generated from the following files: