* Added support for LED status indicators.
* The look isn't perfect yet, but well; improvements welcome. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29706 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src preferences keymap ;
|
|||||||
|
|
||||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||||
|
|
||||||
UsePrivateHeaders interface ;
|
UsePrivateHeaders interface shared ;
|
||||||
|
|
||||||
Preference Keymap :
|
Preference Keymap :
|
||||||
KeyboardLayout.cpp
|
KeyboardLayout.cpp
|
||||||
|
|||||||
@@ -11,8 +11,11 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <File.h>
|
#include <File.h>
|
||||||
|
#include <InterfaceDefs.h>
|
||||||
|
|
||||||
|
|
||||||
|
#undef TRACE
|
||||||
|
|
||||||
//#define TRACE_LAYOUT
|
//#define TRACE_LAYOUT
|
||||||
#ifdef TRACE_LAYOUT
|
#ifdef TRACE_LAYOUT
|
||||||
# define TRACE(x...) printf(x)
|
# define TRACE(x...) printf(x)
|
||||||
@@ -25,7 +28,8 @@ KeyboardLayout::KeyboardLayout()
|
|||||||
:
|
:
|
||||||
fKeys(NULL),
|
fKeys(NULL),
|
||||||
fKeyCount(0),
|
fKeyCount(0),
|
||||||
fKeyCapacity(0)
|
fKeyCapacity(0),
|
||||||
|
fIndicators(5, true)
|
||||||
{
|
{
|
||||||
_SetDefault();
|
_SetDefault();
|
||||||
}
|
}
|
||||||
@@ -61,10 +65,17 @@ KeyboardLayout::KeyAt(int32 index)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Key*
|
int32
|
||||||
KeyboardLayout::KeyAt(BPoint point)
|
KeyboardLayout::CountIndicators()
|
||||||
{
|
{
|
||||||
return NULL;
|
return fIndicators.CountItems();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Indicator*
|
||||||
|
KeyboardLayout::IndicatorAt(int32 index)
|
||||||
|
{
|
||||||
|
return fIndicators.ItemAt(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -136,7 +147,8 @@ KeyboardLayout::_SetDefault()
|
|||||||
"$f = 10,20\n"
|
"$f = 10,20\n"
|
||||||
"$g = 13,10\n"
|
"$g = 13,10\n"
|
||||||
// Key rows
|
// Key rows
|
||||||
"[ 0,0; d:0x01; :-; :+4; $b:-; d:+4; $b:-; :+4; $b:-; d:+3 ]\n"
|
"[ 0,0; d:0x01; :-; :+4; $b:-; d:+4; $b:-; :+4; $b:-; d:+3; $b:-; "
|
||||||
|
"$g:led-num; $g:led-caps; $g:led-scroll ]\n"
|
||||||
"[ 0,20; :+13; d$c:+; $b:-; d:+3; $b:-; d:+4 ]\n"
|
"[ 0,20; :+13; d$c:+; $b:-; d:+3; $b:-; d:+4 ]\n"
|
||||||
"[ 0,30; d$d:0x26; :+12; $d:+1; $b:-; d:+3; $b:-; :+3; "
|
"[ 0,30; d$d:0x26; :+12; $d:+1; $b:-; d:+3; $b:-; :+3; "
|
||||||
"d$f:+1 ]\n"
|
"d$f:+1 ]\n"
|
||||||
@@ -333,7 +345,34 @@ KeyboardLayout::_AddKeyCodes(const parse_state& state, BPoint& rowLeftTop,
|
|||||||
int32 modifier = 0;
|
int32 modifier = 0;
|
||||||
|
|
||||||
if (isalpha(data[0])) {
|
if (isalpha(data[0])) {
|
||||||
// TODO: get modifier (ie. "num")
|
bool led = false;
|
||||||
|
if (!strcmp("led-caps", data)) {
|
||||||
|
modifier = B_CAPS_LOCK;
|
||||||
|
led = true;
|
||||||
|
} else if (!strcmp("led-num", data)) {
|
||||||
|
modifier = B_NUM_LOCK;
|
||||||
|
led = true;
|
||||||
|
} else if (!strcmp("led-scroll", data)) {
|
||||||
|
modifier = B_SCROLL_LOCK;
|
||||||
|
led = true;
|
||||||
|
} else {
|
||||||
|
// TODO: get modifier (ie. "num")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (led) {
|
||||||
|
key.frame.OffsetTo(rowLeftTop);
|
||||||
|
rowLeftTop.x = key.frame.right;
|
||||||
|
fBounds = key.frame | fBounds;
|
||||||
|
|
||||||
|
Indicator* indicator = new(std::nothrow) Indicator;
|
||||||
|
if (indicator != NULL) {
|
||||||
|
indicator->modifier = modifier;
|
||||||
|
indicator->frame = key.frame;
|
||||||
|
|
||||||
|
fIndicators.AddItem(indicator);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int32 first;
|
int32 first;
|
||||||
|
|||||||
@@ -8,6 +8,7 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
|
|
||||||
|
#include <ObjectList.h>
|
||||||
#include <Point.h>
|
#include <Point.h>
|
||||||
#include <Rect.h>
|
#include <Rect.h>
|
||||||
#include <String.h>
|
#include <String.h>
|
||||||
@@ -29,6 +30,11 @@ struct Key {
|
|||||||
bool dark;
|
bool dark;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct Indicator {
|
||||||
|
int32 modifier;
|
||||||
|
BRect frame;
|
||||||
|
};
|
||||||
|
|
||||||
typedef std::map<BString, BString> VariableMap;
|
typedef std::map<BString, BString> VariableMap;
|
||||||
|
|
||||||
class KeyboardLayout {
|
class KeyboardLayout {
|
||||||
@@ -40,13 +46,17 @@ public:
|
|||||||
|
|
||||||
int32 CountKeys();
|
int32 CountKeys();
|
||||||
Key* KeyAt(int32 index);
|
Key* KeyAt(int32 index);
|
||||||
Key* KeyAt(BPoint point);
|
|
||||||
|
int32 CountIndicators();
|
||||||
|
Indicator* IndicatorAt(int32 index);
|
||||||
|
|
||||||
BRect Bounds();
|
BRect Bounds();
|
||||||
BSize DefaultKeySize();
|
BSize DefaultKeySize();
|
||||||
|
|
||||||
status_t Load(const char* path);
|
status_t Load(const char* path);
|
||||||
|
|
||||||
|
int32 IndexForModifier(int32 modifier);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
enum parse_mode {
|
enum parse_mode {
|
||||||
kPairs,
|
kPairs,
|
||||||
@@ -97,6 +107,8 @@ private:
|
|||||||
int32 fKeyCapacity;
|
int32 fKeyCapacity;
|
||||||
BRect fBounds;
|
BRect fBounds;
|
||||||
BSize fDefaultKeySize;
|
BSize fDefaultKeySize;
|
||||||
|
int32 fAlternateIndex[3];
|
||||||
|
BObjectList<Indicator> fIndicators;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // KEYBOARD_LAYOUT_H
|
#endif // KEYBOARD_LAYOUT_H
|
||||||
|
|||||||
@@ -18,6 +18,7 @@ static const rgb_color kBrightColor = {230, 230, 230, 255};
|
|||||||
static const rgb_color kDarkColor = {200, 200, 200, 255};
|
static const rgb_color kDarkColor = {200, 200, 200, 255};
|
||||||
static const rgb_color kSecondDeadKeyColor = {240, 240, 150, 255};
|
static const rgb_color kSecondDeadKeyColor = {240, 240, 150, 255};
|
||||||
static const rgb_color kDeadKeyColor = {152, 203, 255, 255};
|
static const rgb_color kDeadKeyColor = {152, 203, 255, 255};
|
||||||
|
static const rgb_color kLitIndicatorColor = {116, 212, 83, 255};
|
||||||
|
|
||||||
|
|
||||||
KeyboardLayoutView::KeyboardLayoutView(const char* name)
|
KeyboardLayoutView::KeyboardLayoutView(const char* name)
|
||||||
@@ -88,6 +89,7 @@ KeyboardLayoutView::AttachedToWindow()
|
|||||||
|
|
||||||
SetFont(*be_plain_font);
|
SetFont(*be_plain_font);
|
||||||
fSpecialFont = *be_fixed_font;
|
fSpecialFont = *be_fixed_font;
|
||||||
|
fModifiers = modifiers();
|
||||||
|
|
||||||
_LayoutKeyboard();
|
_LayoutKeyboard();
|
||||||
}
|
}
|
||||||
@@ -227,12 +229,63 @@ KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
|
|||||||
void
|
void
|
||||||
KeyboardLayoutView::Draw(BRect updateRect)
|
KeyboardLayoutView::Draw(BRect updateRect)
|
||||||
{
|
{
|
||||||
|
// Draw keys
|
||||||
|
|
||||||
for (int32 i = 0; i < fLayout->CountKeys(); i++) {
|
for (int32 i = 0; i < fLayout->CountKeys(); i++) {
|
||||||
Key* key = fLayout->KeyAt(i);
|
Key* key = fLayout->KeyAt(i);
|
||||||
|
|
||||||
_DrawKey(this, updateRect, key, _FrameFor(key),
|
_DrawKey(this, updateRect, key, _FrameFor(key),
|
||||||
_IsKeyPressed(key->code));
|
_IsKeyPressed(key->code));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Draw LED indicators
|
||||||
|
|
||||||
|
for (int32 i = 0; i < fLayout->CountIndicators(); i++) {
|
||||||
|
Indicator* indicator = fLayout->IndicatorAt(i);
|
||||||
|
|
||||||
|
BRect rect = _FrameFor(indicator->frame);
|
||||||
|
float rectTop = rect.top;
|
||||||
|
rect.top += 2 * rect.Height() / 3;
|
||||||
|
|
||||||
|
const char* label = NULL;
|
||||||
|
if (indicator->modifier == B_CAPS_LOCK)
|
||||||
|
label = "caps";
|
||||||
|
else if (indicator->modifier == B_NUM_LOCK)
|
||||||
|
label = "num";
|
||||||
|
else if (indicator->modifier == B_SCROLL_LOCK)
|
||||||
|
label = "scroll";
|
||||||
|
if (label != NULL) {
|
||||||
|
_SetFontSize(this, kIndicator);
|
||||||
|
|
||||||
|
font_height fontHeight;
|
||||||
|
GetFontHeight(&fontHeight);
|
||||||
|
if (ceilf(rect.top - fontHeight.ascent + fontHeight.descent - 2)
|
||||||
|
>= rectTop) {
|
||||||
|
SetHighColor(0, 0, 0);
|
||||||
|
SetLowColor(ViewColor());
|
||||||
|
|
||||||
|
BString text(label);
|
||||||
|
TruncateString(&text, B_TRUNCATE_END, rect.Width());
|
||||||
|
DrawString(text.String(), BPoint(ceilf(rect.left + (rect.Width()
|
||||||
|
- StringWidth(text.String())) / 2),
|
||||||
|
ceilf(rect.top - fontHeight.descent - 2)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
rect.left += rect.Width() / 4;
|
||||||
|
rect.right -= rect.Width() / 3;
|
||||||
|
|
||||||
|
rgb_color base;
|
||||||
|
if ((fModifiers & indicator->modifier) != 0)
|
||||||
|
base = kLitIndicatorColor;
|
||||||
|
else
|
||||||
|
base = kDarkColor;
|
||||||
|
|
||||||
|
be_control_look->DrawButtonFrame(this, rect, updateRect, base,
|
||||||
|
BControlLook::B_DISABLED);
|
||||||
|
be_control_look->DrawButtonBackground(this, rect, updateRect,
|
||||||
|
base, BControlLook::B_DISABLED);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -653,14 +706,14 @@ KeyboardLayoutView::_KeyAt(BPoint point)
|
|||||||
|
|
||||||
|
|
||||||
BRect
|
BRect
|
||||||
KeyboardLayoutView::_FrameFor(const Key* key)
|
KeyboardLayoutView::_FrameFor(BRect keyFrame)
|
||||||
{
|
{
|
||||||
BRect rect;
|
BRect rect;
|
||||||
rect.left = key->frame.left * fFactor;
|
rect.left = keyFrame.left * fFactor;
|
||||||
rect.right = (key->frame.right - key->frame.left) * fFactor + rect.left
|
rect.right = (keyFrame.right - keyFrame.left) * fFactor + rect.left
|
||||||
- fGap - 1;
|
- fGap - 1;
|
||||||
rect.top = key->frame.top * fFactor;
|
rect.top = keyFrame.top * fFactor;
|
||||||
rect.bottom = (key->frame.bottom - key->frame.top) * fFactor + rect.top
|
rect.bottom = (keyFrame.bottom - keyFrame.top) * fFactor + rect.top
|
||||||
- fGap - 1;
|
- fGap - 1;
|
||||||
rect.OffsetBy(fOffset);
|
rect.OffsetBy(fOffset);
|
||||||
|
|
||||||
@@ -668,6 +721,13 @@ KeyboardLayoutView::_FrameFor(const Key* key)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
BRect
|
||||||
|
KeyboardLayoutView::_FrameFor(const Key* key)
|
||||||
|
{
|
||||||
|
return _FrameFor(key->frame);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
KeyboardLayoutView::_SetFontSize(BView* view, key_kind keyKind)
|
KeyboardLayoutView::_SetFontSize(BView* view, key_kind keyKind)
|
||||||
{
|
{
|
||||||
@@ -692,6 +752,14 @@ KeyboardLayoutView::_SetFontSize(BView* view, key_kind keyKind)
|
|||||||
fSpecialFont.SetSize(fontSize * 1.6);
|
fSpecialFont.SetSize(fontSize * 1.6);
|
||||||
view->SetFont(&fSpecialFont);
|
view->SetFont(&fSpecialFont);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case kIndicator:
|
||||||
|
{
|
||||||
|
BFont font;
|
||||||
|
font.SetSize(fontSize * 0.8);
|
||||||
|
view->SetFont(&font);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -46,7 +46,8 @@ private:
|
|||||||
enum key_kind {
|
enum key_kind {
|
||||||
kNormalKey,
|
kNormalKey,
|
||||||
kSpecialKey,
|
kSpecialKey,
|
||||||
kSymbolKey
|
kSymbolKey,
|
||||||
|
kIndicator
|
||||||
};
|
};
|
||||||
|
|
||||||
void _LayoutKeyboard();
|
void _LayoutKeyboard();
|
||||||
@@ -68,6 +69,7 @@ private:
|
|||||||
bool _HandleDeadKey(int32 key, int32 modifiers);
|
bool _HandleDeadKey(int32 key, int32 modifiers);
|
||||||
void _KeyChanged(const BMessage* message);
|
void _KeyChanged(const BMessage* message);
|
||||||
Key* _KeyAt(BPoint point);
|
Key* _KeyAt(BPoint point);
|
||||||
|
BRect _FrameFor(BRect keyFrame);
|
||||||
BRect _FrameFor(const Key* key);
|
BRect _FrameFor(const Key* key);
|
||||||
void _SetFontSize(BView* view, key_kind keyKind);
|
void _SetFontSize(BView* view, key_kind keyKind);
|
||||||
void _EvaluateDropTarget(BPoint point);
|
void _EvaluateDropTarget(BPoint point);
|
||||||
|
|||||||
Reference in New Issue
Block a user