From 547f5fa2bc53739d07cdb001cf949d490189e8e0 Mon Sep 17 00:00:00 2001 From: Nats-ji Date: Tue, 2 Feb 2021 01:32:01 +0800 Subject: [PATCH 1/5] Fix for cet sandbox --- .gitignore | 12 +- CPStyling.lua => CPStyling/init.lua | 235 +----------------- {png-lua => CPStyling/png-lua}/README.md | 0 {png-lua => CPStyling/png-lua}/deflatelua.lua | 22 +- {png-lua => CPStyling/png-lua}/png.lua | 2 +- CPStyling/styles.lua | 128 ++++++++++ CPStyling/theme.lua | 123 +++++++++ README.md | 20 +- 8 files changed, 282 insertions(+), 260 deletions(-) rename CPStyling.lua => CPStyling/init.lua (50%) rename {png-lua => CPStyling/png-lua}/README.md (100%) rename {png-lua => CPStyling/png-lua}/deflatelua.lua (99%) rename {png-lua => CPStyling/png-lua}/png.lua (99%) create mode 100644 CPStyling/styles.lua create mode 100644 CPStyling/theme.lua diff --git a/.gitignore b/.gitignore index 0cbba6b..0fb9583 100644 --- a/.gitignore +++ b/.gitignore @@ -2,12 +2,6 @@ /demo.lua /init.lua /init.lua_disabled -/mushroom.png -/foxgirl.png -/ghost_in_shell.png -/cyberpunk.png -/lucario.png -/CPStyling_local.lua -/png-lua/deflatelua_local.lua -/png-lua/png_local.lua -/cp_styling.log +/img/ +/cp_styling*.log +/db.sqlite3 diff --git a/CPStyling.lua b/CPStyling/init.lua similarity index 50% rename from CPStyling.lua rename to CPStyling/init.lua index 761a277..d087b37 100644 --- a/CPStyling.lua +++ b/CPStyling/init.lua @@ -1,6 +1,8 @@ -- MIT License -- --- - CPStyling.lua +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua -- -- Copyright (c) 2021 Mingming Cui -- @@ -23,219 +25,14 @@ -- SOFTWARE. local CPStyle = {} -local currentFilePath = (...):gsub("CPStyling$","") - -local function isModuleAvailable(module) - res = pcall(require,module) - if res then return true - elseif not(res) then - return false - end -end - -if isModuleAvailable(currentFilePath.."png-lua/png") then - png = require(currentFilePath.."png-lua/png") -end +local currentFilePath = "CPStyling/" +CPStyle.theme = require(currentFilePath.."theme") +local styles = require(currentFilePath.."styles") +local ImGuiStyleNames = styles.ImGuiStyleNames +print(table.unpack(styles.color.black)) +CPStyle.color = styles.color -CPStyle.theme = { - Text = { 1.00, 0.38, 0.33, 1.00 }, - TextDisabled = { 0.48, 0.39, 0.40, 1.00 }, - WindowBg = { 0.06, 0.04, 0.06, 0.90 }, - ChildBg = { 0.00, 0.00, 0.00, 0.00 }, - PopupBg = { 0.06, 0.04, 0.06, 0.90 }, - Border = { 0.30, 0.07, 0.08, 1.00 }, - BorderShadow = { 0.00, 0.00, 0.00, 0.00 }, - FrameBg = { 0.50, 0.13, 0.16, 0.50 }, - FrameBgHovered = { 0.32, 0.11, 0.12, 0.50 }, - FrameBgActive = { 0.50, 0.13, 0.16, 0.50 }, - -- FrameBgDisabled = { 0.48, 0.39, 0.40, 1.00 }, - -- FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1.00 }, - -- FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1.00 }, - TitleBg = { 0.06, 0.04, 0.06, 0.90 }, - TitleBgActive = { 0.06, 0.04, 0.06, 0.90 }, - TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.90 }, - MenuBarBg = { 0.00, 0.00, 0.00, 0.00 }, - ScrollbarBg = { 0.23, 0.07, 0.09, 1.00 }, - ScrollbarGrab = { 0.95, 0.30, 0.28, 1.00 }, - ScrollbarGrabHovered = { 0.95, 0.30, 0.28, 1.00 }, - ScrollbarGrabActive = { 0.95, 0.30, 0.28, 1.00 }, - CheckMark = { 1.00, 0.44, 0.40, 1.00 }, - -- CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1.00 }, - -- CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1.00 }, - SliderGrab = { 0.64, 0.22, 0.21, 1.00 }, - SliderGrabActive = { 0.64, 0.22, 0.21, 1.00 }, - Button = { 0.57, 0.17, 0.16, 1.00 }, - ButtonHovered = { 0.45, 0.13, 0.14, 1.00 }, - ButtonActive = { 0.57, 0.17, 0.16, 1.00 }, - Header = { 0.08, 0.08, 0.15, 1.00 }, - HeaderHovered = { 0.22, 0.64, 0.69, 0.30 }, - HeaderActive = { 0.22, 0.64, 0.69, 0.50 }, - Separator = { 0.26, 0.09, 0.09, 1.00 }, - SeparatorHovered = { 0.26, 0.09, 0.09, 1.00 }, - SeparatorActive = { 0.26, 0.09, 0.09, 1.00 }, - ResizeGrip = { 0.00, 0.00, 0.00, 0.00 }, - ResizeGripHovered = { 0.45, 0.13, 0.14, 1.00 }, - ResizeGripActive = { 0.57, 0.17, 0.16, 1.00 }, - Tab = { 0.57, 0.17, 0.16, 1.00 }, - TabHovered = { 0.45, 0.13, 0.14, 1.00 }, - TabActive = { 0.57, 0.17, 0.16, 1.00 }, - TabUnfocused = { 0.45, 0.14, 0.13, 1.00 }, - TabUnfocusedActive = { 0.58, 0.18, 0.16, 1.00 }, - -- PlotLines = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotLinesHovered = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotHistogram = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotHistogramHovered = { 0.00, 0.00, 0.00, 0.00 }, - TextSelectedBg = { 0.06, 0.06, 0.12, 1.00 }, - -- DragDropTarget = { 0.00, 0.00, 0.00, 0.00 }, - -- NavHighlight = { 0.00, 0.00, 0.00, 0.00 }, - -- NavWindowingHighlight = { 0.00, 0.00, 0.00, 0.00 }, - -- NavWindowingDimBg = { 0.00, 0.00, 0.00, 0.00 }, - ModalWindowDimBg = { 0.00, 0.00, 0.00, 0.40 }, - CPButton = { 0.06, 0.06, 0.12, 1.00 }, - CPButtonHovered = { 0.43, 0.13, 0.13, 1.00 }, - CPButtonActive = { 0.57, 0.16, 0.16, 1.00 }, - CPButtonText = { 0.34, 0.95, 0.98, 1.00 }, - CPButtonBorder = { 0.40, 0.08, 0.09, 1.00 }, - CPButtonBorderHovered = { 0.34, 0.95, 0.98, 1.00 }, - CPToggleOn = { 0.37, 0.96, 1.00, 1.00 }, - CPToggleOnHovered = { 0.29, 0.77, 0.80, 1.00 }, - CPToggleOnText = { 0.00, 0.00, 0.00, 1.00 }, - CPToggleOnTextHovered = { 0.00, 0.00, 0.00, 1.00 }, - CPToggleOnBorder = { 0.29, 0.61, 0.58, 1.00 }, - CPToggleOnBorderHovered = { 0.26, 0.66, 0.65, 1.00 }, - CPToggleOnDisabled = { 0.03, 0.12, 0.12, 1.00 }, - CPToggleOnDisabledHovered = { 0.05, 0.16, 0.16, 1.00 }, - CPToggleOnDisabledText = { 0.08, 0.23, 0.25, 1.00 }, - CPToggleOnDisabledTextHovered = { 0.09, 0.29, 0.30, 1.00 }, - CPToggleOnDisabledBorder = { 0.06, 0.15, 0.15, 1.00 }, - CPToggleOnDisabledBorderHovered = { 0.09, 0.24, 0.25, 1.00 }, - CPToggleOff = { 0.58, 0.18, 0.16, 1.00 }, - CPToggleOffHovered = { 0.45, 0.14, 0.13, 1.00 }, - CPToggleOffText = { 1.00, 0.44, 0.41, 1.00 }, - CPToggleOffTextHovered = { 1.00, 0.36, 0.33, 1.00 }, - CPToggleOffBorder = { 0.92, 0.29, 0.26, 1.00 }, - CPToggleOffBorderHovered = { 0.76, 0.23, 0.21, 1.00 }, - CPToggleOffDisabled = { 0.09, 0.04, 0.07, 1.00 }, - CPToggleOffDisabledHovered = { 0.16, 0.06, 0.07, 1.00 }, - CPToggleOffDisabledText = { 0.32, 0.09, 0.10, 1.00 }, - CPToggleOffDisabledTextHovered = { 0.36, 0.11, 0.11, 1.00 }, - CPToggleOffDisabledBorder = { 0.19, 0.08, 0.09, 1.00 }, - CPToggleOffDisabledBorderHovered = { 0.30, 0.09, 0.10, 1.00 }, - CPFrameBg = { 0.06, 0.06, 0.12, 1.00 }, - CPFrameBgHovered = { 0.31, 0.11, 0.11, 1.00 }, - CPFrameBgActive = { 0.57, 0.19, 0.19, 1.00 }, - CPSliderGrab = { 0.64, 0.21, 0.21, 1.00 }, - CPSliderGrabActive = { 0.64, 0.21, 0.21, 1.00 }, - CPFrameBorder = { 0.40, 0.08, 0.09, 1.00 }, - CPTextSelectedBg = { 0.45, 0.14, 0.13, 1.00 }, - CPToolTip2Bg = { 0.11, 0.22, 0.25, 0.60 }, - CPToolTip2Border = { 0.18, 0.42, 0.46, 1.00 }, - CPToolTip2Separator = { 0.24, 0.55, 0.58, 1.00 }, - CPToolTip2SideBg = { 0.12, 0.24, 0.27, 1.00 }, - Hidden = { 0.00, 0.00, 0.00, 0.00 } -} - -CPStyle.color = { - red = { 1.00, 0.00, 0.00, 1.00 }, - cyan = { 0.00, 1.00, 1.00, 1.00 }, - blue = { 0.00, 0.00, 1.00, 1.00 }, - darkBlue = { 0.00, 0.00, 0.63, 1.00 }, - lightBlue = { 0.68, 0.85, 0.90, 1.00 }, - purple = { 0.50, 0.00, 0.50, 1.00 }, - yellow = { 1.00, 1.00, 0.00, 1.00 }, - lime = { 0.00, 1.00, 0.00, 1.00 }, - magenta = { 1.00, 0.00, 1.00, 1.00 }, - white = { 1.00, 1.00, 1.00, 1.00 }, - silver = { 0.75, 0.75, 0.75, 1.00 }, - grey = { 0.50, 0.50, 0.50, 1.00 }, - black = { 0.00, 0.00, 0.00, 1.00 }, - orange = { 1.00, 0.65, 0.00, 1.00 }, - brown = { 0.65, 0.16, 0.16, 1.00 }, - maroon = { 0.50, 0.00, 0.00, 1.00 }, - green = { 0.00, 0.50, 0.00, 1.00 }, - olive = { 0.50, 0.50, 0.00, 1.00 } -} - - -local ImGuiStyleNames = { - Col = { - { ImGuiStyle = ImGuiCol.Text , ImGuiStyleShort = "Text" }, - { ImGuiStyle = ImGuiCol.TextDisabled , ImGuiStyleShort = "TextDisabled" }, - { ImGuiStyle = ImGuiCol.WindowBg , ImGuiStyleShort = "WindowBg" }, - { ImGuiStyle = ImGuiCol.ChildBg , ImGuiStyleShort = "ChildBg" }, - { ImGuiStyle = ImGuiCol.PopupBg , ImGuiStyleShort = "PopupBg" }, - { ImGuiStyle = ImGuiCol.Border , ImGuiStyleShort = "Border" }, - { ImGuiStyle = ImGuiCol.BorderShadow , ImGuiStyleShort = "BorderShadow" }, - { ImGuiStyle = ImGuiCol.FrameBg , ImGuiStyleShort = "FrameBg" }, - { ImGuiStyle = ImGuiCol.FrameBgHovered , ImGuiStyleShort = "FrameBgHovered" }, - { ImGuiStyle = ImGuiCol.FrameBgActive , ImGuiStyleShort = "FrameBgActive" }, - { ImGuiStyle = ImGuiCol.TitleBg , ImGuiStyleShort = "TitleBg" }, - { ImGuiStyle = ImGuiCol.TitleBgActive , ImGuiStyleShort = "TitleBgActive" }, - { ImGuiStyle = ImGuiCol.TitleBgCollapsed , ImGuiStyleShort = "TitleBgCollapsed" }, - { ImGuiStyle = ImGuiCol.MenuBarBg , ImGuiStyleShort = "MenuBarBg" }, - { ImGuiStyle = ImGuiCol.ScrollbarBg , ImGuiStyleShort = "ScrollbarBg" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrab , ImGuiStyleShort = "ScrollbarGrab" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrabHovered , ImGuiStyleShort = "ScrollbarGrabHovered" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrabActive , ImGuiStyleShort = "ScrollbarGrabActive" }, - { ImGuiStyle = ImGuiCol.CheckMark , ImGuiStyleShort = "CheckMark" }, - { ImGuiStyle = ImGuiCol.SliderGrab , ImGuiStyleShort = "SliderGrab" }, - { ImGuiStyle = ImGuiCol.SliderGrabActive , ImGuiStyleShort = "SliderGrabActive" }, - { ImGuiStyle = ImGuiCol.Button , ImGuiStyleShort = "Button" }, - { ImGuiStyle = ImGuiCol.ButtonHovered , ImGuiStyleShort = "ButtonHovered" }, - { ImGuiStyle = ImGuiCol.ButtonActive , ImGuiStyleShort = "ButtonActive" }, - { ImGuiStyle = ImGuiCol.Header , ImGuiStyleShort = "Header" }, - { ImGuiStyle = ImGuiCol.HeaderHovered , ImGuiStyleShort = "HeaderHovered" }, - { ImGuiStyle = ImGuiCol.HeaderActive , ImGuiStyleShort = "HeaderActive" }, - { ImGuiStyle = ImGuiCol.Separator , ImGuiStyleShort = "Separator" }, - { ImGuiStyle = ImGuiCol.SeparatorHovered , ImGuiStyleShort = "SeparatorHovered" }, - { ImGuiStyle = ImGuiCol.SeparatorActive , ImGuiStyleShort = "SeparatorActive" }, - { ImGuiStyle = ImGuiCol.ResizeGrip , ImGuiStyleShort = "ResizeGrip" }, - { ImGuiStyle = ImGuiCol.ResizeGripHovered , ImGuiStyleShort = "ResizeGripHovered" }, - { ImGuiStyle = ImGuiCol.ResizeGripActive , ImGuiStyleShort = "ResizeGripActive" }, - { ImGuiStyle = ImGuiCol.Tab , ImGuiStyleShort = "Tab" }, - { ImGuiStyle = ImGuiCol.TabHovered , ImGuiStyleShort = "TabHovered" }, - { ImGuiStyle = ImGuiCol.TabActive , ImGuiStyleShort = "TabActive" }, - { ImGuiStyle = ImGuiCol.TabUnfocused , ImGuiStyleShort = "TabUnfocused" }, - { ImGuiStyle = ImGuiCol.TabUnfocusedActive , ImGuiStyleShort = "TabUnfocusedActive" }, - { ImGuiStyle = ImGuiCol.PlotLines , ImGuiStyleShort = "PlotLines" }, - { ImGuiStyle = ImGuiCol.PlotLinesHovered , ImGuiStyleShort = "PlotLinesHovered" }, - { ImGuiStyle = ImGuiCol.PlotHistogram , ImGuiStyleShort = "PlotHistogram" }, - { ImGuiStyle = ImGuiCol.PlotHistogramHovered , ImGuiStyleShort = "PlotHistogramHovered" }, - { ImGuiStyle = ImGuiCol.TextSelectedBg , ImGuiStyleShort = "TextSelectedBg" }, - { ImGuiStyle = ImGuiCol.DragDropTarget , ImGuiStyleShort = "DragDropTarget" }, - { ImGuiStyle = ImGuiCol.NavHighlight , ImGuiStyleShort = "NavHighlight" }, - { ImGuiStyle = ImGuiCol.NavWindowingHighlight , ImGuiStyleShort = "NavWindowingHighlight" }, - { ImGuiStyle = ImGuiCol.NavWindowingDimBg , ImGuiStyleShort = "NavWindowingDimBg" }, - { ImGuiStyle = ImGuiCol.ModalWindowDimBg , ImGuiStyleShort = "ModalWindowDimBg" }, - { ImGuiStyle = ImGuiCol.COUNT , ImGuiStyleShort = "COUNT" } - }, - Var = { - { ImGuiStyle = ImGuiStyleVar.Alpha , ImGuiStyleShort = "Alpha" }, - { ImGuiStyle = ImGuiStyleVar.WindowPadding , ImGuiStyleShort = "WindowPadding" }, - { ImGuiStyle = ImGuiStyleVar.WindowRounding , ImGuiStyleShort = "WindowRounding" }, - { ImGuiStyle = ImGuiStyleVar.WindowBorderSize , ImGuiStyleShort = "WindowBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.WindowMinSize , ImGuiStyleShort = "WindowMinSize" }, - { ImGuiStyle = ImGuiStyleVar.WindowTitleAlign , ImGuiStyleShort = "WindowTitleAlign" }, - { ImGuiStyle = ImGuiStyleVar.ChildRounding , ImGuiStyleShort = "ChildRounding" }, - { ImGuiStyle = ImGuiStyleVar.ChildBorderSize , ImGuiStyleShort = "ChildBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.PopupRounding , ImGuiStyleShort = "PopupRounding" }, - { ImGuiStyle = ImGuiStyleVar.PopupBorderSize , ImGuiStyleShort = "PopupBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.FramePadding , ImGuiStyleShort = "FramePadding" }, - { ImGuiStyle = ImGuiStyleVar.FrameRounding , ImGuiStyleShort = "FrameRounding" }, - { ImGuiStyle = ImGuiStyleVar.FrameBorderSize , ImGuiStyleShort = "FrameBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.ItemSpacing , ImGuiStyleShort = "ItemSpacing" }, - { ImGuiStyle = ImGuiStyleVar.ItemInnerSpacing , ImGuiStyleShort = "ItemInnerSpacing" }, - { ImGuiStyle = ImGuiStyleVar.IndentSpacing , ImGuiStyleShort = "IndentSpacing" }, - { ImGuiStyle = ImGuiStyleVar.ScrollbarSize , ImGuiStyleShort = "ScrollbarSize" }, - { ImGuiStyle = ImGuiStyleVar.ScrollbarRounding , ImGuiStyleShort = "ScrollbarRounding" }, - { ImGuiStyle = ImGuiStyleVar.GrabMinSize , ImGuiStyleShort = "GrabMinSize" }, - { ImGuiStyle = ImGuiStyleVar.GrabRounding , ImGuiStyleShort = "GrabRounding" }, - { ImGuiStyle = ImGuiStyleVar.TabRounding , ImGuiStyleShort = "TabRounding" }, - { ImGuiStyle = ImGuiStyleVar.SelectableTextAlign , ImGuiStyleShort = "SelectableTextAlign" }, - { ImGuiStyle = ImGuiStyleVar.ButtonTextAlign , ImGuiStyleShort = "ButtonTextAlign" }, - { ImGuiStyle = ImGuiStyleVar.COUNT , ImGuiStyleShort = "COUNT" } - } -} +png = require(currentFilePath.."png-lua/png") local function ToImGuiStyleName(style, which) if which == "Col" then @@ -599,7 +396,7 @@ function CPStyle.CPDraw(name, image, scale) for i = 1, totalPixel do ImGui.SetCursorPos(cursorx, cursory) if image.pixels[pixely][pixelx][4] ~= 0 then - CPStyle.CPRect2("##"..name..i, scale, scale, image.pixels[pixely][pixelx]) + CPStyle.CPRect2("##"..name..i, scale*1.2, scale*1.2, image.pixels[pixely][pixelx]) end pixelx = pixelx + 1 if pixelx > image.width then pixelx = 1 pixely = pixely + 1 end @@ -632,14 +429,4 @@ function CPStyle.fileExists(filename) if (f~=nil) then io.close(f) return true else return false end end -function CPStyle.getCWD(mod_name) - if CPStyle.fileExists("./bin/x64/plugins/cyber_engine_tweaks/mods/"..mod_name.."/init.lua") then - return "./bin/x64/plugins/cyber_engine_tweaks/mods/"..mod_name.."/" - elseif CPStyle.fileExists("./plugins/cyber_engine_tweaks/mods/"..mod_name.."/init.lua") then - return "./plugins/cyber_engine_tweaks/mods/"..mod_name.."/" - elseif CPStyle.fileExists("./"..mod_name.."/init.lua") then - return "./"..mod_name.."/" - end -end - return CPStyle diff --git a/png-lua/README.md b/CPStyling/png-lua/README.md similarity index 100% rename from png-lua/README.md rename to CPStyling/png-lua/README.md diff --git a/png-lua/deflatelua.lua b/CPStyling/png-lua/deflatelua.lua similarity index 99% rename from png-lua/deflatelua.lua rename to CPStyling/png-lua/deflatelua.lua index 4d8276a..7e8a8bf 100644 --- a/png-lua/deflatelua.lua +++ b/CPStyling/png-lua/deflatelua.lua @@ -338,7 +338,7 @@ local function bitstream_from_bytestream(bys) return bits end end - + is_bitstream[o] = true return o @@ -441,7 +441,7 @@ local function HuffmanTable(init, is_full) end return res end - + local tfirstcode = memoize( function(bits) return pow2[minbits] + msb(bits, minbits) end) @@ -545,7 +545,7 @@ local function parse_zlib_header(bs) local flevel = bs:read(2) -- FLaGs: FLEVEL (compression level) local cmf = cinfo * 16 + cm -- CMF (Compresion Method and flags) local flg = fcheck + fdict * 32 + flevel * 64 -- FLaGs - + if cm ~= 8 then -- not "deflate" runtime_error("unrecognized zlib compression method: " .. cm) end @@ -553,16 +553,16 @@ local function parse_zlib_header(bs) runtime_error("invalid zlib window size: cinfo=" .. cinfo) end local window_size = 2^(cinfo + 8) - + if (cmf*256 + flg) % 31 ~= 0 then runtime_error("invalid zlib header (bad fcheck sum)") end - + if fdict == 1 then runtime_error("FIX:TODO - FDICT not currently implemented") local dictid_ = bs:read(32) end - + return window_size end @@ -819,11 +819,11 @@ function M.inflate_zlib(t) local outbs = get_obytestream(t.output) local disable_crc = t.disable_crc if disable_crc == nil then disable_crc = false end - + local window_size_ = parse_zlib_header(bs) - + local data_adler32 = 1 - + inflate{input=bs, output= disable_crc and outbs or function(byte) @@ -833,7 +833,7 @@ function M.inflate_zlib(t) } bs:read(bs:nbits_left_in_byte()) - + local b3 = bs:read(8) local b2 = bs:read(8) local b1 = bs:read(8) @@ -853,4 +853,4 @@ function M.inflate_zlib(t) end -return M \ No newline at end of file +return M diff --git a/png-lua/png.lua b/CPStyling/png-lua/png.lua similarity index 99% rename from png-lua/png.lua rename to CPStyling/png-lua/png.lua index c2df3b3..bae2008 100644 --- a/png-lua/png.lua +++ b/CPStyling/png-lua/png.lua @@ -19,7 +19,7 @@ -- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -local currentFilePath = (...):gsub("png$","") +local currentFilePath = "CPStyling/png-lua/" local deflate = require(currentFilePath.."deflatelua") local requiredDeflateVersion = "0.3.20111128" diff --git a/CPStyling/styles.lua b/CPStyling/styles.lua new file mode 100644 index 0000000..e5b2ce3 --- /dev/null +++ b/CPStyling/styles.lua @@ -0,0 +1,128 @@ +-- MIT License +-- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- +-- Copyright (c) 2021 Mingming Cui +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + +return { + color = { + red = { 1.00, 0.00, 0.00, 1.00 }, + cyan = { 0.00, 1.00, 1.00, 1.00 }, + blue = { 0.00, 0.00, 1.00, 1.00 }, + darkblue = { 0.00, 0.00, 0.63, 1.00 }, + lightblue = { 0.68, 0.85, 0.90, 1.00 }, + purple = { 0.50, 0.00, 0.50, 1.00 }, + yellow = { 1.00, 1.00, 0.00, 1.00 }, + lime = { 0.00, 1.00, 0.00, 1.00 }, + magenta = { 1.00, 0.00, 1.00, 1.00 }, + white = { 1.00, 1.00, 1.00, 1.00 }, + silver = { 0.75, 0.75, 0.75, 1.00 }, + grey = { 0.50, 0.50, 0.50, 1.00 }, + black = { 0.00, 0.00, 0.00, 1.00 }, + orange = { 1.00, 0.65, 0.00, 1.00 }, + brown = { 0.65, 0.16, 0.16, 1.00 }, + maroon = { 0.50, 0.00, 0.00, 1.00 }, + green = { 0.00, 0.50, 0.00, 1.00 }, + olive = { 0.50, 0.50, 0.00, 1.00 } + }, + + ImGuiStyleNames = { + Col = { + { ImGuiStyle = ImGuiCol.Text , ImGuiStyleShort = "Text" }, + { ImGuiStyle = ImGuiCol.TextDisabled , ImGuiStyleShort = "TextDisabled" }, + { ImGuiStyle = ImGuiCol.WindowBg , ImGuiStyleShort = "WindowBg" }, + { ImGuiStyle = ImGuiCol.ChildBg , ImGuiStyleShort = "ChildBg" }, + { ImGuiStyle = ImGuiCol.PopupBg , ImGuiStyleShort = "PopupBg" }, + { ImGuiStyle = ImGuiCol.Border , ImGuiStyleShort = "Border" }, + { ImGuiStyle = ImGuiCol.BorderShadow , ImGuiStyleShort = "BorderShadow" }, + { ImGuiStyle = ImGuiCol.FrameBg , ImGuiStyleShort = "FrameBg" }, + { ImGuiStyle = ImGuiCol.FrameBgHovered , ImGuiStyleShort = "FrameBgHovered" }, + { ImGuiStyle = ImGuiCol.FrameBgActive , ImGuiStyleShort = "FrameBgActive" }, + { ImGuiStyle = ImGuiCol.TitleBg , ImGuiStyleShort = "TitleBg" }, + { ImGuiStyle = ImGuiCol.TitleBgActive , ImGuiStyleShort = "TitleBgActive" }, + { ImGuiStyle = ImGuiCol.TitleBgCollapsed , ImGuiStyleShort = "TitleBgCollapsed" }, + { ImGuiStyle = ImGuiCol.MenuBarBg , ImGuiStyleShort = "MenuBarBg" }, + { ImGuiStyle = ImGuiCol.ScrollbarBg , ImGuiStyleShort = "ScrollbarBg" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrab , ImGuiStyleShort = "ScrollbarGrab" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrabHovered , ImGuiStyleShort = "ScrollbarGrabHovered" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrabActive , ImGuiStyleShort = "ScrollbarGrabActive" }, + { ImGuiStyle = ImGuiCol.CheckMark , ImGuiStyleShort = "CheckMark" }, + { ImGuiStyle = ImGuiCol.SliderGrab , ImGuiStyleShort = "SliderGrab" }, + { ImGuiStyle = ImGuiCol.SliderGrabActive , ImGuiStyleShort = "SliderGrabActive" }, + { ImGuiStyle = ImGuiCol.Button , ImGuiStyleShort = "Button" }, + { ImGuiStyle = ImGuiCol.ButtonHovered , ImGuiStyleShort = "ButtonHovered" }, + { ImGuiStyle = ImGuiCol.ButtonActive , ImGuiStyleShort = "ButtonActive" }, + { ImGuiStyle = ImGuiCol.Header , ImGuiStyleShort = "Header" }, + { ImGuiStyle = ImGuiCol.HeaderHovered , ImGuiStyleShort = "HeaderHovered" }, + { ImGuiStyle = ImGuiCol.HeaderActive , ImGuiStyleShort = "HeaderActive" }, + { ImGuiStyle = ImGuiCol.Separator , ImGuiStyleShort = "Separator" }, + { ImGuiStyle = ImGuiCol.SeparatorHovered , ImGuiStyleShort = "SeparatorHovered" }, + { ImGuiStyle = ImGuiCol.SeparatorActive , ImGuiStyleShort = "SeparatorActive" }, + { ImGuiStyle = ImGuiCol.ResizeGrip , ImGuiStyleShort = "ResizeGrip" }, + { ImGuiStyle = ImGuiCol.ResizeGripHovered , ImGuiStyleShort = "ResizeGripHovered" }, + { ImGuiStyle = ImGuiCol.ResizeGripActive , ImGuiStyleShort = "ResizeGripActive" }, + { ImGuiStyle = ImGuiCol.Tab , ImGuiStyleShort = "Tab" }, + { ImGuiStyle = ImGuiCol.TabHovered , ImGuiStyleShort = "TabHovered" }, + { ImGuiStyle = ImGuiCol.TabActive , ImGuiStyleShort = "TabActive" }, + { ImGuiStyle = ImGuiCol.TabUnfocused , ImGuiStyleShort = "TabUnfocused" }, + { ImGuiStyle = ImGuiCol.TabUnfocusedActive , ImGuiStyleShort = "TabUnfocusedActive" }, + { ImGuiStyle = ImGuiCol.PlotLines , ImGuiStyleShort = "PlotLines" }, + { ImGuiStyle = ImGuiCol.PlotLinesHovered , ImGuiStyleShort = "PlotLinesHovered" }, + { ImGuiStyle = ImGuiCol.PlotHistogram , ImGuiStyleShort = "PlotHistogram" }, + { ImGuiStyle = ImGuiCol.PlotHistogramHovered , ImGuiStyleShort = "PlotHistogramHovered" }, + { ImGuiStyle = ImGuiCol.TextSelectedBg , ImGuiStyleShort = "TextSelectedBg" }, + { ImGuiStyle = ImGuiCol.DragDropTarget , ImGuiStyleShort = "DragDropTarget" }, + { ImGuiStyle = ImGuiCol.NavHighlight , ImGuiStyleShort = "NavHighlight" }, + { ImGuiStyle = ImGuiCol.NavWindowingHighlight , ImGuiStyleShort = "NavWindowingHighlight" }, + { ImGuiStyle = ImGuiCol.NavWindowingDimBg , ImGuiStyleShort = "NavWindowingDimBg" }, + { ImGuiStyle = ImGuiCol.ModalWindowDimBg , ImGuiStyleShort = "ModalWindowDimBg" }, + { ImGuiStyle = ImGuiCol.COUNT , ImGuiStyleShort = "COUNT" } + }, + Var = { + { ImGuiStyle = ImGuiStyleVar.Alpha , ImGuiStyleShort = "Alpha" }, + { ImGuiStyle = ImGuiStyleVar.WindowPadding , ImGuiStyleShort = "WindowPadding" }, + { ImGuiStyle = ImGuiStyleVar.WindowRounding , ImGuiStyleShort = "WindowRounding" }, + { ImGuiStyle = ImGuiStyleVar.WindowBorderSize , ImGuiStyleShort = "WindowBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.WindowMinSize , ImGuiStyleShort = "WindowMinSize" }, + { ImGuiStyle = ImGuiStyleVar.WindowTitleAlign , ImGuiStyleShort = "WindowTitleAlign" }, + { ImGuiStyle = ImGuiStyleVar.ChildRounding , ImGuiStyleShort = "ChildRounding" }, + { ImGuiStyle = ImGuiStyleVar.ChildBorderSize , ImGuiStyleShort = "ChildBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.PopupRounding , ImGuiStyleShort = "PopupRounding" }, + { ImGuiStyle = ImGuiStyleVar.PopupBorderSize , ImGuiStyleShort = "PopupBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.FramePadding , ImGuiStyleShort = "FramePadding" }, + { ImGuiStyle = ImGuiStyleVar.FrameRounding , ImGuiStyleShort = "FrameRounding" }, + { ImGuiStyle = ImGuiStyleVar.FrameBorderSize , ImGuiStyleShort = "FrameBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.ItemSpacing , ImGuiStyleShort = "ItemSpacing" }, + { ImGuiStyle = ImGuiStyleVar.ItemInnerSpacing , ImGuiStyleShort = "ItemInnerSpacing" }, + { ImGuiStyle = ImGuiStyleVar.IndentSpacing , ImGuiStyleShort = "IndentSpacing" }, + { ImGuiStyle = ImGuiStyleVar.ScrollbarSize , ImGuiStyleShort = "ScrollbarSize" }, + { ImGuiStyle = ImGuiStyleVar.ScrollbarRounding , ImGuiStyleShort = "ScrollbarRounding" }, + { ImGuiStyle = ImGuiStyleVar.GrabMinSize , ImGuiStyleShort = "GrabMinSize" }, + { ImGuiStyle = ImGuiStyleVar.GrabRounding , ImGuiStyleShort = "GrabRounding" }, + { ImGuiStyle = ImGuiStyleVar.TabRounding , ImGuiStyleShort = "TabRounding" }, + { ImGuiStyle = ImGuiStyleVar.SelectableTextAlign , ImGuiStyleShort = "SelectableTextAlign" }, + { ImGuiStyle = ImGuiStyleVar.ButtonTextAlign , ImGuiStyleShort = "ButtonTextAlign" }, + { ImGuiStyle = ImGuiStyleVar.COUNT , ImGuiStyleShort = "COUNT" } + } + } +} diff --git a/CPStyling/theme.lua b/CPStyling/theme.lua new file mode 100644 index 0000000..0d2635c --- /dev/null +++ b/CPStyling/theme.lua @@ -0,0 +1,123 @@ +-- MIT License +-- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- +-- Copyright (c) 2021 Mingming Cui +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + +return { + Text = { 1.00, 0.38, 0.33, 1.00 }, + TextDisabled = { 0.48, 0.39, 0.40, 1.00 }, + WindowBg = { 0.06, 0.04, 0.06, 0.90 }, + ChildBg = { 0.00, 0.00, 0.00, 0.00 }, + PopupBg = { 0.06, 0.04, 0.06, 0.90 }, + Border = { 0.30, 0.07, 0.08, 1.00 }, + BorderShadow = { 0.00, 0.00, 0.00, 0.00 }, + FrameBg = { 0.50, 0.13, 0.16, 0.50 }, + FrameBgHovered = { 0.32, 0.11, 0.12, 0.50 }, + FrameBgActive = { 0.50, 0.13, 0.16, 0.50 }, + -- FrameBgDisabled = { 0.48, 0.39, 0.40, 1.00 }, + -- FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1.00 }, + -- FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1.00 }, + TitleBg = { 0.06, 0.04, 0.06, 0.90 }, + TitleBgActive = { 0.06, 0.04, 0.06, 0.90 }, + TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.90 }, + MenuBarBg = { 0.00, 0.00, 0.00, 0.00 }, + ScrollbarBg = { 0.23, 0.07, 0.09, 1.00 }, + ScrollbarGrab = { 0.95, 0.30, 0.28, 1.00 }, + ScrollbarGrabHovered = { 0.95, 0.30, 0.28, 1.00 }, + ScrollbarGrabActive = { 0.95, 0.30, 0.28, 1.00 }, + CheckMark = { 1.00, 0.44, 0.40, 1.00 }, + -- CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1.00 }, + -- CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1.00 }, + SliderGrab = { 0.64, 0.22, 0.21, 1.00 }, + SliderGrabActive = { 0.64, 0.22, 0.21, 1.00 }, + Button = { 0.57, 0.17, 0.16, 1.00 }, + ButtonHovered = { 0.45, 0.13, 0.14, 1.00 }, + ButtonActive = { 0.57, 0.17, 0.16, 1.00 }, + Header = { 0.08, 0.08, 0.15, 1.00 }, + HeaderHovered = { 0.22, 0.64, 0.69, 0.30 }, + HeaderActive = { 0.22, 0.64, 0.69, 0.50 }, + Separator = { 0.26, 0.09, 0.09, 1.00 }, + SeparatorHovered = { 0.26, 0.09, 0.09, 1.00 }, + SeparatorActive = { 0.26, 0.09, 0.09, 1.00 }, + ResizeGrip = { 0.00, 0.00, 0.00, 0.00 }, + ResizeGripHovered = { 0.45, 0.13, 0.14, 1.00 }, + ResizeGripActive = { 0.57, 0.17, 0.16, 1.00 }, + Tab = { 0.57, 0.17, 0.16, 1.00 }, + TabHovered = { 0.45, 0.13, 0.14, 1.00 }, + TabActive = { 0.57, 0.17, 0.16, 1.00 }, + TabUnfocused = { 0.45, 0.14, 0.13, 1.00 }, + TabUnfocusedActive = { 0.58, 0.18, 0.16, 1.00 }, + -- PlotLines = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotLinesHovered = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotHistogram = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotHistogramHovered = { 0.00, 0.00, 0.00, 0.00 }, + TextSelectedBg = { 0.06, 0.06, 0.12, 1.00 }, + -- DragDropTarget = { 0.00, 0.00, 0.00, 0.00 }, + -- NavHighlight = { 0.00, 0.00, 0.00, 0.00 }, + -- NavWindowingHighlight = { 0.00, 0.00, 0.00, 0.00 }, + -- NavWindowingDimBg = { 0.00, 0.00, 0.00, 0.00 }, + ModalWindowDimBg = { 0.00, 0.00, 0.00, 0.40 }, + CPButton = { 0.06, 0.06, 0.12, 1.00 }, + CPButtonHovered = { 0.43, 0.13, 0.13, 1.00 }, + CPButtonActive = { 0.57, 0.16, 0.16, 1.00 }, + CPButtonText = { 0.34, 0.95, 0.98, 1.00 }, + CPButtonBorder = { 0.40, 0.08, 0.09, 1.00 }, + CPButtonBorderHovered = { 0.34, 0.95, 0.98, 1.00 }, + CPToggleOn = { 0.37, 0.96, 1.00, 1.00 }, + CPToggleOnHovered = { 0.29, 0.77, 0.80, 1.00 }, + CPToggleOnText = { 0.00, 0.00, 0.00, 1.00 }, + CPToggleOnTextHovered = { 0.00, 0.00, 0.00, 1.00 }, + CPToggleOnBorder = { 0.29, 0.61, 0.58, 1.00 }, + CPToggleOnBorderHovered = { 0.26, 0.66, 0.65, 1.00 }, + CPToggleOnDisabled = { 0.03, 0.12, 0.12, 1.00 }, + CPToggleOnDisabledHovered = { 0.05, 0.16, 0.16, 1.00 }, + CPToggleOnDisabledText = { 0.08, 0.23, 0.25, 1.00 }, + CPToggleOnDisabledTextHovered = { 0.09, 0.29, 0.30, 1.00 }, + CPToggleOnDisabledBorder = { 0.06, 0.15, 0.15, 1.00 }, + CPToggleOnDisabledBorderHovered = { 0.09, 0.24, 0.25, 1.00 }, + CPToggleOff = { 0.58, 0.18, 0.16, 1.00 }, + CPToggleOffHovered = { 0.45, 0.14, 0.13, 1.00 }, + CPToggleOffText = { 1.00, 0.44, 0.41, 1.00 }, + CPToggleOffTextHovered = { 1.00, 0.36, 0.33, 1.00 }, + CPToggleOffBorder = { 0.92, 0.29, 0.26, 1.00 }, + CPToggleOffBorderHovered = { 0.76, 0.23, 0.21, 1.00 }, + CPToggleOffDisabled = { 0.09, 0.04, 0.07, 1.00 }, + CPToggleOffDisabledHovered = { 0.16, 0.06, 0.07, 1.00 }, + CPToggleOffDisabledText = { 0.32, 0.09, 0.10, 1.00 }, + CPToggleOffDisabledTextHovered = { 0.36, 0.11, 0.11, 1.00 }, + CPToggleOffDisabledBorder = { 0.19, 0.08, 0.09, 1.00 }, + CPToggleOffDisabledBorderHovered = { 0.30, 0.09, 0.10, 1.00 }, + CPFrameBg = { 0.06, 0.06, 0.12, 1.00 }, + CPFrameBgHovered = { 0.31, 0.11, 0.11, 1.00 }, + CPFrameBgActive = { 0.57, 0.19, 0.19, 1.00 }, + CPSliderGrab = { 0.64, 0.21, 0.21, 1.00 }, + CPSliderGrabActive = { 0.64, 0.21, 0.21, 1.00 }, + CPFrameBorder = { 0.40, 0.08, 0.09, 1.00 }, + CPTextSelectedBg = { 0.45, 0.14, 0.13, 1.00 }, + CPToolTip2Bg = { 0.11, 0.22, 0.25, 0.60 }, + CPToolTip2Border = { 0.18, 0.42, 0.46, 1.00 }, + CPToolTip2Separator = { 0.24, 0.55, 0.58, 1.00 }, + CPToolTip2SideBg = { 0.12, 0.24, 0.27, 1.00 }, + Hidden = { 0.00, 0.00, 0.00, 0.00 } +} diff --git a/README.md b/README.md index 697208e..d422bf1 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,6 @@ Made for Cyber Engine Tweaks Mod creation. This is a set of color schemes and widgets I made to match the style of Cyberpunk 2077's UI. I also included some useful functions for easier and faster ImGui styling. -To use it under CET 1.8.3, checkout cet-1.8.3-fix branch Please make PR if you want to fix bugs or make improvements ### How to use @@ -13,14 +12,7 @@ theme = CPS.theme color = CPS.color ``` -To use `CPS.loadPNG()` and `CPS.CPDraw()` functions, you need to include the `png.lua`, `deflatelua.lua` library. - -and open `CPStyling.lua` and `png.lua` change the `rootPath` to your project's root path. - -**Note:** Due to some issue of CET 1.9.2, the root path of `io.open()` is different depending on how people launch their games. You need to setup something like a `rootPathIO` in your `init.lua` for your png file path. -If they launch with admin privilege (that's what **Vortex** does) the `rootPathIO` should be starting from`.\plugins\..`, otherwise it should be from `.\bin\x64\plugins\..`. -After press ReloadALLMods button in CET, the root path will change into `mods\` -You can use the `rootPathIO = CPS.getCWD(mod_name)` function to acquire the `rootPathIO` value automatically. +To use `CPS.loadPNG()` and `CPS.CPDraw()` functions, you need to include the `png-lua` library. #This project is still WIP, will add more widgets. You can also download the demo to play with it yourself. @@ -37,9 +29,6 @@ CP77-Braindance Protocol [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/ ### Utilities ```lua ---Get Current Working directory (For finxing the pathing issue in CET1.9) -rootPathIO = CPS.getCWD("mymod") - --Check if a file exists CPS.fileExists(filename) --returns bool @@ -68,7 +57,8 @@ CPS.colorEnd(count) --Same as ImGui.PopStyleColor(count) ---Example--- CPS.colorBegin("Button", { 1, 0, 0, 1 }) CPS.colorBegin("Button", "672b1f") -CPS.colorBegin("Button", CPC.Button) -- get color from cpc.lua +CPS.colorBegin("Button", theme.Button) -- get color from theme.lua +CPS.colorBegin("Button", color.blue) -- get color from styles.lua ImGui.Button("I'm a Button") CPS.colorEnd(1) @@ -175,8 +165,8 @@ CPS.CPDraw("logo", image, 5) "red" "cyan" "blue" -"darkBlue" -"lightBlue" +"darkblue" +"lightblue" "purple" "yellow" "lime" From 7d66b67f31cf6419947bb44e6ae455db26883abb Mon Sep 17 00:00:00 2001 From: Nats-ji Date: Tue, 2 Feb 2021 01:35:36 +0800 Subject: [PATCH 2/5] Updated demo --- CPStyling/init.lua | 1 - demo/CPStyling.lua | 648 -------------------- demo/CPStyling/init.lua | 431 +++++++++++++ demo/CPStyling/png-lua/README.md | 63 ++ demo/{ => CPStyling}/png-lua/deflatelua.lua | 22 +- demo/{ => CPStyling}/png-lua/png.lua | 4 +- demo/CPStyling/styles.lua | 128 ++++ demo/CPStyling/theme.lua | 123 ++++ demo/{ => img}/cyberpunk.png | Bin demo/{ => img}/foxgirl.png | Bin demo/{ => img}/ghost_in_shell.png | Bin demo/{ => img}/lucario.png | Bin demo/{ => img}/mushroom.png | Bin demo/init.lua | 56 +- 14 files changed, 796 insertions(+), 680 deletions(-) delete mode 100644 demo/CPStyling.lua create mode 100644 demo/CPStyling/init.lua create mode 100644 demo/CPStyling/png-lua/README.md rename demo/{ => CPStyling}/png-lua/deflatelua.lua (99%) rename demo/{ => CPStyling}/png-lua/png.lua (98%) create mode 100644 demo/CPStyling/styles.lua create mode 100644 demo/CPStyling/theme.lua rename demo/{ => img}/cyberpunk.png (100%) rename demo/{ => img}/foxgirl.png (100%) rename demo/{ => img}/ghost_in_shell.png (100%) rename demo/{ => img}/lucario.png (100%) rename demo/{ => img}/mushroom.png (100%) diff --git a/CPStyling/init.lua b/CPStyling/init.lua index d087b37..5eace71 100644 --- a/CPStyling/init.lua +++ b/CPStyling/init.lua @@ -29,7 +29,6 @@ local currentFilePath = "CPStyling/" CPStyle.theme = require(currentFilePath.."theme") local styles = require(currentFilePath.."styles") local ImGuiStyleNames = styles.ImGuiStyleNames -print(table.unpack(styles.color.black)) CPStyle.color = styles.color png = require(currentFilePath.."png-lua/png") diff --git a/demo/CPStyling.lua b/demo/CPStyling.lua deleted file mode 100644 index 74bb810..0000000 --- a/demo/CPStyling.lua +++ /dev/null @@ -1,648 +0,0 @@ --- MIT License --- --- - CPStyling.lua --- --- Copyright (c) 2021 Mingming Cui --- --- Permission is hereby granted, free of charge, to any person obtaining a copy --- of this software and associated documentation files (the "Software"), to deal --- in the Software without restriction, including without limitation the rights --- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell --- copies of the Software, and to permit persons to whom the Software is --- furnished to do so, subject to the following conditions: --- --- The above copyright notice and this permission notice shall be included in all --- copies or substantial portions of the Software. --- --- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR --- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, --- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE --- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER --- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, --- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE --- SOFTWARE. - -local CPStyle = {} -local rootPath = "./plugins/cyber_engine_tweaks/mods/demo/" - -local function isModuleAvailable(module) - res = pcall(require,module) - if res then return true - elseif not(res) then - return false - end -end - -if isModuleAvailable(rootPath.."png-lua/png") then - png = require(rootPath.."png-lua/png") -end - -CPStyle.theme = { - Text = { 1.00, 0.38, 0.33, 1.00 }, - TextDisabled = { 0.48, 0.39, 0.40, 1.00 }, - WindowBg = { 0.06, 0.04, 0.06, 0.90 }, - ChildBg = { 0.00, 0.00, 0.00, 0.00 }, - PopupBg = { 0.06, 0.04, 0.06, 0.90 }, - Border = { 0.30, 0.07, 0.08, 1.00 }, - BorderShadow = { 0.00, 0.00, 0.00, 0.00 }, - FrameBg = { 0.50, 0.13, 0.16, 0.50 }, - FrameBgHovered = { 0.32, 0.11, 0.12, 0.50 }, - FrameBgActive = { 0.50, 0.13, 0.16, 0.50 }, - -- FrameBgDisabled = { 0.48, 0.39, 0.40, 1.00 }, - -- FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1.00 }, - -- FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1.00 }, - TitleBg = { 0.06, 0.04, 0.06, 0.90 }, - TitleBgActive = { 0.06, 0.04, 0.06, 0.90 }, - TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.90 }, - MenuBarBg = { 0.00, 0.00, 0.00, 0.00 }, - ScrollbarBg = { 0.23, 0.07, 0.09, 1.00 }, - ScrollbarGrab = { 0.95, 0.30, 0.28, 1.00 }, - ScrollbarGrabHovered = { 0.95, 0.30, 0.28, 1.00 }, - ScrollbarGrabActive = { 0.95, 0.30, 0.28, 1.00 }, - CheckMark = { 1.00, 0.44, 0.40, 1.00 }, - -- CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1.00 }, - -- CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1.00 }, - SliderGrab = { 0.64, 0.22, 0.21, 1.00 }, - SliderGrabActive = { 0.64, 0.22, 0.21, 1.00 }, - Button = { 0.57, 0.17, 0.16, 1.00 }, - ButtonHovered = { 0.45, 0.13, 0.14, 1.00 }, - ButtonActive = { 0.57, 0.17, 0.16, 1.00 }, - Header = { 0.08, 0.08, 0.15, 1.00 }, - HeaderHovered = { 0.22, 0.64, 0.69, 0.30 }, - HeaderActive = { 0.22, 0.64, 0.69, 0.50 }, - Separator = { 0.26, 0.09, 0.09, 1.00 }, - SeparatorHovered = { 0.26, 0.09, 0.09, 1.00 }, - SeparatorActive = { 0.26, 0.09, 0.09, 1.00 }, - ResizeGrip = { 0.00, 0.00, 0.00, 0.00 }, - ResizeGripHovered = { 0.45, 0.13, 0.14, 1.00 }, - ResizeGripActive = { 0.57, 0.17, 0.16, 1.00 }, - Tab = { 0.57, 0.17, 0.16, 1.00 }, - TabHovered = { 0.45, 0.13, 0.14, 1.00 }, - TabActive = { 0.57, 0.17, 0.16, 1.00 }, - TabUnfocused = { 0.45, 0.14, 0.13, 1.00 }, - TabUnfocusedActive = { 0.58, 0.18, 0.16, 1.00 }, - -- PlotLines = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotLinesHovered = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotHistogram = { 0.00, 0.00, 0.00, 0.00 }, - -- PlotHistogramHovered = { 0.00, 0.00, 0.00, 0.00 }, - TextSelectedBg = { 0.06, 0.06, 0.12, 1.00 }, - -- DragDropTarget = { 0.00, 0.00, 0.00, 0.00 }, - -- NavHighlight = { 0.00, 0.00, 0.00, 0.00 }, - -- NavWindowingHighlight = { 0.00, 0.00, 0.00, 0.00 }, - -- NavWindowingDimBg = { 0.00, 0.00, 0.00, 0.00 }, - -- ModalWindowDimBg = { 0.00, 0.00, 0.00, 0.00 }, - -- ModalWindowDarkening = { 0.00, 0.00, 0.00, 0.00 }, - CPButton = { 0.06, 0.06, 0.12, 1.00 }, - CPButtonHovered = { 0.43, 0.13, 0.13, 1.00 }, - CPButtonActive = { 0.57, 0.16, 0.16, 1.00 }, - CPButtonText = { 0.34, 0.95, 0.98, 1.00 }, - CPButtonBorder = { 0.40, 0.08, 0.09, 1.00 }, - CPButtonBorderHovered = { 0.34, 0.95, 0.98, 1.00 }, - CPToggleOn = { 0.37, 0.96, 1.00, 1.00 }, - CPToggleOnHovered = { 0.29, 0.77, 0.80, 1.00 }, - CPToggleOnText = { 0.00, 0.00, 0.00, 1.00 }, - CPToggleOnTextHovered = { 0.00, 0.00, 0.00, 1.00 }, - CPToggleOnBorder = { 0.29, 0.61, 0.58, 1.00 }, - CPToggleOnBorderHovered = { 0.26, 0.66, 0.65, 1.00 }, - CPToggleOnDisabled = { 0.03, 0.12, 0.12, 1.00 }, - CPToggleOnDisabledHovered = { 0.05, 0.16, 0.16, 1.00 }, - CPToggleOnDisabledText = { 0.08, 0.23, 0.25, 1.00 }, - CPToggleOnDisabledTextHovered = { 0.09, 0.29, 0.30, 1.00 }, - CPToggleOnDisabledBorder = { 0.06, 0.15, 0.15, 1.00 }, - CPToggleOnDisabledBorderHovered = { 0.09, 0.24, 0.25, 1.00 }, - CPToggleOff = { 0.58, 0.18, 0.16, 1.00 }, - CPToggleOffHovered = { 0.45, 0.14, 0.13, 1.00 }, - CPToggleOffText = { 1.00, 0.44, 0.41, 1.00 }, - CPToggleOffTextHovered = { 1.00, 0.36, 0.33, 1.00 }, - CPToggleOffBorder = { 0.92, 0.29, 0.26, 1.00 }, - CPToggleOffBorderHovered = { 0.76, 0.23, 0.21, 1.00 }, - CPToggleOffDisabled = { 0.09, 0.04, 0.07, 1.00 }, - CPToggleOffDisabledHovered = { 0.16, 0.06, 0.07, 1.00 }, - CPToggleOffDisabledText = { 0.32, 0.09, 0.10, 1.00 }, - CPToggleOffDisabledTextHovered = { 0.36, 0.11, 0.11, 1.00 }, - CPToggleOffDisabledBorder = { 0.19, 0.08, 0.09, 1.00 }, - CPToggleOffDisabledBorderHovered = { 0.30, 0.09, 0.10, 1.00 }, - CPFrameBg = { 0.06, 0.06, 0.12, 1.00 }, - CPFrameBgHovered = { 0.31, 0.11, 0.11, 1.00 }, - CPFrameBgActive = { 0.57, 0.19, 0.19, 1.00 }, - CPSliderGrab = { 0.64, 0.21, 0.21, 1.00 }, - CPSliderGrabActive = { 0.64, 0.21, 0.21, 1.00 }, - CPFrameBorder = { 0.40, 0.08, 0.09, 1.00 }, - CPTextSelectedBg = { 0.45, 0.14, 0.13, 1.00 }, - CPToolTip2Bg = { 0.11, 0.22, 0.25, 0.60 }, - CPToolTip2Border = { 0.18, 0.42, 0.46, 1.00 }, - CPToolTip2Separator = { 0.24, 0.55, 0.58, 1.00 }, - CPToolTip2SideBg = { 0.12, 0.24, 0.27, 1.00 }, - Hidden = { 0.00, 0.00, 0.00, 0.00 } -} - -CPStyle.color = { - red = { 1.00, 0.00, 0.00, 1.00 }, - cyan = { 0.00, 1.00, 1.00, 1.00 }, - blue = { 0.00, 0.00, 1.00, 1.00 }, - darkBlue = { 0.00, 0.00, 0.63, 1.00 }, - lightBlue = { 0.68, 0.85, 0.90, 1.00 }, - purple = { 0.50, 0.00, 0.50, 1.00 }, - yellow = { 1.00, 1.00, 0.00, 1.00 }, - lime = { 0.00, 1.00, 0.00, 1.00 }, - magenta = { 1.00, 0.00, 1.00, 1.00 }, - white = { 1.00, 1.00, 1.00, 1.00 }, - silver = { 0.75, 0.75, 0.75, 1.00 }, - grey = { 0.50, 0.50, 0.50, 1.00 }, - black = { 0.00, 0.00, 0.00, 1.00 }, - orange = { 1.00, 0.65, 0.00, 1.00 }, - brown = { 0.65, 0.16, 0.16, 1.00 }, - maroon = { 0.50, 0.00, 0.00, 1.00 }, - green = { 0.00, 0.50, 0.00, 1.00 }, - olive = { 0.50, 0.50, 0.00, 1.00 } -} - - -local ImGuiStyleNames = { - Col = { - { ImGuiStyle = ImGuiCol.Text , ImGuiStyleShort = "Text" }, - { ImGuiStyle = ImGuiCol.TextDisabled , ImGuiStyleShort = "TextDisabled" }, - { ImGuiStyle = ImGuiCol.WindowBg , ImGuiStyleShort = "WindowBg" }, - { ImGuiStyle = ImGuiCol.ChildBg , ImGuiStyleShort = "ChildBg" }, - { ImGuiStyle = ImGuiCol.PopupBg , ImGuiStyleShort = "PopupBg" }, - { ImGuiStyle = ImGuiCol.Border , ImGuiStyleShort = "Border" }, - { ImGuiStyle = ImGuiCol.BorderShadow , ImGuiStyleShort = "BorderShadow" }, - { ImGuiStyle = ImGuiCol.FrameBg , ImGuiStyleShort = "FrameBg" }, - { ImGuiStyle = ImGuiCol.FrameBgHovered , ImGuiStyleShort = "FrameBgHovered" }, - { ImGuiStyle = ImGuiCol.FrameBgActive , ImGuiStyleShort = "FrameBgActive" }, - { ImGuiStyle = ImGuiCol.TitleBg , ImGuiStyleShort = "TitleBg" }, - { ImGuiStyle = ImGuiCol.TitleBgActive , ImGuiStyleShort = "TitleBgActive" }, - { ImGuiStyle = ImGuiCol.TitleBgCollapsed , ImGuiStyleShort = "TitleBgCollapsed" }, - { ImGuiStyle = ImGuiCol.MenuBarBg , ImGuiStyleShort = "MenuBarBg" }, - { ImGuiStyle = ImGuiCol.ScrollbarBg , ImGuiStyleShort = "ScrollbarBg" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrab , ImGuiStyleShort = "ScrollbarGrab" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrabHovered , ImGuiStyleShort = "ScrollbarGrabHovered" }, - { ImGuiStyle = ImGuiCol.ScrollbarGrabActive , ImGuiStyleShort = "ScrollbarGrabActive" }, - { ImGuiStyle = ImGuiCol.CheckMark , ImGuiStyleShort = "CheckMark" }, - { ImGuiStyle = ImGuiCol.SliderGrab , ImGuiStyleShort = "SliderGrab" }, - { ImGuiStyle = ImGuiCol.SliderGrabActive , ImGuiStyleShort = "SliderGrabActive" }, - { ImGuiStyle = ImGuiCol.Button , ImGuiStyleShort = "Button" }, - { ImGuiStyle = ImGuiCol.ButtonHovered , ImGuiStyleShort = "ButtonHovered" }, - { ImGuiStyle = ImGuiCol.ButtonActive , ImGuiStyleShort = "ButtonActive" }, - { ImGuiStyle = ImGuiCol.Header , ImGuiStyleShort = "Header" }, - { ImGuiStyle = ImGuiCol.HeaderHovered , ImGuiStyleShort = "HeaderHovered" }, - { ImGuiStyle = ImGuiCol.HeaderActive , ImGuiStyleShort = "HeaderActive" }, - { ImGuiStyle = ImGuiCol.Separator , ImGuiStyleShort = "Separator" }, - { ImGuiStyle = ImGuiCol.SeparatorHovered , ImGuiStyleShort = "SeparatorHovered" }, - { ImGuiStyle = ImGuiCol.SeparatorActive , ImGuiStyleShort = "SeparatorActive" }, - { ImGuiStyle = ImGuiCol.ResizeGrip , ImGuiStyleShort = "ResizeGrip" }, - { ImGuiStyle = ImGuiCol.ResizeGripHovered , ImGuiStyleShort = "ResizeGripHovered" }, - { ImGuiStyle = ImGuiCol.ResizeGripActive , ImGuiStyleShort = "ResizeGripActive" }, - { ImGuiStyle = ImGuiCol.Tab , ImGuiStyleShort = "Tab" }, - { ImGuiStyle = ImGuiCol.TabHovered , ImGuiStyleShort = "TabHovered" }, - { ImGuiStyle = ImGuiCol.TabActive , ImGuiStyleShort = "TabActive" }, - { ImGuiStyle = ImGuiCol.TabUnfocused , ImGuiStyleShort = "TabUnfocused" }, - { ImGuiStyle = ImGuiCol.TabUnfocusedActive , ImGuiStyleShort = "TabUnfocusedActive" }, - { ImGuiStyle = ImGuiCol.PlotLines , ImGuiStyleShort = "PlotLines" }, - { ImGuiStyle = ImGuiCol.PlotLinesHovered , ImGuiStyleShort = "PlotLinesHovered" }, - { ImGuiStyle = ImGuiCol.PlotHistogram , ImGuiStyleShort = "PlotHistogram" }, - { ImGuiStyle = ImGuiCol.PlotHistogramHovered , ImGuiStyleShort = "PlotHistogramHovered" }, - { ImGuiStyle = ImGuiCol.TextSelectedBg , ImGuiStyleShort = "TextSelectedBg" }, - { ImGuiStyle = ImGuiCol.DragDropTarget , ImGuiStyleShort = "DragDropTarget" }, - { ImGuiStyle = ImGuiCol.NavHighlight , ImGuiStyleShort = "NavHighlight" }, - { ImGuiStyle = ImGuiCol.NavWindowingHighlight , ImGuiStyleShort = "NavWindowingHighlight" }, - { ImGuiStyle = ImGuiCol.NavWindowingDimBg , ImGuiStyleShort = "NavWindowingDimBg" }, - { ImGuiStyle = ImGuiCol.ModalWindowDimBg , ImGuiStyleShort = "ModalWindowDimBg" }, - { ImGuiStyle = ImGuiCol.ModalWindowDarkening , ImGuiStyleShort = "ModalWindowDarkening" }, - { ImGuiStyle = ImGuiCol.COUNT , ImGuiStyleShort = "COUNT" } - }, - Var = { - { ImGuiStyle = ImGuiStyleVar.Alpha , ImGuiStyleShort = "Alpha" }, - { ImGuiStyle = ImGuiStyleVar.WindowPadding , ImGuiStyleShort = "WindowPadding" }, - { ImGuiStyle = ImGuiStyleVar.WindowRounding , ImGuiStyleShort = "WindowRounding" }, - { ImGuiStyle = ImGuiStyleVar.WindowBorderSize , ImGuiStyleShort = "WindowBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.WindowMinSize , ImGuiStyleShort = "WindowMinSize" }, - { ImGuiStyle = ImGuiStyleVar.WindowTitleAlign , ImGuiStyleShort = "WindowTitleAlign" }, - { ImGuiStyle = ImGuiStyleVar.ChildRounding , ImGuiStyleShort = "ChildRounding" }, - { ImGuiStyle = ImGuiStyleVar.ChildBorderSize , ImGuiStyleShort = "ChildBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.PopupRounding , ImGuiStyleShort = "PopupRounding" }, - { ImGuiStyle = ImGuiStyleVar.PopupBorderSize , ImGuiStyleShort = "PopupBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.FramePadding , ImGuiStyleShort = "FramePadding" }, - { ImGuiStyle = ImGuiStyleVar.FrameRounding , ImGuiStyleShort = "FrameRounding" }, - { ImGuiStyle = ImGuiStyleVar.FrameBorderSize , ImGuiStyleShort = "FrameBorderSize" }, - { ImGuiStyle = ImGuiStyleVar.ItemSpacing , ImGuiStyleShort = "ItemSpacing" }, - { ImGuiStyle = ImGuiStyleVar.ItemInnerSpacing , ImGuiStyleShort = "ItemInnerSpacing" }, - { ImGuiStyle = ImGuiStyleVar.IndentSpacing , ImGuiStyleShort = "IndentSpacing" }, - { ImGuiStyle = ImGuiStyleVar.ScrollbarSize , ImGuiStyleShort = "ScrollbarSize" }, - { ImGuiStyle = ImGuiStyleVar.ScrollbarRounding , ImGuiStyleShort = "ScrollbarRounding" }, - { ImGuiStyle = ImGuiStyleVar.GrabMinSize , ImGuiStyleShort = "GrabMinSize" }, - { ImGuiStyle = ImGuiStyleVar.GrabRounding , ImGuiStyleShort = "GrabRounding" }, - { ImGuiStyle = ImGuiStyleVar.TabRounding , ImGuiStyleShort = "TabRounding" }, - { ImGuiStyle = ImGuiStyleVar.SelectableTextAlign , ImGuiStyleShort = "SelectableTextAlign" }, - { ImGuiStyle = ImGuiStyleVar.ButtonTextAlign , ImGuiStyleShort = "ButtonTextAlign" }, - { ImGuiStyle = ImGuiStyleVar.COUNT , ImGuiStyleShort = "COUNT" } - } -} - -local function ToImGuiStyleName(style, which) - if which == "Col" then - for i in pairs(ImGuiStyleNames.Col) do - if style == ImGuiStyleNames.Col[i].ImGuiStyleShort then - return ImGuiStyleNames.Col[i].ImGuiStyle - end - end - elseif which == "Var" then - for i in pairs(ImGuiStyleNames.Var) do - if style == ImGuiStyleNames.Var[i].ImGuiStyleShort then - return ImGuiStyleNames.Var[i].ImGuiStyle - end - end - end -end - -local function hex2rgb(hex) - local hex = hex:gsub("#","") - if hex:len() == 3 then - return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255 - else - return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255 - end -end - -function CPStyle.colorBegin(style, color) - if type(color) == "number" then - ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color) - elseif type(color) == "string" then - local r, g, b = hex2rgb(color) - ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), r, g, b, 1) - elseif type(color) == "table" then - if type(color[1]) == "string" and type(color[2]) == "number" then - local r, g, b = hex2rgb(color[1]) - ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), r, g, b, color[2]) - elseif type(color[1]) == "number" and type(color[2]) == "number" and type(color[3]) == "number" then - if color[4] == nil then - ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color[1], color[2], color[3], 1) - else - ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color[1], color[2], color[3], color[4]) - end - end - end -end - -function CPStyle.colorEnd(count) - if count == nil then - ImGui.PopStyleColor() - else - ImGui.PopStyleColor(count) - end -end --- -function CPStyle.styleBegin(style, var1, var2) - if var2 == nil then - ImGui.PushStyleVar(ToImGuiStyleName(style, "Var"), var1) - else - ImGui.PushStyleVar(ToImGuiStyleName(style, "Var"), var1, var2) - end -end - -function CPStyle.styleEnd(count) - if count == nil then - ImGui.PopStyleVar() - else - ImGui.PopStyleVar(count) - end -end - -function CPStyle.setThemeBegin() - CPStyle.colorBegin("Text" , CPStyle.theme.Text) - CPStyle.colorBegin("TextDisabled" , CPStyle.theme.TextDisabled) - CPStyle.colorBegin("WindowBg" , CPStyle.theme.WindowBg) - CPStyle.colorBegin("ChildBg" , CPStyle.theme.ChildBg) - CPStyle.colorBegin("PopupBg" , CPStyle.theme.PopupBg) - CPStyle.colorBegin("Border" , CPStyle.theme.Border) - CPStyle.colorBegin("BorderShadow" , CPStyle.theme.BorderShadow) - CPStyle.colorBegin("FrameBg" , CPStyle.theme.FrameBg) - CPStyle.colorBegin("FrameBgHovered" , CPStyle.theme.FrameBgHovered) - CPStyle.colorBegin("FrameBgActive" , CPStyle.theme.FrameBgActive) - CPStyle.colorBegin("TitleBg" , CPStyle.theme.TitleBg) - CPStyle.colorBegin("TitleBgActive" , CPStyle.theme.TitleBgActive) - CPStyle.colorBegin("TitleBgCollapsed" , CPStyle.theme.TitleBgCollapsed) - CPStyle.colorBegin("MenuBarBg" , CPStyle.theme.MenuBarBg) - CPStyle.colorBegin("ScrollbarBg" , CPStyle.theme.ScrollbarBg) - CPStyle.colorBegin("ScrollbarGrab" , CPStyle.theme.ScrollbarGrab) - CPStyle.colorBegin("ScrollbarGrabHovered" , CPStyle.theme.ScrollbarGrabHovered) - CPStyle.colorBegin("ScrollbarGrabActive" , CPStyle.theme.ScrollbarGrabActive) - CPStyle.colorBegin("CheckMark" , CPStyle.theme.CheckMark) - CPStyle.colorBegin("SliderGrab" , CPStyle.theme.SliderGrab) - CPStyle.colorBegin("SliderGrabActive" , CPStyle.theme.SliderGrabActive) - CPStyle.colorBegin("Button" , CPStyle.theme.Button) - CPStyle.colorBegin("ButtonHovered" , CPStyle.theme.ButtonHovered) - CPStyle.colorBegin("ButtonActive" , CPStyle.theme.ButtonActive) - CPStyle.colorBegin("Header" , CPStyle.theme.Header) - CPStyle.colorBegin("HeaderHovered" , CPStyle.theme.HeaderHovered) - CPStyle.colorBegin("HeaderActive" , CPStyle.theme.HeaderActive) - CPStyle.colorBegin("Separator" , CPStyle.theme.Separator) - CPStyle.colorBegin("SeparatorHovered" , CPStyle.theme.SeparatorHovered) - CPStyle.colorBegin("SeparatorActive" , CPStyle.theme.SeparatorActive) - CPStyle.colorBegin("ResizeGrip" , CPStyle.theme.ResizeGrip) - CPStyle.colorBegin("ResizeGripHovered" , CPStyle.theme.ResizeGripHovered) - CPStyle.colorBegin("ResizeGripActive" , CPStyle.theme.ResizeGripActive) - CPStyle.colorBegin("Tab" , CPStyle.theme.Tab) - CPStyle.colorBegin("TabHovered" , CPStyle.theme.TabHovered) - CPStyle.colorBegin("TabActive" , CPStyle.theme.TabActive) - CPStyle.colorBegin("TabUnfocused" , CPStyle.theme.TabUnfocused) - CPStyle.colorBegin("TabUnfocusedActive" , CPStyle.theme.TabUnfocusedActive) - -- CPStyle.colorBegin("PlotLines" , CPStyle.theme.PlotLines) - -- CPStyle.colorBegin("PlotLinesHovered" , CPStyle.theme.PlotLinesHovered) - -- CPStyle.colorBegin("PlotHistogram" , CPStyle.theme.PlotHistogram) - -- CPStyle.colorBegin("PlotHistogramHovered" , CPStyle.theme.PlotHistogramHovered) - CPStyle.colorBegin("TextSelectedBg" , CPStyle.theme.TextSelectedBg) - -- CPStyle.colorBegin("DragDropTarget" , CPStyle.theme.DragDropTarget) - -- CPStyle.colorBegin("NavHighlight" , CPStyle.theme.NavHighlight) - -- CPStyle.colorBegin("NavWindowingHighlight" , CPStyle.theme.NavWindowingHighlight) - -- CPStyle.colorBegin("NavWindowingDimBg" , CPStyle.theme.NavWindowingDimBg) - -- CPStyle.colorBegin("ModalWindowDimBg" , CPStyle.theme.ModalWindowDimBg) - -- CPStyle.colorBegin("ModalWindowDarkening" , CPStyle.theme.ModalWindowDarkening) - CPStyle.styleBegin("WindowRounding" , 0) - CPStyle.styleBegin("ScrollbarSize" , 9) -end - -function CPStyle.setThemeEnd() - CPStyle.styleEnd(2) - CPStyle.colorEnd(39) -end - -function CPStyle.setFrameThemeBegin() - CPStyle.colorBegin("FrameBg" , CPStyle.theme.CPFrameBg) - CPStyle.colorBegin("FrameBgHovered" , CPStyle.theme.CPFrameBgHovered) - CPStyle.colorBegin("FrameBgActive" , CPStyle.theme.CPFrameBgActive) - CPStyle.colorBegin("SliderGrab" , CPStyle.theme.CPSliderGrab) - CPStyle.colorBegin("SliderGrabActive" , CPStyle.theme.CPSliderGrabActive) - CPStyle.colorBegin("Border" , CPStyle.theme.CPFrameBorder) - CPStyle.colorBegin("TextSelectedBg" , CPStyle.theme.CPTextSelectedBg) - CPStyle.styleBegin("FrameBorderSize" , 1) -end - -function CPStyle.setFrameThemeEnd() - CPStyle.styleEnd(1) - CPStyle.colorEnd(7) -end - --- CPButton - -function CPStyle.CPButton(label, sizex, sizey) - local press, hovered - ImGui.BeginGroup() - CPStyle.styleBegin("FrameBorderSize", 1) - CPStyle.colorBegin("Button", CPStyle.theme.CPButton) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPButtonHovered) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPButtonActive) - CPStyle.colorBegin("Text", CPStyle.theme.CPButtonText) - CPStyle.colorBegin("Border", CPStyle.theme.CPButtonBorder) - if sizex == nil or sizey == nil then - press = ImGui.Button(label) - else - press = ImGui.Button(label, sizex, sizey) - end - CPStyle.colorEnd(5) - hovered = ImGui.IsItemHovered() - if hovered then - ImGui.SameLine(0.0001) - CPStyle.colorBegin("Border", CPStyle.theme.CPButtonBorderHovered) - CPStyle.colorBegin("Text", CPStyle.theme.Hidden) - CPStyle.colorBegin("Button", CPStyle.theme.Hidden) - if sizex == nil or sizey == nil then - ImGui.Button(label.."##hovered") - else - ImGui.Button(label.."##hovered", sizex, sizey) - end - CPStyle.colorEnd(3) - end - CPStyle.styleEnd(1) - ImGui.EndGroup() - return press -end - --- CPToggle - -function CPStyle.CPToggle(label, label_off, label_on, value, sizex, sizey) - local press_off, press_on, hovered - ImGui.BeginGroup() - CPStyle.styleBegin("FrameBorderSize", 1) - ImGui.BeginGroup() - if value then - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffDisabled) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffDisabledText) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOffDisabledHovered) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOffDisabled) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffDisabledBorder) - press_off = ImGui.Button(label_off.."##cp", sizex/2-1,sizey) - ImGui.PopStyleColor(5) - ImGui.SameLine(sizex/2+1) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOn) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnText) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOnHovered) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOn) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnBorder) - press_on = ImGui.Button(label_on.."##cp", sizex/2-1, sizey) - ImGui.PopStyleColor(5) - - else - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOff) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffText) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOffHovered) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOff) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffBorder) - press_off = ImGui.Button(label_off.."##cp", sizex/2-1,sizey) - ImGui.PopStyleColor(5) - ImGui.SameLine(sizex/2+1) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnDisabled) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnDisabledText) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOnDisabledHovered) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOnDisabled) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnDisabledBorder) - press_on = ImGui.Button(label_on.."##cp", sizex/2-1, sizey) - ImGui.PopStyleColor(5) - end - - if press_off and value == false then - value = true - elseif press_off and value == true then - value = false - elseif press_on and value == true then - value = false - elseif press_on and value == false then - value = true - end - if press_off or press_on then press = true else press = false end - ImGui.EndGroup() - hovered = ImGui.IsItemHovered() - - if hovered then --show hovered border color and text color - ImGui.SameLine(0.0001) - ImGui.BeginGroup() - if value then - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffDisabledBorderHovered) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffDisabledHovered) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffDisabledTextHovered) - ImGui.Button(label_off.."##hovered", sizex/2-1,sizey) - ImGui.PopStyleColor(3) - ImGui.SameLine(sizex/2+1) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnBorderHovered) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnHovered) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnTextHovered) - ImGui.Button(label_on.."##hovered", sizex/2-1, sizey) - ImGui.PopStyleColor(3) - - else - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffBorderHovered) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffHovered) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffTextHovered) - ImGui.Button(label_off.."##hovered", sizex/2-1,sizey) - ImGui.PopStyleColor(3) - ImGui.SameLine(sizex/2+1) - CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnDisabledBorderHovered) - CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnDisabledHovered) - CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnDisabledTextHovered) - ImGui.Button(label_on.."##hovered", sizex/2-1, sizey) - ImGui.PopStyleColor(3) - end - ImGui.EndGroup() - end - CPStyle.styleEnd(1) - if label ~= nil and label ~= "" and label:match("^##") == nil then - CPStyle.colorBegin("Button", CPStyle.theme.Hidden) - CPStyle.colorBegin("Text", CPStyle.theme.Text) - CPStyle.colorBegin("ButtonHovered", CPStyle.theme.Hidden) - CPStyle.colorBegin("ButtonActive", CPStyle.theme.Hidden) - CPStyle.styleBegin("FrameBorderSize", 0) - CPStyle.styleBegin("ButtonTextAlign", 0, 0.5) - ImGui.SameLine(sizex) - ImGui.Button(label, 0, sizey) - CPStyle.styleEnd(2) - CPStyle.colorEnd(4) - end - ImGui.EndGroup() - return value, press -end - -function CPStyle.CPToolTip1Begin(sizex, sizey) - CPStyle.styleBegin("WindowRounding", 0) - CPStyle.styleBegin("PopupBorderSize", 0) - CPStyle.styleBegin("ChildBorderSize", 1) - CPStyle.colorBegin("PopupBg", CPStyle.theme.Hidden) - CPStyle.colorBegin("ChildBg", CPStyle.theme.CPFrameBg) - ImGui.BeginTooltip() - CPStyle.CPRect("##SideRect", 8, sizey, CPStyle.theme.CPFrameBg, CPStyle.theme.CPFrameBorder, 1, 0) - ImGui.SameLine(20) - ImGui.BeginGroup() - ImGui.BeginChild("ToolTipMain", sizex, sizey, true) -end - -function CPStyle.CPToolTip1End() - ImGui.EndChild() - ImGui.EndGroup() - ImGui.EndTooltip() - CPStyle.colorEnd(2) - CPStyle.styleEnd(3) -end - -function CPStyle.CPToolTip2Begin(sizex, sizey) - CPStyle.styleBegin("WindowRounding", 0) - CPStyle.styleBegin("PopupBorderSize", 0) - CPStyle.styleBegin("ChildBorderSize", 1) - CPStyle.colorBegin("PopupBg", CPStyle.theme.Hidden) - CPStyle.colorBegin("ChildBg", CPStyle.theme.CPToolTip2Bg) - CPStyle.colorBegin("Border", CPStyle.theme.CPToolTip2Border) - CPStyle.colorBegin("Separator", CPStyle.theme.CPToolTip2Separator) - ImGui.BeginTooltip() - CPStyle.CPRect("##SideRect", 8, sizey, CPStyle.theme.CPToolTip2SideBg, CPStyle.theme.CPToolTip2Border, 1, 0) - ImGui.SameLine(16) - ImGui.BeginGroup() - ImGui.BeginChild("ToolTip2Main", sizex, sizey, true) -end - -function CPStyle.CPToolTip2End() - ImGui.EndChild() - ImGui.EndGroup() - ImGui.EndTooltip() - CPStyle.colorEnd(4) - CPStyle.styleEnd(3) -end - -function CPStyle.CPRect(label, sizex, sizey, color, border_color, border_size, border_rounding, textalignx, textaligny) - if border_color == nil then border_color = CPStyle.theme.Border end - if border_size == nil then border_size = 0 end - if border_rounding == nil then border_rounding = 0 end - if textalignx == nil then textalignx = 0.5 end - if textaligny == nil then textaligny = 0.5 end - CPStyle.colorBegin("Border", border_color) - CPStyle.colorBegin("Button", color) - CPStyle.colorBegin("ButtonActive", color) - CPStyle.colorBegin("ButtonHovered", color) - CPStyle.styleBegin("FrameBorderSize", border_size) - CPStyle.styleBegin("FrameRounding", border_rounding) - CPStyle.styleBegin("ButtonTextAlign", textalignx, textaligny) - local press = ImGui.Button(label, sizex, sizey) - CPStyle.styleEnd(3) - CPStyle.colorEnd(4) - return press -end - -function CPStyle.CPRect2(label, sizex, sizey, color) - CPStyle.colorBegin("ChildBg", color) - ImGui.BeginChild(label, sizex, sizey) - ImGui.EndChild() - CPStyle.colorEnd(1) -end - -function CPStyle.CPDraw(name, image, scale) - ImGui.BeginGroup() - local basex, basey = ImGui.GetCursorPos() - local pixelx = 1 - local pixely = 1 - local cursorx = basex - local cursory = basey - local totalPixel = image.width*image.height - for i = 1, totalPixel do - ImGui.SetCursorPos(cursorx, cursory) - if image.pixels[pixely][pixelx][4] ~= 0 then - CPStyle.CPRect2("##"..name..i, scale, scale, image.pixels[pixely][pixelx]) - end - pixelx = pixelx + 1 - if pixelx > image.width then pixelx = 1 pixely = pixely + 1 end - cursorx = basex+(pixelx-1)*scale - cursory = basey+(pixely-1)*scale - end - ImGui.EndGroup() -end - -function CPStyle.loadPNG(imagepath) - local imgraw = png(imagepath) - local img = {} - local x = {} - local y = {} - img.width = imgraw.width - img.height = imgraw.height - for i in pairs(imgraw.pixels) do - for t in pairs(imgraw.pixels[i]) do - y[t] = { imgraw.pixels[i][t].R/255, imgraw.pixels[i][t].G/255, imgraw.pixels[i][t].B/255, imgraw.pixels[i][t].A/255 } - end - x[i] = y - y = {} - end - img.pixels = x - return img -end - -function CPStyle.fileExists(filename) - local f=io.open(filename,"r") - if (f~=nil) then io.close(f) return true else return false end -end - -function CPStyle.getCWD(mod_name) - if CPStyle.fileExists("./bin/x64/plugins/cyber_engine_tweaks/mods/"..mod_name.."/init.lua") then - return "./bin/x64/plugins/cyber_engine_tweaks/mods/"..mod_name.."/" - elseif CPStyle.fileExists("./plugins/cyber_engine_tweaks/mods/"..mod_name.."/init.lua") then - return "./plugins/cyber_engine_tweaks/mods/"..mod_name.."/" - elseif CPStyle.fileExists("./"..mod_name.."/init.lua") then - return "./"..mod_name.."/" - end -end - -return CPStyle diff --git a/demo/CPStyling/init.lua b/demo/CPStyling/init.lua new file mode 100644 index 0000000..5eace71 --- /dev/null +++ b/demo/CPStyling/init.lua @@ -0,0 +1,431 @@ +-- MIT License +-- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- +-- Copyright (c) 2021 Mingming Cui +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + +local CPStyle = {} +local currentFilePath = "CPStyling/" +CPStyle.theme = require(currentFilePath.."theme") +local styles = require(currentFilePath.."styles") +local ImGuiStyleNames = styles.ImGuiStyleNames +CPStyle.color = styles.color + +png = require(currentFilePath.."png-lua/png") + +local function ToImGuiStyleName(style, which) + if which == "Col" then + for i in pairs(ImGuiStyleNames.Col) do + if style == ImGuiStyleNames.Col[i].ImGuiStyleShort then + return ImGuiStyleNames.Col[i].ImGuiStyle + end + end + elseif which == "Var" then + for i in pairs(ImGuiStyleNames.Var) do + if style == ImGuiStyleNames.Var[i].ImGuiStyleShort then + return ImGuiStyleNames.Var[i].ImGuiStyle + end + end + end +end + +local function hex2rgb(hex) + local hex = hex:gsub("#","") + if hex:len() == 3 then + return (tonumber("0x"..hex:sub(1,1))*17)/255, (tonumber("0x"..hex:sub(2,2))*17)/255, (tonumber("0x"..hex:sub(3,3))*17)/255 + else + return tonumber("0x"..hex:sub(1,2))/255, tonumber("0x"..hex:sub(3,4))/255, tonumber("0x"..hex:sub(5,6))/255 + end +end + +function CPStyle.colorBegin(style, color) + if type(color) == "number" then + ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color) + elseif type(color) == "string" then + local r, g, b = hex2rgb(color) + ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), r, g, b, 1) + elseif type(color) == "table" then + if type(color[1]) == "string" and type(color[2]) == "number" then + local r, g, b = hex2rgb(color[1]) + ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), r, g, b, color[2]) + elseif type(color[1]) == "number" and type(color[2]) == "number" and type(color[3]) == "number" then + if color[4] == nil then + ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color[1], color[2], color[3], 1) + else + ImGui.PushStyleColor(ToImGuiStyleName(style, "Col"), color[1], color[2], color[3], color[4]) + end + end + end +end + +function CPStyle.colorEnd(count) + if count == nil then + ImGui.PopStyleColor() + else + ImGui.PopStyleColor(count) + end +end +-- +function CPStyle.styleBegin(style, var1, var2) + if var2 == nil then + ImGui.PushStyleVar(ToImGuiStyleName(style, "Var"), var1) + else + ImGui.PushStyleVar(ToImGuiStyleName(style, "Var"), var1, var2) + end +end + +function CPStyle.styleEnd(count) + if count == nil then + ImGui.PopStyleVar() + else + ImGui.PopStyleVar(count) + end +end + +function CPStyle.setThemeBegin() + CPStyle.colorBegin("Text" , CPStyle.theme.Text) + CPStyle.colorBegin("TextDisabled" , CPStyle.theme.TextDisabled) + CPStyle.colorBegin("WindowBg" , CPStyle.theme.WindowBg) + CPStyle.colorBegin("ChildBg" , CPStyle.theme.ChildBg) + CPStyle.colorBegin("PopupBg" , CPStyle.theme.PopupBg) + CPStyle.colorBegin("Border" , CPStyle.theme.Border) + CPStyle.colorBegin("BorderShadow" , CPStyle.theme.BorderShadow) + CPStyle.colorBegin("FrameBg" , CPStyle.theme.FrameBg) + CPStyle.colorBegin("FrameBgHovered" , CPStyle.theme.FrameBgHovered) + CPStyle.colorBegin("FrameBgActive" , CPStyle.theme.FrameBgActive) + CPStyle.colorBegin("TitleBg" , CPStyle.theme.TitleBg) + CPStyle.colorBegin("TitleBgActive" , CPStyle.theme.TitleBgActive) + CPStyle.colorBegin("TitleBgCollapsed" , CPStyle.theme.TitleBgCollapsed) + CPStyle.colorBegin("MenuBarBg" , CPStyle.theme.MenuBarBg) + CPStyle.colorBegin("ScrollbarBg" , CPStyle.theme.ScrollbarBg) + CPStyle.colorBegin("ScrollbarGrab" , CPStyle.theme.ScrollbarGrab) + CPStyle.colorBegin("ScrollbarGrabHovered" , CPStyle.theme.ScrollbarGrabHovered) + CPStyle.colorBegin("ScrollbarGrabActive" , CPStyle.theme.ScrollbarGrabActive) + CPStyle.colorBegin("CheckMark" , CPStyle.theme.CheckMark) + CPStyle.colorBegin("SliderGrab" , CPStyle.theme.SliderGrab) + CPStyle.colorBegin("SliderGrabActive" , CPStyle.theme.SliderGrabActive) + CPStyle.colorBegin("Button" , CPStyle.theme.Button) + CPStyle.colorBegin("ButtonHovered" , CPStyle.theme.ButtonHovered) + CPStyle.colorBegin("ButtonActive" , CPStyle.theme.ButtonActive) + CPStyle.colorBegin("Header" , CPStyle.theme.Header) + CPStyle.colorBegin("HeaderHovered" , CPStyle.theme.HeaderHovered) + CPStyle.colorBegin("HeaderActive" , CPStyle.theme.HeaderActive) + CPStyle.colorBegin("Separator" , CPStyle.theme.Separator) + CPStyle.colorBegin("SeparatorHovered" , CPStyle.theme.SeparatorHovered) + CPStyle.colorBegin("SeparatorActive" , CPStyle.theme.SeparatorActive) + CPStyle.colorBegin("ResizeGrip" , CPStyle.theme.ResizeGrip) + CPStyle.colorBegin("ResizeGripHovered" , CPStyle.theme.ResizeGripHovered) + CPStyle.colorBegin("ResizeGripActive" , CPStyle.theme.ResizeGripActive) + CPStyle.colorBegin("Tab" , CPStyle.theme.Tab) + CPStyle.colorBegin("TabHovered" , CPStyle.theme.TabHovered) + CPStyle.colorBegin("TabActive" , CPStyle.theme.TabActive) + CPStyle.colorBegin("TabUnfocused" , CPStyle.theme.TabUnfocused) + CPStyle.colorBegin("TabUnfocusedActive" , CPStyle.theme.TabUnfocusedActive) + -- CPStyle.colorBegin("PlotLines" , CPStyle.theme.PlotLines) + -- CPStyle.colorBegin("PlotLinesHovered" , CPStyle.theme.PlotLinesHovered) + -- CPStyle.colorBegin("PlotHistogram" , CPStyle.theme.PlotHistogram) + -- CPStyle.colorBegin("PlotHistogramHovered" , CPStyle.theme.PlotHistogramHovered) + CPStyle.colorBegin("TextSelectedBg" , CPStyle.theme.TextSelectedBg) + -- CPStyle.colorBegin("DragDropTarget" , CPStyle.theme.DragDropTarget) + -- CPStyle.colorBegin("NavHighlight" , CPStyle.theme.NavHighlight) + -- CPStyle.colorBegin("NavWindowingHighlight" , CPStyle.theme.NavWindowingHighlight) + -- CPStyle.colorBegin("NavWindowingDimBg" , CPStyle.theme.NavWindowingDimBg) + CPStyle.colorBegin("ModalWindowDimBg" , CPStyle.theme.ModalWindowDimBg) + CPStyle.styleBegin("WindowRounding" , 0) + CPStyle.styleBegin("ScrollbarSize" , 9) +end + +function CPStyle.setThemeEnd() + CPStyle.styleEnd(2) + CPStyle.colorEnd(40) +end + +function CPStyle.setFrameThemeBegin() + CPStyle.colorBegin("FrameBg" , CPStyle.theme.CPFrameBg) + CPStyle.colorBegin("FrameBgHovered" , CPStyle.theme.CPFrameBgHovered) + CPStyle.colorBegin("FrameBgActive" , CPStyle.theme.CPFrameBgActive) + CPStyle.colorBegin("SliderGrab" , CPStyle.theme.CPSliderGrab) + CPStyle.colorBegin("SliderGrabActive" , CPStyle.theme.CPSliderGrabActive) + CPStyle.colorBegin("Border" , CPStyle.theme.CPFrameBorder) + CPStyle.colorBegin("TextSelectedBg" , CPStyle.theme.CPTextSelectedBg) + CPStyle.styleBegin("FrameBorderSize" , 1) +end + +function CPStyle.setFrameThemeEnd() + CPStyle.styleEnd(1) + CPStyle.colorEnd(7) +end + +-- CPButton + +function CPStyle.CPButton(label, sizex, sizey) + local press, hovered + ImGui.BeginGroup() + CPStyle.styleBegin("FrameBorderSize", 1) + CPStyle.colorBegin("Button", CPStyle.theme.CPButton) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPButtonHovered) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPButtonActive) + CPStyle.colorBegin("Text", CPStyle.theme.CPButtonText) + CPStyle.colorBegin("Border", CPStyle.theme.CPButtonBorder) + if sizex == nil or sizey == nil then + press = ImGui.Button(label) + else + press = ImGui.Button(label, sizex, sizey) + end + CPStyle.colorEnd(5) + hovered = ImGui.IsItemHovered() + if hovered then + ImGui.SameLine(0.0001) + CPStyle.colorBegin("Border", CPStyle.theme.CPButtonBorderHovered) + CPStyle.colorBegin("Text", CPStyle.theme.Hidden) + CPStyle.colorBegin("Button", CPStyle.theme.Hidden) + if sizex == nil or sizey == nil then + ImGui.Button(label.."##hovered") + else + ImGui.Button(label.."##hovered", sizex, sizey) + end + CPStyle.colorEnd(3) + end + CPStyle.styleEnd(1) + ImGui.EndGroup() + return press +end + +-- CPToggle + +function CPStyle.CPToggle(label, label_off, label_on, value, sizex, sizey) + local press_off, press_on, hovered + ImGui.BeginGroup() + CPStyle.styleBegin("FrameBorderSize", 1) + ImGui.BeginGroup() + if value then + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffDisabled) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffDisabledText) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOffDisabledHovered) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOffDisabled) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffDisabledBorder) + press_off = ImGui.Button(label_off.."##cp", sizex/2-1,sizey) + ImGui.PopStyleColor(5) + ImGui.SameLine(sizex/2+1) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOn) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnText) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOnHovered) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOn) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnBorder) + press_on = ImGui.Button(label_on.."##cp", sizex/2-1, sizey) + ImGui.PopStyleColor(5) + + else + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOff) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffText) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOffHovered) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOff) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffBorder) + press_off = ImGui.Button(label_off.."##cp", sizex/2-1,sizey) + ImGui.PopStyleColor(5) + ImGui.SameLine(sizex/2+1) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnDisabled) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnDisabledText) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.CPToggleOnDisabledHovered) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.CPToggleOnDisabled) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnDisabledBorder) + press_on = ImGui.Button(label_on.."##cp", sizex/2-1, sizey) + ImGui.PopStyleColor(5) + end + + if press_off and value == false then + value = true + elseif press_off and value == true then + value = false + elseif press_on and value == true then + value = false + elseif press_on and value == false then + value = true + end + if press_off or press_on then press = true else press = false end + ImGui.EndGroup() + hovered = ImGui.IsItemHovered() + + if hovered then --show hovered border color and text color + ImGui.SameLine(0.0001) + ImGui.BeginGroup() + if value then + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffDisabledBorderHovered) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffDisabledHovered) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffDisabledTextHovered) + ImGui.Button(label_off.."##hovered", sizex/2-1,sizey) + ImGui.PopStyleColor(3) + ImGui.SameLine(sizex/2+1) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnBorderHovered) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnHovered) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnTextHovered) + ImGui.Button(label_on.."##hovered", sizex/2-1, sizey) + ImGui.PopStyleColor(3) + + else + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOffBorderHovered) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOffHovered) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOffTextHovered) + ImGui.Button(label_off.."##hovered", sizex/2-1,sizey) + ImGui.PopStyleColor(3) + ImGui.SameLine(sizex/2+1) + CPStyle.colorBegin("Border", CPStyle.theme.CPToggleOnDisabledBorderHovered) + CPStyle.colorBegin("Button", CPStyle.theme.CPToggleOnDisabledHovered) + CPStyle.colorBegin("Text", CPStyle.theme.CPToggleOnDisabledTextHovered) + ImGui.Button(label_on.."##hovered", sizex/2-1, sizey) + ImGui.PopStyleColor(3) + end + ImGui.EndGroup() + end + CPStyle.styleEnd(1) + if label ~= nil and label ~= "" and label:match("^##") == nil then + CPStyle.colorBegin("Button", CPStyle.theme.Hidden) + CPStyle.colorBegin("Text", CPStyle.theme.Text) + CPStyle.colorBegin("ButtonHovered", CPStyle.theme.Hidden) + CPStyle.colorBegin("ButtonActive", CPStyle.theme.Hidden) + CPStyle.styleBegin("FrameBorderSize", 0) + CPStyle.styleBegin("ButtonTextAlign", 0, 0.5) + ImGui.SameLine(sizex) + ImGui.Button(label, 0, sizey) + CPStyle.styleEnd(2) + CPStyle.colorEnd(4) + end + ImGui.EndGroup() + return value, press +end + +function CPStyle.CPToolTip1Begin(sizex, sizey) + CPStyle.styleBegin("WindowRounding", 0) + CPStyle.styleBegin("PopupBorderSize", 0) + CPStyle.styleBegin("ChildBorderSize", 1) + CPStyle.colorBegin("PopupBg", CPStyle.theme.Hidden) + CPStyle.colorBegin("ChildBg", CPStyle.theme.CPFrameBg) + ImGui.BeginTooltip() + CPStyle.CPRect("##SideRect", 8, sizey, CPStyle.theme.CPFrameBg, CPStyle.theme.CPFrameBorder, 1, 0) + ImGui.SameLine(20) + ImGui.BeginGroup() + ImGui.BeginChild("ToolTipMain", sizex, sizey, true) +end + +function CPStyle.CPToolTip1End() + ImGui.EndChild() + ImGui.EndGroup() + ImGui.EndTooltip() + CPStyle.colorEnd(2) + CPStyle.styleEnd(3) +end + +function CPStyle.CPToolTip2Begin(sizex, sizey) + CPStyle.styleBegin("WindowRounding", 0) + CPStyle.styleBegin("PopupBorderSize", 0) + CPStyle.styleBegin("ChildBorderSize", 1) + CPStyle.colorBegin("PopupBg", CPStyle.theme.Hidden) + CPStyle.colorBegin("ChildBg", CPStyle.theme.CPToolTip2Bg) + CPStyle.colorBegin("Border", CPStyle.theme.CPToolTip2Border) + CPStyle.colorBegin("Separator", CPStyle.theme.CPToolTip2Separator) + ImGui.BeginTooltip() + CPStyle.CPRect("##SideRect", 8, sizey, CPStyle.theme.CPToolTip2SideBg, CPStyle.theme.CPToolTip2Border, 1, 0) + ImGui.SameLine(16) + ImGui.BeginGroup() + ImGui.BeginChild("ToolTip2Main", sizex, sizey, true) +end + +function CPStyle.CPToolTip2End() + ImGui.EndChild() + ImGui.EndGroup() + ImGui.EndTooltip() + CPStyle.colorEnd(4) + CPStyle.styleEnd(3) +end + +function CPStyle.CPRect(label, sizex, sizey, color, border_color, border_size, border_rounding, textalignx, textaligny) + if border_color == nil then border_color = CPStyle.theme.Border end + if border_size == nil then border_size = 0 end + if border_rounding == nil then border_rounding = 0 end + if textalignx == nil then textalignx = 0.5 end + if textaligny == nil then textaligny = 0.5 end + CPStyle.colorBegin("Border", border_color) + CPStyle.colorBegin("Button", color) + CPStyle.colorBegin("ButtonActive", color) + CPStyle.colorBegin("ButtonHovered", color) + CPStyle.styleBegin("FrameBorderSize", border_size) + CPStyle.styleBegin("FrameRounding", border_rounding) + CPStyle.styleBegin("ButtonTextAlign", textalignx, textaligny) + local press = ImGui.Button(label, sizex, sizey) + CPStyle.styleEnd(3) + CPStyle.colorEnd(4) + return press +end + +function CPStyle.CPRect2(label, sizex, sizey, color) + CPStyle.colorBegin("ChildBg", color) + ImGui.BeginChild(label, sizex, sizey) + ImGui.EndChild() + CPStyle.colorEnd(1) +end + +function CPStyle.CPDraw(name, image, scale) + ImGui.BeginGroup() + local basex, basey = ImGui.GetCursorPos() + local pixelx = 1 + local pixely = 1 + local cursorx = basex + local cursory = basey + local totalPixel = image.width*image.height + for i = 1, totalPixel do + ImGui.SetCursorPos(cursorx, cursory) + if image.pixels[pixely][pixelx][4] ~= 0 then + CPStyle.CPRect2("##"..name..i, scale*1.2, scale*1.2, image.pixels[pixely][pixelx]) + end + pixelx = pixelx + 1 + if pixelx > image.width then pixelx = 1 pixely = pixely + 1 end + cursorx = basex+(pixelx-1)*scale + cursory = basey+(pixely-1)*scale + end + ImGui.EndGroup() +end + +function CPStyle.loadPNG(imagepath) + local imgraw = png(imagepath) + local img = {} + local x = {} + local y = {} + img.width = imgraw.width + img.height = imgraw.height + for i in pairs(imgraw.pixels) do + for t in pairs(imgraw.pixels[i]) do + y[t] = { imgraw.pixels[i][t].R/255, imgraw.pixels[i][t].G/255, imgraw.pixels[i][t].B/255, imgraw.pixels[i][t].A/255 } + end + x[i] = y + y = {} + end + img.pixels = x + return img +end + +function CPStyle.fileExists(filename) + local f=io.open(filename,"r") + if (f~=nil) then io.close(f) return true else return false end +end + +return CPStyle diff --git a/demo/CPStyling/png-lua/README.md b/demo/CPStyling/png-lua/README.md new file mode 100644 index 0000000..eb7ad4b --- /dev/null +++ b/demo/CPStyling/png-lua/README.md @@ -0,0 +1,63 @@ +Forked from https://github.com/Didericis/png-lua + +PNGLua +====== + +A pure lua implementation of a PNG decoder + +Usage +----- + +To initialize a new png image: + + img = pngImage(, newRowCallback, verbose, memSave) + +The argument "verbose" should be a boolean. If true, it will print messages while decoding. The argument "memSave" should also be a boolean. If true, it will not save pixel data after it has been decoded (you must use the pixel data passed to the newRowCallback to deal with image data).The available data from the image is as follows: + +``` +img.width = 0 +img.height = 0 +img.depth = 0 +img.colorType = 0 +img.pixels = { + 1: { + 1: { R: ..., G: ..., B: ..., A: ...}, + 2: { R: ..., G: ..., B: ..., A: ...}, + ... + }, + 2: { + 1: { R: ..., G: ..., B: ..., A: ...}, + 2: { R: ..., G: ..., B: ..., A: ...}, + ... + } + ... + } + +``` + +The newRowCallback argument should have the following structure: + + newRowCallback(rowNum, rowTotal, rowPixels) + +"rowNum" refers to the current row, "rowTotal" refers to the total number of rows in the image, and "rowPixels" refers to the table of pixels in the current row. + +Support +------- + +The supported colortypes are as follows: + +- Grayscale +- Truecolor +- Indexed +- Greyscale/alpha +- Truecolor/alpha + +So far the module only supports 256 Colors in png-8, png-24 as well as png-32 files. and no ancillary chunks. + +More than 256 colors might be supported (Bit-depths over 8) as long as they align with whole bytes. These have not been tested. + +Multiple IDAT chunks of arbitrary lengths are supported. Filter type 0 is currently the only supported filter type. + +Errors +------- +So far no error-checking has been implemented. No crc32 checks are done. diff --git a/demo/png-lua/deflatelua.lua b/demo/CPStyling/png-lua/deflatelua.lua similarity index 99% rename from demo/png-lua/deflatelua.lua rename to demo/CPStyling/png-lua/deflatelua.lua index 4d8276a..7e8a8bf 100644 --- a/demo/png-lua/deflatelua.lua +++ b/demo/CPStyling/png-lua/deflatelua.lua @@ -338,7 +338,7 @@ local function bitstream_from_bytestream(bys) return bits end end - + is_bitstream[o] = true return o @@ -441,7 +441,7 @@ local function HuffmanTable(init, is_full) end return res end - + local tfirstcode = memoize( function(bits) return pow2[minbits] + msb(bits, minbits) end) @@ -545,7 +545,7 @@ local function parse_zlib_header(bs) local flevel = bs:read(2) -- FLaGs: FLEVEL (compression level) local cmf = cinfo * 16 + cm -- CMF (Compresion Method and flags) local flg = fcheck + fdict * 32 + flevel * 64 -- FLaGs - + if cm ~= 8 then -- not "deflate" runtime_error("unrecognized zlib compression method: " .. cm) end @@ -553,16 +553,16 @@ local function parse_zlib_header(bs) runtime_error("invalid zlib window size: cinfo=" .. cinfo) end local window_size = 2^(cinfo + 8) - + if (cmf*256 + flg) % 31 ~= 0 then runtime_error("invalid zlib header (bad fcheck sum)") end - + if fdict == 1 then runtime_error("FIX:TODO - FDICT not currently implemented") local dictid_ = bs:read(32) end - + return window_size end @@ -819,11 +819,11 @@ function M.inflate_zlib(t) local outbs = get_obytestream(t.output) local disable_crc = t.disable_crc if disable_crc == nil then disable_crc = false end - + local window_size_ = parse_zlib_header(bs) - + local data_adler32 = 1 - + inflate{input=bs, output= disable_crc and outbs or function(byte) @@ -833,7 +833,7 @@ function M.inflate_zlib(t) } bs:read(bs:nbits_left_in_byte()) - + local b3 = bs:read(8) local b2 = bs:read(8) local b1 = bs:read(8) @@ -853,4 +853,4 @@ function M.inflate_zlib(t) end -return M \ No newline at end of file +return M diff --git a/demo/png-lua/png.lua b/demo/CPStyling/png-lua/png.lua similarity index 98% rename from demo/png-lua/png.lua rename to demo/CPStyling/png-lua/png.lua index 608a8e9..bae2008 100644 --- a/demo/png-lua/png.lua +++ b/demo/CPStyling/png-lua/png.lua @@ -19,8 +19,8 @@ -- IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN -- CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -local rootPath = "./plugins/cyber_engine_tweaks/mods/demo/png-lua/" -local deflate = require(rootPath.."deflatelua") +local currentFilePath = "CPStyling/png-lua/" +local deflate = require(currentFilePath.."deflatelua") local requiredDeflateVersion = "0.3.20111128" if (deflate._VERSION ~= requiredDeflateVersion) then diff --git a/demo/CPStyling/styles.lua b/demo/CPStyling/styles.lua new file mode 100644 index 0000000..e5b2ce3 --- /dev/null +++ b/demo/CPStyling/styles.lua @@ -0,0 +1,128 @@ +-- MIT License +-- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- +-- Copyright (c) 2021 Mingming Cui +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + +return { + color = { + red = { 1.00, 0.00, 0.00, 1.00 }, + cyan = { 0.00, 1.00, 1.00, 1.00 }, + blue = { 0.00, 0.00, 1.00, 1.00 }, + darkblue = { 0.00, 0.00, 0.63, 1.00 }, + lightblue = { 0.68, 0.85, 0.90, 1.00 }, + purple = { 0.50, 0.00, 0.50, 1.00 }, + yellow = { 1.00, 1.00, 0.00, 1.00 }, + lime = { 0.00, 1.00, 0.00, 1.00 }, + magenta = { 1.00, 0.00, 1.00, 1.00 }, + white = { 1.00, 1.00, 1.00, 1.00 }, + silver = { 0.75, 0.75, 0.75, 1.00 }, + grey = { 0.50, 0.50, 0.50, 1.00 }, + black = { 0.00, 0.00, 0.00, 1.00 }, + orange = { 1.00, 0.65, 0.00, 1.00 }, + brown = { 0.65, 0.16, 0.16, 1.00 }, + maroon = { 0.50, 0.00, 0.00, 1.00 }, + green = { 0.00, 0.50, 0.00, 1.00 }, + olive = { 0.50, 0.50, 0.00, 1.00 } + }, + + ImGuiStyleNames = { + Col = { + { ImGuiStyle = ImGuiCol.Text , ImGuiStyleShort = "Text" }, + { ImGuiStyle = ImGuiCol.TextDisabled , ImGuiStyleShort = "TextDisabled" }, + { ImGuiStyle = ImGuiCol.WindowBg , ImGuiStyleShort = "WindowBg" }, + { ImGuiStyle = ImGuiCol.ChildBg , ImGuiStyleShort = "ChildBg" }, + { ImGuiStyle = ImGuiCol.PopupBg , ImGuiStyleShort = "PopupBg" }, + { ImGuiStyle = ImGuiCol.Border , ImGuiStyleShort = "Border" }, + { ImGuiStyle = ImGuiCol.BorderShadow , ImGuiStyleShort = "BorderShadow" }, + { ImGuiStyle = ImGuiCol.FrameBg , ImGuiStyleShort = "FrameBg" }, + { ImGuiStyle = ImGuiCol.FrameBgHovered , ImGuiStyleShort = "FrameBgHovered" }, + { ImGuiStyle = ImGuiCol.FrameBgActive , ImGuiStyleShort = "FrameBgActive" }, + { ImGuiStyle = ImGuiCol.TitleBg , ImGuiStyleShort = "TitleBg" }, + { ImGuiStyle = ImGuiCol.TitleBgActive , ImGuiStyleShort = "TitleBgActive" }, + { ImGuiStyle = ImGuiCol.TitleBgCollapsed , ImGuiStyleShort = "TitleBgCollapsed" }, + { ImGuiStyle = ImGuiCol.MenuBarBg , ImGuiStyleShort = "MenuBarBg" }, + { ImGuiStyle = ImGuiCol.ScrollbarBg , ImGuiStyleShort = "ScrollbarBg" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrab , ImGuiStyleShort = "ScrollbarGrab" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrabHovered , ImGuiStyleShort = "ScrollbarGrabHovered" }, + { ImGuiStyle = ImGuiCol.ScrollbarGrabActive , ImGuiStyleShort = "ScrollbarGrabActive" }, + { ImGuiStyle = ImGuiCol.CheckMark , ImGuiStyleShort = "CheckMark" }, + { ImGuiStyle = ImGuiCol.SliderGrab , ImGuiStyleShort = "SliderGrab" }, + { ImGuiStyle = ImGuiCol.SliderGrabActive , ImGuiStyleShort = "SliderGrabActive" }, + { ImGuiStyle = ImGuiCol.Button , ImGuiStyleShort = "Button" }, + { ImGuiStyle = ImGuiCol.ButtonHovered , ImGuiStyleShort = "ButtonHovered" }, + { ImGuiStyle = ImGuiCol.ButtonActive , ImGuiStyleShort = "ButtonActive" }, + { ImGuiStyle = ImGuiCol.Header , ImGuiStyleShort = "Header" }, + { ImGuiStyle = ImGuiCol.HeaderHovered , ImGuiStyleShort = "HeaderHovered" }, + { ImGuiStyle = ImGuiCol.HeaderActive , ImGuiStyleShort = "HeaderActive" }, + { ImGuiStyle = ImGuiCol.Separator , ImGuiStyleShort = "Separator" }, + { ImGuiStyle = ImGuiCol.SeparatorHovered , ImGuiStyleShort = "SeparatorHovered" }, + { ImGuiStyle = ImGuiCol.SeparatorActive , ImGuiStyleShort = "SeparatorActive" }, + { ImGuiStyle = ImGuiCol.ResizeGrip , ImGuiStyleShort = "ResizeGrip" }, + { ImGuiStyle = ImGuiCol.ResizeGripHovered , ImGuiStyleShort = "ResizeGripHovered" }, + { ImGuiStyle = ImGuiCol.ResizeGripActive , ImGuiStyleShort = "ResizeGripActive" }, + { ImGuiStyle = ImGuiCol.Tab , ImGuiStyleShort = "Tab" }, + { ImGuiStyle = ImGuiCol.TabHovered , ImGuiStyleShort = "TabHovered" }, + { ImGuiStyle = ImGuiCol.TabActive , ImGuiStyleShort = "TabActive" }, + { ImGuiStyle = ImGuiCol.TabUnfocused , ImGuiStyleShort = "TabUnfocused" }, + { ImGuiStyle = ImGuiCol.TabUnfocusedActive , ImGuiStyleShort = "TabUnfocusedActive" }, + { ImGuiStyle = ImGuiCol.PlotLines , ImGuiStyleShort = "PlotLines" }, + { ImGuiStyle = ImGuiCol.PlotLinesHovered , ImGuiStyleShort = "PlotLinesHovered" }, + { ImGuiStyle = ImGuiCol.PlotHistogram , ImGuiStyleShort = "PlotHistogram" }, + { ImGuiStyle = ImGuiCol.PlotHistogramHovered , ImGuiStyleShort = "PlotHistogramHovered" }, + { ImGuiStyle = ImGuiCol.TextSelectedBg , ImGuiStyleShort = "TextSelectedBg" }, + { ImGuiStyle = ImGuiCol.DragDropTarget , ImGuiStyleShort = "DragDropTarget" }, + { ImGuiStyle = ImGuiCol.NavHighlight , ImGuiStyleShort = "NavHighlight" }, + { ImGuiStyle = ImGuiCol.NavWindowingHighlight , ImGuiStyleShort = "NavWindowingHighlight" }, + { ImGuiStyle = ImGuiCol.NavWindowingDimBg , ImGuiStyleShort = "NavWindowingDimBg" }, + { ImGuiStyle = ImGuiCol.ModalWindowDimBg , ImGuiStyleShort = "ModalWindowDimBg" }, + { ImGuiStyle = ImGuiCol.COUNT , ImGuiStyleShort = "COUNT" } + }, + Var = { + { ImGuiStyle = ImGuiStyleVar.Alpha , ImGuiStyleShort = "Alpha" }, + { ImGuiStyle = ImGuiStyleVar.WindowPadding , ImGuiStyleShort = "WindowPadding" }, + { ImGuiStyle = ImGuiStyleVar.WindowRounding , ImGuiStyleShort = "WindowRounding" }, + { ImGuiStyle = ImGuiStyleVar.WindowBorderSize , ImGuiStyleShort = "WindowBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.WindowMinSize , ImGuiStyleShort = "WindowMinSize" }, + { ImGuiStyle = ImGuiStyleVar.WindowTitleAlign , ImGuiStyleShort = "WindowTitleAlign" }, + { ImGuiStyle = ImGuiStyleVar.ChildRounding , ImGuiStyleShort = "ChildRounding" }, + { ImGuiStyle = ImGuiStyleVar.ChildBorderSize , ImGuiStyleShort = "ChildBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.PopupRounding , ImGuiStyleShort = "PopupRounding" }, + { ImGuiStyle = ImGuiStyleVar.PopupBorderSize , ImGuiStyleShort = "PopupBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.FramePadding , ImGuiStyleShort = "FramePadding" }, + { ImGuiStyle = ImGuiStyleVar.FrameRounding , ImGuiStyleShort = "FrameRounding" }, + { ImGuiStyle = ImGuiStyleVar.FrameBorderSize , ImGuiStyleShort = "FrameBorderSize" }, + { ImGuiStyle = ImGuiStyleVar.ItemSpacing , ImGuiStyleShort = "ItemSpacing" }, + { ImGuiStyle = ImGuiStyleVar.ItemInnerSpacing , ImGuiStyleShort = "ItemInnerSpacing" }, + { ImGuiStyle = ImGuiStyleVar.IndentSpacing , ImGuiStyleShort = "IndentSpacing" }, + { ImGuiStyle = ImGuiStyleVar.ScrollbarSize , ImGuiStyleShort = "ScrollbarSize" }, + { ImGuiStyle = ImGuiStyleVar.ScrollbarRounding , ImGuiStyleShort = "ScrollbarRounding" }, + { ImGuiStyle = ImGuiStyleVar.GrabMinSize , ImGuiStyleShort = "GrabMinSize" }, + { ImGuiStyle = ImGuiStyleVar.GrabRounding , ImGuiStyleShort = "GrabRounding" }, + { ImGuiStyle = ImGuiStyleVar.TabRounding , ImGuiStyleShort = "TabRounding" }, + { ImGuiStyle = ImGuiStyleVar.SelectableTextAlign , ImGuiStyleShort = "SelectableTextAlign" }, + { ImGuiStyle = ImGuiStyleVar.ButtonTextAlign , ImGuiStyleShort = "ButtonTextAlign" }, + { ImGuiStyle = ImGuiStyleVar.COUNT , ImGuiStyleShort = "COUNT" } + } + } +} diff --git a/demo/CPStyling/theme.lua b/demo/CPStyling/theme.lua new file mode 100644 index 0000000..0d2635c --- /dev/null +++ b/demo/CPStyling/theme.lua @@ -0,0 +1,123 @@ +-- MIT License +-- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- +-- Copyright (c) 2021 Mingming Cui +-- +-- Permission is hereby granted, free of charge, to any person obtaining a copy +-- of this software and associated documentation files (the "Software"), to deal +-- in the Software without restriction, including without limitation the rights +-- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +-- copies of the Software, and to permit persons to whom the Software is +-- furnished to do so, subject to the following conditions: +-- +-- The above copyright notice and this permission notice shall be included in all +-- copies or substantial portions of the Software. +-- +-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +-- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +-- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +-- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +-- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +-- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +-- SOFTWARE. + +return { + Text = { 1.00, 0.38, 0.33, 1.00 }, + TextDisabled = { 0.48, 0.39, 0.40, 1.00 }, + WindowBg = { 0.06, 0.04, 0.06, 0.90 }, + ChildBg = { 0.00, 0.00, 0.00, 0.00 }, + PopupBg = { 0.06, 0.04, 0.06, 0.90 }, + Border = { 0.30, 0.07, 0.08, 1.00 }, + BorderShadow = { 0.00, 0.00, 0.00, 0.00 }, + FrameBg = { 0.50, 0.13, 0.16, 0.50 }, + FrameBgHovered = { 0.32, 0.11, 0.12, 0.50 }, + FrameBgActive = { 0.50, 0.13, 0.16, 0.50 }, + -- FrameBgDisabled = { 0.48, 0.39, 0.40, 1.00 }, + -- FrameBgHoveredDisabled = { 0.48, 0.39, 0.40, 1.00 }, + -- FrameBgActiveDisabled = { 0.48, 0.39, 0.40, 1.00 }, + TitleBg = { 0.06, 0.04, 0.06, 0.90 }, + TitleBgActive = { 0.06, 0.04, 0.06, 0.90 }, + TitleBgCollapsed = { 0.06, 0.04, 0.06, 0.90 }, + MenuBarBg = { 0.00, 0.00, 0.00, 0.00 }, + ScrollbarBg = { 0.23, 0.07, 0.09, 1.00 }, + ScrollbarGrab = { 0.95, 0.30, 0.28, 1.00 }, + ScrollbarGrabHovered = { 0.95, 0.30, 0.28, 1.00 }, + ScrollbarGrabActive = { 0.95, 0.30, 0.28, 1.00 }, + CheckMark = { 1.00, 0.44, 0.40, 1.00 }, + -- CheckMarkTrueDisabled = { 0.34, 0.22, 0.24, 1.00 }, + -- CheckMarkFalseDisabled = { 0.48, 0.39, 0.40, 1.00 }, + SliderGrab = { 0.64, 0.22, 0.21, 1.00 }, + SliderGrabActive = { 0.64, 0.22, 0.21, 1.00 }, + Button = { 0.57, 0.17, 0.16, 1.00 }, + ButtonHovered = { 0.45, 0.13, 0.14, 1.00 }, + ButtonActive = { 0.57, 0.17, 0.16, 1.00 }, + Header = { 0.08, 0.08, 0.15, 1.00 }, + HeaderHovered = { 0.22, 0.64, 0.69, 0.30 }, + HeaderActive = { 0.22, 0.64, 0.69, 0.50 }, + Separator = { 0.26, 0.09, 0.09, 1.00 }, + SeparatorHovered = { 0.26, 0.09, 0.09, 1.00 }, + SeparatorActive = { 0.26, 0.09, 0.09, 1.00 }, + ResizeGrip = { 0.00, 0.00, 0.00, 0.00 }, + ResizeGripHovered = { 0.45, 0.13, 0.14, 1.00 }, + ResizeGripActive = { 0.57, 0.17, 0.16, 1.00 }, + Tab = { 0.57, 0.17, 0.16, 1.00 }, + TabHovered = { 0.45, 0.13, 0.14, 1.00 }, + TabActive = { 0.57, 0.17, 0.16, 1.00 }, + TabUnfocused = { 0.45, 0.14, 0.13, 1.00 }, + TabUnfocusedActive = { 0.58, 0.18, 0.16, 1.00 }, + -- PlotLines = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotLinesHovered = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotHistogram = { 0.00, 0.00, 0.00, 0.00 }, + -- PlotHistogramHovered = { 0.00, 0.00, 0.00, 0.00 }, + TextSelectedBg = { 0.06, 0.06, 0.12, 1.00 }, + -- DragDropTarget = { 0.00, 0.00, 0.00, 0.00 }, + -- NavHighlight = { 0.00, 0.00, 0.00, 0.00 }, + -- NavWindowingHighlight = { 0.00, 0.00, 0.00, 0.00 }, + -- NavWindowingDimBg = { 0.00, 0.00, 0.00, 0.00 }, + ModalWindowDimBg = { 0.00, 0.00, 0.00, 0.40 }, + CPButton = { 0.06, 0.06, 0.12, 1.00 }, + CPButtonHovered = { 0.43, 0.13, 0.13, 1.00 }, + CPButtonActive = { 0.57, 0.16, 0.16, 1.00 }, + CPButtonText = { 0.34, 0.95, 0.98, 1.00 }, + CPButtonBorder = { 0.40, 0.08, 0.09, 1.00 }, + CPButtonBorderHovered = { 0.34, 0.95, 0.98, 1.00 }, + CPToggleOn = { 0.37, 0.96, 1.00, 1.00 }, + CPToggleOnHovered = { 0.29, 0.77, 0.80, 1.00 }, + CPToggleOnText = { 0.00, 0.00, 0.00, 1.00 }, + CPToggleOnTextHovered = { 0.00, 0.00, 0.00, 1.00 }, + CPToggleOnBorder = { 0.29, 0.61, 0.58, 1.00 }, + CPToggleOnBorderHovered = { 0.26, 0.66, 0.65, 1.00 }, + CPToggleOnDisabled = { 0.03, 0.12, 0.12, 1.00 }, + CPToggleOnDisabledHovered = { 0.05, 0.16, 0.16, 1.00 }, + CPToggleOnDisabledText = { 0.08, 0.23, 0.25, 1.00 }, + CPToggleOnDisabledTextHovered = { 0.09, 0.29, 0.30, 1.00 }, + CPToggleOnDisabledBorder = { 0.06, 0.15, 0.15, 1.00 }, + CPToggleOnDisabledBorderHovered = { 0.09, 0.24, 0.25, 1.00 }, + CPToggleOff = { 0.58, 0.18, 0.16, 1.00 }, + CPToggleOffHovered = { 0.45, 0.14, 0.13, 1.00 }, + CPToggleOffText = { 1.00, 0.44, 0.41, 1.00 }, + CPToggleOffTextHovered = { 1.00, 0.36, 0.33, 1.00 }, + CPToggleOffBorder = { 0.92, 0.29, 0.26, 1.00 }, + CPToggleOffBorderHovered = { 0.76, 0.23, 0.21, 1.00 }, + CPToggleOffDisabled = { 0.09, 0.04, 0.07, 1.00 }, + CPToggleOffDisabledHovered = { 0.16, 0.06, 0.07, 1.00 }, + CPToggleOffDisabledText = { 0.32, 0.09, 0.10, 1.00 }, + CPToggleOffDisabledTextHovered = { 0.36, 0.11, 0.11, 1.00 }, + CPToggleOffDisabledBorder = { 0.19, 0.08, 0.09, 1.00 }, + CPToggleOffDisabledBorderHovered = { 0.30, 0.09, 0.10, 1.00 }, + CPFrameBg = { 0.06, 0.06, 0.12, 1.00 }, + CPFrameBgHovered = { 0.31, 0.11, 0.11, 1.00 }, + CPFrameBgActive = { 0.57, 0.19, 0.19, 1.00 }, + CPSliderGrab = { 0.64, 0.21, 0.21, 1.00 }, + CPSliderGrabActive = { 0.64, 0.21, 0.21, 1.00 }, + CPFrameBorder = { 0.40, 0.08, 0.09, 1.00 }, + CPTextSelectedBg = { 0.45, 0.14, 0.13, 1.00 }, + CPToolTip2Bg = { 0.11, 0.22, 0.25, 0.60 }, + CPToolTip2Border = { 0.18, 0.42, 0.46, 1.00 }, + CPToolTip2Separator = { 0.24, 0.55, 0.58, 1.00 }, + CPToolTip2SideBg = { 0.12, 0.24, 0.27, 1.00 }, + Hidden = { 0.00, 0.00, 0.00, 0.00 } +} diff --git a/demo/cyberpunk.png b/demo/img/cyberpunk.png similarity index 100% rename from demo/cyberpunk.png rename to demo/img/cyberpunk.png diff --git a/demo/foxgirl.png b/demo/img/foxgirl.png similarity index 100% rename from demo/foxgirl.png rename to demo/img/foxgirl.png diff --git a/demo/ghost_in_shell.png b/demo/img/ghost_in_shell.png similarity index 100% rename from demo/ghost_in_shell.png rename to demo/img/ghost_in_shell.png diff --git a/demo/lucario.png b/demo/img/lucario.png similarity index 100% rename from demo/lucario.png rename to demo/img/lucario.png diff --git a/demo/mushroom.png b/demo/img/mushroom.png similarity index 100% rename from demo/mushroom.png rename to demo/img/mushroom.png diff --git a/demo/init.lua b/demo/init.lua index 5d37c69..7a79e78 100644 --- a/demo/init.lua +++ b/demo/init.lua @@ -1,5 +1,9 @@ -- MIT License -- +-- CPStyling.lua https://github.com/Nats-ji/CPStyling.lua +-- +-- This file is a part of CPStyling.lua +-- -- Copyright (c) 2021 Mingming Cui -- -- Permission is hereby granted, free of charge, to any person obtaining a copy @@ -21,17 +25,14 @@ -- SOFTWARE. registerForEvent("onInit", function() - rootPath = "./plugins/cyber_engine_tweaks/mods/demo/" - package.loaded[rootPath.."CPStyling"] = nil - CPS = require (rootPath.."CPStyling") + CPS = require ("CPStyling") print("CPStyling.lua loaded") - theme = CPS.theme + theme = CPS.theme color = CPS.color - print("Theme Loaded") - rootPathIO = CPS.getCWD("demo") - draw = true + print("Theme Loaded") + draw = true drawPNGViewer = false - wWidth, wHeight = GetDisplayResolution() + wWidth, wHeight = GetDisplayResolution() checkboxdef = { {name = "My Checkbox1", value = false}, {name = "My Checkbox2", value = true}, @@ -54,17 +55,22 @@ registerForEvent("onInit", function() cpcb_pressed = {} print("Loading Images") images = { - { name = "Mushroom", scale = 5, data = CPS.loadPNG(rootPathIO.."foxgirl.png")}, - { name = "Fox Girl", scale = 5, data = CPS.loadPNG(rootPathIO.."mushroom.png")}, - { name = "Lucario", scale = 5, data = CPS.loadPNG(rootPathIO.."lucario.png")}, - { name = "Ghost in the shell", scale = 2, data = CPS.loadPNG(rootPathIO.."ghost_in_shell.png")}, - { name = "Cyberpunk 2077", scale = 1, data = CPS.loadPNG(rootPathIO.."cyberpunk.png")} + { name = "Mushroom", scale = 5, data = CPS.loadPNG("img/foxgirl.png")}, + { name = "Fox Girl", scale = 5, data = CPS.loadPNG("img/mushroom.png")}, + { name = "Lucario", scale = 5, data = CPS.loadPNG("img/lucario.png")}, + { name = "Ghost in the shell", scale = 2, data = CPS.loadPNG("img/ghost_in_shell.png")}, + { name = "Cyberpunk 2077", scale = 1, data = CPS.loadPNG("img/cyberpunk.png")} } + print("Images Loaded") image = images[1] DrawSel = 0 print("Initiated") end) +registerHotkey("overlay", "Open Demo", function() + draw = not draw +end) + registerForEvent("onUpdate", function() for i in pairs(checkbox) do if checkbox[i].pressed then @@ -86,7 +92,7 @@ end) registerForEvent("onDraw", function() if draw then CPS.setThemeBegin() - ImGui.Begin("CPStyling.lua Demo", true, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoResize) + draw = ImGui.Begin("CPStyling.lua Demo", true, ImGuiWindowFlags.MenuBar | ImGuiWindowFlags.NoResize) ImGui.SetWindowFontScale(1.0) ImGui.SetWindowPos(wWidth/2-250, wHeight/2-400, ImGuiCond.FirstUseEver) ImGui.SetWindowSize(505, 800) @@ -230,6 +236,20 @@ registerForEvent("onDraw", function() image.scale , sldDraw = ImGui.SliderInt("PNG Scale", image.scale, 1, 25, "%dx") ImGui.PopItemWidth() end + +-- Modal + if ImGui.Button("Pop Button", 120, 0) then + ImGui.OpenPopup("Delete?") + end + + if ImGui.BeginPopupModal("Delete?", true, ImGuiWindowFlags.AlwaysAutoResize | ImGuiWindowFlags.NoMove) then + local x, y = ImGui.GetWindowSize() + ImGui.SetWindowPos((wWidth-x)*0.5, (wHeight-y)*0.5) + ImGui.Text("This is a popup") + if ImGui.Button("Close") then ImGui.CloseCurrentPopup() end + ImGui.EndPopup() + end + ImGui.EndTabItem() end if ImGui.BeginTabItem("Default style") then @@ -237,8 +257,8 @@ registerForEvent("onDraw", function() ImGui.InputText("Textbox", "Lorem ipsum dolor", 100, ImGuiInputTextFlags.AutoSelectAll) ImGui.InputTextWithHint("Textbox with hint", "Password...", "", 10, ImGuiInputTextFlags.Password) ImGui.InputFloat("Textbox float", 1.00000, 1, 10, "%.5f", ImGuiInputTextFlags.None) - ImGui.SliderFloat("Slider float", 1.00000, -10, 10, "%.5fx", 0.5) - ImGui.DragFloat("Drag float##2", 1.2354, 0.01, -10, 10, "%.5f", 0.5) + ImGui.SliderFloat("Slider float", 1.00000, -10, 10, "%.5fx") + ImGui.DragFloat("Drag float##2", 1.2354, 0.01, -10, 10, "%.5f") ImGui.Combo("Combo box", 2, { "Option 1 ", "Option 2", "Option 3", "Option 4", "Option 5" }, 5, 3) if ImGui.ListBoxHeader("ListBox", 5) then ImGui.SetWindowFontScale(1.0) @@ -262,8 +282,8 @@ registerForEvent("onDraw", function() ImGui.InputText("Textbox##2", "Lorem ipsum dolor", 100, ImGuiInputTextFlags.AutoSelectAll) ImGui.InputTextWithHint("Textbox with hint##2", "Password...", "", 10, ImGuiInputTextFlags.Password) ImGui.InputFloat("Textbox float##2", 1.00000, 1, 10, "%.5f", ImGuiInputTextFlags.None) - ImGui.SliderFloat("Slider float##2", 1.00000, -10, 10, "%.5fx", 0.5) - ImGui.DragFloat("Drag float##2", 1.2354, 0.01, -10, 10, "%.5f", 0.5) + ImGui.SliderFloat("Slider float##2", 1.00000, -10, 10, "%.5fx") + ImGui.DragFloat("Drag float##2", 1.2354, 0.01, -10, 10, "%.5f") ImGui.Combo("Combo box##2", 2, { "Option 1 ", "Option 2", "Option 3", "Option 4", "Option 5" }, 5, 3) if ImGui.ListBoxHeader("ListBox##2", 5) then ImGui.SetWindowFontScale(1.0) From 9641b28fb18851b9f1e4b3c52ea389fa0e6b3698 Mon Sep 17 00:00:00 2001 From: Nats-ji Date: Tue, 2 Feb 2021 01:45:41 +0800 Subject: [PATCH 3/5] Update readme --- CPStyling/README.md | 278 ++++++++++++++++++++++++++++++++++++++++++++ README.md | 4 + 2 files changed, 282 insertions(+) create mode 100644 CPStyling/README.md diff --git a/CPStyling/README.md b/CPStyling/README.md new file mode 100644 index 0000000..3df32a2 --- /dev/null +++ b/CPStyling/README.md @@ -0,0 +1,278 @@ +# CPStyling.lua + +This project can be found at https://github.com/Nats-ji/CPStyling.lua + +### What is this +Made for Cyber Engine Tweaks Mod creation. +This is a set of color schemes and widgets I made to match the style of Cyberpunk 2077's UI. +I also included some useful functions for easier and faster ImGui styling. + + +Please make PR if you want to fix bugs or make improvements +### How to use +```lua +CPS = require "CPStyling" +theme = CPS.theme +color = CPS.color +``` + +To use `CPS.loadPNG()` and `CPS.CPDraw()` functions, you need to include the `png-lua` library. + + #This project is still WIP, will add more widgets. You can also download the demo to play with it yourself. + +![Imgur](https://i.imgur.com/fe3cd4w.png) + +### Projects using this library +CP77-TetrisArcade [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/1118) | [[Github]](https://github.com/justarandomguyintheinternet/cp77_arcade_tetris) + +![Imgur](https://i.imgur.com/zrhar0j.png) + +CP77-Braindance Protocol [[Nexus]](https://www.nexusmods.com/cyberpunk2077/mods/616) | [[Github]](https://github.com/WolvenKit/BraindanceProtocol) + +![Imgur](https://i.imgur.com/bVqLG7c.png) + +### Utilities +```lua +--Check if a file exists +CPS.fileExists(filename) +--returns bool + +--Setup the style for a new window and it's content. +CPS.setThemeBegin() +-- ImGui.Begin("I'm a window") +-- ImGui.End() +CPS.setThemeEnd() + +--Setup the style for frame items (Checkbox, Combobox, Inputbox, etc.), +--Needs to be put bellow ImGui.Begin() or window's title will also be bordered. +CPS.setFrameThemeBegin() +CPS.setFrameThemeEnd() + +--Same as ImGui.PushStyleColor(ImGuiCol.style, r, g, b, a), but can take any color format. +CPS.colorBegin(style, color) +-- style (string): style = "Text" +-- color can be u32 (number): color = 0x00000000 +-- color can be rgb (table): color = { 0.40 , 0.17 , 0.12 } +-- color can be rgba (table): color = { 0.40 , 0.17 , 0.12 , 0.5 } +-- color can be hex (string): color = "#672b1f" color = "672b1f" +-- color can be hex with alpha (table): color = { "672b1f", 0.5 } +CPS.colorEnd(count) --Same as ImGui.PopStyleColor(count) + +---Example--- +CPS.colorBegin("Button", { 1, 0, 0, 1 }) +CPS.colorBegin("Button", "672b1f") +CPS.colorBegin("Button", theme.Button) -- get color from theme.lua +CPS.colorBegin("Button", color.blue) -- get color from styles.lua +ImGui.Button("I'm a Button") +CPS.colorEnd(1) + +--Same as ImGui.PushStyleVar() +CPS.styleBegin(style, var1) +CPS.styleBegin(style, var1, var2) +-- Same as ImGui.PushStyleVar(ImGuiStyleVar.style, var1, var2) +-- style (string): style = "ChildRounding" +-- var1 (float), var2 (float) +CPS.styleEnd(count) -- Same as ImGui.PopStyleVar(count) + +---Example--- +CPS.styleBegin("FrameBorderSize", 5) +ImGui.Button("I'm a bordered button", 200, 30) +CPS.styleEnd(1) +``` +### Cyberpunk Style Widgets + +CPButton: + +![Imgur](https://i.imgur.com/4neA19J.gif) +```lua +press = CPS.CPButton(label) +press = CPS.CPButton(label, sizex, sizey) +-- label (string), sizex (float), sizey (float) +-- Returns press (bool) + +---Example--- +btn1 = CPS.CPButton("Btn1") +btn2 = CPS.CPButton("Btn2", 50, 30) +``` +CPToggle: + +![Imgur](https://i.imgur.com/gTwpaLY.gif) +```lua +value, press = CPS.CPToggle(label, label_on, label_off, value, sizex, sizey) +-- label (string), label_on (string), label_off (string), value (bool), sizex (float), sizey (float) +-- Returns value (bool), press (bool) + +---Example--- +value, press = CPS.CPToggle("Toggle godmode", "OFF", "ON", value, 180, 0) +``` +CPToolTip: + +![Imgur](https://i.imgur.com/i467ORZ.gif) +```lua +CPS.CPToolTip1Begin(sizex, sizey) +-- ImGui.Text("This is a CPToolTip1") +CPS.CPToolTip1End() + +CPS.CPToolTip2Begin(sizex, sizey) +-- ImGui.Text("This is a CPToolTip2") +CPS.CPToolTip2End() +``` +CPRect: + +![Imgur](https://i.imgur.com/M5FHWtb.png) +```lua +press = CPS.CPRect1(label, sizex, sizey, color, border_color [O], border_size [O], border_rounding [O], textalignx [O], textaligny [O]) +-- lable (string), sizex (float), sizey (float), color (any format), border_color (any format) +-- border_size (float), border_rounding (float), textalignx (float), textaligny (float) +-- Returns press (bool) + +CPS.CPRect2(text_id, sizex, sizey, color) +-- text_id (string), sizex (float), sizey(float), color (any format) +-- Faster than CPRect1 but without return value. +-- Also used in CPS.CPDraw() + +---Example--- +-- Draw a red 50x50 Circle +CPS.CPRect1("##circle", 50, 50, {0,0,0,0}, color.red, 5, 25) +-- Draw a green rounded rectangle with a brown border and text inside aligned to the right. +CPS.CPRect1("I'm the text", 150, 50, color.green, color.brown, 3, 10, 1, 0.5) +``` +loadPNG and CPDraw: + +![img](https://github.com/Nats-ji/CPStyling.lua/raw/master/.image/cpdraw.gif) + +```lua +-- Load a png image from file +image = CPS.loadPNG(path_to_png) +-- Return image = { wdith = int, height = int, pixels = { + [1]:{ + [1]:{ R, G, B, A }, + [2]:{ R, G, B, A }, + ...... + }, + [2]:{ + ...... + }, + ..... + } +-- Draw the png image +CPS.CPDraw(text_id, image, scale) +-- text_id (string), image (table), scale (number) + +---Example--- +image = CPS.loadPNG("./images/logo.png") +CPS.CPDraw("logo", image, 5) +``` + +### Color Names +```lua +"red" +"cyan" +"blue" +"darkblue" +"lightblue" +"purple" +"yellow" +"lime" +"magenta" +"white" +"silver" +"grey" +"black" +"orange" +"brown" +"maroon" +"green" +"olive" +``` + + +### ImGui style names +Color +```lua +"Text" +"TextDisabled" +"WindowBg" +"ChildBg" +"PopupBg" +"Border" +"BorderShadow" +"FrameBg" +"FrameBgHovered" +"FrameBgActive" +"FrameBgDisabled" +"FrameBgHoveredDisabled" +"FrameBgActiveDisabled" +"TitleBg" +"TitleBgActive" +"TitleBgCollapsed" +"MenuBarBg" +"ScrollbarBg" +"ScrollbarGrab" +"ScrollbarGrabHovered" +"ScrollbarGrabActive" +"CheckMark" +"CheckMarkTrueDisabled" +"CheckMarkFalseDisabled" +"SliderGrab" +"SliderGrabActive" +"Button" +"ButtonHovered" +"ButtonActive" +"Header" +"HeaderHovered" +"HeaderActive" +"Separator" +"SeparatorHovered" +"SeparatorActive" +"ResizeGrip" +"ResizeGripHovered" +"ResizeGripActive" +"Tab" +"TabHovered" +"TabActive" +"TabUnfocused" +"TabUnfocusedActive" +"DockingPreview" +"DockingEmptyBg" +"PlotLines" +"PlotLinesHovered" +"PlotHistogram" +"PlotHistogramHovered" +"TextSelectedBg" +"DragDropTarget" +"NavHighlight" +"NavWindowingHighlight" +"NavWindowingDimBg" +"ModalWindowDimBg" +"ModalWindowDarkening" +"COUNT" +``` + +StyleVar +```lua +"Alpha" +"WindowPadding" +"WindowRounding" +"WindowBorderSize" +"WindowMinSize" +"WindowTitleAlign" +"ChildRounding" +"ChildBorderSize" +"PopupRounding" +"PopupBorderSize" +"FramePadding" +"FrameRounding" +"FrameBorderSize" +"ItemSpacing" +"ItemInnerSpacing" +"IndentSpacing" +"ScrollbarSize" +"ScrollbarRounding" +"GrabMinSize" +"GrabRounding" +"TabRounding" +"SelectableTextAlign" +"ButtonTextAlign" +"COUNT" +``` diff --git a/README.md b/README.md index d422bf1..3df32a2 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,7 @@ +# CPStyling.lua + +This project can be found at https://github.com/Nats-ji/CPStyling.lua + ### What is this Made for Cyber Engine Tweaks Mod creation. This is a set of color schemes and widgets I made to match the style of Cyberpunk 2077's UI. From 732a4a4e9ae718e8d383585e767a861f3764062f Mon Sep 17 00:00:00 2001 From: Nats-ji Date: Tue, 2 Feb 2021 01:46:21 +0800 Subject: [PATCH 4/5] Update --- CPStyling/LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 CPStyling/LICENSE diff --git a/CPStyling/LICENSE b/CPStyling/LICENSE new file mode 100644 index 0000000..97be4f1 --- /dev/null +++ b/CPStyling/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Mingming Cui + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 7b0e62b9e19b895f7c752a543ac66f768b15b621 Mon Sep 17 00:00:00 2001 From: Nats-ji Date: Thu, 4 Feb 2021 09:04:34 +0800 Subject: [PATCH 5/5] Add CPDraw2 using ImDrawlist --- CPStyling/init.lua | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/CPStyling/init.lua b/CPStyling/init.lua index 5eace71..f4486c9 100644 --- a/CPStyling/init.lua +++ b/CPStyling/init.lua @@ -405,6 +405,25 @@ function CPStyle.CPDraw(name, image, scale) ImGui.EndGroup() end +function CPStyle.CPDraw2(drawlist, posX, posY, image, scale) + ImGui.BeginGroup() + local pixelx = 1 + local pixely = 1 + local cursorx = posX + local cursory = posY + local totalPixel = image.width*image.height + for i = 1, totalPixel do + if image.pixels[pixely][pixelx][4] ~= 0 then + ImGui.ImDrawListAddRectFilled(drawlist, cursorx, cursory, cursorx+scale, cursory+scale, ImGui.GetColorU32(table.unpack(image.pixels[pixely][pixelx]))) + end + pixelx = pixelx + 1 + if pixelx > image.width then pixelx = 1 pixely = pixely + 1 end + cursorx = posX+(pixelx-1)*scale + cursory = posY+(pixely-1)*scale + end + ImGui.EndGroup() +end + function CPStyle.loadPNG(imagepath) local imgraw = png(imagepath) local img = {}