├── EasyAudio ├── EasyAudio │ ├── EasyAudio.vcxproj.user │ ├── EasyAudio.vcxproj.filters │ ├── main.cpp │ └── EasyAudio.vcxproj ├── EasyAudio.sln └── README.md ├── EasyDraw ├── Lua-NonStandardLibs │ ├── Lua-NonStandardLibs.vcxproj.user │ ├── Lua-NonStandardLibs.vcxproj.filters │ ├── Lua-NonStandardLibs.vcxproj │ └── main.cpp ├── EasyDraw.sln └── README.md └── README.md /EasyAudio/EasyAudio/EasyAudio.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /EasyDraw/Lua-NonStandardLibs/Lua-NonStandardLibs.vcxproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # EasyGame 2 | Some libraries for Lua to develop games. (Windows Platform Only !) 3 | 4 | + EasyDraw: A simple library for graphic and mouse or keyboard event processing.[LearnMore...](https://github.com/VoidmatrixHeathcliff/EasyLua/tree/master/EasyDraw) 5 | + EasyAudio: A simple library for music and sound processing.[LearnMore...](https://github.com/VoidmatrixHeathcliff/EasyLua/blob/master/EasyAudio/README.md) 6 | -------------------------------------------------------------------------------- /EasyAudio/EasyAudio/EasyAudio.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | -------------------------------------------------------------------------------- /EasyDraw/Lua-NonStandardLibs/Lua-NonStandardLibs.vcxproj.filters: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | {4FC737F1-C7A5-4376-A066-2A32D752A2FF} 6 | cpp;c;cc;cxx;c++;def;odl;idl;hpj;bat;asm;asmx 7 | 8 | 9 | {93995380-89BD-4b04-88EB-625FBE52EBFB} 10 | h;hh;hpp;hxx;h++;hm;inl;inc;ipp;xsd 11 | 12 | 13 | {67DA6AB6-F800-4c08-8B7A-83BB121AAD01} 14 | rc;ico;cur;bmp;dlg;rc2;rct;bin;rgs;gif;jpg;jpeg;jpe;resx;tiff;tif;png;wav;mfcribbon-ms 15 | 16 | 17 | 18 | 19 | 源文件 20 | 21 | 22 | 23 | -------------------------------------------------------------------------------- /EasyAudio/EasyAudio.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30204.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "EasyAudio", "EasyAudio\EasyAudio.vcxproj", "{DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Debug|x64.ActiveCfg = Debug|x64 17 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Debug|x64.Build.0 = Debug|x64 18 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Debug|x86.ActiveCfg = Debug|Win32 19 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Debug|x86.Build.0 = Debug|Win32 20 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Release|x64.ActiveCfg = Release|x64 21 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Release|x64.Build.0 = Release|x64 22 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Release|x86.ActiveCfg = Release|Win32 23 | {DBB0FEB1-F211-4A4C-9DAE-99FF24C96934}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {24FF03B0-5BA6-40FB-BF0E-23C911F31139} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /EasyDraw/EasyDraw.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30204.135 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "Lua-NonStandardLibs", "Lua-NonStandardLibs\Lua-NonStandardLibs.vcxproj", "{AF619351-49D7-496E-98E4-A953D4358BE3}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Debug|x64.ActiveCfg = Debug|x64 17 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Debug|x64.Build.0 = Debug|x64 18 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Debug|x86.ActiveCfg = Debug|Win32 19 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Debug|x86.Build.0 = Debug|Win32 20 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Release|x64.ActiveCfg = Release|x64 21 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Release|x64.Build.0 = Release|x64 22 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Release|x86.ActiveCfg = Release|Win32 23 | {AF619351-49D7-496E-98E4-A953D4358BE3}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {5F164A28-675D-4C03-A74C-0BAE2A886E23} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /EasyAudio/EasyAudio/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | // 初始化声音库,2参数:采样频率(常见的有22050、44100)、声道数(仅作用于音乐播放) 6 | extern "C" int init(lua_State * L) 7 | { 8 | int frequency = lua_tonumber(L, 1); 9 | int channels = lua_tonumber(L, 2); 10 | Mix_Init(MIX_INIT_FLAC | MIX_INIT_MOD | MIX_INIT_MP3 | MIX_INIT_OGG); 11 | Mix_OpenAudio(frequency, MIX_DEFAULT_FORMAT, channels, 2048); 12 | return 0; 13 | } 14 | 15 | // 退出声音库,无参数 16 | extern "C" int quit(lua_State * L) 17 | { 18 | Mix_CloseAudio(); 19 | Mix_Quit(); 20 | return 0; 21 | } 22 | 23 | // 播放音乐,2参数:音乐文件路径、音乐播放的次数(-1为循环播放) 24 | extern "C" int playMusic(lua_State * L) 25 | { 26 | const char* path = lua_tostring(L, 1); 27 | int loops = lua_tonumber(L, 2); 28 | Mix_PlayMusic(Mix_LoadMUS(path), loops); 29 | return 0; 30 | } 31 | 32 | // 播放淡入音乐,3参数:音乐文件路径、音乐播放的次数、淡入音效持续时间(ms) 33 | extern "C" int playFadeInMusic(lua_State * L) 34 | { 35 | const char* path = lua_tostring(L, 1); 36 | int loops = lua_tonumber(L, 2); 37 | int delay = lua_tonumber(L, 3); 38 | Mix_FadeInMusic(Mix_LoadMUS(path), loops, delay); 39 | return 0; 40 | } 41 | 42 | // 设置音乐音量,1参数:音量大小(0-128) 43 | extern "C" int setMusicVolume(lua_State * L) 44 | { 45 | int value = lua_tonumber(L, 1); 46 | Mix_VolumeMusic(value); 47 | return 0; 48 | } 49 | 50 | // 获取当前音乐音量,无参数 51 | // 返回值:当前音乐音量大小 52 | extern "C" int getMusicVolume(lua_State * L) 53 | { 54 | int value = Mix_VolumeMusic(-1); 55 | lua_pushnumber(L, value); 56 | return 1; 57 | } 58 | 59 | // 暂停当前正在播放的音乐,无参数 60 | extern "C" int pauseMusic(lua_State * L) 61 | { 62 | Mix_PauseMusic(); 63 | return 0; 64 | } 65 | 66 | // 恢复当前暂停状态的音乐,无参数 67 | extern "C" int resumeMusic(lua_State * L) 68 | { 69 | Mix_ResumeMusic(); 70 | return 0; 71 | } 72 | 73 | // 播放音效,2参数:音效文件路径、音乐播放的次数(-1为循环播放) 74 | // 备注:音效文件支持以下格式:WAVE, AIFF, RIFF, OGG, VOC 75 | extern "C" int playSound(lua_State * L) 76 | { 77 | const char* path = lua_tostring(L, 1); 78 | int loops = lua_tonumber(L, 2); 79 | if (loops > 0) 80 | { 81 | Mix_PlayChannel(-1, Mix_LoadWAV(path), loops - 1); 82 | } 83 | else 84 | { 85 | Mix_PlayChannel(-1, Mix_LoadWAV(path), loops); 86 | } 87 | return 0; 88 | } 89 | 90 | // 暂停程序,无参数 91 | extern "C" int pause(lua_State * L) 92 | { 93 | system("pause"); 94 | return 0; 95 | } 96 | 97 | // 挂起程序指定时间,1参数:挂起时间(单位:毫秒) 98 | extern "C" int sleep(lua_State * L) 99 | { 100 | int delay = lua_tonumber(L, 1); 101 | SDL_Delay(delay); 102 | return 0; 103 | } 104 | 105 | static luaL_Reg cMethods[] = { 106 | { "Init", init }, 107 | { "Quit", quit }, 108 | { "PlayMusic", playMusic }, 109 | { "PlayFadeInMusic", playFadeInMusic }, 110 | { "SetMusicVolume", setMusicVolume }, 111 | { "GetMusicVolume", getMusicVolume }, 112 | { "PauseMusic", pauseMusic }, 113 | { "ResumeMusic", resumeMusic }, 114 | { "PlaySound", playSound }, 115 | { "Pause", pause }, 116 | { "Sleep", sleep }, 117 | { NULL, NULL } 118 | }; 119 | 120 | extern "C" __declspec(dllexport) 121 | int luaopen_EasyAudio(lua_State * L) 122 | { 123 | luaL_newlib(L, cMethods); 124 | return 1; 125 | } 126 | -------------------------------------------------------------------------------- /EasyAudio/README.md: -------------------------------------------------------------------------------- 1 | # EasyAudio开发文档 2 | 3 | 编译需要第三方库[SDL2.0](http://www.libsdl.org/)和[SDL_mixer2.0](http://www.libsdl.org/projects/SDL_mixer/)支持 4 | *** 5 | 6 | > ## Init 7 | 初始化声音库 8 | ```Lua 9 | Init(frequency, channels) 10 | ``` 11 | ### 参数 12 | + ***[number] frequency***:声音的采样频率,常见频率为22050或44100 13 | + ***[number] channels***:声道数(仅作用于音乐播放),可以是如下值: 14 | 15 | | 值 | 描述 | 16 | | :-- | :---- | 17 | | 1 | 单声道 | 18 | | 2 | 双声道 | 19 | 20 | ### 返回值 21 | 无 22 | ### 示例 23 | ```Lua 24 | EasyAudio = require("EasyAudio") 25 | EasyAudio.Init(44100, 2) -- 初始化声音库为44.1KHz、双声道 26 | ``` 27 | 28 | > ## Quit 29 | 关闭并退出声音库 30 | ```Lua 31 | Quit() 32 | ``` 33 | ### 参数 34 | 无 35 | ### 返回值 36 | 无 37 | ### 示例 38 | ```Lua 39 | EasyAudio = require("EasyAudio") 40 | EasyAudio.Init(44100, 2) 41 | EasyAudio.Quit() 42 | ``` 43 | 44 | > ## PlayMusic 45 | 播放指定音乐文件 46 | ```Lua 47 | PlayMusic(filepath, loops) 48 | ``` 49 | ### 参数 50 | + ***[string] filepaths***:音乐文件路径 51 | + ***[number] loops***:音乐文件播放次数,-1为循环播放 52 | ### 返回值 53 | 无 54 | ### 备注 55 | 支持的编码格式有:FLAC、MOD、MP3、OGG 56 | ### 示例 57 | ```Lua 58 | EasyAudio = require("EasyAudio") 59 | EasyAudio.Init(44100, 2) 60 | EasyAudio.PlayMusic("bgm.mp3", -1) 61 | ``` 62 | 63 | > ## PlayFadeInMusic 64 | 使用淡入效果播放指定音乐文件 65 | ```Lua 66 | PlayFadeInMusic(filepath, loops, ms) 67 | ``` 68 | ### 参数 69 | + ***[string] filepaths***:音乐文件路径 70 | + ***[number] loops***:音乐文件播放次数,-1为循环播放 71 | + ***[number] ms***:淡入效果持续时间,单位为毫秒 72 | ### 返回值 73 | 无 74 | ### 备注 75 | 支持的编码格式有:FLAC、MOD、MP3、OGG 76 | ### 示例 77 | ```Lua 78 | EasyAudio = require("EasyAudio") 79 | EasyAudio.Init(44100, 2) 80 | EasyAudio.PlayFadeInMusic("bgm.mp3", -1) 81 | ``` 82 | 83 | > ## SetMusicVolume 84 | 设置音乐播放的音量 85 | ```Lua 86 | SetMusicVolume(value) 87 | ``` 88 | ### 参数 89 | + ***[number] value***:音乐播放的音量,为0-128之间整数 90 | ### 返回值 91 | 无 92 | ### 示例 93 | ```Lua 94 | EasyAudio = require("EasyAudio") 95 | EasyAudio.Init(44100, 2) 96 | EasyAudio.SetMusicVolume(50) 97 | ``` 98 | 99 | > ## GetMusicVolume 100 | 获取当前音乐播放的音量 101 | ```Lua 102 | GetMusicVolume() 103 | ``` 104 | ### 参数 105 | 无 106 | ### 返回值 107 | + ***[number] value***:当前音乐播放的音量 108 | ### 示例 109 | ```Lua 110 | EasyAudio = require("EasyAudio") 111 | EasyAudio.Init(44100, 2) 112 | volume = EasyAudio.GetMusicVolume() 113 | ``` 114 | 115 | > ## PauseMusic 116 | 暂停当前正在播放的音乐 117 | ```Lua 118 | PauseMusic() 119 | ``` 120 | ### 参数 121 | 无 122 | ### 返回值 123 | 无 124 | ### 示例 125 | ```Lua 126 | EasyAudio = require("EasyAudio") 127 | EasyAudio.Init(44100, 2) 128 | EasyAudio.PlayFadeInMusic("bgm.mp3", -1) 129 | EasyAudio.Sleep(5000) -- 播放音乐五秒后暂停 130 | EasyAudio.PauseMusics() 131 | ``` 132 | 133 | > ## ResumeMusic 134 | 恢复当前暂停状态的音乐 135 | ```Lua 136 | ResumeMusic() 137 | ``` 138 | ### 参数 139 | 无 140 | ### 返回值 141 | 无 142 | ### 示例 143 | ```Lua 144 | EasyAudio = require("EasyAudio") 145 | EasyAudio.Init(44100, 2) 146 | EasyAudio.PlayFadeInMusic("bgm.mp3", -1) 147 | EasyAudio.Sleep(5000) -- 播放音乐五秒后暂停 148 | EasyAudio.PauseMusics() 149 | EasyAudio.Sleep(5000) -- 暂停音乐五秒后恢复 150 | EasyAudio.ResumeMusic() 151 | ``` 152 | 153 | > ## PlaySound 154 | 播放指定的音效文件 155 | ```Lua 156 | PlaySound(filepath, loops) 157 | ``` 158 | ### 参数 159 | + ***[string] filepaths***:音效文件路径 160 | + ***[number] loops***:音效文件播放次数,-1为循环播放 161 | ### 返回值 162 | 无 163 | ### 备注 164 | 支持的编码格式有:WAVE、AIFF、RIFF、OGG、VOC 165 | ### 示例 166 | ```Lua 167 | EasyAudio = require("EasyAudio") 168 | EasyAudio.Init(44100, 2) 169 | EasyAudio.PlaySound("boom.wav", 1) 170 | ``` 171 | 172 | > ## Pause 173 | 暂停程序 174 | ```Lua 175 | Pause() 176 | ``` 177 | ### 参数 178 | 无 179 | ### 返回值 180 | 无 181 | ### 示例 182 | ```Lua 183 | EasyDraw = require("EasyDraw") 184 | EasyDraw.Init(1280, 720) 185 | EasyDraw.Circle(400, 400, 150) 186 | EasyDraw.Pause() -- 暂停程序,防止窗口在绘制完成后立刻退出 187 | EasyDraw.Close() 188 | ``` 189 | 190 | > ## Sleep 191 | 挂起程序指定时间 192 | ```Lua 193 | Sleep(ms) 194 | ``` 195 | ### 参数 196 | + ***[number] ms***:程序挂起时间,单位为毫秒 197 | ### 返回值 198 | 无 199 | ### 示例 200 | ```Lua 201 | EasyDraw = require("EasyDraw") 202 | EasyDraw.Init(1280, 720) 203 | EasyDraw.Circle(400, 400, 150) 204 | EasyDraw.Sleep(5000) -- 挂起程序5秒,防止窗口在绘制完成后立刻退出 205 | EasyDraw.Close() 206 | ``` 207 | -------------------------------------------------------------------------------- /EasyDraw/Lua-NonStandardLibs/Lua-NonStandardLibs.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 16.0 26 | Win32Proj 27 | {af619351-49d7-496e-98e4-a953d4358be3} 28 | LuaNonStandardLibs 29 | 10.0 30 | EasyDraw 31 | 32 | 33 | 34 | DynamicLibrary 35 | true 36 | v142 37 | Unicode 38 | 39 | 40 | DynamicLibrary 41 | false 42 | v142 43 | true 44 | Unicode 45 | 46 | 47 | DynamicLibrary 48 | true 49 | v142 50 | Unicode 51 | 52 | 53 | DynamicLibrary 54 | false 55 | v142 56 | true 57 | Unicode 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | true 79 | 80 | 81 | false 82 | 83 | 84 | true 85 | 86 | 87 | false 88 | 89 | 90 | 91 | Level3 92 | true 93 | WIN32;_DEBUG;LUANONSTANDARDLIBS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 94 | true 95 | NotUsing 96 | pch.h 97 | D:\lua-5.4.0\src;%(AdditionalIncludeDirectories) 98 | Default 99 | 100 | 101 | Windows 102 | true 103 | false 104 | D:\lua-build-5.4.0\x86\Debug;%(AdditionalLibraryDirectories) 105 | LuaLib-5.4.0.lib;%(AdditionalDependencies) 106 | 107 | 108 | 109 | 110 | Level3 111 | true 112 | true 113 | true 114 | WIN32;NDEBUG;LUANONSTANDARDLIBS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 115 | true 116 | NotUsing 117 | pch.h 118 | D:\lua-5.4.0\src;%(AdditionalIncludeDirectories) 119 | Default 120 | 121 | 122 | Windows 123 | true 124 | true 125 | true 126 | false 127 | D:\lua-build-5.4.0\x86\Debug;%(AdditionalLibraryDirectories) 128 | LuaLib-5.4.0.lib;%(AdditionalDependencies) 129 | 130 | 131 | 132 | 133 | Level3 134 | true 135 | _DEBUG;LUANONSTANDARDLIBS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 136 | true 137 | Use 138 | pch.h 139 | 140 | 141 | Windows 142 | true 143 | false 144 | 145 | 146 | 147 | 148 | Level3 149 | true 150 | true 151 | true 152 | NDEBUG;LUANONSTANDARDLIBS_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 153 | true 154 | Use 155 | pch.h 156 | 157 | 158 | Windows 159 | true 160 | true 161 | true 162 | false 163 | 164 | 165 | 166 | 167 | 168 | 169 | -------------------------------------------------------------------------------- /EasyAudio/EasyAudio/EasyAudio.vcxproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | Win32 7 | 8 | 9 | Release 10 | Win32 11 | 12 | 13 | Debug 14 | x64 15 | 16 | 17 | Release 18 | x64 19 | 20 | 21 | 22 | 23 | 24 | 25 | 16.0 26 | Win32Proj 27 | {dbb0feb1-f211-4a4c-9dae-99ff24c96934} 28 | EasyAudio 29 | 10.0 30 | 31 | 32 | 33 | DynamicLibrary 34 | true 35 | v142 36 | Unicode 37 | 38 | 39 | DynamicLibrary 40 | false 41 | v142 42 | true 43 | Unicode 44 | 45 | 46 | DynamicLibrary 47 | true 48 | v142 49 | Unicode 50 | 51 | 52 | DynamicLibrary 53 | false 54 | v142 55 | true 56 | Unicode 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | true 78 | 79 | 80 | false 81 | 82 | 83 | true 84 | 85 | 86 | false 87 | 88 | 89 | 90 | Level3 91 | true 92 | WIN32;_DEBUG;EASYAUDIO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 93 | true 94 | NotUsing 95 | pch.h 96 | D:\SDL2-2.0.12\include;D:\lua-5.4.0\src;D:\SDL2_mixer-2.0.4\include;%(AdditionalIncludeDirectories) 97 | 98 | 99 | Windows 100 | true 101 | false 102 | D:\lua-build-5.4.0\x86\Debug;D:\SDL2-2.0.12\lib\x86;D:\SDL2_mixer-2.0.4\lib\x86;%(AdditionalLibraryDirectories) 103 | LuaLib-5.4.0.lib;SDL2_mixer.lib;SDL2.lib;%(AdditionalDependencies) 104 | 105 | 106 | 107 | 108 | Level3 109 | true 110 | true 111 | true 112 | WIN32;NDEBUG;EASYAUDIO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 113 | true 114 | NotUsing 115 | pch.h 116 | D:\SDL2-2.0.12\include;D:\lua-5.4.0\src;D:\SDL2_mixer-2.0.4\include;%(AdditionalIncludeDirectories) 117 | 118 | 119 | Windows 120 | true 121 | true 122 | true 123 | false 124 | D:\lua-build-5.4.0\x86\Debug;D:\SDL2-2.0.12\lib\x86;D:\SDL2_mixer-2.0.4\lib\x86;%(AdditionalLibraryDirectories) 125 | LuaLib-5.4.0.lib;SDL2_mixer.lib;SDL2.lib;%(AdditionalDependencies) 126 | 127 | 128 | 129 | 130 | Level3 131 | true 132 | _DEBUG;EASYAUDIO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 133 | true 134 | Use 135 | pch.h 136 | 137 | 138 | Windows 139 | true 140 | false 141 | 142 | 143 | 144 | 145 | Level3 146 | true 147 | true 148 | true 149 | NDEBUG;EASYAUDIO_EXPORTS;_WINDOWS;_USRDLL;%(PreprocessorDefinitions) 150 | true 151 | Use 152 | pch.h 153 | 154 | 155 | Windows 156 | true 157 | true 158 | true 159 | false 160 | 161 | 162 | 163 | 164 | 165 | -------------------------------------------------------------------------------- /EasyDraw/README.md: -------------------------------------------------------------------------------- 1 | # EasyDraw开发文档 2 | 3 | 编译需要第三方库[EasyX](https://easyx.cn/)支持 4 | *** 5 | 6 | > ## Init 7 | 初始化绘图窗口 8 | ```Lua 9 | Init(width, height) 10 | ``` 11 | ### 参数 12 | + ***[number] width***:窗口宽度 13 | + ***[number] height***:窗口高度 14 | ### 返回值 15 | 无 16 | ### 示例 17 | ```Lua 18 | EasyDraw = require("EasyDraw") 19 | EasyDraw.Init(1280, 720) -- 初始化窗口大小为1280x720 20 | ``` 21 | 22 | > ## Clear 23 | 使用当前背景色清空绘图窗口 24 | ```Lua 25 | Clear() 26 | ``` 27 | ### 参数 28 | 无 29 | ### 返回值 30 | 无 31 | ### 示例 32 | ```Lua 33 | EasyDraw = require("EasyDraw") 34 | EasyDraw.Init(1280, 720) 35 | EasyDraw.Clear() 36 | ``` 37 | 38 | > ## Close 39 | 关闭当前绘图窗口 40 | ```Lua 41 | Close() 42 | ``` 43 | ### 参数 44 | 无 45 | ### 返回值 46 | 无 47 | ### 示例 48 | ```Lua 49 | EasyDraw = require("EasyDraw") 50 | EasyDraw.Init(1280, 720) 51 | EasyDraw.Close() 52 | ``` 53 | 54 | > ## SetTitle 55 | 设置绘图窗口标题 56 | ```Lua 57 | SetTitle(title) 58 | ``` 59 | ### 参数 60 | + ***[string] title***:窗口标题 61 | ### 返回值 62 | 无 63 | ### 示例 64 | ```Lua 65 | EasyDraw = require("EasyDraw") 66 | EasyDraw.Init(1280, 720) 67 | EasyDraw.SetTitle("HelloWorld") 68 | ``` 69 | 70 | > ## SetBGColor 71 | 设置绘图窗口背景颜色 72 | ```Lua 73 | SetBGColor(R, G, B) 74 | ``` 75 | ### 参数 76 | + ***[number] R***:颜色的红色分量 77 | + ***[number] G***:颜色的绿色分量 78 | + ***[number] B***:颜色的蓝色分量 79 | ### 返回值 80 | 无 81 | ## 备注 82 | 在设置当前绘图窗口背景色后,并不会改变现有的颜色,而是只改变背景色的值,之后执行的绘图语句会使用此背景色,例如在"OPAQUE"的填充模式下执行DrawText(),文本底色便为新设置的窗口背景色;如需立刻修改全部背景色,则需在设置背景色后执行Clear()语句 83 | ### 示例 84 | ```Lua 85 | EasyDraw = require("EasyDraw") 86 | EasyDraw.Init(1280, 720) 87 | EasyDraw.SetBGColor(0, 0, 255) -- 设置背景色为蓝色 88 | EasyDraw.Clear() -- 使用当前背景色清空窗口 89 | ``` 90 | 91 | > ## SetBGMode 92 | 设置绘图窗口背景颜色填充模式 93 | ```Lua 94 | SetBGMode(mode) 95 | ``` 96 | ### 参数 97 | + ***[string] mode***:背景模式,可以是如下值: 98 | 99 | | 值 | 描述 | 100 | | :------------ | :------------------- | 101 | | "OPAQUE" | 使用当前背景色填充背景 | 102 | | "TRANSPARENT" | 背景为透明 | 103 | 104 | ### 返回值 105 | 无 106 | ### 示例 107 | ```Lua 108 | EasyDraw = require("EasyDraw") 109 | EasyDraw.Init(1280, 720) 110 | EasyDraw.SetBGColor(0, 0, 255) -- 设置背景颜色为蓝色 111 | ``` 112 | 113 | > ## SetFillColor 114 | 设置填充颜色 115 | ```Lua 116 | SetFillColor(R, G, B) 117 | ``` 118 | ### 参数 119 | + ***[number] R***:颜色的红色分量 120 | + ***[number] G***:颜色的绿色分量 121 | + ***[number] B***:颜色的蓝色分量 122 | ### 返回值 123 | 无 124 | ### 示例 125 | ```Lua 126 | EasyDraw = require("EasyDraw") 127 | EasyDraw.Init(1280, 720) 128 | EasyDraw.SetFillColor(0, 0, 255) -- 设置填充颜色为蓝色 129 | ``` 130 | 131 | > ## SetLineColor 132 | 设置画线颜色 133 | ```Lua 134 | SetLineColor(R, G, B) 135 | ``` 136 | ### 参数 137 | + ***[number] R***:颜色的红色分量 138 | + ***[number] G***:颜色的绿色分量 139 | + ***[number] B***:颜色的蓝色分量 140 | ### 返回值 141 | 无 142 | ### 示例 143 | ```Lua 144 | EasyDraw = require("EasyDraw") 145 | EasyDraw.Init(1280, 720) 146 | EasyDraw.SetLineColor(0, 0, 255) -- 设置画线颜色为蓝色 147 | ``` 148 | 149 | > ## SetTextColor 150 | 设置文本颜色 151 | ```Lua 152 | SetTextColor(R, G, B) 153 | ``` 154 | ### 参数 155 | + ***[number] R***:颜色的红色分量 156 | + ***[number] G***:颜色的绿色分量 157 | + ***[number] B***:颜色的蓝色分量 158 | ### 返回值 159 | 无 160 | ### 示例 161 | ```Lua 162 | EasyDraw = require("EasyDraw") 163 | EasyDraw.Init(1280, 720) 164 | EasyDraw.SetTextColor(0, 0, 255) -- 设置文本颜色为蓝色 165 | ``` 166 | 167 | > ## SetLineStyle 168 | 设置画线样式 169 | ```Lua 170 | SetLineStyle(style) 171 | ``` 172 | ### 参数 173 | + ***[string] style***:画线样式,可以是如下值: 174 | 175 | | 值 | 描述 | 176 | | :----------- | :-------- | 177 | | "SOLID" | 实线 | 178 | | "DASH" | ---- | 179 | | "DOT" | ···· | 180 | | "DASHDOT" | -·-·-·- | 181 | | "DASHDOTDOT" | -··-··-·· | 182 | | "NULL" | 不可见 | 183 | 184 | ### 返回值 185 | 无 186 | ### 示例 187 | ```Lua 188 | EasyDraw = require("EasyDraw") 189 | EasyDraw.Init(1280, 720) 190 | EasyDraw.SetLineStyle("SOLID") -- 设置画线样式为实线 191 | ``` 192 | 193 | > ## Point 194 | 绘制指定颜色的像素点 195 | ```Lua 196 | Point(x, y, R, G, B) 197 | ``` 198 | ### 参数 199 | + ***[number] x***:像素点的x坐标 200 | + ***[number] y***:像素点的y坐标 201 | + ***[number] R***:颜色的红色分量 202 | + ***[number] G***:颜色的绿色分量 203 | + ***[number] B***:颜色的蓝色分量 204 | ### 返回值 205 | 无 206 | ### 示例 207 | ```Lua 208 | EasyDraw = require("EasyDraw") 209 | EasyDraw.Init(1280, 720) 210 | EasyDraw.Point(100, 100, 255, 0, 0) -- 在(100, 100)位置绘制一个红色像素点 211 | ``` 212 | 213 | > ## Line 214 | 绘制直线 215 | ```Lua 216 | Line(x1, y1, y1, y2) 217 | ``` 218 | ### 参数 219 | + ***[number] x1***:直线起始位置的x坐标 220 | + ***[number] y1***:直线起始位置的y坐标 221 | + ***[number] x2***:直线结束位置的x坐标 222 | + ***[number] y2***:直线结束位置的y坐标 223 | ### 返回值 224 | 无 225 | ### 示例 226 | ```Lua 227 | EasyDraw = require("EasyDraw") 228 | EasyDraw.Init(1280, 720) 229 | EasyDraw.Line(0, 0, 100, 100) -- 从(0, 0)位置到(100, 100)位置画一条直线 230 | ``` 231 | 232 | > ## Roundrect 233 | 绘制无填充圆角矩形 234 | ```Lua 235 | Roundrect(left, top, right, bottom, ellipsewidth, ellipseheight) 236 | ``` 237 | ### 参数 238 | + ***[number] left***:矩形左边线坐标 239 | + ***[number] top***:矩形上边线坐标 240 | + ***[number] right***:矩形右边线坐标 241 | + ***[number] bottom***:矩形下边线坐标 242 | + ***[number] ellipsewidth***:圆角椭圆宽度 243 | + ***[number] ellipseheight***:圆角椭圆高度 244 | ### 返回值 245 | 无 246 | ### 示例 247 | ```Lua 248 | EasyDraw = require("EasyDraw") 249 | EasyDraw.Init(1280, 720) 250 | EasyDraw.Roundrect(100, 100, 300, 200, 20, 10) 251 | ``` 252 | 253 | > ## FillRoundrect 254 | 绘制有填充圆角矩形 255 | ```Lua 256 | FillRoundrect(left, top, right, bottom, ellipsewidth, ellipseheight) 257 | ``` 258 | ### 参数 259 | + ***[number] left***:矩形左边线坐标 260 | + ***[number] top***:矩形上边线坐标 261 | + ***[number] right***:矩形右边线坐标 262 | + ***[number] bottom***:矩形下边线坐标 263 | + ***[number] ellipsewidth***:圆角椭圆宽度 264 | + ***[number] ellipseheight***:圆角椭圆高度 265 | ### 返回值 266 | 无 267 | ### 示例 268 | ```Lua 269 | EasyDraw = require("EasyDraw") 270 | EasyDraw.Init(1280, 720) 271 | EasyDraw.FillRoundrect(100, 100, 300, 200, 20, 10) 272 | ``` 273 | 274 | > ## SolidRoundrect 275 | 绘制填充无边框圆角矩形 276 | ```Lua 277 | SolidRoundrect(left, top, right, bottom, ellipsewidth, ellipseheight) 278 | ``` 279 | ### 参数 280 | + ***[number] left***:矩形左边线坐标 281 | + ***[number] top***:矩形上边线坐标 282 | + ***[number] right***:矩形右边线坐标 283 | + ***[number] bottom***:矩形下边线坐标 284 | + ***[number] ellipsewidth***:圆角椭圆宽度 285 | + ***[number] ellipseheight***:圆角椭圆高度 286 | ### 返回值 287 | 无 288 | ### 示例 289 | ```Lua 290 | EasyDraw = require("EasyDraw") 291 | EasyDraw.Init(1280, 720) 292 | EasyDraw.SolidRoundrect(100, 100, 300, 200, 20, 10) 293 | ``` 294 | 295 | > ## Ellipse 296 | 绘制无填充椭圆 297 | ```Lua 298 | Ellipse(left, top, right, bottom) 299 | ``` 300 | ### 参数 301 | + ***[number] left***:椭圆外切矩形左上角x坐标 302 | + ***[number] top***:椭圆外切矩形左上角y坐标 303 | + ***[number] right***:椭圆外切矩形右下角x坐标 304 | + ***[number] bottom***:椭圆外切矩形右下角y坐标 305 | ### 返回值 306 | 无 307 | ### 示例 308 | ```Lua 309 | EasyDraw = require("EasyDraw") 310 | EasyDraw.Init(1280, 720) 311 | EasyDraw.Ellipse(100, 100, 300, 200) 312 | ``` 313 | 314 | > ## FillEllipse 315 | 绘制有填充椭圆 316 | ```Lua 317 | FillEllipse(left, top, right, bottom) 318 | ``` 319 | ### 参数 320 | + ***[number] left***:椭圆外切矩形左上角x坐标 321 | + ***[number] top***:椭圆外切矩形左上角y坐标 322 | + ***[number] right***:椭圆外切矩形右下角x坐标 323 | + ***[number] bottom***:椭圆外切矩形右下角y坐标 324 | ### 返回值 325 | 无 326 | ### 示例 327 | ```Lua 328 | EasyDraw = require("EasyDraw") 329 | EasyDraw.Init(1280, 720) 330 | EasyDraw.FillEllipse(100, 100, 300, 200) 331 | ``` 332 | 333 | > ## SolidEllipse 334 | 绘制填充无边框椭圆 335 | ```Lua 336 | SolidEllipse(left, top, right, bottom) 337 | ``` 338 | ### 参数 339 | + ***[number] left***:椭圆外切矩形左上角x坐标 340 | + ***[number] top***:椭圆外切矩形左上角y坐标 341 | + ***[number] right***:椭圆外切矩形右下角x坐标 342 | + ***[number] bottom***:椭圆外切矩形右下角y坐标 343 | ### 返回值 344 | 无 345 | ### 示例 346 | ```Lua 347 | EasyDraw = require("EasyDraw") 348 | EasyDraw.Init(1280, 720) 349 | EasyDraw.SolidEllipse(100, 100, 300, 200) 350 | ``` 351 | 352 | > ## Circle 353 | 绘制无填充圆 354 | ```Lua 355 | Circle(x, y, radius) 356 | ``` 357 | ### 参数 358 | + ***[number] x***:圆心x坐标 359 | + ***[number] y***:圆心y坐标 360 | + ***[number] radius***:半径 361 | ### 返回值 362 | 无 363 | ### 示例 364 | ```Lua 365 | EasyDraw = require("EasyDraw") 366 | EasyDraw.Init(1280, 720) 367 | EasyDraw.Circle(100, 100, 40) 368 | ``` 369 | 370 | > ## FillCircle 371 | 绘制有填充圆 372 | ```Lua 373 | FillCircle(x, y, radius) 374 | ``` 375 | ### 参数 376 | + ***[number] x***:圆心x坐标 377 | + ***[number] y***:圆心y坐标 378 | + ***[number] radius***:半径 379 | ### 返回值 380 | 无 381 | ### 示例 382 | ```Lua 383 | EasyDraw = require("EasyDraw") 384 | EasyDraw.Init(1280, 720) 385 | EasyDraw.FillCircle(100, 100, 40) 386 | ``` 387 | 388 | > ## SolidCircle 389 | 绘制填充无边框圆 390 | ```Lua 391 | SolidCircle(x, y, radius) 392 | ``` 393 | ### 参数 394 | + ***[number] x***:圆心x坐标 395 | + ***[number] y***:圆心y坐标 396 | + ***[number] radius***:半径 397 | ### 返回值 398 | 无 399 | ### 示例 400 | ```Lua 401 | EasyDraw = require("EasyDraw") 402 | EasyDraw.Init(1280, 720) 403 | EasyDraw.SolidCircle(100, 100, 40) 404 | ``` 405 | 406 | > ## Rectangle 407 | 绘制无填充矩形 408 | ```Lua 409 | Rectangle(left, top, right, bottom) 410 | ``` 411 | ### 参数 412 | + ***[number] left***:矩形左边线坐标 413 | + ***[number] top***:矩形上边线坐标 414 | + ***[number] right***:矩形右边线坐标 415 | + ***[number] bottom***:矩形下边线坐标 416 | ### 返回值 417 | 无 418 | ### 示例 419 | ```Lua 420 | EasyDraw = require("EasyDraw") 421 | EasyDraw.Init(1280, 720) 422 | EasyDraw.Rectangle(100, 100, 300, 200) 423 | ``` 424 | 425 | > ## FillRectangle 426 | 绘制有填充矩形 427 | ```Lua 428 | FillRectangle(left, top, right, bottom) 429 | ``` 430 | ### 参数 431 | + ***[number] left***:矩形左边线坐标 432 | + ***[number] top***:矩形上边线坐标 433 | + ***[number] right***:矩形右边线坐标 434 | + ***[number] bottom***:矩形下边线坐标 435 | ### 返回值 436 | 无 437 | ### 示例 438 | ```Lua 439 | EasyDraw = require("EasyDraw") 440 | EasyDraw.Init(1280, 720) 441 | EasyDraw.FillRectangle(100, 100, 300, 200) 442 | ``` 443 | 444 | > ## SolidRectangle 445 | 绘制填充无边框矩形 446 | ```Lua 447 | SolidRectangle(left, top, right, bottom) 448 | ``` 449 | ### 参数 450 | + ***[number] left***:矩形左边线坐标 451 | + ***[number] top***:矩形上边线坐标 452 | + ***[number] right***:矩形右边线坐标 453 | + ***[number] bottom***:矩形下边线坐标 454 | ### 返回值 455 | 无 456 | ### 示例 457 | ```Lua 458 | EasyDraw = require("EasyDraw") 459 | EasyDraw.Init(1280, 720) 460 | EasyDraw.SolidRectangle(100, 100, 300, 200) 461 | ``` 462 | 463 | > ## SetTextStyle 464 | 设置文本字体样式 465 | ```Lua 466 | SetTextStyle(height, width, font) 467 | ``` 468 | ### 参数 469 | + ***[number] height***:字体高度 470 | + ***[number] width***:字体宽度,0为自适应 471 | + ***[string] font***:字体名称 472 | ### 返回值 473 | 无 474 | ### 示例 475 | ```Lua 476 | EasyDraw = require("EasyDraw") 477 | EasyDraw.Init(1280, 720) 478 | EasyDraw.SetTextStyle(25, 0, "隶书") 479 | ``` 480 | 481 | > ## DrawText 482 | 在指定位置绘制文本 483 | ```Lua 484 | DrawText(x, y, content) 485 | ``` 486 | ### 参数 487 | + ***[number] x***:x坐标 488 | + ***[number] y***:y坐标 489 | + ***[string] content***:文本内容 490 | ### 返回值 491 | 无 492 | ### 示例 493 | ```Lua 494 | EasyDraw = require("EasyDraw") 495 | EasyDraw.Init(1280, 720) 496 | EasyDraw.DrawText(100, 100, "你好,世界!") 497 | ``` 498 | 499 | > ## DrawImage 500 | 在指定位置绘制不带透明度图片 501 | ```Lua 502 | DrawImage(x, y, width, height, filepath) 503 | ``` 504 | ### 参数 505 | + ***[number] x***:x坐标 506 | + ***[number] y***:y坐标 507 | + ***[number] width***:图片缩放宽度 508 | + ***[number] height***:图片缩放高度 509 | + ***[string] filepath***:图片文件路径 510 | ### 返回值 511 | 无 512 | ### 示例 513 | ```Lua 514 | EasyDraw = require("EasyDraw") 515 | EasyDraw.Init(1280, 720) 516 | EasyDraw.DrawImage(0, 0, 1280, 720, "./Background.jpg") 517 | ``` 518 | 519 | > ## DrawTransImage 520 | 在指定位置绘制带透明度的图片 521 | ```Lua 522 | DrawTransImage(x, y, width, height, filepath) 523 | ``` 524 | ### 参数 525 | + ***[number] x***:x坐标 526 | + ***[number] y***:y坐标 527 | + ***[number] width***:图片缩放宽度 528 | + ***[number] height***:图片缩放高度 529 | + ***[string] filepath***:图片文件路径 530 | ### 返回值 531 | 无 532 | ### 示例 533 | ```Lua 534 | EasyDraw = require("EasyDraw") 535 | EasyDraw.Init(1280, 720) 536 | EasyDraw.DrawTransImage(0, 0, 1280, 720, "./Background.jpg") 537 | ``` 538 | 539 | > ## FloodFill 540 | 填充指定区域 541 | ```Lua 542 | FloodFill(x, y, R, G, B, filltype) 543 | ``` 544 | ### 参数 545 | + ***[number] x***:填充起点x坐标 546 | + ***[number] y***:填充起点y坐标 547 | + ***[number] R***:颜色的红色分量 548 | + ***[number] G***:颜色的绿色分量 549 | + ***[number] B***:颜色的蓝色分量 550 | + ***[string] style***:填充类型,可以是如下值: 551 | 552 | | 值 | 描述 | 553 | | :-------- | :-------------------------------- | 554 | | "BORDER" | 填充动作发生在指定颜色围成的封闭区域 | 555 | | "SURFACE" | 填充动作发生在指定颜色的连续表面 | 556 | 557 | ### 返回值 558 | 无 559 | ### 备注 560 | + 对于 BORDER 填充类型,填充动作以指定坐标为起点,向周围扩散,直到指定的颜色才会终止,指定的区域必须是封闭的,故适用于填充具有固定颜色边界的区域 561 | + 对于 SURFACE 填充类型,填充动作以指定坐标为起点,只要邻接的颜色为指定颜色,填充就会延伸,故适用于填充具有多种颜色边界的区域 562 | ### 示例 563 | ```Lua 564 | EasyDraw = require("EasyDraw") 565 | EasyDraw.Init(1280, 720) 566 | EasyDraw.SetBGColor(0, 255, 0) -- 设置当前绘图窗口背景色为绿色 567 | EasyDraw.Clear() -- 使用当前背景色清空整个绘图窗口 568 | EasyDraw.FloodFill(0, 0, 0, 255, 0, "SURFACE") -- 从(0, 0)点开始使用默认白色填充邻接的绿色区域 569 | ``` 570 | 571 | > ## CaptureEvent 572 | 捕获缓冲区的鼠标及部分键盘事件,并更新EasyDraw内部事件变量 573 | ```Lua 574 | CaptureEvent() 575 | ``` 576 | ### 参数 577 | 无 578 | ### 返回值 579 | 无 580 | ### 示例 581 | ```Lua 582 | EasyDraw = require("EasyDraw") 583 | EasyDraw.Init(1280, 720) 584 | while (true) 585 | do 586 | EasyDraw.CaptureEvent() 587 | -- 处理捕获到的事件 -- 588 | end 589 | ``` 590 | 591 | > ## CheckEventType 592 | 判断当前事件类型是否为指定事件 593 | ```Lua 594 | result = CheckEventType(eventtype) 595 | ``` 596 | ### 参数 597 | + ***[string] eventtype***:事件类型,可以是如下值: 598 | 599 | | 值 | 描述 | 600 | | :-------------- | :---------- | 601 | | "MOUSEMOVE" | 鼠标移动 | 602 | | "MOUSEWHELL" | 鼠标滚轮移动 | 603 | | "LBUTTONDOWN" | 鼠标左键按下 | 604 | | "LBUTTONUP" | 鼠标左键抬起 | 605 | | "LBUTTONDBLCLK" | 鼠标左键双击 | 606 | | "MBUTTONDOWN" | 鼠标中键按下 | 607 | | "MBUTTONUP" | 鼠标中键抬起 | 608 | | "MBUTTONDBLCLK" | 鼠标中键双击 | 609 | | "RBUTTONDOWN" | 鼠标右键按下 | 610 | | "RBUTTONUP" | 鼠标右键抬起 | 611 | | "RBUTTONDBLCLK" | 鼠标右键双击 | 612 | | "CTRLDOWN" | Ctrl键按下 | 613 | | "SHIFTDOWN" | Shift键按下 | 614 | 615 | ### 返回值 616 | + ***[number] result***:判断结果,可以是如下值: 617 | 618 | | 值 | 描述 | 619 | | :-- | :----------------- | 620 | | -1 | 指定事件类型不存在 | 621 | | 0 | 当前事件不是指定事件 | 622 | | 1 | 当前事件是指定事件 | 623 | 624 | ### 示例 625 | ```Lua 626 | EasyDraw = require("EasyDraw") 627 | EasyDraw.Init(1280, 720) 628 | while (true) 629 | do 630 | EasyDraw.CaptureEvent() 631 | if (EasyDraw.CheckEventType("LBUTTONDOWN") == 1) 632 | then 633 | -- 处理鼠标左键单击事件 -- 634 | end 635 | end 636 | 637 | ``` 638 | 639 | > ## CaptureEvent 640 | 捕获缓冲区的鼠标及部分键盘事件,并更新EasyDraw内部事件变量 641 | ```Lua 642 | CaptureEvent() 643 | ``` 644 | ### 参数 645 | 无 646 | ### 返回值 647 | 无 648 | ### 示例 649 | ```Lua 650 | EasyDraw = require("EasyDraw") 651 | EasyDraw.Init(1280, 720) 652 | while (true) 653 | do 654 | EasyDraw.CaptureEvent() 655 | -- 处理捕获到的事件 -- 656 | end 657 | ``` 658 | 659 | > ## GetMousePosition 660 | 获取当前鼠标位置 661 | ```Lua 662 | x, y = GetMousePosition() 663 | ``` 664 | ### 参数 665 | 无 666 | ### 返回值 667 | 668 | + ***[number] x***:当前鼠标位置的x坐标 669 | + ***[number] y***:当前鼠标位置的y坐标 670 | 671 | ### 示例 672 | ```Lua 673 | EasyDraw = require("EasyDraw") 674 | EasyDraw.Init(1280, 720) 675 | while (true) 676 | do 677 | EasyDraw.CaptureEvent() 678 | if (EasyDraw.CheckEventType("LBUTTONDOWN") == 1) 679 | then 680 | x, y = GetMousePosition() 681 | print(x, y) -- 当鼠标左键按下时打印当前鼠标所在位置x和y坐标 682 | end 683 | end 684 | ``` 685 | 686 | > ## BeginBatchDraw 687 | 开始批量绘图任务 688 | ```Lua 689 | BeginBatchDraw() 690 | ``` 691 | ### 参数 692 | 无 693 | ### 返回值 694 | 无 695 | ### 备注 696 | 开始批量绘图后,任何绘图操作都将在缓冲区内完成且不输出到绘图窗口上,直到执行 FlushBatchDraw 或 EndBatchDraw 才将之前的绘图输出,可用于解决快速执行绘图任务时产生的闪屏现象 697 | ### 示例 698 | ```Lua 699 | EasyDraw = require("EasyDraw") 700 | EasyDraw.Init(1280, 720) 701 | EasyDraw.SetLineColor(255, 255, 255); -- 设置画线颜色为白色 702 | EasyDraw.SetFillColor(255, 0, 0); -- 设置填充颜色为红色 703 | EasyDraw.BeginBatchDraw() -- 开始批量绘图任务 704 | for i = 1, 1000 do 705 | EasyDraw.Circle(i, 360, 50) 706 | EasyDraw.FloodFill(i, 360, 255, 255, 255, "BORDER") 707 | EasyDraw.FlushBatchDraw() -- 执行未完成的绘图任务 708 | EasyDraw.Sleep(10) 709 | EasyDraw.Clear() 710 | end 711 | EasyDraw.EndBatchDraw() -- 结束批量绘图任务,并执行未完成的绘图任务 712 | EasyDraw.Close() 713 | ``` 714 | 715 | > ## FlushBatchDraw 716 | 执行未完成的绘图任务 717 | ```Lua 718 | FlushBatchDraw() 719 | ``` 720 | ### 参数 721 | 无 722 | ### 返回值 723 | 无 724 | ### 示例 725 | 无(见BeginBatchDraw函数示例) 726 | 727 | > ## EndBatchDraw 728 | 结束批量绘制,并执行未完成的绘制任务 729 | ```Lua 730 | EndBatchDraw() 731 | ``` 732 | ### 参数 733 | 无 734 | ### 返回值 735 | 无 736 | ### 示例 737 | 无(见BeginBatchDraw函数示例) 738 | 739 | > ## Pause 740 | 暂停程序 741 | ```Lua 742 | Pause() 743 | ``` 744 | ### 参数 745 | 无 746 | ### 返回值 747 | 无 748 | ### 示例 749 | ```Lua 750 | EasyDraw = require("EasyDraw") 751 | EasyDraw.Init(1280, 720) 752 | EasyDraw.Circle(400, 400, 150) 753 | EasyDraw.Pause() -- 暂停程序,防止窗口在绘制完成后立刻退出 754 | EasyDraw.Close() 755 | ``` 756 | 757 | > ## Sleep 758 | 挂起程序指定时间 759 | ```Lua 760 | Sleep(ms) 761 | ``` 762 | ### 参数 763 | + ***[number] ms***:程序挂起时间,单位为毫秒 764 | ### 返回值 765 | 无 766 | ### 示例 767 | ```Lua 768 | EasyDraw = require("EasyDraw") 769 | EasyDraw.Init(1280, 720) 770 | EasyDraw.Circle(400, 400, 150) 771 | EasyDraw.Sleep(5000) -- 挂起程序5秒,防止窗口在绘制完成后立刻退出 772 | EasyDraw.Close() 773 | ``` 774 | -------------------------------------------------------------------------------- /EasyDraw/Lua-NonStandardLibs/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | HWND hwnd; // 窗口句柄 6 | 7 | MOUSEMSG msg; // 鼠标消息 8 | 9 | // 初始化窗口,2参数:窗口宽度、窗口高度 10 | extern "C" int init(lua_State * L) 11 | { 12 | int width = lua_tonumber(L, 1); 13 | int height = lua_tonumber(L, 2); 14 | hwnd = initgraph(width, height, EW_DBLCLKS); 15 | return 0; 16 | } 17 | 18 | // 使用当前背景色清空屏幕,无参数 19 | extern "C" int clear(lua_State * L) 20 | { 21 | cleardevice(); 22 | return 0; 23 | } 24 | 25 | // 关闭当前窗口,无参数 26 | extern "C" int close(lua_State * L) 27 | { 28 | closegraph(); 29 | return 0; 30 | } 31 | 32 | // 设置窗口标题,1参数:标题字符串 33 | extern "C" int setTitle(lua_State * L) 34 | { 35 | const char* title = lua_tostring(L, 1); 36 | SetWindowTextA(hwnd, title); 37 | return 0; 38 | } 39 | 40 | // 设置背景颜色,3参数:R、G、B 41 | extern "C" int setBGColor(lua_State * L) 42 | { 43 | int R = lua_tonumber(L, 1); 44 | int G = lua_tonumber(L, 2); 45 | int B = lua_tonumber(L, 3); 46 | setbkcolor(RGB(R, G, B)); 47 | return 0; 48 | } 49 | 50 | // 设置背景颜色填充模式,1参数:模式名 51 | // 可选值为:OPAQUE(背景用当前背景色填充),TRANSPARENT(透明背景) 52 | extern "C" int setBGMode(lua_State * L) 53 | { 54 | const char* mode = lua_tostring(L, 1); 55 | if (!strcmp(mode, "TRANSPARENT")) 56 | { 57 | setbkmode(TRANSPARENT); 58 | } 59 | else if (!strcmp(mode, "OPAQUE")) 60 | { 61 | setbkmode(OPAQUE); 62 | } 63 | return 0; 64 | } 65 | 66 | // 设置填充颜色,3参数:R、G、B 67 | extern "C" int setFillColor(lua_State * L) 68 | { 69 | int R = lua_tonumber(L, 1); 70 | int G = lua_tonumber(L, 2); 71 | int B = lua_tonumber(L, 3); 72 | setfillcolor(RGB(R, G, B)); 73 | return 0; 74 | } 75 | 76 | // 设置画线颜色,3参数:R、G、B 77 | extern "C" int setLineColor(lua_State * L) 78 | { 79 | int R = lua_tonumber(L, 1); 80 | int G = lua_tonumber(L, 2); 81 | int B = lua_tonumber(L, 3); 82 | setlinecolor(RGB(R, G, B)); 83 | return 0; 84 | } 85 | 86 | // 设置字体颜色,3参数:R、G、B 87 | extern "C" int setTextColor(lua_State * L) 88 | { 89 | int R = lua_tonumber(L, 1); 90 | int G = lua_tonumber(L, 2); 91 | int B = lua_tonumber(L, 3); 92 | settextcolor(RGB(R, G, B)); 93 | return 0; 94 | } 95 | 96 | // 设置填充颜色,1参数:类型名 97 | // 可选值为:"SOLID"(实线),"DASH"(----),"DOT"(····),"DASHDOT"(-·-·-·-),"DASHDOTDOT"(-··-··-··),"NULL"(不可见) 98 | extern "C" int setLineStyle(lua_State * L) 99 | { 100 | const char* style = lua_tostring(L, 1); 101 | if (!strcmp(style, "SOLID")) 102 | { 103 | setlinestyle(PS_SOLID); 104 | } 105 | else if (!strcmp(style, "DASH")) 106 | { 107 | setlinestyle(PS_DASH); 108 | } 109 | else if (!strcmp(style, "DOT")) 110 | { 111 | setlinestyle(PS_DOT); 112 | } 113 | else if (!strcmp(style, "DASHDOT")) 114 | { 115 | setlinestyle(PS_DASHDOT); 116 | } 117 | else if (!strcmp(style, "DASHDOTDOT")) 118 | { 119 | setlinestyle(PS_DASHDOTDOT); 120 | } 121 | else if (!strcmp(style, "NULL")) 122 | { 123 | setlinestyle(PS_NULL); 124 | } 125 | return 0; 126 | } 127 | 128 | // 绘制像素点,5参数:x坐标、y坐标、R、G、B 129 | extern "C" int drawPixel(lua_State * L) 130 | { 131 | int x = lua_tonumber(L, 1); 132 | int y = lua_tonumber(L, 2); 133 | int R = lua_tonumber(L, 3); 134 | int G = lua_tonumber(L, 4); 135 | int B = lua_tonumber(L, 5); 136 | putpixel(x, y, RGB(R, G, B)); 137 | return 0; 138 | } 139 | 140 | // 绘制直线,4参数:起始位置x坐标、起始位置y坐标、终止位置x坐标、终止位置y坐标 141 | extern "C" int drawLine(lua_State * L) 142 | { 143 | int x1 = lua_tonumber(L, 1); 144 | int y1 = lua_tonumber(L, 2); 145 | int x2 = lua_tonumber(L, 3); 146 | int y2 = lua_tonumber(L, 4); 147 | line(x1, y1, x2, y2); 148 | return 0; 149 | } 150 | 151 | // 绘制无填充圆角矩形,6参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标、圆角椭圆宽度、圆角椭圆高度 152 | extern "C" int drawRoundrect(lua_State * L) 153 | { 154 | int left = lua_tonumber(L, 1); 155 | int top = lua_tonumber(L, 2); 156 | int right = lua_tonumber(L, 3); 157 | int bottom = lua_tonumber(L, 4); 158 | int ellipsewidth = lua_tonumber(L, 5); 159 | int ellipseheight = lua_tonumber(L, 6); 160 | roundrect(left, top, right, bottom, ellipsewidth, ellipseheight); 161 | return 0; 162 | } 163 | 164 | // 绘制有填充圆角矩形,6参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标、圆角椭圆宽度、圆角椭圆高度 165 | extern "C" int drawFillRoundrect(lua_State * L) 166 | { 167 | int left = lua_tonumber(L, 1); 168 | int top = lua_tonumber(L, 2); 169 | int right = lua_tonumber(L, 3); 170 | int bottom = lua_tonumber(L, 4); 171 | int ellipsewidth = lua_tonumber(L, 5); 172 | int ellipseheight = lua_tonumber(L, 6); 173 | fillroundrect(left, top, right, bottom, ellipsewidth, ellipseheight); 174 | return 0; 175 | } 176 | 177 | // 绘制填充无边框圆角矩形,6参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标、圆角椭圆宽度、圆角椭圆高度 178 | extern "C" int drawSolidRoundrect(lua_State * L) 179 | { 180 | int left = lua_tonumber(L, 1); 181 | int top = lua_tonumber(L, 2); 182 | int right = lua_tonumber(L, 3); 183 | int bottom = lua_tonumber(L, 4); 184 | int ellipsewidth = lua_tonumber(L, 5); 185 | int ellipseheight = lua_tonumber(L, 6); 186 | solidroundrect(left, top, right, bottom, ellipsewidth, ellipseheight); 187 | return 0; 188 | } 189 | 190 | // 绘制无填充椭圆,4参数:椭圆外切矩形左上角x坐标、椭圆外切矩形左上角y坐标、椭圆外切矩形右下角x坐标、椭圆外切矩形右下角y坐标 191 | extern "C" int drawEllipse(lua_State * L) 192 | { 193 | int left = lua_tonumber(L, 1); 194 | int top = lua_tonumber(L, 2); 195 | int right = lua_tonumber(L, 3); 196 | int bottom = lua_tonumber(L, 4); 197 | ellipse(left, top, right, bottom); 198 | return 0; 199 | } 200 | 201 | // 绘制无填充椭圆,4参数:椭圆外切矩形左上角x坐标、椭圆外切矩形左上角y坐标、椭圆外切矩形右下角x坐标、椭圆外切矩形右下角y坐标 202 | extern "C" int drawFillEllipse(lua_State * L) 203 | { 204 | int left = lua_tonumber(L, 1); 205 | int top = lua_tonumber(L, 2); 206 | int right = lua_tonumber(L, 3); 207 | int bottom = lua_tonumber(L, 4); 208 | fillellipse(left, top, right, bottom); 209 | return 0; 210 | } 211 | 212 | // 绘制填充无边框椭圆,4参数:椭圆外切矩形左上角x坐标、椭圆外切矩形左上角y坐标、椭圆外切矩形右下角x坐标、椭圆外切矩形右下角y坐标 213 | extern "C" int drawSolidEllipse(lua_State * L) 214 | { 215 | int left = lua_tonumber(L, 1); 216 | int top = lua_tonumber(L, 2); 217 | int right = lua_tonumber(L, 3); 218 | int bottom = lua_tonumber(L, 4); 219 | solidellipse(left, top, right, bottom); 220 | return 0; 221 | } 222 | 223 | // 绘制无填充圆,3参数:圆心x坐标、圆心y坐标、半径 224 | extern "C" int drawCircle(lua_State * L) 225 | { 226 | int x = lua_tonumber(L, 1); 227 | int y = lua_tonumber(L, 2); 228 | int radius = lua_tonumber(L, 3); 229 | circle(x, y, radius); 230 | return 0; 231 | } 232 | 233 | // 绘制有填充圆,3参数:圆心x坐标、圆心y坐标、半径 234 | extern "C" int drawFillCircle(lua_State * L) 235 | { 236 | int x = lua_tonumber(L, 1); 237 | int y = lua_tonumber(L, 2); 238 | int radius = lua_tonumber(L, 3); 239 | fillcircle(x, y, radius); 240 | return 0; 241 | } 242 | 243 | // 绘制填充无边框圆,3参数:圆心x坐标、圆心y坐标、半径 244 | extern "C" int drawSolidCircle(lua_State * L) 245 | { 246 | int x = lua_tonumber(L, 1); 247 | int y = lua_tonumber(L, 2); 248 | int radius = lua_tonumber(L, 3); 249 | solidcircle(x, y, radius); 250 | return 0; 251 | } 252 | 253 | // 绘制无填充矩形,4参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标 254 | extern "C" int drawRectangle(lua_State * L) 255 | { 256 | int left = lua_tonumber(L, 1); 257 | int top = lua_tonumber(L, 2); 258 | int right = lua_tonumber(L, 3); 259 | int bottom = lua_tonumber(L, 4); 260 | rectangle(left, top, right, bottom); 261 | return 0; 262 | } 263 | 264 | // 绘制有填充矩形,4参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标 265 | extern "C" int drawFillRectangle(lua_State * L) 266 | { 267 | int left = lua_tonumber(L, 1); 268 | int top = lua_tonumber(L, 2); 269 | int right = lua_tonumber(L, 3); 270 | int bottom = lua_tonumber(L, 4); 271 | fillrectangle(left, top, right, bottom); 272 | return 0; 273 | } 274 | 275 | // 绘制有填充无边框矩形,4参数:矩形左边线坐标、矩形上边线坐标、矩形右边线坐标、矩形下边线坐标 276 | extern "C" int drawSolidRectangle(lua_State * L) 277 | { 278 | int left = lua_tonumber(L, 1); 279 | int top = lua_tonumber(L, 2); 280 | int right = lua_tonumber(L, 3); 281 | int bottom = lua_tonumber(L, 4); 282 | solidrectangle(left, top, right, bottom); 283 | return 0; 284 | } 285 | 286 | // 设置当前字体样式,3参数:字体高度、字体宽度(0为自适应)、字体名称 287 | extern "C" int setTextStyle(lua_State * L) 288 | { 289 | int height = lua_tonumber(L, 1); 290 | int width = lua_tonumber(L, 2); 291 | const char* name = lua_tostring(L, 3); 292 | int num = MultiByteToWideChar(0, 0, name, -1, NULL, 0); 293 | wchar_t* w_name = new wchar_t[num]; 294 | MultiByteToWideChar(0, 0, name, -1, w_name, num); 295 | settextstyle(height, width, w_name); 296 | return 0; 297 | } 298 | 299 | // 在指定位置输出字符串,3参数:x坐标、y坐标、字符串内容 300 | extern "C" int drawText(lua_State * L) 301 | { 302 | int x = lua_tonumber(L, 1); 303 | int y = lua_tonumber(L, 2); 304 | const char* content = lua_tostring(L, 3); 305 | int num = MultiByteToWideChar(0, 0, content, -1, NULL, 0); 306 | wchar_t* w_content = new wchar_t[num]; 307 | MultiByteToWideChar(0, 0, content, -1, w_content, num); 308 | outtextxy(x, y, w_content); 309 | return 0; 310 | } 311 | 312 | // 在指定位置绘制图片,5参数:x坐标、y坐标、图片宽度、图片高度、图片路径 313 | extern "C" int drawImage(lua_State * L) 314 | { 315 | int x = lua_tonumber(L, 1); 316 | int y = lua_tonumber(L, 2); 317 | int width = lua_tonumber(L, 3); 318 | int height = lua_tonumber(L, 4); 319 | const char* path = lua_tostring(L, 5); 320 | int num = MultiByteToWideChar(0, 0, path, -1, NULL, 0); 321 | wchar_t* w_path = new wchar_t[num]; 322 | MultiByteToWideChar(0, 0, path, -1, w_path, num); 323 | IMAGE image; 324 | loadimage(&image, w_path, width, height); 325 | putimage(x, y, &image); 326 | return 0; 327 | } 328 | 329 | // 在指定位置绘制透明图片,5参数:x坐标、y坐标、图片宽度、图片高度、图片路径 330 | extern "C" int drawTransImage(lua_State * L) 331 | { 332 | int x = lua_tonumber(L, 1); 333 | int y = lua_tonumber(L, 2); 334 | int width = lua_tonumber(L, 3); 335 | int height = lua_tonumber(L, 4); 336 | const char* path = lua_tostring(L, 5); 337 | int num = MultiByteToWideChar(0, 0, path, -1, NULL, 0); 338 | wchar_t* w_path = new wchar_t[num]; 339 | MultiByteToWideChar(0, 0, path, -1, w_path, num); 340 | IMAGE srcimg; 341 | loadimage(&srcimg, w_path, width, height); 342 | 343 | DWORD* dst = GetImageBuffer(NULL); 344 | DWORD* src = GetImageBuffer(&srcimg); 345 | int src_width = (&srcimg)->getwidth(); 346 | int src_height = (&srcimg)->getheight(); 347 | int dst_width = getwidth(); 348 | int dst_height = getheight(); 349 | 350 | int iwidth = (x + src_width > dst_width) ? dst_width - x : src_width; 351 | int iheight = (y + src_height > dst_height) ? dst_height - y : src_height; 352 | if (x < 0) { src += -x; iwidth -= -x; x = 0; } 353 | if (y < 0) { src += src_width * -y; iheight -= -y; y = 0; } 354 | 355 | dst += dst_width * y + x; 356 | 357 | for (int iy = 0; iy < iheight; iy++) 358 | { 359 | for (int ix = 0; ix < iwidth; ix++) 360 | { 361 | int sa = ((src[ix] & 0xff000000) >> 24); 362 | int sr = ((src[ix] & 0xff0000) >> 16); 363 | int sg = ((src[ix] & 0xff00) >> 8); 364 | int sb = src[ix] & 0xff; 365 | int dr = ((dst[ix] & 0xff0000) >> 16); 366 | int dg = ((dst[ix] & 0xff00) >> 8); 367 | int db = dst[ix] & 0xff; 368 | 369 | dst[ix] = ((sr + dr * (255 - sa) / 255) << 16) 370 | | ((sg + dg * (255 - sa) / 255) << 8) 371 | | (sb + db * (255 - sa) / 255); 372 | } 373 | dst += dst_width; 374 | src += src_width; 375 | } 376 | 377 | return 0; 378 | } 379 | 380 | // 填充指定区域,6参数:起点x坐标、起点y坐标、R、G、B、填充类型 381 | // 填充类型可选值为:"BORDER"(填充动作发生在指定颜色围成的封闭区域),"SURFACE"(填充动作发生在指定颜色的连续表面) 382 | extern "C" int floodFill(lua_State * L) 383 | { 384 | int x = lua_tonumber(L, 1); 385 | int y = lua_tonumber(L, 2); 386 | int R = lua_tonumber(L, 3); 387 | int G = lua_tonumber(L, 4); 388 | int B = lua_tonumber(L, 5); 389 | const char* fillType = lua_tostring(L, 6); 390 | if (!strcmp(fillType, "SURFACE")) 391 | { 392 | floodfill(x, y, RGB(R, G, B), FLOODFILLSURFACE); 393 | } 394 | else 395 | { 396 | floodfill(x, y, RGB(R, G, B), FLOODFILLBORDER); 397 | } 398 | return 0; 399 | } 400 | 401 | // 捕获事件,无参数 402 | extern "C" int captureEvent(lua_State * L) 403 | { 404 | msg = GetMouseMsg(); 405 | return 0; 406 | } 407 | 408 | // 判断交互事件类型,1参数:类型名 409 | // 可选值为:"MOUSEMOVE"(鼠标移动),"MOUSEWHELL"(鼠标滚轮移动),"LBUTTONDOWN"(鼠标左键按下),"LBUTTONUP"(鼠标左键抬起),"LBUTTONDBLCLK"(鼠标左键双击),"MBUTTONDOWN"(鼠标中键按下),"MBUTTONUP"(鼠标中键抬起),"MBUTTONDBLCLK"(鼠标中键双击),"RBUTTONDOWN"(鼠标右键按下),"RBUTTONUP"(鼠标右键抬起),"RBUTTONDBLCLK"(鼠标右键双击),"CTRLDOWN"(Ctrl键按下),"SHIFTDOWN"(Shift键按下) 410 | // 1个返回值:0 - 不是当前事件,1 - 是当前事件,-1 - 不存在当前事件 411 | extern "C" int checkEventType(lua_State * L) 412 | { 413 | const char* eventType = lua_tostring(L, 1); 414 | int result = -1; 415 | if (!strcmp(eventType, "MOUSEMOVE")) 416 | { 417 | if (msg.uMsg == WM_MOUSEMOVE) 418 | result = 1; 419 | else 420 | result = 0; 421 | } 422 | else if (!strcmp(eventType, "MOUSEWHELL")) 423 | { 424 | if (msg.uMsg == WM_MOUSEWHEEL) 425 | result = 1; 426 | else 427 | result = 0; 428 | } 429 | else if (!strcmp(eventType, "LBUTTONDOWN")) 430 | { 431 | if (msg.uMsg == WM_LBUTTONDOWN) 432 | result = 1; 433 | else 434 | result = 0; 435 | } 436 | else if (!strcmp(eventType, "LBUTTONDBLCLK")) 437 | { 438 | if (msg.uMsg == WM_LBUTTONDBLCLK) 439 | result = 1; 440 | else 441 | result = 0; 442 | } 443 | else if (!strcmp(eventType, "MBUTTONDOWN")) 444 | { 445 | if (msg.uMsg == WM_MBUTTONDOWN) 446 | result = 1; 447 | else 448 | result = 0; 449 | } 450 | else if (!strcmp(eventType, "MBUTTONUP")) 451 | { 452 | if (msg.uMsg == WM_MBUTTONUP) 453 | result = 1; 454 | else 455 | result = 0; 456 | } 457 | else if (!strcmp(eventType, "MBUTTONDBLCLK")) 458 | { 459 | if (msg.uMsg == WM_MBUTTONDBLCLK) 460 | result = 1; 461 | else 462 | result = 0; 463 | } 464 | else if (!strcmp(eventType, "RBUTTONDOWN")) 465 | { 466 | if (msg.uMsg == WM_RBUTTONDOWN) 467 | result = 1; 468 | else 469 | result = 0; 470 | } 471 | else if (!strcmp(eventType, "RBUTTONUP")) 472 | { 473 | if (msg.uMsg == WM_RBUTTONUP) 474 | result = 1; 475 | else 476 | result = 0; 477 | } 478 | else if (!strcmp(eventType, "RBUTTONDBLCLK")) 479 | { 480 | if (msg.uMsg == WM_RBUTTONDBLCLK) 481 | result = 1; 482 | else 483 | result = 0; 484 | } 485 | else if (!strcmp(eventType, "CTRLDOWN")) 486 | { 487 | if (msg.mkCtrl) 488 | result = 1; 489 | else 490 | result = 0; 491 | } 492 | else if (!strcmp(eventType, "SHIFTDOWN")) 493 | { 494 | if (msg.mkShift) 495 | result = 1; 496 | else 497 | result = 0; 498 | } 499 | lua_pushnumber(L, result); 500 | return 1; 501 | } 502 | 503 | // 获取当前鼠标位置,无参数 504 | // 2个返回值:x坐标、y坐标 505 | extern "C" int getMousePosition(lua_State * L) 506 | { 507 | MOUSEMSG msg = GetMouseMsg(); 508 | lua_pushnumber(L, msg.x); 509 | lua_pushnumber(L, msg.y); 510 | return 2; 511 | } 512 | 513 | // 开始批量绘图,无参数 514 | extern "C" int beginBatchDraw(lua_State * L) 515 | { 516 | BeginBatchDraw(); 517 | return 0; 518 | } 519 | 520 | // 执行未完成绘图任务,无参数 521 | extern "C" int flushBatchDraw(lua_State * L) 522 | { 523 | FlushBatchDraw(); 524 | return 0; 525 | } 526 | 527 | // 结束批量绘图,无参数 528 | extern "C" int endBatchDraw(lua_State * L) 529 | { 530 | EndBatchDraw(); 531 | return 0; 532 | } 533 | 534 | // 暂停程序,无参数 535 | extern "C" int pause(lua_State * L) 536 | { 537 | system("pause"); 538 | return 0; 539 | } 540 | 541 | // 挂起程序指定时间,1参数:挂起时间(单位:毫秒) 542 | extern "C" int sleep(lua_State * L) 543 | { 544 | int delay = lua_tonumber(L, 1); 545 | Sleep(delay); 546 | return 0; 547 | } 548 | 549 | 550 | 551 | static luaL_Reg cMethods[] = { 552 | { "Init", init }, 553 | { "Clear", clear }, 554 | { "Close", close }, 555 | { "SetTitle", setTitle }, 556 | { "SetBGColor", setBGColor }, 557 | { "SetBGMode", setBGMode }, 558 | { "SetFillColor", setFillColor }, 559 | { "SetLineColor", setLineColor }, 560 | { "SetTextColor", setTextColor }, 561 | { "SetLineStyle", setLineStyle }, 562 | { "Point", drawPixel}, 563 | { "Line", drawLine }, 564 | { "Roundrect" , drawRoundrect }, 565 | { "FillRoundrect" , drawFillRoundrect }, 566 | { "SolidRoundrect", drawSolidRoundrect }, 567 | { "Ellipse", drawEllipse }, 568 | { "FillEllipse", drawFillEllipse }, 569 | { "SolidEllipse", drawSolidEllipse}, 570 | { "Circle", drawCircle }, 571 | { "FillCircle", drawFillCircle }, 572 | { "SolidCircle", drawSolidCircle }, 573 | { "Rectangle", drawRectangle }, 574 | { "FillRectangle", drawFillRectangle }, 575 | { "SolidRectangle", drawSolidRectangle }, 576 | { "SetTextStyle", setTextStyle }, 577 | { "DrawText", drawText }, 578 | { "DrawImage", drawImage }, 579 | { "DrawTransImage", drawTransImage }, 580 | { "FloodFill", floodFill }, 581 | { "CaptureEvent", captureEvent}, 582 | { "CheckEventType", checkEventType}, 583 | { "GetMousePosition", getMousePosition}, 584 | { "BeginBatchDraw", beginBatchDraw }, 585 | { "FlushBatchDraw", flushBatchDraw }, 586 | { "EndBatchDraw", endBatchDraw }, 587 | { "Pause", pause }, 588 | { "Sleep", sleep }, 589 | { NULL, NULL } 590 | }; 591 | 592 | extern "C" __declspec(dllexport) 593 | int luaopen_EasyDraw(lua_State * L) 594 | { 595 | luaL_newlib(L, cMethods); 596 | return 1; 597 | } 598 | --------------------------------------------------------------------------------