diff options
| author | ruki <[email protected]> | 2017-12-16 00:57:23 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-12-15 23:44:19 +0800 |
| commit | e5ed897840214b66fd746292fff15c56606d3251 (patch) | |
| tree | 6a5820bfcb1acf95536b673cd79587aff198dab5 /xmake/core/ui/event.lua | |
| parent | d81f894af27987981ef3fe39e013ad3f1fadfbcf (diff) | |
add event to ui
Diffstat (limited to 'xmake/core/ui/event.lua')
| -rw-r--r-- | xmake/core/ui/event.lua | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/xmake/core/ui/event.lua b/xmake/core/ui/event.lua new file mode 100644 index 000000000..82beb7959 --- /dev/null +++ b/xmake/core/ui/event.lua @@ -0,0 +1,62 @@ +--!A cross-platform build utility based on Lua +-- +-- Licensed to the Apache Software Foundation (ASF) under one +-- or more contributor license agreements. See the NOTICE file +-- distributed with this work for additional information +-- regarding copyright ownership. The ASF licenses this file +-- to you 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. +-- +-- Copyright (C) 2015 - 2017, TBOOX Open Source Group. +-- +-- @author ruki +-- @file event.lua +-- + +--[[ Console User Interface (cui) ]----------------------------------------- +Author: Tiago Dionizio (tiago.dionizio AT gmail.com) +$Id: event.lua 18 2007-06-21 20:43:52Z tngd $ +--------------------------------------------------------------------------]] + +-- load modules +local object = require("ui/object") + +-- define module +local event = event or object { _init = {"type", "command", "extra"} } + +-- register event types +function event:register(tag, ...) + local base = self[tag] or 0 + local enums = {...} + local n = #enums + for i = 1, n do + self[enums[i]] = i + base + end + self[tag] = base + n +end + +-- register event types, event.ev_keyboard = 1, event.ev_mouse = 2, ... , event.ev_idle = 5, event.ev_max = 5 +event:register("ev_max", "ev_keyboard", "ev_mouse", "ev_command", "ev_broadcast", "ev_idle") + +-- define keyboard event +-- +-- keyname = key name +-- keycode = key code +-- keymeta = ALT key was pressed +-- +event.keyboard = object {_init = { "key_code", "key_name", "key_meta" }, type = event.ev_keyboard} + +-- define idle event +event.idle = object {_init = {}, type = event.ev_idle} + +-- return module +return event |
