fix hover tracking

This commit is contained in:
Vadim Lopatin 2014-04-14 11:36:37 +04:00
parent 01fcb4ba8c
commit cb9b46719c
5 changed files with 29 additions and 17 deletions

View File

@ -2,24 +2,24 @@
<selector xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:drawable="btn_default_small_normal_disable_focused"
color_transform_add1="100,0,0,0"
color_transform_add1="0,0,0,0"
android:state_enabled="false"
android:state_focused="true" />
<item
android:drawable="btn_default_small_normal_disable"
color_transform_add1="100,0,0,0"
color_transform_add1="0,0,0,0"
android:state_focused="true" />
<item
android:drawable="btn_default_small_pressed"
color_transform_add1="100,0,0,0"
color_transform_add1="0,0,0,0"
android:state_pressed="true" />
<item
android:drawable="btn_default_small_selected"
color_transform_add1="100,0,0,0"
color_transform_add1="0,0,0,0"
android:state_selected="true" />
<item
android:drawable="btn_default_small_normal_hover"
color_transform_add1="100,0,0,0"
color_transform_add1="0,0,0,0"
android:state_hovered="true" />
<item
android:drawable="@null" />

View File

@ -123,7 +123,6 @@ class Window {
_mouseCaptureWidget = root;
_mouseCaptureButtons = event.flags & (MouseFlag.LButton|MouseFlag.RButton|MouseFlag.MButton);
} else if (event.action == MouseAction.Move) {
Log.d("Setting tracking widget");
addTracking(root);
}
return true;
@ -135,10 +134,15 @@ class Window {
//protected Widget _mouseTrackingWidget;
protected Widget[] _mouseTrackingWidgets;
private void addTracking(Widget w) {
foreach(widget; _mouseTrackingWidgets)
if (widget is w)
for(int i = 0; i < _mouseTrackingWidgets.length; i++)
if (w is _mouseTrackingWidgets[i])
return;
//foreach(widget; _mouseTrackingWidgets)
// if (widget is w)
// return;
//Log.d("addTracking ", w.id, " items before: ", _mouseTrackingWidgets.length);
_mouseTrackingWidgets ~= w;
//Log.d("addTracking ", w.id, " items after: ", _mouseTrackingWidgets.length);
}
private bool checkRemoveTracking(MouseEvent event) {
import std.algorithm;
@ -146,7 +150,11 @@ class Window {
for(int i = _mouseTrackingWidgets.length - 1; i >=0; i--) {
Widget w = _mouseTrackingWidgets[i];
if (!_mainWidget.isChild(w)) {
_mouseTrackingWidgets.remove(i);
// std.algorithm.remove does not work for me
//_mouseTrackingWidgets.remove(i);
for (int j = i; j < _mouseTrackingWidgets.length - 1; j++)
_mouseTrackingWidgets[j] = _mouseTrackingWidgets[j + 1];
_mouseTrackingWidgets.length--;
continue;
}
if (!w.isPointInside(event.x, event.y)) {
@ -154,7 +162,14 @@ class Window {
MouseEvent leaveEvent = new MouseEvent(event);
leaveEvent.changeAction(MouseAction.Leave);
res = w.onMouseEvent(leaveEvent) || res;
_mouseTrackingWidgets.remove(i);
// std.algorithm.remove does not work for me
//Log.d("removeTracking ", w.id, " items before: ", _mouseTrackingWidgets.length);
//_mouseTrackingWidgets.remove(i);
//_mouseTrackingWidgets.length--;
for (int j = i; j < _mouseTrackingWidgets.length - 1; j++)
_mouseTrackingWidgets[j] = _mouseTrackingWidgets[j + 1];
_mouseTrackingWidgets.length--;
//Log.d("removeTracking ", w.id, " items after: ", _mouseTrackingWidgets.length);
}
}
return res;

View File

@ -48,6 +48,7 @@ class MenuItemWidget : HorizontalLayout {
protected MenuItem _item;
protected TextWidget _label;
this(MenuItem item) {
id="menuitem";
_item = item;
styleId = "MENU_ITEM";
_label = new TextWidget("MENU_LABEL");
@ -65,10 +66,6 @@ class MainMenu : HorizontalLayout {
_item = item;
for (int i = 0; i < item.subitemCount; i++) {
MenuItemWidget subitem = new MenuItemWidget(item.subitem(i));
if (i == 1)
subitem.setState(State.Focused);
else if (i == 2)
subitem.setState(State.Pressed);
addChild(subitem);
}

View File

@ -665,10 +665,10 @@ Theme createDefaultTheme() {
//res.dumpStats();
Style mainMenu = res.createSubstyle("MAIN_MENU").backgroundColor(0xE0E0E0).layoutWidth(FILL_PARENT);
Style menuItem = res.createSubstyle("MENU_ITEM").padding(Rect(4,2,4,2)).backgroundColor(0xE0E080) ;
Style menuItem = res.createSubstyle("MENU_ITEM").padding(Rect(4,2,4,2)); //.backgroundColor(0xE0E080) ;
menuItem.createState(State.Focused, State.Focused).backgroundColor(0x40C0C000);
menuItem.createState(State.Pressed, State.Pressed).backgroundColor(0x4080C000);
menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0x80E0E000);
menuItem.createState(State.Hovered, State.Hovered).backgroundColor(0x80FFFF00);
return res;
}

View File

@ -306,7 +306,7 @@ class Widget {
/// process mouse event; return true if event is processed by widget.
bool onMouseEvent(MouseEvent event) {
//Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
Log.d("onMouseEvent ", id, " ", event.action, " (", event.x, ",", event.y, ")");
// support onClick
if (_onClickListener !is null) {
if (event.action == MouseAction.ButtonDown && event.button == MouseButton.Left) {