示例#1
0
 public void OnKey(NkKeys Key, bool Down)
 {
     Events.Enqueue(new NuklearEvent()
     {
         EvtType = NuklearEvent.EventType.KeyboardKey, Key = Key, Down = Down
     });
 }
        public static int nk_input_is_key_pressed(nk_input i, NkKeys key)
        {
            nk_key *k;

            if (i == null)
            {
                return((int)(nk_false));
            }
            k = (nk_key *)i.keyboard.Keys + (int)key;
            if ((((k->down) != 0) && ((k->clicked) != 0)) || ((k->down == 0) && ((k->clicked) >= (2))))
            {
                return((int)(nk_true));
            }
            return((int)(nk_false));
        }
        public static void nk_textedit_key(nk_text_edit state, NkKeys key, int shift_mod, NkUserFont font, float row_height)
        {
retry:
            ;
            switch (key)
            {
            case NkKeys.NONE:
            case NkKeys.CTRL:
            case NkKeys.ENTER:
            case NkKeys.SHIFT:
            case NkKeys.TAB:
            case NkKeys.COPY:
            case NkKeys.CUT:
            case NkKeys.PASTE:
            case NkKeys.MAX:
            default:
                break;

            case NkKeys.TEXT_UNDO:
                nk_textedit_undo(state);
                state.has_preferred_x = (byte)(0);
                break;

            case NkKeys.TEXT_REDO:
                nk_textedit_redo(state);
                state.has_preferred_x = (byte)(0);
                break;

            case NkKeys.TEXT_SELECT_ALL:
                nk_textedit_select_all(state);
                state.has_preferred_x = (byte)(0);
                break;

            case NkKeys.TEXT_INSERT_MODE:
                if ((state.mode) == (NkTextEditMode.VIEW))
                {
                    state.mode = (NkTextEditMode.INSERT);
                }
                break;

            case NkKeys.TEXT_REPLACE_MODE:
                if ((state.mode) == (NkTextEditMode.VIEW))
                {
                    state.mode = (NkTextEditMode.REPLACE);
                }
                break;

            case NkKeys.TEXT_RESET_MODE:
                if (((state.mode) == (NkTextEditMode.INSERT)) || ((state.mode) == (NkTextEditMode.REPLACE)))
                {
                    state.mode = (byte)(NkTextEditMode.VIEW);
                }
                break;

            case NkKeys.LEFT:
                if ((shift_mod) != 0)
                {
                    nk_textedit_clamp(state);
                    nk_textedit_prep_selection_at_cursor(state);
                    if ((state.select_end) > (0))
                    {
                        --state.select_end;
                    }
                    state.cursor          = (int)(state.select_end);
                    state.has_preferred_x = (byte)(0);
                }
                else
                {
                    if (((state).select_start != (state).select_end))
                    {
                        nk_textedit_move_to_first(state);
                    }
                    else if ((state.cursor) > (0))
                    {
                        --state.cursor;
                    }
                    state.has_preferred_x = (byte)(0);
                }
                break;

            case NkKeys.RIGHT:
                if ((shift_mod) != 0)
                {
                    nk_textedit_prep_selection_at_cursor(state);
                    ++state.select_end;
                    nk_textedit_clamp(state);
                    state.cursor          = (int)(state.select_end);
                    state.has_preferred_x = (byte)(0);
                }
                else
                {
                    if (((state).select_start != (state).select_end))
                    {
                        nk_textedit_move_to_last(state);
                    }
                    else
                    {
                        ++state.cursor;
                    }
                    nk_textedit_clamp(state);
                    state.has_preferred_x = (byte)(0);
                }
                break;

            case NkKeys.TEXT_WORD_LEFT:
                if ((shift_mod) != 0)
                {
                    if (!((state).select_start != (state).select_end))
                    {
                        nk_textedit_prep_selection_at_cursor(state);
                    }
                    state.cursor     = (int)(nk_textedit_move_to_word_previous(state));
                    state.select_end = (int)(state.cursor);
                    nk_textedit_clamp(state);
                }
                else
                {
                    if (((state).select_start != (state).select_end))
                    {
                        nk_textedit_move_to_first(state);
                    }
                    else
                    {
                        state.cursor = (int)(nk_textedit_move_to_word_previous(state));
                        nk_textedit_clamp(state);
                    }
                }
                break;

            case NkKeys.TEXT_WORD_RIGHT:
                if ((shift_mod) != 0)
                {
                    if (!((state).select_start != (state).select_end))
                    {
                        nk_textedit_prep_selection_at_cursor(state);
                    }
                    state.cursor     = (int)(nk_textedit_move_to_word_next(state));
                    state.select_end = (int)(state.cursor);
                    nk_textedit_clamp(state);
                }
                else
                {
                    if (((state).select_start != (state).select_end))
                    {
                        nk_textedit_move_to_last(state);
                    }
                    else
                    {
                        state.cursor = (int)(nk_textedit_move_to_word_next(state));
                        nk_textedit_clamp(state);
                    }
                }
                break;

            case NkKeys.DOWN:
            {
                nk_text_find     find = new nk_text_find();
                nk_text_edit_row row  = new nk_text_edit_row();
                int i;
                int sel = (int)(shift_mod);
                if ((state.single_line) != 0)
                {
                    key = (NkKeys.RIGHT);
                    goto retry;
                }
                if ((sel) != 0)
                {
                    nk_textedit_prep_selection_at_cursor(state);
                }
                else if (((state).select_start != (state).select_end))
                {
                    nk_textedit_move_to_last(state);
                }
                nk_textedit_clamp(state);
                nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                if ((find.length) != 0)
                {
                    float x;
                    float goal_x = (float)((state.has_preferred_x) != 0 ? state.preferred_x : find.x);
                    int   start  = (int)(find.first_char + find.length);
                    state.cursor = (int)(start);
                    nk_textedit_layout_row(&row, state, (int)(state.cursor), (float)(row_height), font);
                    x = (float)(row.x0);
                    for (i = (int)(0); ((i) < (row.num_chars)) && ((x) < (row.x1)); ++i)
                    {
                        float dx = (float)(nk_textedit_get_width(state, (int)(start), (int)(i), font));
                        x += (float)(dx);
                        if ((x) > (goal_x))
                        {
                            break;
                        }
                        ++state.cursor;
                    }
                    nk_textedit_clamp(state);
                    state.has_preferred_x = (byte)(1);
                    state.preferred_x     = (float)(goal_x);
                    if ((sel) != 0)
                    {
                        state.select_end = (int)(state.cursor);
                    }
                }
            }
            break;

            case NkKeys.UP:
            {
                nk_text_find     find = new nk_text_find();
                nk_text_edit_row row  = new nk_text_edit_row();
                int i;
                int sel = (int)(shift_mod);
                if ((state.single_line) != 0)
                {
                    key = (NkKeys.LEFT);
                    goto retry;
                }
                if ((sel) != 0)
                {
                    nk_textedit_prep_selection_at_cursor(state);
                }
                else if (((state).select_start != (state).select_end))
                {
                    nk_textedit_move_to_first(state);
                }
                nk_textedit_clamp(state);
                nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                if (find.prev_first != find.first_char)
                {
                    float x;
                    float goal_x = (float)((state.has_preferred_x) != 0 ? state.preferred_x : find.x);
                    state.cursor = (int)(find.prev_first);
                    nk_textedit_layout_row(&row, state, (int)(state.cursor), (float)(row_height), font);
                    x = (float)(row.x0);
                    for (i = (int)(0); ((i) < (row.num_chars)) && ((x) < (row.x1)); ++i)
                    {
                        float dx = (float)(nk_textedit_get_width(state, (int)(find.prev_first), (int)(i), font));
                        x += (float)(dx);
                        if ((x) > (goal_x))
                        {
                            break;
                        }
                        ++state.cursor;
                    }
                    nk_textedit_clamp(state);
                    state.has_preferred_x = (byte)(1);
                    state.preferred_x     = (float)(goal_x);
                    if ((sel) != 0)
                    {
                        state.select_end = (int)(state.cursor);
                    }
                }
            }
            break;

            case NkKeys.DEL:
                if ((state.mode) == (NkTextEditMode.VIEW))
                {
                    break;
                }
                if (((state).select_start != (state).select_end))
                {
                    nk_textedit_delete_selection(state);
                }
                else
                {
                    int n = (int)(state._string_.Len);
                    if ((state.cursor) < (n))
                    {
                        nk_textedit_delete(state, (int)(state.cursor), (int)(1));
                    }
                }
                state.has_preferred_x = (byte)(0);
                break;

            case NkKeys.BACKSPACE:
                if ((state.mode) == (NkTextEditMode.VIEW))
                {
                    break;
                }
                if (((state).select_start != (state).select_end))
                {
                    nk_textedit_delete_selection(state);
                }
                else
                {
                    nk_textedit_clamp(state);
                    if ((state.cursor) > (0))
                    {
                        nk_textedit_delete(state, (int)(state.cursor - 1), (int)(1));
                        --state.cursor;
                    }
                }
                state.has_preferred_x = (byte)(0);
                break;

            case NkKeys.TEXT_START:
                if ((shift_mod) != 0)
                {
                    nk_textedit_prep_selection_at_cursor(state);
                    state.cursor          = (int)(state.select_end = (int)(0));
                    state.has_preferred_x = (byte)(0);
                }
                else
                {
                    state.cursor          = (int)(state.select_start = (int)(state.select_end = (int)(0)));
                    state.has_preferred_x = (byte)(0);
                }
                break;

            case NkKeys.TEXT_END:
                if ((shift_mod) != 0)
                {
                    nk_textedit_prep_selection_at_cursor(state);
                    state.cursor          = (int)(state.select_end = (int)(state._string_.Len));
                    state.has_preferred_x = (byte)(0);
                }
                else
                {
                    state.cursor          = (int)(state._string_.Len);
                    state.select_start    = (int)(state.select_end = (int)(0));
                    state.has_preferred_x = (byte)(0);
                }
                break;

            case NkKeys.TEXT_LINE_START:
            {
                if ((shift_mod) != 0)
                {
                    nk_text_find find = new nk_text_find();
                    nk_textedit_clamp(state);
                    nk_textedit_prep_selection_at_cursor(state);
                    if (((state._string_.Len) != 0) && ((state.cursor) == (state._string_.Len)))
                    {
                        --state.cursor;
                    }
                    nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                    state.cursor          = (int)(state.select_end = (int)(find.first_char));
                    state.has_preferred_x = (byte)(0);
                }
                else
                {
                    nk_text_find find = new nk_text_find();
                    if (((state._string_.Len) != 0) && ((state.cursor) == (state._string_.Len)))
                    {
                        --state.cursor;
                    }
                    nk_textedit_clamp(state);
                    nk_textedit_move_to_first(state);
                    nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                    state.cursor          = (int)(find.first_char);
                    state.has_preferred_x = (byte)(0);
                }
            }
            break;

            case NkKeys.TEXT_LINE_END:
            {
                if ((shift_mod) != 0)
                {
                    nk_text_find find = new nk_text_find();
                    nk_textedit_clamp(state);
                    nk_textedit_prep_selection_at_cursor(state);
                    nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                    state.has_preferred_x = (byte)(0);
                    state.cursor          = (int)(find.first_char + find.length);
                    if (((find.length) > (0)) && ((state._string_[(int)(state.cursor - 1)]) == ('\n')))
                    {
                        --state.cursor;
                    }
                    state.select_end = (int)(state.cursor);
                }
                else
                {
                    nk_text_find find = new nk_text_find();
                    nk_textedit_clamp(state);
                    nk_textedit_move_to_first(state);
                    nk_textedit_find_charpos(&find, state, (int)(state.cursor), (int)(state.single_line), font, (float)(row_height));
                    state.has_preferred_x = (byte)(0);
                    state.cursor          = (int)(find.first_char + find.length);
                    if (((find.length) > (0)) && ((state._string_[(int)(state.cursor - 1)]) == ('\n')))
                    {
                        --state.cursor;
                    }
                }
            }
            break;
            }
        }
示例#4
0
        static void LoadContent()
        {
            string GameDllPath = Path.Combine(CVar.GetString("game"), "Game.dll");

            if (!File.Exists(GameDllPath))
            {
                FatalError("File not found: {0}", GameDllPath);
            }

            Assembly GameAssembly = Reflect.LoadAssembly(GameDllPath);

            Importers.RegisterAll(GameAssembly);

            Type[] GameImplementations = Reflect.GetAllImplementationsOf(GameAssembly, typeof(LibTechGame)).ToArray();

            if (GameImplementations.Length == 0)
            {
                FatalError("Could not find game implementation in {0}", GameDllPath);
            }
            if (GameImplementations.Length > 1)
            {
                FatalError("Found too many game implementations in {0}", GameDllPath);
            }

            Game = (LibTechGame)Activator.CreateInstance(GameImplementations[0]);
            Game.Load();

            RenderDevice = new RenderDevice(ShaderProgram.GUI, Width, Height);
            NuklearAPI.Init(RenderDevice);
            NuklearAPI.SetClipboardCallback((Txt) => {
                if (string.IsNullOrEmpty(Txt))
                {
                    return;
                }

                Glfw.SetClipboardString(Window, Txt);
            }, () => {
                string Str = Glfw.GetClipboardString(Window);
                if (Str == null)
                {
                    Str = "";
                }

                return(Str);
            });

            Glfw.SetCursorPosCallback(Window, (Wnd, X, Y) => {
                RenderDevice.OnMouseMove((int)X, (int)Y);
            });

            Glfw.SetMouseButtonCallback(Window, (Wnd, Button, State, Mods) => {
                NuklearEvent.MouseButton NkButton;
                bool IsDown = State == Glfw.InputState.Press ? true : false;

                if (!(State == Glfw.InputState.Press || State == Glfw.InputState.Release))
                {
                    return;
                }

                if (Button == Glfw.MouseButton.ButtonLeft)
                {
                    NkButton = NuklearEvent.MouseButton.Left;
                }
                else if (Button == Glfw.MouseButton.ButtonMiddle)
                {
                    NkButton = NuklearEvent.MouseButton.Middle;
                }
                else if (Button == Glfw.MouseButton.ButtonRight)
                {
                    NkButton = NuklearEvent.MouseButton.Right;
                }
                else
                {
                    return;
                }

                RenderDevice.OnMouseButton(NkButton, (int)MousePos.X, (int)MousePos.Y, IsDown);
            });

            Glfw.SetScrollCallback(Window, (Wnd, X, Y) => {
                RenderDevice.OnScroll((float)X, (float)Y);
            });

            Glfw.SetCharCallback(Window, (Wnd, Chr) => {
                RenderDevice.OnText(((char)Chr).ToString());
            });

            Glfw.SetKeyCallback(Window, (Wnd, KCode, SCode, State, Mods) => {
                if (KCode == Glfw.KeyCode.F1 && State == Glfw.InputState.Press)
                {
                    GConsole.Open = true;
                }

                NkKeys K = ConvertToNkKey(KCode, Mods);

                if (K != NkKeys.None)
                {
                    RenderDevice.OnKey(K, State == Glfw.InputState.Press);
                    if (State == Glfw.InputState.Repeat)
                    {
                        RenderDevice.OnKey(K, true);
                    }
                }
            });

            Glfw.SetDropCallback(Window, (Wnd, Cnt, Paths) => {
                DragDropPaths = Paths;
            });
        }
示例#5
0
 public static bool IsKeyPressed(NkKeys Key)
 {
     //Nuklear.nk_input_is_key_pressed()
     return(Nuklear.nk_input_is_key_pressed(&Ctx->input, Key) != 0);
 }
 public void InputKey(NkKeys key, bool down)
 {
     Nk.nk_input_key(_ctx, key, down ? 1 : 0);
 }
示例#7
0
 public static extern int nk_input_is_key_down(nk_input *inp, NkKeys keys);
示例#8
0
 public static extern int nk_input_is_key_released(nk_input *inp, NkKeys keys);
示例#9
0
 public static extern void nk_input_key(nk_context *context, NkKeys keys, int down);