aboutsummaryrefslogtreecommitdiffstats
path: root/ardor3d-examples/.settings/org.eclipse.jdt.ui.prefs
blob: 2cb0f4c6d13d54980e5ef31f508a302f12661db2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=true
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_serial_version_id=true
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=true
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=true
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=true
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=false
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=false
cleanup.remove_private_constructors=true
cleanup.remove_trailing_whitespaces=true
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=false
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=false
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_parentheses_in_expressions=false
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup_profile=_ArdorLabs
cleanup_settings_version=2
eclipse.preferences.version=1
editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true
formatter_profile=_ArdorLabs
formatter_settings_version=11
org.eclipse.jdt.ui.exception.name=ex
org.eclipse.jdt.ui.gettersetter.use.is=true
org.eclipse.jdt.ui.javadoc=false
org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="true" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment">/**\r\n * @return the ${bare_field_name}\r\n */</template><template autoinsert\="true" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment">/**\r\n * @param ${param} the ${bare_field_name} to set\r\n */</template><template autoinsert\="true" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * \r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="true" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment">/**\r\n * \r\n */</template><template autoinsert\="true" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment">/**\r\n * ${tags}\r\n */</template><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="true" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment">/**\r\n * ${tags}\r\n * ${see_to_target}\r\n */</template><template autoinsert\="false" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">/**\r\n * Copyright (c) 2008-2010 Ardor Labs, Inc.\r\n *\r\n * This file is part of Ardor3D.\r\n *\r\n * Ardor3D is free software\: you can redistribute it and/or modify it \r\n * under the terms of its license which may be found in the accompanying\r\n * LICENSE file or at &lt;http\://www.ardor3d.com/LICENSE&gt;.\r\n */\r\n\r\n${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="true" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">// ${todo} Auto-generated catch block\r\n${exception_var}.printStackTrace();</template><template autoinsert\="true" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">// ${todo} Auto-generated method stub\r\n${body_statement}</template><template autoinsert\="true" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}\r\n// ${todo} Auto-generated constructor stub</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
sp_cleanup.add_missing_deprecated_annotations=true
sp_cleanup.add_missing_methods=false
sp_cleanup.add_missing_nls_tags=false
sp_cleanup.add_missing_override_annotations=true
sp_cleanup.add_serial_version_id=false
sp_cleanup.always_use_blocks=true
sp_cleanup.always_use_parentheses_in_expressions=false
sp_cleanup.always_use_this_for_non_static_field_access=false
sp_cleanup.always_use_this_for_non_static_method_access=false
sp_cleanup.convert_to_enhanced_for_loop=false
sp_cleanup.correct_indentation=true
sp_cleanup.format_source_code=true
sp_cleanup.format_source_code_changes_only=false
sp_cleanup.make_local_variable_final=true
sp_cleanup.make_parameters_final=true
sp_cleanup.make_private_fields_final=true
sp_cleanup.make_type_abstract_if_missing_method=false
sp_cleanup.make_variable_declarations_final=true
sp_cleanup.never_use_blocks=false
sp_cleanup.never_use_parentheses_in_expressions=true
sp_cleanup.on_save_use_additional_actions=true
sp_cleanup.organize_imports=true
sp_cleanup.qualify_static_field_accesses_with_declaring_class=false
sp_cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
sp_cleanup.qualify_static_member_accesses_with_declaring_class=true
sp_cleanup.qualify_static_method_accesses_with_declaring_class=false
sp_cleanup.remove_private_constructors=true
sp_cleanup.remove_trailing_whitespaces=true
sp_cleanup.remove_trailing_whitespaces_all=true
sp_cleanup.remove_trailing_whitespaces_ignore_empty=false
sp_cleanup.remove_unnecessary_casts=true
sp_cleanup.remove_unnecessary_nls_tags=true
sp_cleanup.remove_unused_imports=true
sp_cleanup.remove_unused_local_variables=false
sp_cleanup.remove_unused_private_fields=true
sp_cleanup.remove_unused_private_members=false
sp_cleanup.remove_unused_private_methods=true
sp_cleanup.remove_unused_private_types=true
sp_cleanup.sort_members=false
sp_cleanup.sort_members_all=false
sp_cleanup.use_blocks=true
sp_cleanup.use_blocks_only_for_return_and_throw=false
sp_cleanup.use_parentheses_in_expressions=false
sp_cleanup.use_this_for_non_static_field_access=true
sp_cleanup.use_this_for_non_static_field_access_only_if_necessary=true
sp_cleanup.use_this_for_non_static_method_access=true
sp_cleanup.use_this_for_non_static_method_access_only_if_necessary=true
/a> 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932
/************************************************************************************

Filename    :   OptionMenu.h
Content     :   Option selection and editing for OculusWorldDemo
Created     :   March 7, 2014
Authors     :   Michael Antonov, Caleb Leak

Copyright   :   Copyright 2012 Oculus VR, Inc. All Rights reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

*************************************************************************************/

#include "OptionMenu.h"

// Embed the font.
#include "../Render/Render_FontEmbed_DejaVu48.h"


//-------------------------------------------------------------------------------------
bool OptionShortcut::MatchKey(OVR::KeyCode key, bool shift) const
{
    for (uint32_t i = 0; i < Keys.GetSize(); i++)
    {
        if (Keys[i].Key != key)
            continue;
        
        if (!shift && Keys[i].ShiftUsage == ShortcutKey::Shift_RequireOn)
            continue;

        if (shift && Keys[i].ShiftUsage == ShortcutKey::Shift_RequireOff)
            continue;

        if(Keys[i].ShiftUsage == ShortcutKey::Shift_Modify)
        {
            pNotify->CallNotify(&shift);
        }
        else
        {
            pNotify->CallNotify();
        }
        return true;
    }
    return false;
}

bool OptionShortcut::MatchGamepadButton(uint32_t gamepadButtonMask) const
{
    for (uint32_t i = 0; i < GamepadButtons.GetSize(); i++)
    {
        if (GamepadButtons[i] & gamepadButtonMask)
        {
            if (pNotify != NULL)
            {
                pNotify->CallNotify();
            }
            return true;
        }
    }
    return false;
}


//-------------------------------------------------------------------------------------
String OptionMenuItem::PopNamespaceFrom(OptionMenuItem* menuItem)
{
    String label = menuItem->Label;
    for (uint32_t i = 0; i < label.GetLength(); i++)
    {
        if (label.GetCharAt(i) == '.')
        {
            String ns = label.Substring(0, i);
            menuItem->Label = label.Substring(i + 1, label.GetLength());
            return ns;
        }
    }
    return "";
}

//-------------------------------------------------------------------------------------

String OptionVar::FormatEnum(OptionVar* var)
{
    uint32_t index = var->GetEnumIndex();
    if (index < var->EnumValues.GetSize())
        return var->EnumValues[index].Name;
    return String("<Bad enum index>");    
}

String OptionVar::FormatInt(OptionVar* var)
{
    char buff[64];
    OVR_sprintf(buff, sizeof(buff), var->FormatString, *var->AsInt());
    return String(buff);
}

String OptionVar::FormatFloat(OptionVar* var)
{
    char buff[64];
    OVR_sprintf(buff, sizeof(buff), var->FormatString, *var->AsFloat() * var->FormatScale);
    return String(buff);
}

String OptionVar::FormatBool(OptionVar* var)
{
    return *var->AsBool() ? "On" : "Off";
}

String OptionVar::FormatTrigger(OptionVar* var)
{
	OVR_UNUSED(var);
    return "[Trigger]";
}


OptionVar::OptionVar(const char* name, void* pvar, VarType type,
                     FormatFunction formatFunction,
                     UpdateFunction updateFunction)
{
    Label       = name;
    Type        = type;
    this->pVar  = pvar;
    fFormat     = ((Type == Type_Trigger) && !formatFunction) ? FormatTrigger : formatFunction;
    fUpdate     = updateFunction;
    pNotify     = 0;
    FormatString= 0;

    MaxFloat    = MATH_FLOAT_MAXVALUE;
    MinFloat    = -MATH_FLOAT_MAXVALUE;
    StepFloat   = 1.0f;
    FormatScale = 1.0f;

    MaxInt      = 0x7FFFFFFF;
    MinInt      = -(MaxInt) - 1;
    StepInt     = 1;

    SelectedIndex = 0;

    ShortcutUp.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::NextValue);
    ShortcutDown.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::PrevValue);
}

OptionVar::OptionVar(const char* name, int32_t* pvar,
                     int32_t min, int32_t max, int32_t stepSize,
                     const char* formatString,
                     FormatFunction formatFunction,
                     UpdateFunction updateFunction)
{
    Label       = name;
    Type        = Type_Int;
    this->pVar  = pvar;
    fFormat     = formatFunction ? formatFunction : FormatInt;
    fUpdate     = updateFunction;
    pNotify     = 0;
    FormatString= formatString;

    MinInt      = min;
    MaxInt      = max;
    StepInt     = stepSize;

    SelectedIndex = 0;

    ShortcutUp.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::NextValue);
    ShortcutDown.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::PrevValue);
}

// Float with range and step size.
OptionVar::OptionVar(const char* name, float* pvar, 
                     float minf, float maxf, float stepSize,
                     const char* formatString, float formatScale,
                     FormatFunction formatFunction, 
                     UpdateFunction updateFunction)
{
    Label       = name;
    Type        = Type_Float;
    this->pVar  = pvar;
    fFormat     = formatFunction ? formatFunction : FormatFloat;
    fUpdate     = updateFunction;
    pNotify     = 0;
    FormatString= formatString ? formatString : "%.3f";

    MinFloat    = minf;
    MaxFloat    = maxf;
    StepFloat   = stepSize;
    FormatScale = formatScale;

    SelectedIndex = 0;

    ShortcutUp.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::NextValue);
    ShortcutDown.pNotify = new FunctionNotifyContext<OptionVar, bool>(this, &OptionVar::PrevValue);
}

OptionVar::~OptionVar()
{
    if (pNotify)
        delete pNotify;
}

void OptionVar::NextValue(bool* pFastStep)
{
    bool fastStep = (pFastStep != NULL && *pFastStep);
    switch (Type)
    {
    case Type_Enum:
        *AsInt() = ((GetEnumIndex() + 1) % EnumValues.GetSize());
        break;

    case Type_Int:
        *AsInt() = Alg::Min<int32_t>(*AsInt() + StepInt * (fastStep ? 5 : 1), MaxInt);
        break;

    case Type_Float:
        // TODO: Will behave strange with NaN values.
        *AsFloat() = Alg::Min<float>(*AsFloat() + StepFloat * (fastStep ? 5.0f : 1.0f), MaxFloat);
        break;

    case Type_Bool:
        *AsBool() = !*AsBool();
        break;

    case Type_Trigger:
        break;  // nothing to do

    default: OVR_ASSERT(false); break; // unhandled
    }

    SignalUpdate();
}

void OptionVar::PrevValue(bool* pFastStep)
{
    bool fastStep = (pFastStep != NULL && *pFastStep);
    switch (Type)
    {
    case Type_Enum:
        *AsInt() = ((GetEnumIndex() + (uint32_t)EnumValues.GetSize() - 1) % EnumValues.GetSize());
        break;

    case Type_Int:
        *AsInt() = Alg::Max<int32_t>(*AsInt() - StepInt * (fastStep ? 5 : 1), MinInt);
        break;

    case Type_Float:
        // TODO: Will behave strange with NaN values.
        *AsFloat() = Alg::Max<float>(*AsFloat() - StepFloat * (fastStep ? 5.0f : 1.0f), MinFloat);
        break;

    case Type_Bool:
        *AsBool() = !*AsBool();
        break;

    case Type_Trigger:
        break;  // nothing to do

    default: OVR_ASSERT(false); break; // unhandled
    }

    SignalUpdate();
}

String OptionVar::HandleShortcutUpdate()
{
    if(Type != Type_Trigger)
    {
        SignalUpdate();
        return Label + " - " + GetValue();
    }
    else
    {
        // Avoid double trigger (shortcut key already triggers NextValue())
        return String("Triggered: ") + Label;
    }
}

String OptionVar::ProcessShortcutKey(OVR::KeyCode key, bool shift)
{
    if (ShortcutUp.MatchKey(key, shift) || ShortcutDown.MatchKey(key, shift))
    {
        return HandleShortcutUpdate();
    }

    return String();
}

String OptionVar::ProcessShortcutButton(uint32_t buttonMask)
{
    if (ShortcutUp.MatchGamepadButton(buttonMask) || ShortcutDown.MatchGamepadButton(buttonMask))
    {
        return HandleShortcutUpdate();
    }
    return String();
}


OptionVar& OptionVar::AddEnumValue(const char* displayName, int32_t value)
{
    EnumEntry entry;
    entry.Name = displayName;
    entry.Value = value;
    EnumValues.PushBack(entry);
    return *this;
}

String OptionVar::GetValue()
{
    if(fFormat == NULL)
        return String();
    else
        return fFormat(this);
}

uint32_t OptionVar::GetEnumIndex()
{
    OVR_ASSERT(Type == Type_Enum);
    OVR_ASSERT(EnumValues.GetSize() > 0);

    // TODO: Change this from a linear search to binary or a hash.
    for (uint32_t i = 0; i < EnumValues.GetSize(); i++)
    {
        if (EnumValues[i].Value == *AsInt())
            return i;
    }

    // Enum values should always be found.
    OVR_ASSERT(false);
    return 0;
}


//-------------------------------------------------------------------------------------

OptionSelectionMenu::OptionSelectionMenu(OptionSelectionMenu* parentMenu)
{
    DisplayState	= Display_None;
    SelectedIndex 	= 0;
    SelectionActive = false;
    ParentMenu 		= parentMenu;

    PopupMessageTimeout = 0.0;
    PopupMessageBorder  = false;

    // Setup handlers for menu navigation actions.
    NavShortcuts[Nav_Up].pNotify = new FunctionNotifyContext<OptionSelectionMenu, bool>(this, &OptionSelectionMenu::HandleUp);
    NavShortcuts[Nav_Down].pNotify = new FunctionNotifyContext<OptionSelectionMenu, bool>(this, &OptionSelectionMenu::HandleDown);
    NavShortcuts[Nav_Left].pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleLeft);
    NavShortcuts[Nav_Right].pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleRight);
    NavShortcuts[Nav_Select].pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleSelect);
    NavShortcuts[Nav_Back].pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleBack);
    ToggleShortcut.pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleMenuToggle);
    ToggleSingleItemShortcut.pNotify = new FunctionNotifySimple<OptionSelectionMenu>(this, &OptionSelectionMenu::HandleSingleItemToggle);

    // Bind keys and buttons to menu navigation actions.
    NavShortcuts[Nav_Up].AddShortcut(ShortcutKey(Key_Up, ShortcutKey::Shift_Modify));
    NavShortcuts[Nav_Up].AddShortcut(Gamepad_Up);

    NavShortcuts[Nav_Down].AddShortcut(ShortcutKey(Key_Down, ShortcutKey::Shift_Modify));
    NavShortcuts[Nav_Down].AddShortcut(Gamepad_Down);

    NavShortcuts[Nav_Left].AddShortcut(ShortcutKey(Key_Left));
    NavShortcuts[Nav_Left].AddShortcut(Gamepad_Left);

    NavShortcuts[Nav_Right].AddShortcut(ShortcutKey(Key_Right));
    NavShortcuts[Nav_Right].AddShortcut(Gamepad_Right);

    NavShortcuts[Nav_Select].AddShortcut(ShortcutKey(Key_Return));
    NavShortcuts[Nav_Select].AddShortcut(Gamepad_A);

    NavShortcuts[Nav_Back].AddShortcut(ShortcutKey(Key_Escape));
    NavShortcuts[Nav_Back].AddShortcut(Gamepad_B);

    ToggleShortcut.AddShortcut(ShortcutKey(Key_Tab, ShortcutKey::Shift_Ignore));
    ToggleShortcut.AddShortcut(Gamepad_Start);

    ToggleSingleItemShortcut.AddShortcut(ShortcutKey(Key_Backspace, ShortcutKey::Shift_Ignore));
}

OptionSelectionMenu::~OptionSelectionMenu()
{
    for (uint32_t i = 0; i < Items.GetSize(); i++)
        delete Items[i];
}

bool OptionSelectionMenu::OnKey(OVR::KeyCode key, int chr, bool down, int modifiers)
{
    bool shift = ((modifiers & Mod_Shift) != 0);
       
    if (down)
    {
        String s = ProcessShortcutKey(key, shift);
        if (!s.IsEmpty())
        {
            PopupMessage  = s;
            PopupMessageTimeout = ovr_GetTimeInSeconds() + 4.0f;
            PopupMessageBorder = false;
            return true;
        }
    }

    if (GetSubmenu() != NULL)
    {
        return GetSubmenu()->OnKey(key, chr, down, modifiers);
    }

    if (down)
    {
        if (ToggleShortcut.MatchKey(key, shift))
            return true;

        if (ToggleSingleItemShortcut.MatchKey(key, shift))
            return true;

        if (DisplayState == Display_None)
            return false;

        for (int i = 0; i < Nav_LAST; i++)
        {
            if (NavShortcuts[i].MatchKey(key, shift))
                return true;
        }
    }

    // Let the caller process keystroke
    return false;
}

bool OptionSelectionMenu::OnGamepad(uint32_t buttonMask)
{
    // Check global shortcuts first.
    String s = ProcessShortcutButton(buttonMask);
    if (!s.IsEmpty())
    {
        PopupMessage  = s;
        PopupMessageTimeout = ovr_GetTimeInSeconds() + 4.0f;
        return true;
    }

    if (GetSubmenu() != NULL)
    {
        return GetSubmenu()->OnGamepad(buttonMask);
    }

    if (ToggleShortcut.MatchGamepadButton(buttonMask))
        return true;

    if (DisplayState == Display_None)
        return false;

    for (int i = 0; i < Nav_LAST; i++)
    {
        if (NavShortcuts[i].MatchGamepadButton(buttonMask))
            return true;
    }

    // Let the caller process keystroke
    return false;
}

String OptionSelectionMenu::ProcessShortcutKey(OVR::KeyCode key, bool shift)
{
    String s;

    for (size_t i = 0; (i < Items.GetSize()) && s.IsEmpty(); i++)
    {
        s = Items[i]->ProcessShortcutKey(key, shift);
    }

    return s;
}

String OptionSelectionMenu::ProcessShortcutButton(uint32_t buttonMask)
{
    String s;

    for (size_t i = 0; (i < Items.GetSize()) && s.IsEmpty(); i++)
    {
        s = Items[i]->ProcessShortcutButton(buttonMask);
    }

    return s;
}

// Fills in inclusive character range; returns false if line not found.
bool FindLineCharRange(const char* text, int searchLine, size_t charRange[2])
{
    size_t i    = 0;
    
    for (int line = 0; line <= searchLine; line ++)
    {
        if (line == searchLine)
        {
            charRange[0] = i;
        }

        // Find end of line.
        while (text[i] != '\n' && text[i] != 0)
        {
            i++;
        }

        if (line == searchLine)
        {            
            charRange[1] = (charRange[0] == i) ? charRange[0] : i-1;
            return true;
        }

        if (text[i] == 0)
            break;
        // Skip newline
        i++;
    }

    return false;
}


void OptionSelectionMenu::Render(RenderDevice* prender, String title)
{
    // If we are invisible, render shortcut notifications.
    // Both child and parent have visible == true even if only child is shown.
    if (DisplayState == Display_None)
    {
        renderShortcutChangeMessage(prender);
        return;
    }

    title += Label;

    // Delegate to sub-menu if active.
    if (GetSubmenu() != NULL)
    {
        if (title.GetSize() > 0)
            title += " > ";

        GetSubmenu()->Render(prender, title);
        return;
    }

    Color focusColor(180, 80, 20, 210);
    Color pickedColor(120, 55, 10, 140);
    Color titleColor(0x18, 0x1A, 0x4D, 210);
    Color titleOutlineColor(0x18, 0x18, 0x18, 240);

    float    labelsSize[2]     = {0.0f, 0.0f};
    float    bufferSize[2]     = {0.0f, 0.0f};
    float    valuesSize[2]     = {0.0f, 0.0f};
    float    maxValueWidth     = 0.0f;

    size_t   selection[2] = { 0, 0 };
    Vector2f labelSelectionRect[2];
    Vector2f valueSelectionRect[2];

    float textSize = 22.0f;
    prender->MeasureText(&DejaVu, "      ", textSize, bufferSize);

    String values;
    String menuItems;

    int highlightIndex = 0;
    if (DisplayState == Display_Menu)
    {
        highlightIndex = SelectedIndex;
        for (uint32_t i = 0; i < Items.GetSize(); i++)
        {
            if (i > 0)
                values += "\n";
            values += Items[i]->GetValue();
        }

        for (uint32_t i = 0; i < Items.GetSize(); i++)
        {
            if (i > 0)
                menuItems += "\n";
            menuItems += Items[i]->GetLabel();
        }
    }
    else
    {
        values = Items[SelectedIndex]->GetValue();
        menuItems = Items[SelectedIndex]->GetLabel();
    }

    // Measure labels
    const char* menuItemsCStr = menuItems.ToCStr();
    bool havelLabelSelection = FindLineCharRange(menuItemsCStr, highlightIndex, selection);
	OVR_UNUSED(havelLabelSelection);
    prender->MeasureText(&DejaVu, menuItemsCStr, textSize, labelsSize,
                         selection, labelSelectionRect);

    // Measure label-to-value gap
    const char* valuesCStr = values.ToCStr();
    bool haveValueSelection = FindLineCharRange(valuesCStr, highlightIndex, selection);
	OVR_UNUSED(haveValueSelection);
    prender->MeasureText(&DejaVu, valuesCStr, textSize, valuesSize, selection, valueSelectionRect);

    // Measure max value size (absolute size varies, so just use a reasonable max)
    maxValueWidth = prender->MeasureText(&DejaVu, "Max value width", textSize);
    maxValueWidth = Alg::Max(maxValueWidth, valuesSize[0]);

    Vector2f borderSize(4.0f, 4.0f);
    Vector2f totalDimensions = borderSize * 2 + Vector2f(bufferSize[0], 0) + Vector2f(maxValueWidth, 0)
                                + Vector2f(labelsSize[0], labelsSize[1]);
    
    Vector2f fudgeOffset= Vector2f(10.0f, 25.0f);  // This offset looks better
    Vector2f topLeft    = (-totalDimensions / 2.0f)  + fudgeOffset;    
    Vector2f bottomRight = topLeft + totalDimensions;

    // If displaying a single item, shift it down.
    if (DisplayState == Display_SingleItem)
    {
        topLeft.y     += textSize * 7;
        bottomRight.y += textSize * 7;
    }

    prender->FillRect(topLeft.x, topLeft.y, bottomRight.x, bottomRight.y, Color(40,40,100,210));

    Vector2f labelsPos = topLeft + borderSize;
    Vector2f valuesPos = labelsPos + Vector2f(labelsSize[0], 0) + Vector2f(bufferSize[0], 0);

    // Highlight selected label
    Vector2f selectionInset = Vector2f(0.3f, 2.0f);
    if (DisplayState == Display_Menu)
    {
        Vector2f labelSelectionTopLeft = labelsPos + labelSelectionRect[0] - selectionInset;
        Vector2f labelSelectionBottomRight = labelsPos + labelSelectionRect[1] + selectionInset;

        prender->FillRect(labelSelectionTopLeft.x, labelSelectionTopLeft.y,
                          labelSelectionBottomRight.x, labelSelectionBottomRight.y,
                          SelectionActive ? pickedColor : focusColor);
    }

    // Highlight selected value if active
    if (SelectionActive)
    {
        Vector2f valueSelectionTopLeft = valuesPos + valueSelectionRect[0] - selectionInset;
        Vector2f valueSelectionBottomRight = valuesPos + valueSelectionRect[1] + selectionInset;
        prender->FillRect(valueSelectionTopLeft.x, valueSelectionTopLeft.y,
                          valueSelectionBottomRight.x, valueSelectionBottomRight.y,
                          focusColor);
    }

    // Measure and draw title
    if (DisplayState == Display_Menu && title.GetLength() > 0)
    {
        Vector2f titleDimensions;
        prender->MeasureText(&DejaVu, title.ToCStr(), textSize, &titleDimensions.x);
        Vector2f titleTopLeft = topLeft - Vector2f(0, borderSize.y) * 2 - Vector2f(0, titleDimensions.y);
        titleDimensions.x = totalDimensions.x;
        
        prender->FillRect(titleTopLeft.x, titleTopLeft.y,
                          titleTopLeft.x + totalDimensions.x,
                          titleTopLeft.y + titleDimensions.y + borderSize.y * 2,
                          titleOutlineColor);
        
        prender->FillRect(titleTopLeft.x + borderSize.x / 2, titleTopLeft.y + borderSize.y / 2,
                          titleTopLeft.x + totalDimensions.x - borderSize.x / 2,
                          titleTopLeft.y + borderSize.y / 2 + titleDimensions.y,
                          titleColor);
                          
        prender->RenderText(&DejaVu, title.ToCStr(), titleTopLeft.x + borderSize.x,
                            titleTopLeft.y + borderSize.y, textSize, Color(255,255,0,210));
    }

    prender->RenderText(&DejaVu, menuItemsCStr, labelsPos.x, labelsPos.y, textSize, Color(255,255,0,210));

    prender->RenderText(&DejaVu, valuesCStr, valuesPos.x, valuesPos.y, textSize, Color(255,255,0,210));
}


void OptionSelectionMenu::renderShortcutChangeMessage(RenderDevice* prender)
{
    if (ovr_GetTimeInSeconds() < PopupMessageTimeout)
    {
        DrawTextBox(prender, 0, 120, 22.0f, PopupMessage.ToCStr(),
                    DrawText_Center | (PopupMessageBorder ? DrawText_Border : 0));
    }
}


void OptionSelectionMenu::SetPopupMessage(const char* format, ...)
{
    //Lock::Locker lock(pManager->GetHandlerLock());
    char textBuff[2048];
    va_list argList;
    va_start(argList, format);
    OVR_vsprintf(textBuff, sizeof(textBuff), format, argList);
    va_end(argList);

    // Message will time out in 4 seconds.
    PopupMessage = textBuff;
    PopupMessageTimeout = ovr_GetTimeInSeconds() + 4.0f;
    PopupMessageBorder = false;
}

void OptionSelectionMenu::SetPopupTimeout(double timeoutSeconds, bool border)
{
    PopupMessageTimeout = ovr_GetTimeInSeconds() + timeoutSeconds;
    PopupMessageBorder = border;
}



void OptionSelectionMenu::AddItem(OptionMenuItem* menuItem)
{
    String ns = PopNamespaceFrom(menuItem);

    if (ns.GetLength() == 0)
    {
        Items.PushBack(menuItem);
    }
    else
    {
        // Item is part of a submenu, add it to that instead.
        GetOrCreateSubmenu(ns)->AddItem(menuItem);
    }
}

//virtual 
void OptionSelectionMenu::Select()
{
    SelectedIndex = 0;
    SelectionActive = false;
    DisplayState = Display_Menu;
}


OptionSelectionMenu* OptionSelectionMenu::GetSubmenu()
{
    if (!SelectionActive || !Items[SelectedIndex]->IsMenu())
        return NULL;

    OptionSelectionMenu* submenu = static_cast<OptionSelectionMenu*>(Items[SelectedIndex]);
    return submenu;
}


OptionSelectionMenu* OptionSelectionMenu::GetOrCreateSubmenu(String submenuName)
{
    for (uint32_t i = 0; i < Items.GetSize(); i++)
    {
        if (!Items[i]->IsMenu())
            continue;

        OptionSelectionMenu* submenu = static_cast<OptionSelectionMenu*>(Items[i]);

        if (submenu->Label == submenuName)
        {
            return submenu;
        }
    }

    // Submenu doesn't exist, create it.
    OptionSelectionMenu* newSubmenu = new OptionSelectionMenu(this);
    newSubmenu->Label = submenuName;
    Items.PushBack(newSubmenu);
    return newSubmenu;
}

void OptionSelectionMenu::HandleUp(bool* pFast)
{
    int numItems = (int)Items.GetSize();
    if (SelectionActive)
        Items[SelectedIndex]->NextValue(pFast);
    else
        SelectedIndex = ((SelectedIndex - 1 + numItems) % numItems);
}

void OptionSelectionMenu::HandleDown(bool* pFast)
{
    if (SelectionActive)
        Items[SelectedIndex]->PrevValue(pFast);
    else
        SelectedIndex = ((SelectedIndex + 1) % Items.GetSize());
}

void OptionSelectionMenu::HandleLeft()
{