* 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:
Axel Dörfler
2009-03-25 17:49:46 +00:00
parent 495c8b848b
commit 3c394ad89e
5 changed files with 135 additions and 14 deletions
+1 -1
View File
@@ -2,7 +2,7 @@ SubDir HAIKU_TOP src preferences keymap ;
SetSubDirSupportedPlatformsBeOSCompatible ;
UsePrivateHeaders interface ;
UsePrivateHeaders interface shared ;
Preference Keymap :
KeyboardLayout.cpp
+45 -6
View File
@@ -11,8 +11,11 @@
#include <vector>
#include <File.h>
#include <InterfaceDefs.h>
#undef TRACE
//#define TRACE_LAYOUT
#ifdef TRACE_LAYOUT
# define TRACE(x...) printf(x)
@@ -25,7 +28,8 @@ KeyboardLayout::KeyboardLayout()
:
fKeys(NULL),
fKeyCount(0),
fKeyCapacity(0)
fKeyCapacity(0),
fIndicators(5, true)
{
_SetDefault();
}
@@ -61,10 +65,17 @@ KeyboardLayout::KeyAt(int32 index)
}
Key*
KeyboardLayout::KeyAt(BPoint point)
int32
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"
"$g = 13,10\n"
// 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,30; d$d:0x26; :+12; $d:+1; $b:-; d:+3; $b:-; :+3; "
"d$f:+1 ]\n"
@@ -333,7 +345,34 @@ KeyboardLayout::_AddKeyCodes(const parse_state& state, BPoint& rowLeftTop,
int32 modifier = 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;
+13 -1
View File
@@ -8,6 +8,7 @@
#include <map>
#include <ObjectList.h>
#include <Point.h>
#include <Rect.h>
#include <String.h>
@@ -29,6 +30,11 @@ struct Key {
bool dark;
};
struct Indicator {
int32 modifier;
BRect frame;
};
typedef std::map<BString, BString> VariableMap;
class KeyboardLayout {
@@ -40,13 +46,17 @@ public:
int32 CountKeys();
Key* KeyAt(int32 index);
Key* KeyAt(BPoint point);
int32 CountIndicators();
Indicator* IndicatorAt(int32 index);
BRect Bounds();
BSize DefaultKeySize();
status_t Load(const char* path);
int32 IndexForModifier(int32 modifier);
private:
enum parse_mode {
kPairs,
@@ -97,6 +107,8 @@ private:
int32 fKeyCapacity;
BRect fBounds;
BSize fDefaultKeySize;
int32 fAlternateIndex[3];
BObjectList<Indicator> fIndicators;
};
#endif // KEYBOARD_LAYOUT_H
+73 -5
View File
@@ -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 kSecondDeadKeyColor = {240, 240, 150, 255};
static const rgb_color kDeadKeyColor = {152, 203, 255, 255};
static const rgb_color kLitIndicatorColor = {116, 212, 83, 255};
KeyboardLayoutView::KeyboardLayoutView(const char* name)
@@ -88,6 +89,7 @@ KeyboardLayoutView::AttachedToWindow()
SetFont(*be_plain_font);
fSpecialFont = *be_fixed_font;
fModifiers = modifiers();
_LayoutKeyboard();
}
@@ -227,12 +229,63 @@ KeyboardLayoutView::MouseMoved(BPoint point, uint32 transit,
void
KeyboardLayoutView::Draw(BRect updateRect)
{
// Draw keys
for (int32 i = 0; i < fLayout->CountKeys(); i++) {
Key* key = fLayout->KeyAt(i);
_DrawKey(this, updateRect, key, _FrameFor(key),
_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
KeyboardLayoutView::_FrameFor(const Key* key)
KeyboardLayoutView::_FrameFor(BRect keyFrame)
{
BRect rect;
rect.left = key->frame.left * fFactor;
rect.right = (key->frame.right - key->frame.left) * fFactor + rect.left
rect.left = keyFrame.left * fFactor;
rect.right = (keyFrame.right - keyFrame.left) * fFactor + rect.left
- fGap - 1;
rect.top = key->frame.top * fFactor;
rect.bottom = (key->frame.bottom - key->frame.top) * fFactor + rect.top
rect.top = keyFrame.top * fFactor;
rect.bottom = (keyFrame.bottom - keyFrame.top) * fFactor + rect.top
- fGap - 1;
rect.OffsetBy(fOffset);
@@ -668,6 +721,13 @@ KeyboardLayoutView::_FrameFor(const Key* key)
}
BRect
KeyboardLayoutView::_FrameFor(const Key* key)
{
return _FrameFor(key->frame);
}
void
KeyboardLayoutView::_SetFontSize(BView* view, key_kind keyKind)
{
@@ -692,6 +752,14 @@ KeyboardLayoutView::_SetFontSize(BView* view, key_kind keyKind)
fSpecialFont.SetSize(fontSize * 1.6);
view->SetFont(&fSpecialFont);
break;
case kIndicator:
{
BFont font;
font.SetSize(fontSize * 0.8);
view->SetFont(&font);
break;
}
}
}
+3 -1
View File
@@ -46,7 +46,8 @@ private:
enum key_kind {
kNormalKey,
kSpecialKey,
kSymbolKey
kSymbolKey,
kIndicator
};
void _LayoutKeyboard();
@@ -68,6 +69,7 @@ private:
bool _HandleDeadKey(int32 key, int32 modifiers);
void _KeyChanged(const BMessage* message);
Key* _KeyAt(BPoint point);
BRect _FrameFor(BRect keyFrame);
BRect _FrameFor(const Key* key);
void _SetFontSize(BView* view, key_kind keyKind);
void _EvaluateDropTarget(BPoint point);