wc3campaigns
WC3C Homepage - www.wc3c.netUser Control Panel (Requires Log-In)Engage in discussions with other users and join contests in the WC3C forums!Read one of our many tutorials, ranging in difficulty from beginner to advanced!Show off your artistic talents in the WC3C Gallery!Download quality models, textures, spells (vJASS/JASS), systems, and scripts!Download maps that have passed through our rigorous approval process!

Go Back   Wc3C.net > Ghost Forums > The Pastebin
User Name
Password
Register Rules Get Hosted! Chat Pastebin FAQ and Rules Members List Calendar



Reply
 
Thread Tools Search this Thread
Old 04-02-2010, 06:42 PM   #1
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default RtC Input API

Collapse KeyboardAPI:
library KeyboardAPI initializer Init requires Table
    globals        
        // - Keyboard Constants
        constant integer EVENT_KEY_UP               = 0
        constant integer EVENT_KEY_DOWN             = 1
        constant integer EVENT_KEY_TYPE             = 2

    endglobals
        // - Keyboard Natives
        
        native TriggerRegisterKeyEvent takes trigger trig, integer key returns nothing
        native GetTriggerKey takes nothing returns integer
        native SetKeyBlock takes integer key, boolean doBlock returns nothing
        
        
        // - Added Functions
        /*
        IsKeyPressed takes integer k returns boolean
        String2Key takes string s returns integer
        Key2String takes integer k returns string
        */
    globals
        private StringTable string2Key // pretend this is an array
        private string array key2String
        private boolean array isPressed[256]
        private trigger onPress = CreateTrigger()
        private trigger onRelease = CreateTrigger()
    endglobals
    
    private function onPressFunc takes nothing returns nothing
        set isPressed[GetTriggerKey()] = true
    endfunction
    
    private function onReleaseFunc takes nothing returns nothing
        set isPressed[GetTriggerKey()] = false
    endfunction
    
    function IsKeyPressed takes integer k returns boolean
        return isPressed[k]
    endfunction
    
    function String2Key takes string s returns integer
        return string2Key[s]
    endfunction
    
    function Key2String takes integer k returns string
        return key2String[k]
    endfunction
        
    
    private function Init takes nothing returns nothing
        set string2Key = StringTable.create()
        set key2String[0x01] = "LBUTTON"
        set key2String[0x02] = "RBUTTON"
        set key2String[0x03] = "CANCEL"
        set key2String[0x04] = "MBUTTON"
        set key2String[0x05] = "XBUTTON1"
        set key2String[0x06] = "XBUTTON2"
        set key2String[0x07] = "0x07"           // unassigned
        set key2String[0x08] = "BACK"
        set key2String[0x09] = "TAB"
        set key2String[0x0A] = "0x0A"           // reserved
        set key2String[0x0B] = "0x0B"           // reserved
        set key2String[0x0C] = "CLEAR"
        set key2String[0x0D] = "RETURN"
        set key2String[0x0E] = "0x0E"           // unassigned
        set key2String[0x0F] = "0x0F"           // unassigned
        set key2String[0x10] = "SHIFT"
        set key2String[0x11] = "CONTROL"
        set key2String[0x12] = "MENU"
        set key2String[0x13] = "PAUSE"
        set key2String[0x14] = "CAPITAL"
        set key2String[0x15] = "KANA"
        set key2String[0x16] = "0x16"           // unassigned
        set key2String[0x17] = "JUNJA"
        set key2String[0x18] = "FINAL"
        set key2String[0x19] = "KANJI"
        set key2String[0x1A] = "0x1A"           // unassigned
        set key2String[0x1B] = "ESCAPE"
        set key2String[0x1C] = "CONVERT"
        set key2String[0x1D] = "NONCONVERT"
        set key2String[0x1E] = "ACCEPT"
        set key2String[0x1F] = "MODECHANGE"
        set key2String[0x20] = "SPACE"
        set key2String[0x21] = "PRIOR"
        set key2String[0x22] = "NEXT"
        set key2String[0x23] = "END"
        set key2String[0x24] = "HOME"
        set key2String[0x25] = "LEFT"
        set key2String[0x26] = "UP"
        set key2String[0x27] = "RIGHT"
        set key2String[0x28] = "DOWN"
        set key2String[0x29] = "SELECT"
        set key2String[0x2A] = "PRINT"
        set key2String[0x2B] = "EXECUTE"
        set key2String[0x2C] = "SNAPSHOT"
        set key2String[0x2D] = "INSERT"
        set key2String[0x2E] = "DELETE"
        set key2String[0x2F] = "HELP"
        set key2String[0x30] = "0"
        set key2String[0x31] = "1"
        set key2String[0x32] = "2"
        set key2String[0x33] = "3"
        set key2String[0x34] = "4"
        set key2String[0x35] = "5"
        set key2String[0x36] = "6"
        set key2String[0x37] = "7"
        set key2String[0x38] = "8"
        set key2String[0x39] = "9"
        set key2String[0x3A] = "0x3A"           // unassigned
        set key2String[0x3B] = "0x3B"           // unassigned
        set key2String[0x3C] = "0x3C"           // unassigned
        set key2String[0x3D] = "0x3D"           // unassigned
        set key2String[0x3E] = "0x3E"           // unassigned
        set key2String[0x3F] = "0x3F"           // unassigned
        set key2String[0x40] = "0x40"           // unassigned
        set key2String[0x41] = "A"
        set key2String[0x42] = "B"
        set key2String[0x43] = "C"
        set key2String[0x44] = "D"
        set key2String[0x45] = "E"
        set key2String[0x46] = "F"
        set key2String[0x47] = "G"
        set key2String[0x48] = "H"
        set key2String[0x49] = "I"
        set key2String[0x4A] = "J"
        set key2String[0x4B] = "K"
        set key2String[0x4C] = "L"
        set key2String[0x4D] = "M"
        set key2String[0x4E] = "N"
        set key2String[0x4F] = "O"
        set key2String[0x50] = "P"
        set key2String[0x51] = "Q"
        set key2String[0x52] = "R"
        set key2String[0x53] = "S"
        set key2String[0x54] = "T"
        set key2String[0x55] = "U"
        set key2String[0x56] = "V"
        set key2String[0x57] = "W"
        set key2String[0x58] = "X"
        set key2String[0x59] = "Y"
        set key2String[0x5A] = "Z"
        set key2String[0x5B] = "LWIN"
        set key2String[0x5C] = "RWIN"
        set key2String[0x5D] = "APPS"
        set key2String[0x5E] = "0x5E"           // reserved
        set key2String[0x5F] = "SLEEP"
        set key2String[0x60] = "NUMPAD0"
        set key2String[0x61] = "NUMPAD1"
        set key2String[0x62] = "NUMPAD2"
        set key2String[0x63] = "NUMPAD3"
        set key2String[0x64] = "NUMPAD4"
        set key2String[0x65] = "NUMPAD5"
        set key2String[0x66] = "NUMPAD6"
        set key2String[0x67] = "NUMPAD7"
        set key2String[0x68] = "NUMPAD8"
        set key2String[0x69] = "NUMPAD9"
        set key2String[0x6A] = "MULTIPLY"
        set key2String[0x6B] = "ADD"
        set key2String[0x6C] = "SEPARATOR"
        set key2String[0x6D] = "SUBTRACT"
        set key2String[0x6E] = "DECIMAL"
        set key2String[0x6F] = "DIVIDE"
        set key2String[0x70] = "F1"
        set key2String[0x71] = "F2"
        set key2String[0x72] = "F3"
        set key2String[0x73] = "F4"
        set key2String[0x74] = "F5"
        set key2String[0x75] = "F6"
        set key2String[0x76] = "F7"
        set key2String[0x77] = "F8"
        set key2String[0x78] = "F9"
        set key2String[0x79] = "F10"
        set key2String[0x7A] = "F11"
        set key2String[0x7B] = "F12"
        set key2String[0x7C] = "F13"
        set key2String[0x7D] = "F14"
        set key2String[0x7E] = "F15"
        set key2String[0x7F] = "F16"
        set key2String[0x80] = "F17"
        set key2String[0x81] = "F18"
        set key2String[0x82] = "F19"
        set key2String[0x83] = "F20"
        set key2String[0x84] = "F21"
        set key2String[0x85] = "F22"
        set key2String[0x86] = "F23"
        set key2String[0x87] = "F24"
        set key2String[0x88] = "0x88"           // unassigned
        set key2String[0x89] = "0x89"           // unassigned
        set key2String[0x8A] = "0x8A"           // unassigned
        set key2String[0x8B] = "0x8B"           // unassigned
        set key2String[0x8C] = "0x8C"           // unassigned
        set key2String[0x8D] = "0x8D"           // unassigned
        set key2String[0x8E] = "0x8E"           // unassigned
        set key2String[0x8F] = "0x8F"           // unassigned
        set key2String[0x90] = "NUMLOCK"
        set key2String[0x91] = "SCROLL"
        set key2String[0x92] = "0x92"
        set key2String[0x93] = "0x93"
        set key2String[0x94] = "0x94"
        set key2String[0x95] = "0x95"
        set key2String[0x96] = "0x96"
        set key2String[0x97] = "0x97"
        set key2String[0x98] = "0x98"
        set key2String[0x99] = "0x99"
        set key2String[0x9A] = "0x9A"
        set key2String[0x9B] = "0x9B"
        set key2String[0x9C] = "0x9C"
        set key2String[0x9D] = "0x9D"
        set key2String[0x9E] = "0x9E"
        set key2String[0x9F] = "0x9F"
        set key2String[0xA0] = "LSHIFT"
        set key2String[0xA1] = "RSHIFT"
        set key2String[0xA2] = "LCONTROL"
        set key2String[0xA3] = "RCONTROL"
        set key2String[0xA4] = "LMENU"
        set key2String[0xA5] = "RMENU"
        set key2String[0xA6] = "BROWSER_BACK"
        set key2String[0xA7] = "BROWSER_FORWARD"
        set key2String[0xA8] = "BROWSER_REFRESH"
        set key2String[0xA9] = "BROWSER_STOP"
        set key2String[0xAA] = "BROWSER_SEARCH"
        set key2String[0xAB] = "BROWSER_FAVORITES"
        set key2String[0xAC] = "BROWSER_HOME"
        set key2String[0xAD] = "VOLUME_MUTE"
        set key2String[0xAE] = "VOLUME_DOWN"
        set key2String[0xAF] = "VOLUME_UP"
        set key2String[0xB0] = "MEDIA_NEXT_TRACK"
        set key2String[0xB1] = "MEDIA_PREV_TRACK"
        set key2String[0xB2] = "MEDIA_STOP"
        set key2String[0xB3] = "MEDIA_PLAY_PAUSE"
        set key2String[0xB4] = "LAUNCH_MAIL"
        set key2String[0xB5] = "LAUNCH_MEDIA_SELECT"
        set key2String[0xB6] = "LAUNCH_APP1"
        set key2String[0xB7] = "LAUNCH_APP2"
        set key2String[0xB8] = "0xB8"           // reserved
        set key2String[0xB9] = "0xB9"           // reserved
        set key2String[0xBA] = "OEM_1"
        set key2String[0xBB] = "OEM_PLUS"
        set key2String[0xBC] = "OEM_COMMA"
        set key2String[0xBD] = "OEM_MINUS"
        set key2String[0xBE] = "OEM_PERIOD"
        set key2String[0xBF] = "OEM_2"
        set key2String[0xC0] = "OEM_3"
        set key2String[0xC1] = "0xC1"           // reserved
        set key2String[0xC2] = "0xC2"           // reserved
        set key2String[0xC3] = "0xC3"           // reserved
        set key2String[0xC4] = "0xC4"           // reserved
        set key2String[0xC5] = "0xC5"           // reserved
        set key2String[0xC6] = "0xC6"           // reserved
        set key2String[0xC7] = "0xC7"           // reserved
        set key2String[0xC8] = "0xC8"           // reserved
        set key2String[0xC9] = "0xC9"           // reserved
        set key2String[0xCA] = "0xCA"           // reserved
        set key2String[0xCB] = "0xCB"           // reserved
        set key2String[0xCC] = "0xCC"           // reserved
        set key2String[0xCD] = "0xCD"           // reserved
        set key2String[0xCE] = "0xCE"           // reserved
        set key2String[0xCF] = "0xCF"           // reserved
        set key2String[0xD0] = "0xD0"           // reserved
        set key2String[0xD1] = "0xD1"           // reserved
        set key2String[0xD2] = "0xD2"           // reserved
        set key2String[0xD3] = "0xD3"           // reserved
        set key2String[0xD4] = "0xD4"           // reserved
        set key2String[0xD5] = "0xD5"           // reserved
        set key2String[0xD6] = "0xD6"           // reserved
        set key2String[0xD7] = "0xD7"           // reserved
        set key2String[0xD8] = "0xD8"           // unassigned
        set key2String[0xD9] = "0xD9"           // unassigned
        set key2String[0xDA] = "0xDA"           // unassigned
        set key2String[0xDB] = "OEM_4"
        set key2String[0xDC] = "OEM_5"
        set key2String[0xDD] = "OEM_6"
        set key2String[0xDE] = "OEM_7"
        set key2String[0xDF] = "OEM_8"
        set key2String[0xE0] = "0xE0"           // reserved
        set key2String[0xE1] = "0xE1"
        set key2String[0xE2] = "0xE2"
        set key2String[0xE3] = "0xE3"
        set key2String[0xE4] = "0xE4"
        set key2String[0xE5] = "0xE5"
        set key2String[0xE6] = "PACKET"
        set key2String[0xE7] = "0xE7"
        set key2String[0xE8] = "0xE8"
        set key2String[0xE9] = "0xE9"
        set key2String[0xEA] = "0xEA"
        set key2String[0xEB] = "0xEB"
        set key2String[0xEC] = "0xEC"
        set key2String[0xED] = "0xED"
        set key2String[0xEE] = "0xEE"
        set key2String[0xEF] = "0xEF"
        set key2String[0xF0] = "0xF0"
        set key2String[0xF1] = "0xF1"
        set key2String[0xF2] = "0xF2"
        set key2String[0xF3] = "0xF3"
        set key2String[0xF4] = "0xF4"
        set key2String[0xF5] = "0xF5"
        set key2String[0xF6] = "ATTN"
        set key2String[0xF7] = "CRSEL"
        set key2String[0xF8] = "EXSEL"
        set key2String[0xF9] = "EREOF"
        set key2String[0xFA] = "PLAY"
        set key2String[0xFB] = "ZOOM"
        set key2String[0xFC] = "NONAME"
        set key2String[0xFD] = "PA1"
        set key2String[0xFE] = "OEM_CLEAR"
        set key2String[0xFF] = "0xFF"
        
        
        set string2Key["LBUTTON"]           = 0x01
        set string2Key["RBUTTON"]           = 0x02
        set string2Key["CANCEL"]            = 0x03
        set string2Key["MBUTTON"]           = 0x04
        set string2Key["XBUTTON1"]          = 0x05
        set string2Key["XBUTTON2"]          = 0x06
        set string2Key["0x07"]              = 0x07           // unassigned
        set string2Key["BACK"]              = 0x08
        set string2Key["TAB"]               = 0x09
        set string2Key["0x0A"]              = 0x0A           // reserved
        set string2Key["0x0B"]              = 0x0B           // reserved
        set string2Key["CLEAR"]             = 0x0C
        set string2Key["RETURN"]            = 0x0D
        set string2Key["0x0E"]              = 0x0E           // unassigned
        set string2Key["0x0F"]              = 0x0F           // unassigned
        set string2Key["SHIFT"]             = 0x10
        set string2Key["CONTROL"]           = 0x11
        set string2Key["MENU"]              = 0x12
        set string2Key["PAUSE"]             = 0x13
        set string2Key["CAPITAL"]           = 0x14
        set string2Key["KANA"]              = 0x15
        set string2Key["0x16"]              = 0x16           // unassigned
        set string2Key["JUNJA"]             = 0x17
        set string2Key["FINAL"]             = 0x18
        set string2Key["KANJI"]             = 0x19
        set string2Key["0x1A"]              = 0x1A           // unassigned
        set string2Key["ESCAPE"]            = 0x1B
        set string2Key["CONVERT"]           = 0x1C
        set string2Key["NONCONVERT"]        = 0x1D
        set string2Key["ACCEPT"]            = 0x1E
        set string2Key["MODECHANGE"]        = 0x1F
        set string2Key["SPACE"]             = 0x20
        set string2Key["PRIOR"]             = 0x21
        set string2Key["NEXT"]              = 0x22
        set string2Key["END"]               = 0x23
        set string2Key["HOME"]              = 0x24
        set string2Key["LEFT"]              = 0x25
        set string2Key["UP"]                = 0x26
        set string2Key["RIGHT"]             = 0x27
        set string2Key["DOWN"]              = 0x28
        set string2Key["SELECT"]            = 0x29
        set string2Key["PRINT"]             = 0x2A
        set string2Key["EXECUTE"]           = 0x2B
        set string2Key["SNAPSHOT"]          = 0x2C
        set string2Key["INSERT"]            = 0x2D
        set string2Key["DELETE"]            = 0x2E
        set string2Key["HELP"]              = 0x2F
        set string2Key["0"]                 = 0x30
        set string2Key["1"]                 = 0x31
        set string2Key["2"]                 = 0x32
        set string2Key["3"]                 = 0x33
        set string2Key["4"]                 = 0x34
        set string2Key["5"]                 = 0x35
        set string2Key["6"]                 = 0x36
        set string2Key["7"]                 = 0x37
        set string2Key["8"]                 = 0x38
        set string2Key["9"]                 = 0x39
        set string2Key["0x3A"]              = 0x3A           // unassigned
        set string2Key["0x3B"]              = 0x3B           // unassigned
        set string2Key["0x3C"]              = 0x3C           // unassigned
        set string2Key["0x3D"]              = 0x3D           // unassigned
        set string2Key["0x3E"]              = 0x3E           // unassigned
        set string2Key["0x3F"]              = 0x3F           // unassigned
        set string2Key["0x40"]              = 0x40           // unassigned
        set string2Key["A"]                 = 0x41
        set string2Key["B"]                 = 0x42
        set string2Key["C"]                 = 0x43
        set string2Key["D"]                 = 0x44
        set string2Key["E"]                 = 0x45
        set string2Key["F"]                 = 0x46
        set string2Key["G"]                 = 0x47
        set string2Key["H"]                 = 0x48
        set string2Key["I"]                 = 0x49
        set string2Key["J"]                 = 0x4A
        set string2Key["K"]                 = 0x4B
        set string2Key["L"]                 = 0x4C
        set string2Key["M"]                 = 0x4D
        set string2Key["N"]                 = 0x4E
        set string2Key["O"]                 = 0x4F
        set string2Key["P"]                 = 0x50
        set string2Key["Q"]                 = 0x51
        set string2Key["R"]                 = 0x52
        set string2Key["S"]                 = 0x53
        set string2Key["T"]                 = 0x54
        set string2Key["U"]                 = 0x55
        set string2Key["V"]                 = 0x56
        set string2Key["W"]                 = 0x57
        set string2Key["X"]                 = 0x58
        set string2Key["Y"]                 = 0x59
        set string2Key["Z"]                 = 0x5A
        set string2Key["LWIN"]              = 0x5B
        set string2Key["RWIN"]              = 0x5C
        set string2Key["APPS"]              = 0x5D
        set string2Key["0x5E"]              = 0x5E           // reserved
        set string2Key["SLEEP"]             = 0x5F
        set string2Key["NUMPAD0"]           = 0x60
        set string2Key["NUMPAD1"]           = 0x61
        set string2Key["NUMPAD2"]           = 0x62
        set string2Key["NUMPAD3"]           = 0x63
        set string2Key["NUMPAD4"]           = 0x64
        set string2Key["NUMPAD5"]           = 0x65
        set string2Key["NUMPAD6"]           = 0x66
        set string2Key["NUMPAD7"]           = 0x67
        set string2Key["NUMPAD8"]           = 0x68
        set string2Key["NUMPAD9"]           = 0x69
        set string2Key["MULTIPLY"]          = 0x6A
        set string2Key["ADD"]               = 0x6B
        set string2Key["SEPARATOR"]         = 0x6C
        set string2Key["SUBTRACT"]          = 0x6D
        set string2Key["DECIMAL"]           = 0x6E
        set string2Key["DIVIDE"]            = 0x6F
        set string2Key["F1"]                = 0x70
        set string2Key["F2"]                = 0x71
        set string2Key["F3"]                = 0x72
        set string2Key["F4"]                = 0x73
        set string2Key["F5"]                = 0x74
        set string2Key["F6"]                = 0x75
        set string2Key["F7"]                = 0x76
        set string2Key["F8"]                = 0x77
        set string2Key["F9"]                = 0x78
        set string2Key["F10"]               = 0x79
        set string2Key["F11"]               = 0x7A
        set string2Key["F12"]               = 0x7B
        set string2Key["F13"]               = 0x7C
        set string2Key["F14"]               = 0x7D
        set string2Key["F15"]               = 0x7E
        set string2Key["F16"]               = 0x7F
        set string2Key["F17"]               = 0x80
        set string2Key["F18"]               = 0x81
        set string2Key["F19"]               = 0x82
        set string2Key["F20"]               = 0x83
        set string2Key["F21"]               = 0x84
        set string2Key["F22"]               = 0x85
        set string2Key["F23"]               = 0x86
        set string2Key["F24"]               = 0x87
        set string2Key["0x88"]              = 0x88           // unassigned
        set string2Key["0x89"]              = 0x89           // unassigned
        set string2Key["0x8A"]              = 0x8A           // unassigned
        set string2Key["0x8B"]              = 0x8B           // unassigned
        set string2Key["0x8C"]              = 0x8C           // unassigned
        set string2Key["0x8D"]              = 0x8D           // unassigned
        set string2Key["0x8E"]              = 0x8E           // unassigned
        set string2Key["0x8F"]              = 0x8F           // unassigned
        set string2Key["NUMLOCK"]           = 0x90
        set string2Key["SCROLL"]            = 0x91
        set string2Key["0x92"]              = 0x92
        set string2Key["0x93"]              = 0x93
        set string2Key["0x94"]              = 0x94
        set string2Key["0x95"]              = 0x95
        set string2Key["0x96"]              = 0x96
        set string2Key["0x97"]              = 0x97
        set string2Key["0x98"]              = 0x98
        set string2Key["0x99"]              = 0x99
        set string2Key["0x9A"]              = 0x9A
        set string2Key["0x9B"]              = 0x9B
        set string2Key["0x9C"]              = 0x9C
        set string2Key["0x9D"]              = 0x9D
        set string2Key["0x9E"]              = 0x9E
        set string2Key["0x9F"]              = 0x9F
        set string2Key["LSHIFT"]            = 0xA0
        set string2Key["RSHIFT"]            = 0xA1
        set string2Key["LCONTROL"]          = 0xA2
        set string2Key["RCONTROL"]          = 0xA3
        set string2Key["LMENU"]             = 0xA4
        set string2Key["RMENU"]             = 0xA5
        set string2Key["BROWSER_BACK"]      = 0xA6
        set string2Key["BROWSER_FORWARD"]   = 0xA7
        set string2Key["BROWSER_REFRESH"]   = 0xA8
        set string2Key["BROWSER_STOP"]      = 0xA9
        set string2Key["BROWSER_SEARCH"]    = 0xAA
        set string2Key["BROWSER_FAVORITES"] = 0xAB
        set string2Key["BROWSER_HOME"]      = 0xAC
        set string2Key["VOLUME_MUTE"]       = 0xAD
        set string2Key["VOLUME_DOWN"]       = 0xAE
        set string2Key["VOLUME_UP"]         = 0xAF
        set string2Key["MEDIA_NEXT_TRACK"]  = 0xB0
        set string2Key["MEDIA_PREV_TRACK"]  = 0xB1
        set string2Key["MEDIA_STOP"]        = 0xB2
        set string2Key["MEDIA_PLAY_PAUSE"]  = 0xB3
        set string2Key["LAUNCH_MAIL"]       = 0xB4
        set string2Key["LAUNCH_MEDIA_SELECT"] = 0xB5
        set string2Key["LAUNCH_APP1"]       = 0xB6
        set string2Key["LAUNCH_APP2"]       = 0xB7
        set string2Key["0xB8"]              = 0xB8           // reserved
        set string2Key["0xB9"]              = 0xB9           // reserved
        set string2Key["OEM_1"]             = 0xBA
        set string2Key["OEM_PLUS"]          = 0xBB
        set string2Key["OEM_COMMA"]         = 0xBC
        set string2Key["OEM_MINUS"]         = 0xBD
        set string2Key["OEM_PERIOD"]        = 0xBE
        set string2Key["OEM_2"]             = 0xBF
        set string2Key["OEM_3"]             = 0xC0
        set string2Key["0xC1"]              = 0xC1           // reserved
        set string2Key["0xC2"]              = 0xC2           // reserved
        set string2Key["0xC3"]              = 0xC3           // reserved
        set string2Key["0xC4"]              = 0xC4           // reserved
        set string2Key["0xC5"]              = 0xC5           // reserved
        set string2Key["0xC6"]              = 0xC6           // reserved
        set string2Key["0xC7"]              = 0xC7           // reserved
        set string2Key["0xC8"]              = 0xC8           // reserved
        set string2Key["0xC9"]              = 0xC9           // reserved
        set string2Key["0xCA"]              = 0xCA           // reserved
        set string2Key["0xCB"]              = 0xCB           // reserved
        set string2Key["0xCC"]              = 0xCC           // reserved
        set string2Key["0xCD"]              = 0xCD           // reserved
        set string2Key["0xCE"]              = 0xCE           // reserved
        set string2Key["0xCF"]              = 0xCF           // reserved
        set string2Key["0xD0"]              = 0xD0           // reserved
        set string2Key["0xD1"]              = 0xD1           // reserved
        set string2Key["0xD2"]              = 0xD2           // reserved
        set string2Key["0xD3"]              = 0xD3           // reserved
        set string2Key["0xD4"]              = 0xD4           // reserved
        set string2Key["0xD5"]              = 0xD5           // reserved
        set string2Key["0xD6"]              = 0xD6           // reserved
        set string2Key["0xD7"]              = 0xD7           // reserved
        set string2Key["0xD8"]              = 0xD8           // unassigned
        set string2Key["0xD9"]              = 0xD9           // unassigned
        set string2Key["0xDA"]              = 0xDA           // unassigned
        set string2Key["OEM_4"]             = 0xDB
        set string2Key["OEM_5"]             = 0xDC
        set string2Key["OEM_6"]             = 0xDD
        set string2Key["OEM_7"]             = 0xDE
        set string2Key["OEM_8"]             = 0xDF
        set string2Key["0xE0"]              = 0xE0           // reserved
        set string2Key["0xE1"]              = 0xE1
        set string2Key["0xE2"]              = 0xE2
        set string2Key["0xE3"]              = 0xE3
        set string2Key["0xE4"]              = 0xE4
        set string2Key["0xE5"]              = 0xE5
        set string2Key["PACKET"]            = 0xE6
        set string2Key["0xE7"]              = 0xE7
        set string2Key["0xE8"]              = 0xE8
        set string2Key["0xE9"]              = 0xE9
        set string2Key["0xEA"]              = 0xEA
        set string2Key["0xEB"]              = 0xEB
        set string2Key["0xEC"]              = 0xEC
        set string2Key["0xED"]              = 0xED
        set string2Key["0xEE"]              = 0xEE
        set string2Key["0xEF"]              = 0xEF
        set string2Key["0xF0"]              = 0xF0
        set string2Key["0xF1"]              = 0xF1
        set string2Key["0xF2"]              = 0xF2
        set string2Key["0xF3"]              = 0xF3
        set string2Key["0xF4"]              = 0xF4
        set string2Key["0xF5"]              = 0xF5
        set string2Key["ATTN"]              = 0xF6
        set string2Key["CRSEL"]             = 0xF7
        set string2Key["EXSEL"]             = 0xF8
        set string2Key["EREOF"]             = 0xF9
        set string2Key["PLAY"]              = 0xFA
        set string2Key["ZOOM"]              = 0xFB
        set string2Key["NONAME"]            = 0xFC
        set string2Key["PA1"]               = 0xFD
        set string2Key["OEM_CLEAR"]         = 0xFE
        set string2Key["0xFF"]              = 0xFF
        
        call TriggerRegisterKeyEvent(onPress, EVENT_KEY_DOWN)
        call TriggerRegisterKeyEvent(onRelease, EVENT_KEY_UP)
        call TriggerAddAction(onPress, function onPressFunc)
        call TriggerAddAction(onRelease, function onReleaseFunc)
    endfunction
endlibrary

Collapse MouseAPI:
library MouseAPI initializer Init requires Table

    globals
        // - Setup
        constant real MOUSE_EVENT_TIMEOUT = 0.01
        // - Mouse Constants
        constant integer EVENT_MOUSE_LEFT_UP        = 0
        constant integer EVENT_MOUSE_LEFT_DOWN      = 1
        constant integer EVENT_MOUSE_RIGHT_UP       = 2
        constant integer EVENT_MOUSE_RIGHT_DOWN     = 3
        constant integer EVENT_MOUSE_MIDDLE_UP      = 4
        constant integer EVENT_MOUSE_MIDDLE_DOWN    = 5
        constant integer EVENT_MOUSE_WHEEL_SCROLL   = 6

        constant integer MOUSE_BUTTON_LEFT          = 0
        constant integer MOUSE_BUTTON_RIGHT         = 1
        constant integer MOUSE_BUTTON_MIDDLE        = 2
        constant integer MOUSE_BUTTON_4             = 4
        constant integer MOUSE_BUTTON_5             = 5
    endglobals
        // - Mouse Natives
    
        native GetMouseTerrainX takes nothing returns real
        native GetMouseTerrainY takes nothing returns real
        native GetMouseTerrainZ takes nothing returns real
        native GetMouseScaleX takes nothing returns real
        native GetMouseScaleY takes nothing returns real
        native GetMouseScreenX takes nothing returns integer
        native GetMouseScreenY takes nothing returns integer
        native SetMouseScreenX takes integer x returns nothing
        native SetMouseScreenY takes integer y returns nothing
        native SetMouseScreenPos takes integer x, integer y returns nothing
        native IsMouseOverUI takes nothing returns boolean
        native TriggerRegisterMouseEvent takes trigger trig, integer key returns nothing
        native GetTriggerWheelDelta takes nothing returns integer
        native SetMouseBlock takes integer key, boolean doBlock returns nothing
        
        
        // - Added Functions
        /*
        IsMouseButtonPressed takes integer b returns boolean
        
        TriggerRegisterMouseMoveEvent takes trigger whichTrigger returns nothing
        
        GetMouseChangeX takes nothing returns integer
        GetMouseChangeY takes nothing returns integer
        GetMouseChangeXScale takes nothing returns real
        GetMouseChangeYScale takes nothing returns real
        
        // these don't trigger the Move event
        SetMouseScreenXEx takes integer x returns nothing
        SetMouseScreenYEx takes integer y returns nothing
        SetMouseScreenPosEx takes integer x, integer y returns nothing
        */
    globals
        private boolean array isPressed[3]
        private trigger onPressL = CreateTrigger()
        private trigger onReleaseL = CreateTrigger()
        private trigger onPressR = CreateTrigger()
        private trigger onReleaseR = CreateTrigger()
        private trigger onPressM = CreateTrigger()
        private trigger onReleaseM = CreateTrigger()
    endglobals
    
    private function onPressLFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_LEFT] = true
    endfunction
    
    private function onReleaseLFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_LEFT] = false
    endfunction
    
    private function onPressRFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_RIGHT] = true
    endfunction
    
    private function onReleaseRFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_RIGHT] = false
    endfunction
    
    private function onPressMFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_MIDDLE] = true
    endfunction
    
    private function onReleaseMFunc takes nothing returns nothing
        set isPressed[MOUSE_BUTTON_MIDDLE] = false
    endfunction
    
    function IsMouseButtonPressed takes integer b returns boolean
        return isPressed[b]
    endfunction
    
    globals
        private HandleTable Storage
    
        private integer mouseX
        private integer mouseY
        private real rmouseX
        private real rmouseY
        
        private integer mouseDX
        private integer mouseDY
        private real rmouseDX
        private real rmouseDY
        
        
        private trigger array mouseMoveTrigs
        private integer mouseMoveCount = 0
        
        private timer mouseEventTimer = CreateTimer()
    endglobals
    
    function GetMouseChangeX takes nothing returns integer
        return mouseDX
    endfunction
    
    function GetMouseChangeY takes nothing returns integer
        return mouseDY
    endfunction
    
    function GetMouseChangeXScale takes nothing returns real
        return rmouseDX
    endfunction
    
    function GetMouseChangeYScale takes nothing returns real
        return rmouseDX
    endfunction
    
    function SetMouseScreenXEx takes integer x returns nothing
        call SetMouseScreenX(x)
        set mouseX = GetMouseScreenX()
        set rmouseX = GetMouseScaleX()
    endfunction
    
    function SetMouseScreenYEx takes integer y returns nothing
        call SetMouseScreenY(y)
        set mouseY = GetMouseScreenY()
        set rmouseY = GetMouseScaleY()
    endfunction
    
    function SetMouseScreenPosEx takes integer x, integer y returns nothing
        call SetMouseScreenPos(x, y)
        set mouseX = GetMouseScreenX()
        set mouseY = GetMouseScreenY()
        set rmouseX = GetMouseScaleX()
        set rmouseY = GetMouseScaleY()
    endfunction

    private function onMouseMoveEvent takes nothing returns nothing
        local integer i = 0
        set mouseDX = GetMouseScreenX() - mouseX
        set mouseDY = GetMouseScreenY() - mouseY
        set rmouseDX = GetMouseScaleX() - rmouseX
        set rmouseDY = GetMouseScaleY() - rmouseY
        
        set mouseX = GetMouseScreenX()
        set mouseY = GetMouseScreenY()
        set rmouseX = GetMouseScaleX()
        set rmouseY = GetMouseScaleY()
        
        if mouseDX != 0 or mouseDY != 0 then // mouse moved
            loop
                exitwhen i >= mouseMoveCount
                if TriggerEvaluate(mouseMoveTrigs[i]) then
                    call TriggerExecute(mouseMoveTrigs[i])
                endif
                set i = i + 1
            endloop
        endif
    endfunction 

    function TriggerRegisterMouseMoveEvent takes trigger whichTrigger returns nothing
        if Storage[whichTrigger] != 0 then
            set mouseMoveTrigs[mouseMoveCount] = whichTrigger
            set Storage[whichTrigger] = mouseMoveCount
            set mouseMoveCount = mouseMoveCount + 1
            if mouseMoveCount <= 1 then // start timer
                call TimerStart(mouseEventTimer, MOUSE_EVENT_TIMEOUT, true, function onMouseMoveEvent)
            endif
        endif
    endfunction
    
    private function onDestroyTrigger takes trigger whichTrigger returns nothing
        local integer i = Storage[whichTrigger]
        if i != 0 then // destroying a trigger that was registered
            set mouseMoveTrigs[i] = mouseMoveTrigs[mouseMoveCount - 1]
            set Storage[mouseMoveTrigs[i]] = i
            set Storage[whichTrigger] = 0
            set mouseMoveCount = mouseMoveCount - 1
            if mouseMoveCount <= 0 then // stop timer, no more triggers
                call PauseTimer(mouseEventTimer)
            endif
        endif
    endfunction
    
    hook DestroyTrigger onDestroyTrigger

    private function Init takes nothing returns nothing
        call TriggerRegisterMouseEvent(onReleaseL, EVENT_MOUSE_LEFT_UP)
        call TriggerRegisterMouseEvent(onPressL, EVENT_MOUSE_LEFT_DOWN)
        call TriggerRegisterMouseEvent(onReleaseR, EVENT_MOUSE_RIGHT_UP)
        call TriggerRegisterMouseEvent(onPressR, EVENT_MOUSE_RIGHT_DOWN)
        call TriggerRegisterMouseEvent(onReleaseL, EVENT_MOUSE_MIDDLE_UP)
        call TriggerRegisterMouseEvent(onPressM, EVENT_MOUSE_MIDDLE_DOWN)
        call TriggerAddAction(onReleaseL, function onReleaseLFunc)
        call TriggerAddAction(onPressL, function onPressLFunc)
        call TriggerAddAction(onReleaseR, function onReleaseRFunc)
        call TriggerAddAction(onPressR, function onPressRFunc)
        call TriggerAddAction(onReleaseM, function onReleaseMFunc)
        call TriggerAddAction(onPressM, function onPressMFunc)
    endfunction

endlibrary
__________________

Last edited by Ammorth : 04-03-2010 at 07:31 AM.
Ammorth is offline   Reply With Quote
Sponsored Links - Login to hide this ad!
Old 04-03-2010, 01:09 AM   #2
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

Collapse Shape:
library Shape

    interface Shape
        method IsPointWithin takes real x, real y returns boolean
        method GetMinX takes nothing returns real
        method GetMinY takes nothing returns real
        method GetMaxX takes nothing returns real
        method GetMaxY takes nothing returns real
    endinterface
    
    // used for polygons
    public struct Point
        private real xx
        private real xy
        
        method operator x takes nothing returns real
            return .xx
        endmethod
        
        method operator y takes nothing returns real
            return .xy
        endmethod
        
        static method create takes real x, real y returns thistype
            local thistype this = thistype.allocate()
            set .xx = x
            set .xy = y
            return this
        endmethod
    endstruct

    public struct Circle extends Shape
        private real xx
        private real xy
        private real xr
        private real xr2 // so we don't have to use SquareRoot() constantly
        
        // faking variables for the win!
        method operator r takes nothing returns real
            return .xr
        endmethod
        
        method operator x takes nothing returns real
            return .xx
        endmethod
        
        method operator y takes nothing returns real
            return .xy
        endmethod
        
        method GetMinX takes nothing returns real
            return .xx - .xr
        endmethod
        
        method GetMinY takes nothing returns real
            return .xy - .xr
        endmethod
        
        method GetMaxX takes nothing returns real
            return .xx + .xr
        endmethod
        
        method GetMaxY takes nothing returns real   
            return .xy + .xr
        endmethod
        
        static method create takes real x, real y, real r returns thistype
            local thistype this = thistype.allocate()
            set .xx = x
            set .xy = y
            set .xr = r
            set .xr2 = r*r
            return this
        endmethod
        
        method IsPointWithin takes real x, real y returns boolean
            return ((.xx-x)*(.xx-x)+(.xy-y)*(.xy-y)) < .xr2
        endmethod
    endstruct
    
    public struct Square extends Shape
        private real xminX
        private real xminY
        private real xmaxX
        private real xmaxY
        
        method GetMinX takes nothing returns real 
            return .xminX
        endmethod
        
        method GetMinY takes nothing returns real 
            return .xminY
        endmethod
        
        method GetMaxX takes nothing returns real 
            return .xmaxX
        endmethod
        
        method GetMaxY takes nothing returns real 
            return .xmaxY
        endmethod
        
        static method create takes real minX, real minY, real maxX, real maxY returns thistype
            local thistype this = thistype.allocate()
            set .xminX = minX
            set .xminY = minY
            set .xmaxX = maxX
            set .xmaxY = maxY
            return this
        endmethod
        
        method IsPointWithin takes real x, real y returns boolean
            return x > .xminX and x < .xmaxX and y > .xminY and y < .xmaxY
        endmethod
    endstruct
    
    public struct Polygon extends Shape
        private List points
        
        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set .points = List.create()
            return this
        endmethod
        
        method addPoint takes real x, real y returns nothing
            local Point p = Point.create(x, y)
            call Link.createLast(.points, p)
        endmethod
        
        method onDestroy takes nothing returns nothing
            local Link temp = .points.first
            loop
                exitwhen temp == 0
                call Point(temp.data).destroy()
                set temp = temp.next
            endloop
            call .points.destroy()
        endmethod
        
        method GetMinX takes nothing returns real
            local Link l = .points.first
            local real temp = Point(l.data).x
            set l = l.next
            loop
                exitwhen l == 0
                if Point(l.data).x < temp then
                    set temp = Point(l.data).x
                endif
                set l = l.next
            endloop
            return temp
        endmethod
        
        method GetMinY takes nothing returns real
            local Link l = .points.first
            local real temp = Point(l.data).y
            set l = l.next
            loop
                exitwhen l == 0
                if Point(l.data).y < temp then
                    set temp = Point(l.data).y
                endif
                set l = l.next
            endloop
            return temp
        endmethod
        
        method GetMaxX takes nothing returns real
            local Link l = .points.first
            local real temp = Point(l.data).x
            set l = l.next
            loop
                exitwhen l == 0
                if Point(l.data).x > temp then
                    set temp = Point(l.data).x
                endif
                set l = l.next
            endloop
            return temp
        endmethod
        
        method GetMaxY takes nothing returns real
            local Link l = .points.first
            local real temp = Point(l.data).y
            set l = l.next
            loop
                exitwhen l == 0
                if Point(l.data).y > temp then
                    set temp = Point(l.data).y
                endif
                set l = l.next
            endloop
            return temp
        endmethod
        
        method IsPointWithin takes real x, real y returns boolean
            local boolean b = false
            local Link l = .points.first
            local Point i = .points.first.data
            local Point j = .points.last.data
            loop
                exitwhen l == 0
                if ( ((i.y > y) != (j.y > y)) and (x < (j.x-i.x) * (y-i.y) / (j.y-i.y) + i.x) ) then
                    set b = not b
                endif
                set j = i
                set l = l.next
                set i = l.data
            endloop
            return b
        endmethod
    endstruct

    
endlibrary

Collapse Zone:
library Zone requires Shape, LinkedList

    globals
        private constant real LARGE_NUMBER = 999999
    endglobals

    struct Zone
        private List shapeAdd
        private List shapeSub
        private real minX
        private real minY
        private real maxX
        private real maxY
        
        
        
        static method create takes nothing returns thistype
            local thistype this = thistype.allocate()
            set .shapeAdd = List.create()
            set .shapeSub = List.create()
            set .minX = LARGE_NUMBER
            set .maxX = -LARGE_NUMBER
            set .minY = LARGE_NUMBER
            set .maxY = -LARGE_NUMBER
            return this
        endmethod
        
        private method updateBounds takes Shape new returns nothing
            local real minx = new.GetMinX()
            local real miny = new.GetMinY()
            local real maxx = new.GetMaxX()
            local real maxy = new.GetMaxY()
            if minx < .minX then 
                set .minX = minx
            endif
            if miny < .minY then
                set .minY = miny
            endif
            if maxx > .maxX then
                set .maxX = maxx
            endif
            if maxy > .maxY then
                set .maxY = maxy
            endif
        endmethod
        
        method Add takes Shape whichShape returns nothing
            call Link.createLast(.shapeAdd, whichShape)
            call updateBounds(whichShape)
        endmethod
        
        // you cannot remove shapes dynamically, but you can cull shapes using Sub.
        // Subbed shapes will always be excluded, even if they contain part of Added Shapes
        method Sub takes Shape whichShape returns nothing
            call Link.createLast(.shapeSub, whichShape)
            call updateBounds(whichShape)
        endmethod
        
        method IsPointWithin takes real x, real y returns boolean
            local Link l = .shapeAdd.first
            //if x < .minX or x > .maxX or y < .minY or y > .maxY then // not within bounds, don't bother
              //  return false
            //endif
            loop
                exitwhen l == 0
                if not Shape(l.data).IsPointWithin(x, y) then
                    return false
                endif
                set l = l.next
            endloop
            set l = .shapeSub.first
            loop
                exitwhen l == 0
                if Shape(l.data).IsPointWithin(x, y) then
                    return false
                endif
                set l = l.next
            endloop
            return true
        endmethod
    endstruct
endlibrary

Collapse Trackables2.0:
library Trackable initializer onInit requires Zone, MouseAPI

    globals
        private constant real LARGE_NUMBER = 999999
        private constant real TIMER_PERIOD = 0.01
        private timer TrackTimer = CreateTimer()
        
        private trigger TrigClickLeft = CreateTrigger()
        private trigger TrigClickRight = CreateTrigger()
        private trigger TrigClickMiddle = CreateTrigger()
        
        private Trackable array allTracks
        private integer allTracksCount = 0
    endglobals

    function interface TrackableAction takes Trackable whichTrackable returns nothing

    struct Trackable
        Zone target
        private integer slot
        integer data // cause everyone needs to attach shit to stuff!
        
        boolean isOver
        
        static method create takes Zone whichZone returns thistype
            local thistype this = thistype.allocate()
            set .target = whichZone
            set allTracks[allTracksCount] = this
            set .slot = allTracksCount
            set .isOver = false
            set allTracksCount = allTracksCount + 1
            return this
        endmethod
        
        method onDestroy takes nothing returns nothing
            set allTracks[.slot] = allTracks[allTracksCount-1]
            set allTracks[.slot].slot = .slot
            set .slot = 0
            set allTracksCount = allTracksCount - 1
            set .target = 0
            set .data = 0
        endmethod
    endstruct
    
    globals
        private TrackableAction array trackOverExe
        private TrackableAction array trackOutExe
        private TrackableAction array clickLeftExe
        private TrackableAction array clickMiddleExe
        private TrackableAction array clickRightExe
        
        private integer trackOverCount = 0
        private integer trackOutCount = 0
        private integer clickLeftCount = 0
        private integer clickMiddleCount = 0
        private integer clickRightCount = 0
    endglobals
    
    function RegisterTrackableTrackOverEvent takes TrackableAction t returns nothing
        set trackOverExe[trackOverCount] = t
        set trackOverCount = trackOverCount + 1
    endfunction
    
    function RegisterTrackableTrackOutEvent takes TrackableAction t returns nothing
        set trackOutExe[trackOutCount] = t
        set trackOutCount = trackOutCount + 1
    endfunction
    
    function RegisterTrackableClickLeftEvent takes TrackableAction t returns nothing
        set clickLeftExe[clickLeftCount] = t
        set clickLeftCount = clickLeftCount + 1
    endfunction
    
    function RegisterTrackableClickRightEvent takes TrackableAction t returns nothing
        set clickRightExe[clickRightCount] = t
        set clickRightCount = clickRightCount + 1
    endfunction
    
    function RegisterTrackableClickMiddleEvent takes TrackableAction t returns nothing
        set clickMiddleExe[clickMiddleCount] = t
        set clickMiddleCount = clickMiddleCount + 1
    endfunction
    
    globals
        private real OldX = LARGE_NUMBER
        private real OldY = LARGE_NUMBER
    endglobals
    
    private function onTimeout takes nothing returns nothing
        local real x = GetMouseTerrainX()
        local real y = GetMouseTerrainY()
        local integer i = 0
        local integer j = 0
        if x == OldX and y == OldY then
            return
        endif
        set OldX = x
        set OldY = y
        loop
            exitwhen i >= allTracksCount
            if allTracks[i].target.IsPointWithin(x, y) then
                if not allTracks[i].isOver then // we tracked
                    set allTracks[i].isOver = true
                    set j = 0
                    loop
                        exitwhen j >= trackOverCount
                        call trackOverExe[j].execute(allTracks[i])
                        set j = j + 1
                    endloop
                endif
            else
                if allTracks[i].isOver then // we left
                    set allTracks[i].isOver = false
                    set j = 0
                    loop
                        exitwhen j >= trackOutCount
                        call trackOutExe[j].execute(allTracks[i])
                        set j = j + 1
                    endloop
                endif
            endif
            set i = i + 1
        endloop
    endfunction
    
    private function onClickLeft takes nothing returns nothing
        local real x = GetMouseTerrainX()
        local real y = GetMouseTerrainY()
        local integer i = 0
        local integer j = 0
        loop
            exitwhen i >= allTracksCount
            if allTracks[i].target.IsPointWithin(x, y) then
                set j = 0
                loop
                    exitwhen j >= clickLeftCount
                    call clickLeftExe[j].execute(allTracks[i])
                    set j = j + 1
                endloop
            endif
            set i = i + 1
        endloop
    endfunction
    
    private function onClickRight takes nothing returns nothing
        local real x = GetMouseTerrainX()
        local real y = GetMouseTerrainY()
        local integer i = 0
        local integer j = 0
        loop
            exitwhen i >= allTracksCount
            if allTracks[i].target.IsPointWithin(x, y) then //
                set j = 0
                loop
                    exitwhen j >= clickRightCount
                    call clickRightExe[j].execute(allTracks[i])
                    set j = j + 1
                endloop
            endif
            set i = i + 1
        endloop
    endfunction
    
    private function onClickMiddle takes nothing returns nothing
        local real x = GetMouseTerrainX()
        local real y = GetMouseTerrainY()
        local integer i = 0
        local integer j = 0
        loop
            exitwhen i >= allTracksCount
            if allTracks[i].target.IsPointWithin(x, y) then //
                set j = 0
                loop
                    exitwhen j >= clickMiddleCount
                    call clickMiddleExe[j].execute(allTracks[i])
                    set j = j + 1
                endloop
            endif
            set i = i + 1
        endloop
    endfunction
    
    private function onInit takes nothing returns nothing
        call TriggerRegisterMouseEvent(TrigClickLeft, EVENT_MOUSE_LEFT_DOWN)
        call TriggerRegisterMouseEvent(TrigClickRight, EVENT_MOUSE_RIGHT_DOWN)
        call TriggerRegisterMouseEvent(TrigClickMiddle, EVENT_MOUSE_MIDDLE_DOWN)
        call TriggerAddAction(TrigClickLeft, function onClickLeft)
        call TriggerAddAction(TrigClickRight, function onClickRight)
        call TriggerAddAction(TrigClickMiddle, function onClickMiddle)
        call TimerStart(TrackTimer, TIMER_PERIOD, true, function onTimeout)
    endfunction
    
endlibrary
__________________

Last edited by Ammorth : 04-03-2010 at 07:29 AM.
Ammorth is offline   Reply With Quote
Old 04-03-2010, 01:36 AM   #3
Deaod
User
 
Join Date: Jan 2007
Posts: 542

Submissions (11)

Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)Deaod is a jewel in the rough (192)

Default

Collapse JASS:
library RtCClickableRect uses RtCMouse
    
    globals
        private constant    real                    TICK                            = 1./40
    endglobals
    
    struct clickablerect
        private real x
        private real y
        
        private real width
        private real height
        
        readonly boolean hovered
        
        private integer i
        
        private static boolean LButtonPressed=false
        private static boolean RButtonPressed=false
        
        private static timer HoverTimer=CreateTimer()
        private static thistype array Structs
        private static integer Count=0
        
        public stub method OnMouseEnter takes nothing returns nothing
        endmethod
        public stub method OnMouseLeave takes nothing returns nothing
        endmethod
        
        public stub method OnClick takes nothing returns nothing
        endmethod
        public stub method OnRightClick takes nothing returns nothing
        endmethod
        public stub method OnDown takes nothing returns nothing
        endmethod
        public stub method OnRightDown takes nothing returns nothing
        endmethod
        
        private static method HoverCallback takes nothing returns nothing
        local real mx=GetMouseTerrainX()
        local real my=GetMouseTerrainY()
        local thistype this
        local integer i=.Count-1
        local boolean b
            loop
                exitwhen i<0
                set this=.Structs[i]
                set b=mx>.x and mx<.x+.width and my>.y and my<.y+.height
                if b!=.hovered then
                    set .hovered=b
                    if b then
                        call .OnMouseEnter()
                    else
                        call .OnMouseLeave()
                    endif
                endif
                set i=i-1
            endloop
        endmethod
        
        static method create takes real x, real y, real width, real height returns thistype
        local thistype s=.allocate()
            set s.x=x
            set s.y=y
            set s.width=width
            set s.height=height
            if .Count==0 then
                call TimerStart(.HoverTimer, TICK, true, function thistype.HoverCallback)
            endif
            set .Structs[.Count]=s
            set s.i=.Count
            set .Count=.Count+1
            return s
        endmethod
        
        private static method OnClickProxy takes nothing returns nothing
        local real mx=GetMouseTerrainX()
        local real my=GetMouseTerrainY()
        local integer i=.Count-1
        local thistype this
            set .LButtonPressed=false
            loop
                exitwhen i<0
                set this=.Structs[i]
                if mx>.x and mx<.x+.width and my>.y and my<.y+.height then
                    call .OnClick()
                endif
                set i=i-1
            endloop
        endmethod
        
        private static method OnRightClickProxy takes nothing returns nothing
        local real mx=GetMouseTerrainX()
        local real my=GetMouseTerrainY()
        local integer i=.Count-1
        local thistype this
            set .RButtonPressed=false
            loop
                exitwhen i<0
                set this=.Structs[i]
                if mx>.x and mx<.x+.width and my>.y and my<.y+.height then
                    call .OnRightClick()
                endif
                set i=i-1
            endloop
        endmethod
        
        private static method OnMouseDownProxy takes nothing returns nothing
        local real mx=GetMouseTerrainX()
        local real my=GetMouseTerrainY()
        local integer i=.Count-1
        local thistype this
            set .LButtonPressed=true
            loop
                exitwhen i<0
                set this=.Structs[i]
                if mx>.x and mx<.x+.width and my>.y and my<.y+.height then
                    call .OnDown()
                endif
                set i=i-1
            endloop
        endmethod
        
        private static method OnMouseRightDownProxy takes nothing returns nothing
        local real mx=GetMouseTerrainX()
        local real my=GetMouseTerrainY()
        local integer i=.Count-1
        local thistype this
            set .RButtonPressed=true
            loop
                exitwhen i<0
                set this=.Structs[i]
                if mx>.x and mx<.x+.width and my>.y and my<.y+.height then
                    call .OnRightDown()
                endif
                set i=i-1
            endloop
        endmethod
        
        private static method onInit takes nothing returns nothing
            call OnMouseLeftUp(function thistype.OnClickProxy)
            call OnMouseRightUp(function thistype.OnRightClickProxy)
            call OnMouseLeftDown(function thistype.OnMouseDownProxy)
            call OnMouseRightDown(function thistype.OnMouseRightDownProxy)
        endmethod
        
        method onDestroy takes nothing returns nothing
            set .Count=.Count-1
            set .Structs[.i]=.Structs[.Count]
            set .Structs[.i].i=.i
            if .Count==0 then
                call PauseTimer(.HoverTimer)
            endif
        endmethod
    endstruct
    
endlibrary

Collapse JASS:
library RtCMouse initializer Init
    
    globals
        // - Mouse Constants
        constant integer EVENT_MOUSE_LEFT_UP        = 0
        constant integer EVENT_MOUSE_LEFT_DOWN      = 1
        constant integer EVENT_MOUSE_RIGHT_UP       = 2
        constant integer EVENT_MOUSE_RIGHT_DOWN     = 3
        constant integer EVENT_MOUSE_MIDDLE_UP      = 4
        constant integer EVENT_MOUSE_MIDDLE_DOWN    = 5
        constant integer EVENT_MOUSE_WHEEL_SCROLL   = 6
        
        constant integer MOUSE_BUTTON_LEFT          = 0
        constant integer MOUSE_BUTTON_RIGHT         = 1
        constant integer MOUSE_BUTTON_MIDDLE        = 2
        constant integer MOUSE_BUTTON_4             = 4
        constant integer MOUSE_BUTTON_5             = 5
    endglobals
    
    native GetMouseTerrainX takes nothing returns real
    native GetMouseTerrainY takes nothing returns real
    native GetMouseTerrainZ takes nothing returns real
    native GetMouseScaleX takes nothing returns real
    native GetMouseScaleY takes nothing returns real
    native GetMouseScreenX takes nothing returns integer
    native GetMouseScreenY takes nothing returns integer
    native SetMouseScreenX takes integer x returns nothing
    native SetMouseScreenY takes integer y returns nothing
    native SetMouseScreenPos takes integer x, integer y returns nothing
    native IsMouseOverUI takes nothing returns boolean
    native TriggerRegisterMouseEvent takes trigger trig, integer key returns nothing
    native GetTriggerWheelDelta takes nothing returns integer
    native SetMouseBlock takes integer key, boolean doBlock returns nothing
    
    globals
        private boolean array ButtonState
        
        private trigger LBU=CreateTrigger()
        private trigger LBD=CreateTrigger()
        private trigger RBU=CreateTrigger()
        private trigger RBD=CreateTrigger()
        private trigger MBU=CreateTrigger()
        private trigger MBD=CreateTrigger()
    endglobals
    
    private function MBUp takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_MIDDLE]=false
    endfunction
    
    private function MBDown takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_MIDDLE]=true
    endfunction
    
    private function RBUp takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_RIGHT]=false
    endfunction
    
    private function RBDown takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_RIGHT]=true
    endfunction
    
    private function LBUp takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_LEFT]=false
    endfunction
    
    private function LBDown takes nothing returns nothing
        set ButtonState[MOUSE_BUTTON_LEFT]=true
    endfunction
    
    function IsMouseButtonPressed takes integer whichButton returns boolean
        return ButtonState[whichButton]
    endfunction
    
    function OnMouseLeftDown takes code func returns nothing
        call TriggerAddAction(LBD, func)
    endfunction
    
    function OnMouseLeftUp takes code func returns nothing
        call TriggerAddAction(LBU, func)
    endfunction
    
    function OnMouseRightDown takes code func returns nothing
        call TriggerAddAction(RBD, func)
    endfunction
    
    function OnMouseRightUp takes code func returns nothing
        call TriggerAddAction(RBU, func)
    endfunction
    
    function OnMouseMiddleDown takes code func returns nothing
        call TriggerAddAction(MBD, func)
    endfunction
    
    function OnMouseMiddleUp takes code func returns nothing
        call TriggerAddAction(MBU, func)
    endfunction
    
    private function Init takes nothing returns nothing
        call TriggerAddAction(LBU, function LBUp)
        call TriggerRegisterMouseEvent(LBU, EVENT_MOUSE_LEFT_UP)
        call TriggerAddAction(LBD, function LBDown)
        call TriggerRegisterMouseEvent(LBD, EVENT_MOUSE_LEFT_DOWN)
        call TriggerAddAction(RBU, function RBUp)
        call TriggerRegisterMouseEvent(RBU, EVENT_MOUSE_RIGHT_UP)
        call TriggerAddAction(RBD, function RBDown)
        call TriggerRegisterMouseEvent(RBD, EVENT_MOUSE_RIGHT_DOWN)
        call TriggerAddAction(MBU, function MBUp)
        call TriggerRegisterMouseEvent(MBU, EVENT_MOUSE_MIDDLE_UP)
        call TriggerAddAction(MBD, function MBDown)
        call TriggerRegisterMouseEvent(MBD, EVENT_MOUSE_MIDDLE_DOWN)
    endfunction
    
endlibrary
__________________
Deaod is offline   Reply With Quote
Old 04-14-2010, 12:09 AM   #4
Ammorth
I blink, therefore I am.
 
Ammorth's Avatar
 
Join Date: Sep 2006
Posts: 1,812

Submissions (10)

Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)Ammorth is a glorious beacon of light (461)

Default

"pool" "tool" should return 1 and "tool" "poop" should return 2, but it always returns 0.

Collapse JASS:
    private function Min3Ints takes integer a, integer b, integer c returns integer
        if a < b then
            if a < c then
                return a
            endif
        else
            if b < c then
                return b
            endif
        endif
        return c
    endfunction

    // returns how much they are off by
    public function LevenshteinDistance takes string s1, string s2 returns integer
        local integer m = StringLength(s1)
        local integer n = StringLength(s2)
        local integer array table
        local integer i = 0
        local integer j = 0
        loop
            exitwhen i >= m
            set table[i+m*j] = i
            set i = i + 1
        endloop
        set i = 0
        loop
            exitwhen j >= n
            set table[i+m*j] = j
            set j = j + 1
        endloop
        set j = 1
        set i = 1
        loop
            exitwhen j >= n
            loop
                exitwhen i >= m
                if SubString(s1, i-1, i) == SubString(s2, j-1, j) then
                    set table[i+m*j] = table[(i-1)+m*(j-1)]
                else
                    set table[i+m*j] = Min3Ints(table[(i-1)+m*j]+1, table[i+m*(j-1)]+1, table[(i-1)+m*(j-1)]+1)
                endif
                set i = i + 1
            endloop
            set j = j + 1
        endloop
        return table[(m-1)+m*(n-1)]
    endfunction
__________________
Ammorth is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off


All times are GMT. The time now is 04:45 PM.


Affiliates
The Hubb The JASS Vault Clan WEnW Campaign Creations Clan CBS GamesModding Flixreel Videos

Powered by vBulletin (Copyright ©2000 - 2019, Jelsoft Enterprises Ltd).
Hosted by www.OICcam.com
IT Support and Services provided by Executive IT Services