├── .gitignore ├── .gitmodules ├── BMPUtils.h ├── BaseMenu.cpp ├── BaseMenu.h ├── Btns.cpp ├── BtnsBMPTable.h ├── CFGScript.cpp ├── CFGScript.h ├── CMakeLists.txt ├── Color.h ├── Coord.h ├── EngineCallback.cpp ├── EventSystem.cpp ├── EventSystem.h ├── Image.h ├── MenuStrings.cpp ├── MenuStrings.h ├── Primitive.h ├── README.md ├── Scissor.cpp ├── Scissor.h ├── Utils.cpp ├── Utils.h ├── WindowSystem.cpp ├── WindowSystem.h ├── controls ├── Action.cpp ├── Action.h ├── AnimatedBanner.cpp ├── AnimatedBanner.h ├── BackgroundBitmap.cpp ├── BackgroundBitmap.h ├── BaseClientWindow.cpp ├── BaseClientWindow.h ├── BaseItem.cpp ├── BaseItem.h ├── BaseWindow.cpp ├── BaseWindow.h ├── Bitmap.cpp ├── Bitmap.h ├── CheckBox.cpp ├── CheckBox.h ├── DropDown.cpp ├── DropDown.h ├── Editable.cpp ├── Editable.h ├── Field.cpp ├── Field.h ├── Framework.cpp ├── Framework.h ├── ItemsHolder.cpp ├── ItemsHolder.h ├── MessageBox.cpp ├── MessageBox.h ├── MovieBanner.cpp ├── MovieBanner.h ├── PicButton.cpp ├── PicButton.h ├── PlayerModelView.cpp ├── PlayerModelView.h ├── ProgressBar.cpp ├── ProgressBar.h ├── ScrollView.cpp ├── ScrollView.h ├── Slider.cpp ├── Slider.h ├── SpinControl.cpp ├── SpinControl.h ├── Switch.cpp ├── Switch.h ├── TabView.cpp ├── TabView.h ├── Table.cpp ├── Table.h ├── YesNoMessageBox.cpp └── YesNoMessageBox.h ├── dictgen.py ├── enginecallback_menu.h ├── exports.txt ├── extdll_menu.h ├── font ├── BaseFontBackend.cpp ├── BaseFontBackend.h ├── BitmapFont.cpp ├── BitmapFont.h ├── FontManager.cpp ├── FontManager.h ├── FontRenderer.h ├── FreeTypeFont.cpp ├── FreeTypeFont.h ├── StbFont.cpp ├── StbFont.h ├── WinAPIFont.cpp ├── WinAPIFont.h └── stb_truetype.h ├── menufont.h ├── menus ├── AdvancedControls.cpp ├── Audio.cpp ├── Configuration.cpp ├── ConnectionProgress.cpp ├── ConnectionWarning.cpp ├── Controls.cpp ├── CreateGame.cpp ├── Credits.cpp ├── CustomGame.cpp ├── FileDialog.cpp ├── GameOptions.cpp ├── Gamepad.cpp ├── InputDevices.cpp ├── LoadGame.cpp ├── Main.cpp ├── Multiplayer.cpp ├── NewGame.cpp ├── PlayerIntroduceDialog.cpp ├── PlayerIntroduceDialog.h ├── PlayerSetup.cpp ├── SaveLoad.cpp ├── ServerBrowser.cpp ├── ServerInfo.cpp ├── Touch.cpp ├── TouchButtons.cpp ├── TouchEdit.cpp ├── TouchOptions.cpp ├── Video.cpp ├── VideoModes.cpp ├── VideoOptions.cpp ├── Zoo.cpp └── dynamic │ └── ScriptMenu.cpp ├── model ├── BaseArrayModel.h ├── BaseModel.h ├── StringArrayModel.h └── StringVectorModel.h ├── sdk_includes ├── README.md ├── common │ ├── bspfile.h │ ├── cl_entity.h │ ├── com_model.h │ ├── con_nprint.h │ ├── const.h │ ├── cvardef.h │ ├── entity_state.h │ ├── entity_types.h │ ├── event_args.h │ ├── gameinfo.h │ ├── kbutton.h │ ├── mathlib.h │ ├── net_api.h │ ├── netadr.h │ ├── ref_params.h │ ├── weaponinfo.h │ ├── wrect.h │ └── xash3d_types.h ├── copy.sh ├── engine │ ├── cursor_type.h │ ├── custom.h │ ├── keydefs.h │ ├── menu_int.h │ └── mobility_int.h ├── pm_shared │ └── pm_info.h └── public │ ├── build.h │ └── buildenums.h ├── test_dictgen.py ├── tests ├── test_english.txt └── testfile ├── translations ├── .gitkeep ├── mainui_skeleton_everything.txt ├── mainui_skeleton_nostringslst.txt └── mainui_skeleton_stripped.txt ├── udll_int.cpp ├── utflib.cpp ├── utflib.h ├── vs2022 ├── IMPORTANT_NOTE_FOR_MOD_DEVELOPER.txt ├── mainui_cpp.sln ├── mainui_cpp.vcxproj └── mainui_cpp.vcxproj.filters └── wscript /.gitignore: -------------------------------------------------------------------------------- 1 | *.user 2 | *.so 3 | *.obj 4 | *.o 5 | *.exp 6 | *.lib 7 | *.dll 8 | Makefile 9 | build/ 10 | 11 | ### CMake ### 12 | CMakeCache.txt 13 | CMakeFiles 14 | Makefile 15 | cmake_install.cmake 16 | install_manifest.txt 17 | # makedepend 18 | Makefile.dep 19 | *.bak 20 | ALL_BUILD.* 21 | INSTALL.* 22 | ZERO_CHECK.* 23 | 24 | # Visual Studio 25 | *.obj 26 | *.dll 27 | *.exp 28 | *.lib 29 | *.suo 30 | *.sdf 31 | Debug/ 32 | Release/ 33 | ipch/ 34 | *.opensdf 35 | *.pdb 36 | 37 | __pycache__ 38 | temp.txt 39 | nonfree_translations 40 | .vs 41 | x64/ 42 | x86/ 43 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "miniutl"] 2 | path = miniutl 3 | url = https://github.com/FWGS/miniutl 4 | -------------------------------------------------------------------------------- /Btns.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | 22 | #include "extdll_menu.h" 23 | #include "BaseMenu.h" 24 | #include "Utils.h" 25 | #include "BtnsBMPTable.h" 26 | #include 27 | 28 | #define ART_BUTTONS_MAIN "gfx/shell/btns_main.bmp" // we support bmp only 29 | 30 | static int UI_GetBlockHeight( int button_height, int points[3], int &empty_height ) 31 | { 32 | empty_height = 1; // don't add pixels in-between 33 | int height = ( button_height + empty_height ) * 2 + button_height; 34 | 35 | points[0] = 0; 36 | points[1] = button_height + empty_height; 37 | points[2] = ( button_height + empty_height ) * 2; // 102: 38 | 39 | return height; 40 | } 41 | 42 | /* 43 | ================= 44 | UI_LoadBmpButtons 45 | ================= 46 | */ 47 | void UI_LoadBmpButtons() 48 | { 49 | memset( uiStatic.buttonsPics, 0, sizeof( uiStatic.buttonsPics )); 50 | 51 | if( uiStatic.lowmemory ) 52 | return; 53 | 54 | CBMP *bmp = CBMP::LoadFile( ART_BUTTONS_MAIN ); 55 | 56 | if( bmp == nullptr ) 57 | return; 58 | 59 | // get default block size 60 | uiStatic.buttons_width = bmp->GetBitmapHdr()->width; // pass to the other parts of ui 61 | uiStatic.buttons_height = 26; // hardcoded! 62 | 63 | // calculate original bmp size 64 | const int stride = (( bmp->GetBitmapHdr()->width * bmp->GetBitmapHdr()->bitsPerPixel / 8 ) + 3 ) & ~3; 65 | const size_t btn_sz = stride * uiStatic.buttons_height; // one button size 66 | 67 | // get our cutted bmp sizes 68 | int empty_height; 69 | const int blockHeight = UI_GetBlockHeight( uiStatic.buttons_height, uiStatic.buttons_points, empty_height ); 70 | const int empty_sz = empty_height * stride; 71 | 72 | // init CBMP and copy data 73 | CBMP cutted_bmp( bmp->GetBitmapHdr(), stride * blockHeight ); 74 | cutted_bmp.GetBitmapHdr()->height = blockHeight; 75 | 76 | byte *src = bmp->GetTextureData(); 77 | byte *dst = cutted_bmp.GetTextureData(); 78 | 79 | int pic_count = bmp->GetBitmapHdr()->height / uiStatic.buttons_height / 3; 80 | int src_pos = bmp->GetBitmapHdr()->height * stride; 81 | 82 | for( int i = 0; i < pic_count; i++ ) 83 | { 84 | int dst_pos = blockHeight * stride; 85 | char fname[256]; 86 | 87 | V_snprintf( fname, sizeof( fname ), "#btns_%d.bmp", i ); 88 | 89 | for( int btn = 0; btn < 3; btn++ ) 90 | { 91 | src_pos -= btn_sz; 92 | dst_pos -= btn_sz; 93 | memcpy( &dst[dst_pos], &src[src_pos], btn_sz ); 94 | 95 | // fixup alpha for half-life infected mod 96 | if( bmp->GetBitmapHdr()->bitsPerPixel == 32 ) 97 | { 98 | for( int j = dst_pos; j < dst_pos + btn_sz; j += 4 ) 99 | dst[j+3] = 255; 100 | } 101 | 102 | // fix misaligned gearbox btns 103 | memset( &dst[dst_pos], 0, stride ); 104 | 105 | // fill the empty space 106 | if( btn < 2 && empty_sz != 0 ) 107 | { 108 | dst_pos -= empty_sz; 109 | memset( &dst[dst_pos], 0, empty_sz ); 110 | } 111 | } 112 | 113 | // upload image into video memory 114 | uiStatic.buttonsPics[i] = EngFuncs::PIC_Load( fname, cutted_bmp.GetBitmap(), cutted_bmp.GetBitmapHdr()->fileSize ); 115 | } 116 | 117 | delete bmp; 118 | } 119 | -------------------------------------------------------------------------------- /BtnsBMPTable.h: -------------------------------------------------------------------------------- 1 | /* 2 | menu_btnsbmp_table.h - btns_main layout 3 | Copyright (C) 2011 CrazyRussian 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef MENU_BTNSBMP_TABLE_H 17 | #define MENU_BTNSBMP_TABLE_H 18 | 19 | enum EDefaultBtns 20 | { 21 | PC_NEW_GAME = 0, 22 | PC_RESUME_GAME, 23 | PC_HAZARD_COURSE, 24 | PC_CONFIG, 25 | PC_LOAD_GAME, 26 | PC_SAVE_LOAD_GAME, 27 | PC_VIEW_README, 28 | PC_QUIT, 29 | PC_MULTIPLAYER, 30 | PC_EASY, 31 | PC_MEDIUM, 32 | PC_DIFFICULT, 33 | PC_SAVE_GAME, 34 | PC_LOAD_GAME2, 35 | PC_CANCEL, 36 | PC_GAME_OPTIONS, 37 | PC_VIDEO, 38 | PC_AUDIO, 39 | PC_CONTROLS, 40 | PC_DONE, 41 | PC_QUICKSTART, 42 | PC_USE_DEFAULTS, 43 | PC_OK, 44 | PC_VID_OPT, 45 | PC_VID_MODES, 46 | PC_ADV_CONTROLS, 47 | PC_ORDER_HL, 48 | PC_DELETE, 49 | PC_INET_GAME, 50 | PC_CHAT_ROOMS, 51 | PC_LAN_GAME, 52 | PC_CUSTOMIZE, 53 | PC_SKIP, 54 | PC_EXIT, 55 | PC_CONNECT, 56 | PC_REFRESH, 57 | PC_FILTER, 58 | PC_FILTER2, 59 | PC_CREATE, 60 | PC_CREATE_GAME, 61 | PC_CHAT_ROOMS2, 62 | PC_LIST_ROOMS, 63 | PC_SEARCH, 64 | PC_SERVERS, 65 | PC_JOIN, 66 | PC_FIND, 67 | PC_CREATE_ROOM, 68 | PC_JOIN_GAME, 69 | PC_SEARCH_GAMES, 70 | PC_FIND_GAME, 71 | PC_START_GAME, 72 | PC_VIEW_GAME_INFO, 73 | PC_UPDATE, 74 | PC_ADD_SERVER, 75 | PC_DISCONNECT, 76 | PC_CONSOLE, 77 | PC_CONTENT_CONTROL, 78 | PC_UPDATE2, 79 | PC_VISIT_WON, 80 | PC_PREVIEWS, 81 | PC_ADV_OPT, 82 | PC_3DINFO_SITE, 83 | PC_CUSTOM_GAME, 84 | PC_ACTIVATE, 85 | PC_INSTALL, 86 | PC_VISIT_WEB_SITE, 87 | PC_REFRESH_LIST, 88 | PC_DEACTIVATE, 89 | PC_ADV_OPT2, 90 | PC_SPECTATE_GAME, 91 | PC_SPECTATE_GAMES, 92 | PC_BUTTONCOUNT // must be last 93 | }; 94 | 95 | // Non-standard button images start here 96 | #define PC_GAMEPAD "gfx/shell/btn_gamepad" 97 | #define PC_TOUCH "gfx/shell/btn_touch" 98 | #define PC_TOUCH_OPTIONS "gfx/shell/btn_touch_options" 99 | #define PC_TOUCH_BUTTONS "gfx/shell/btn_touch_buttons" 100 | #define PC_FAVORITE "gfx/shell/btn_favorite" 101 | #define PC_UNFAVORITE "gfx/shell/btn_unfavorite" 102 | 103 | #define BUTTON_NOFOCUS 0 104 | #define BUTTON_FOCUS 1 105 | #define BUTTON_PRESSED 2 106 | 107 | #endif//MENU_BTNSBMP_TABLE_H 108 | -------------------------------------------------------------------------------- /CFGScript.h: -------------------------------------------------------------------------------- 1 | /* 2 | cfgscript.c - "Valve script" parsing routines 3 | Copyright (C) 2016 mittorn 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #ifndef CFGSCRIPT_H 17 | #define CFGSCRIPT_H 18 | 19 | #define MAX_STRING 256 20 | 21 | #include "StringArrayModel.h" 22 | 23 | typedef enum 24 | { 25 | T_NONE = 0, 26 | T_BOOL, 27 | T_NUMBER, 28 | T_LIST, 29 | T_STRING, 30 | T_COUNT 31 | } cvartype_t; 32 | 33 | struct scrvarlistentry_t 34 | { 35 | scrvarlistentry_t() : szName( NULL ), flValue( 0 ), next( NULL ) {} 36 | 37 | char *szName; 38 | float flValue; 39 | 40 | scrvarlistentry_t *next; 41 | }; 42 | 43 | struct scrvarlist_t 44 | { 45 | scrvarlist_t() : iCount( 0 ), pEntries( NULL ), pLast( NULL ), pArray( NULL ), pModel( NULL ) {} 46 | 47 | int iCount; 48 | scrvarlistentry_t *pEntries; 49 | scrvarlistentry_t *pLast; 50 | const char **pArray; 51 | CStringArrayModel *pModel; // ready model for use in UI 52 | }; 53 | 54 | struct scrvarnumber_t 55 | { 56 | scrvarnumber_t() : fMin( 0 ), fMax( 0 ) {} 57 | 58 | float fMin; 59 | float fMax; 60 | }; 61 | 62 | struct scrvardef_t 63 | { 64 | scrvardef_t() : flags( 0 ), number(), list(), type( T_NONE ), next( NULL ) 65 | { 66 | name[0] = value[0] = desc[0] = 0; 67 | } 68 | 69 | int flags; 70 | char name[MAX_STRING]; 71 | char value[MAX_STRING]; 72 | char desc[MAX_STRING]; 73 | scrvarnumber_t number; 74 | scrvarlist_t list; 75 | cvartype_t type; 76 | struct scrvardef_t *next; 77 | }; 78 | 79 | scrvardef_t *CSCR_LoadDefaultCVars( const char *scriptfilename, int *count ); 80 | void CSCR_FreeList( scrvardef_t *list ); 81 | 82 | #endif // CFGSCRIPT_H 83 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2015 Pavlo Lavrenenko 3 | # 4 | # Permission is hereby granted, free of charge, to any person obtaining a copy 5 | # of this software and associated documentation files (the "Software"), to deal 6 | # in the Software without restriction, including without limitation the rights 7 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | # copies of the Software, and to permit persons to whom the Software is 9 | # furnished to do so, subject to the following conditions: 10 | # 11 | # The above copyright notice and this permission notice shall be included in all 12 | # copies or substantial portions of the Software. 13 | # 14 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | # SOFTWARE. 21 | # 22 | 23 | cmake_minimum_required(VERSION 2.8.12) 24 | project(MAINUI) 25 | 26 | # By default we require C++11 support. 27 | # But it can be overriden with -DMY_COMPILER_SUCKS compiler option 28 | # It's not recommended and may not work(as it's done only for MSVC6 support) 29 | set(CMAKE_CXX_STANDARD 11) 30 | 31 | set(MAINUI_LIBRARY menu) 32 | 33 | option(MAINUI_USE_CUSTOM_FONT_RENDER "Use custom font rendering" ON) 34 | option(MAINUI_USE_STB "Use stb_truetype.h for rendering(*nix-only)" OFF) 35 | option(MAINUI_FONT_SCALE "Scale fonts by height" OFF) 36 | 37 | if(NOT XASH_SDK) 38 | set(XASH_SDK "sdk_includes/") 39 | endif() 40 | 41 | file(GLOB MAINUI_CONTROLS_SOURCES "controls/*.cpp") 42 | file(GLOB MAINUI_MENUS_SOURCES "menus/*.cpp" "menus/dynamic/*.cpp") 43 | file(GLOB MAINUI_FONT_RENDER_SOURCES "font/*.cpp") 44 | file(GLOB MAINUI_SOURCES "miniutl/*.cpp" "*.cpp") 45 | 46 | if(CS16CLIENT) 47 | add_definitions(-DCS16CLIENT) 48 | list(APPEND MAINUI_SOURCES 49 | ${XASH_SDK}/common/interface.cpp 50 | menus/Scoreboard.cpp 51 | menus/client/JoinGame.cpp 52 | menus/client/JoinClass.cpp 53 | menus/client/ClientWindow.cpp 54 | ) 55 | endif() 56 | 57 | list(APPEND MAINUI_SOURCES ${MAINUI_CONTROLS_SOURCES}) 58 | list(APPEND MAINUI_SOURCES ${MAINUI_MENUS_SOURCES}) 59 | list(APPEND MAINUI_SOURCES ${MAINUI_FONT_RENDER_SOURCES}) 60 | add_library(${MAINUI_LIBRARY} MODULE ${MAINUI_SOURCES}) 61 | 62 | if(NOT WIN32 AND NOT MINGW) 63 | add_compile_options(-Wall -Wextra -Wno-unused-parameter -Wno-unused-variable) 64 | else() 65 | # Only for MSVC6 compatibility mode! Newer VC does fail with this define 66 | # add_definitions(-DMY_COMPILER_SUCKS) 67 | endif() 68 | 69 | if(XASH_SAILFISH) 70 | add_definitions(-D__SAILFISH__) 71 | endif() 72 | 73 | if(MAINUI_FONT_SCALE) 74 | add_definitions(-DMAINUI_FONT_SCALE) 75 | endif() 76 | 77 | add_definitions(-DSTDINT_H=) 78 | 79 | # Force stb_truetype for Apple devices, as there is no Apple native font renderer 80 | # And freetype&fontconfig isn't used on this platform by default 81 | if(ANDROID) 82 | set(MAINUI_USE_STB TRUE) 83 | endif() 84 | 85 | include_directories(${XASH_SDK}/common ${XASH_SDK}/engine ${XASH_SDK}/pm_shared ${XASH_SDK}/public . controls/ menus/ miniutl/ font/ model/) 86 | 87 | if(MSVC) 88 | add_definitions(-D_CRT_SECURE_NO_WARNINGS) 89 | endif() 90 | 91 | # Font Rendering(FreeType or WinAPI) 92 | if(MAINUI_USE_CUSTOM_FONT_RENDER) 93 | # Win32 will always use GDI font renderer 94 | if(NOT WIN32) 95 | if(MAINUI_USE_STB) 96 | # Use stbtt 97 | add_definitions(-DMAINUI_USE_STB) 98 | else() 99 | # Use freetype2 100 | find_package(PkgConfig) 101 | pkg_check_modules(FT2 REQUIRED freetype2) 102 | include_directories(${FT2_INCLUDE_DIRS}) 103 | target_link_libraries(${MAINUI_LIBRARY} ${FT2_LIBRARIES}) 104 | add_definitions(-DMAINUI_USE_FREETYPE) 105 | endif() 106 | endif() 107 | 108 | add_definitions(-DMAINUI_USE_CUSTOM_FONT_RENDER) 109 | endif() 110 | 111 | install(TARGETS ${MAINUI_LIBRARY} DESTINATION .) 112 | 113 | if(MSVC) 114 | install(FILES $ DESTINATION . OPTIONAL) 115 | endif() 116 | -------------------------------------------------------------------------------- /Color.h: -------------------------------------------------------------------------------- 1 | /* 2 | Color.cpp -- color class 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #pragma once 17 | #ifndef COLOR_H 18 | #define COLOR_H 19 | 20 | class CColor 21 | { 22 | public: 23 | CColor( ) : rgba( 0 ), init( false ), 24 | a(3,rgba), r(2,rgba), g(1,rgba), b(0,rgba) { } 25 | CColor( unsigned int rgba_ ) : rgba( rgba_ ), init( false ), 26 | a(3,rgba), r(2,rgba), g(1,rgba), b(0,rgba) { } 27 | 28 | inline unsigned int operator =( unsigned int color ) 29 | { 30 | Set( color ); 31 | return color; 32 | } 33 | 34 | inline CColor& operator =( CColor& c ) 35 | { 36 | Set( c.rgba ); 37 | return c; 38 | } 39 | 40 | inline operator unsigned int() { return rgba; } 41 | 42 | inline void Set( unsigned int color ) 43 | { 44 | rgba = color; 45 | init = true; 46 | } 47 | 48 | inline void SetDefault( unsigned int color ) 49 | { 50 | if( !IsOk() ) Set( color ); 51 | } 52 | 53 | // get rid of this someday 54 | inline bool IsOk() { return init; } 55 | 56 | unsigned int rgba; 57 | private: 58 | class ColorWrap 59 | { 60 | private: 61 | const byte _byte; 62 | unsigned int & _rgba; 63 | 64 | ColorWrap(int bytenum, unsigned int &rgba): _byte(bytenum), _rgba(rgba) {} 65 | public: 66 | inline unsigned int operator =(unsigned int value) const 67 | { 68 | value &= 0xff; 69 | _rgba = (_rgba & ~(0xff << (_byte*8)) ) | ( value << (_byte*8) ); 70 | return value; 71 | } 72 | inline operator unsigned int() const 73 | { 74 | return (_rgba >> _byte * 8) & 0xff; 75 | } 76 | friend class CColor; 77 | }; 78 | bool init; 79 | public: 80 | const ColorWrap r,g,b,a; 81 | }; 82 | 83 | #endif // COLOR_H 84 | -------------------------------------------------------------------------------- /Coord.h: -------------------------------------------------------------------------------- 1 | /* 2 | Coord.h -- simple coordinate and size management 3 | Copyright (C) 2017 a1batross 4 | 5 | 6 | This program is free software; you can redistribute it and/or 7 | modify it under the terms of the GNU General Public License 8 | as published by the Free Software Foundation; either version 2 9 | of the License, or (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 14 | 15 | See the GNU General Public License for more details. 16 | 17 | You should have received a copy of the GNU General Public License 18 | along with this program; if not, write to the Free Software 19 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 20 | */ 21 | #pragma once 22 | #ifndef COORD_H 23 | #define COORD_H 24 | 25 | struct Point 26 | { 27 | Point() { x = y = 0; } 28 | Point( int x, int y ) : x(x), y(y) {} 29 | 30 | int x, y; 31 | Point Scale(); 32 | friend Point operator +( Point &a, Point &b ) { return Point( a.x + b.x, a.y + b.y ); } 33 | friend Point operator -( Point &a, Point &b ) { return Point( a.x - b.x, a.y - b.y ); } 34 | 35 | Point& operator+=( Point &a ) 36 | { 37 | x += a.x; 38 | y += a.y; 39 | return *this; 40 | } 41 | 42 | Point& operator-=( Point &a ) 43 | { 44 | x -= a.x; 45 | y -= a.y; 46 | return *this; 47 | } 48 | 49 | Point operator *( float scale ) { return Point( x * scale, y * scale ); } 50 | Point operator /( float scale ) { return Point( x / scale, y / scale ); } 51 | }; 52 | 53 | struct Size 54 | { 55 | Size() { w = h = 0; } 56 | Size( int w, int h ) : w(w), h(h) {} 57 | 58 | int w, h; 59 | Size Scale(); 60 | }; 61 | 62 | #endif // COORD_H 63 | -------------------------------------------------------------------------------- /EngineCallback.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | enginecallback.cpp - actual engine callbacks 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #include "extdll_menu.h" 17 | #include "BaseMenu.h" 18 | #include "Utils.h" 19 | 20 | void EngFuncs::PIC_Set( HIMAGE hPic, int r, int g, int b, int a) 21 | { 22 | if( uiStatic.enableAlphaFactor ) 23 | a *= uiStatic.alphaFactor; 24 | 25 | engfuncs.pfnPIC_Set( hPic, r, g, b, a ); 26 | } 27 | 28 | void EngFuncs::FillRGBA(int x, int y, int width, int height, int r, int g, int b, int a) 29 | { 30 | if( uiStatic.enableAlphaFactor ) 31 | a *= uiStatic.alphaFactor; 32 | 33 | engfuncs.pfnFillRGBA( x, y, width, height, r, g, b, a ); 34 | } 35 | 36 | void EngFuncs::DrawLogo( const char *filename, float x, float y, float width, float height ) 37 | { 38 | if( uiStatic.enableAlphaFactor ) 39 | return; 40 | 41 | engfuncs.pfnDrawLogo( filename, x, y, width, height ); 42 | } 43 | 44 | 45 | void EngFuncs::DrawCharacter(int x, int y, int width, int height, int ch, int ulRGBA, HIMAGE hFont) 46 | { 47 | engfuncs.pfnDrawCharacter( x, y, width, height, ch, ulRGBA, hFont ); 48 | } 49 | 50 | static unsigned int color; 51 | 52 | void EngFuncs::DrawSetTextColor(int r, int g, int b, int alpha) 53 | { 54 | color = PackRGBA( r, g, b, alpha ); 55 | } 56 | 57 | int EngFuncs::DrawConsoleString(int x, int y, const char *string) 58 | { 59 | Point pt( x, y ); 60 | Size sz; 61 | int charSz; 62 | 63 | sz.w = ScreenWidth - pt.x; 64 | sz.h = ScreenHeight - pt.y; 65 | 66 | charSz = g_FontMgr->GetFontTall( uiStatic.hConsoleFont ); 67 | 68 | return UI_DrawString( uiStatic.hConsoleFont, pt, sz, string, color, charSz, QM_TOPLEFT ); 69 | } 70 | 71 | void EngFuncs::ConsoleStringLen(const char *string, int *length, int *height) 72 | { 73 | g_FontMgr->GetTextSize( uiStatic.hConsoleFont, string, length, height ); 74 | } 75 | 76 | int EngFuncs::ConsoleCharacterHeight() 77 | { 78 | return g_FontMgr->GetFontTall( uiStatic.hConsoleFont ); 79 | } 80 | 81 | // We have full unicode support now 82 | int EngFuncs::UtfProcessChar(int ch) 83 | { 84 | return Con_UtfProcessChar( ch ); 85 | } 86 | 87 | int EngFuncs::UtfMoveLeft(const char *str, int pos) 88 | { 89 | return Con_UtfMoveLeft( str, pos ); 90 | } 91 | 92 | int EngFuncs::UtfMoveRight(const char *str, int pos, int length) 93 | { 94 | return Con_UtfMoveRight( str, pos, length ); 95 | } 96 | -------------------------------------------------------------------------------- /EventSystem.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | EventSystem.h -- event system implementation 3 | Copyright(C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "BaseMenu.h" 16 | #include "BaseItem.h" 17 | #include "EventSystem.h" 18 | 19 | CEventCallback::CEventCallback() : 20 | pExtra( 0 ), type( CB_OLD_EXTRA ), szName( 0 ) 21 | { 22 | memset(&u, 0, sizeof(u)); 23 | } 24 | 25 | CEventCallback::CEventCallback( EventCallback cb, void *ex ) : 26 | pExtra( ex ), type( CB_OLD_EXTRA ), szName( 0 ) 27 | { 28 | memset(&u, 0, sizeof(u)); 29 | u.cb = cb; 30 | } 31 | 32 | CEventCallback::CEventCallback(int execute_now, const char *sz) : 33 | szName( 0 ) 34 | { 35 | memset(&u, 0, sizeof(u)); 36 | SetCommand( execute_now, sz ); 37 | } 38 | 39 | CEventCallback::CEventCallback(VoidCallback cb) : 40 | pExtra( 0 ), type( CB_OLD_VOID ), szName( 0 ) 41 | { 42 | memset(&u, 0, sizeof(u)); 43 | u.voidCb = cb; 44 | } 45 | 46 | CEventCallback::CEventCallback( IHCallback cb, void *ex ) : 47 | pExtra( ex ), type( CB_IH_EXTRA ), szName( 0 ) 48 | { 49 | memset(&u, 0, sizeof(u)); 50 | u.itemsHolderCb = cb; 51 | } 52 | 53 | CEventCallback::CEventCallback( VoidIHCallback cb ) : 54 | pExtra( 0 ), type( CB_IH_VOID ), szName( 0 ) 55 | { 56 | memset(&u, 0, sizeof(u)); 57 | u.voidItemsHolderCb = cb; 58 | } 59 | 60 | void CEventCallback::operator()(CMenuBaseItem *pSelf) 61 | { 62 | switch( type ) 63 | { 64 | case CB_OLD_EXTRA: u.cb( pSelf, pExtra ); break; 65 | case CB_OLD_VOID: u.voidCb(); break; 66 | case CB_IH_EXTRA: (pSelf->Parent()->*u.itemsHolderCb)( pExtra ); break; 67 | case CB_IH_VOID: (pSelf->Parent()->*u.voidItemsHolderCb)(); break; 68 | } 69 | } 70 | 71 | EventCallback CEventCallback::operator =( EventCallback cb ) 72 | { 73 | type = CB_OLD_EXTRA; 74 | return u.cb = cb; 75 | } 76 | 77 | VoidCallback CEventCallback::operator =( VoidCallback cb ) 78 | { 79 | type = CB_OLD_VOID; 80 | return u.voidCb = cb; 81 | } 82 | 83 | IHCallback CEventCallback::operator =( IHCallback cb ) 84 | { 85 | type = CB_IH_EXTRA; 86 | return u.itemsHolderCb = cb; 87 | } 88 | 89 | VoidIHCallback CEventCallback::operator =( VoidIHCallback cb ) 90 | { 91 | type = CB_IH_VOID; 92 | return u.voidItemsHolderCb = cb; 93 | } 94 | 95 | void CEventCallback::Reset() 96 | { 97 | type = CB_OLD_EXTRA; 98 | u.cb = 0; 99 | } 100 | 101 | void CEventCallback::SetCommand( int execute_now, const char *sz ) 102 | { 103 | execute_now ? operator =(CmdExecuteNowCb) : operator =(CmdExecuteNextFrameCb); 104 | pExtra = (void*)sz; 105 | } 106 | 107 | size_t CEventCallback::operator =( size_t null ) 108 | { 109 | Reset(); 110 | return 0; 111 | } 112 | void* CEventCallback::operator =( void *null ) 113 | { 114 | Reset(); 115 | return NULL; 116 | } 117 | -------------------------------------------------------------------------------- /Image.h: -------------------------------------------------------------------------------- 1 | /* 2 | Image.h -- image class 3 | Copyright (C) 2019 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef IMAGE_H 16 | #define IMAGE_H 17 | 18 | #include "enginecallback_menu.h" 19 | 20 | class CImage 21 | { 22 | public: 23 | CImage() : m_szPath( NULL ), m_hPic( 0 ) { } 24 | CImage( HIMAGE hPic ) : m_szPath( NULL ), m_hPic( hPic ) { } 25 | CImage( const char *szPath, int flags = 0 ) 26 | { 27 | Load( szPath, flags ); 28 | } 29 | CImage( const char *szPath, const byte *rgbdata, int size, int flags = 0 ) 30 | { 31 | Load( szPath, rgbdata, size, flags ); 32 | } 33 | 34 | void Set( HIMAGE handle ) 35 | { 36 | m_hPic = handle; 37 | m_szPath = NULL; 38 | } 39 | 40 | void Load( const char *szPath, int flags = 0 ) 41 | { 42 | Set( EngFuncs::PIC_Load( szPath, flags ) ); 43 | m_szPath = szPath; 44 | } 45 | 46 | void Load( const char *szPath, const byte *rgbdata, int size, int flags = 0 ) 47 | { 48 | Set( EngFuncs::PIC_Load( szPath, rgbdata, size, flags )); 49 | m_szPath = szPath; 50 | } 51 | 52 | void Reset( void ) 53 | { 54 | m_szPath = NULL; 55 | m_hPic = 0; 56 | } 57 | 58 | // a1ba: why there is no destructor? 59 | // Engine doesn't track the reference count of texture 60 | // so unloading texture may behave not as you may expect 61 | // Moreover, you can't unload texture by it's handle, only by name 62 | // If you still want to unload image, there is a function for you 63 | void ForceUnload() 64 | { 65 | if( m_szPath ) 66 | EngFuncs::PIC_Free( m_szPath ); 67 | m_hPic = 0; 68 | } 69 | 70 | const char * operator =( const char *path ) 71 | { 72 | // don't pass NULL to engine 73 | if( path ) Load( path ); 74 | else Reset(); 75 | return path; 76 | } 77 | 78 | HIMAGE operator = ( HIMAGE handle ) 79 | { 80 | Set( handle ); 81 | return handle; 82 | } 83 | 84 | operator HIMAGE() 85 | { 86 | return m_hPic; 87 | } 88 | 89 | friend inline bool operator == ( CImage &a, CImage &b ) 90 | { 91 | return a.m_hPic == b.m_hPic; 92 | } 93 | 94 | bool IsValid() const { return m_hPic != 0; } 95 | const char *Path() const { return m_szPath; } 96 | HIMAGE Handle() const { return m_hPic; } 97 | private: 98 | const char *m_szPath; 99 | HIMAGE m_hPic; 100 | }; 101 | 102 | #endif // IMAGE_H 103 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # mainui_cpp 2 | 3 | Main Menu UI for Xash3D FWGS engine, built entirely in C++. 4 | 5 | Key features: 6 | * Custom font renderer with multiple backends based on FreeType, stb_truetype and GDI on Windows 7 | * Unicode and l10n support 8 | * Completely self-contained, just clone this repo (with --recursive) and add to your mod 9 | * Complex widget containers system, ability to put widget into containers into container 10 | * Window system as a continuation of containers system 11 | * Client-side menus (needs to be documented) 12 | 13 | ### Including mainui_cpp in your mod 14 | 15 | 1. Clone this repo: `git clone --recursive https://github.com/FWGS/mainui_cpp` to your mod source code tree. 16 | 2. If you use: 17 | * CMake: invoke `add_subdirectory(mainui_cpp)` in your CMakeLists.txt file 18 | * Waf/WAiFu: invoke `ctx.add_subdirectory('mainui_cpp')` in your wscript file 19 | * Visual Studio: if you want to build it from your mod tree, include `vs2022/mainui_cpp.vcxproj` to your mod solution, or use `vs2022/mainui_cpp.sln`. 20 | 3. Place your built `menu.dll`/`libmenu.so` ALONGSIDE your `client.dll`/`client.so`. 21 | 4. Check that everything is working and happy hacking! 22 | 23 | If you have any troubles setting this up, create an issue in https://github.com/FWGS/mainui_cpp/issues. 24 | 25 | ### Notes and restrictions 26 | 27 | * mainui_cpp doesn't supports original Xash3D anymore. If it's possible, you can switch to Xash3D FWGS, otherwise you're on your own. I will accept patches to enable other Xash3D forks, but I won't support them on my own. 28 | 29 | -------------------------------------------------------------------------------- /Scissor.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseMenu.h" 2 | #include "Scissor.h" 3 | 4 | #define MAX_SCISSORS 16 5 | 6 | static class CScissorState 7 | { 8 | public: 9 | CScissorState() : iDepth( 0 ) { } 10 | 11 | int iDepth; 12 | Point coordStack[MAX_SCISSORS]; 13 | Size sizeStack[MAX_SCISSORS]; 14 | } scissor; 15 | 16 | void CropByPreviousScissors( Point pt, Size sz, int &x, int &y, int &w, int &h ) 17 | { 18 | int inRight = pt.x + sz.w; 19 | int inBottom = pt.y + sz.h; 20 | 21 | int outLeft = x, outRight = x + w; 22 | int outTop = y, outBottom = y + h; 23 | 24 | if( outLeft < pt.x ) 25 | outLeft = pt.x; 26 | 27 | if( outTop < pt.y ) 28 | outTop = pt.y; 29 | 30 | if( outRight > inRight ) 31 | outRight = inRight; 32 | 33 | if( outBottom > inBottom ) 34 | outBottom = inBottom; 35 | 36 | x = outLeft; 37 | y = outTop; 38 | 39 | w = outRight - outLeft; 40 | h = outBottom - outTop; 41 | } 42 | 43 | void UI::Scissor::PushScissor(int x, int y, int w, int h) 44 | { 45 | if( scissor.iDepth + 1 > MAX_SCISSORS ) 46 | { 47 | Con_DPrintf( "UI::PushScissor: Scissor stack limit exceeded" ); 48 | return; 49 | } 50 | 51 | // have active scissors. Disable current 52 | if( scissor.iDepth > 0 ) 53 | { 54 | EngFuncs::PIC_DisableScissor(); 55 | CropByPreviousScissors( scissor.coordStack[scissor.iDepth - 1 ], scissor.sizeStack[scissor.iDepth - 1], 56 | x, y, w, h ); 57 | } 58 | 59 | scissor.coordStack[scissor.iDepth].x = x; 60 | scissor.coordStack[scissor.iDepth].y = y; 61 | scissor.sizeStack[scissor.iDepth].w = w; 62 | scissor.sizeStack[scissor.iDepth].h = h; 63 | 64 | EngFuncs::PIC_EnableScissor( x, y, w, h ); 65 | scissor.iDepth++; 66 | } 67 | 68 | void UI::Scissor::PopScissor() 69 | { 70 | if( scissor.iDepth <= 0 ) 71 | { 72 | Con_DPrintf( "UI::PopScissor: no stack" ); 73 | return; 74 | } 75 | 76 | EngFuncs::PIC_DisableScissor(); 77 | scissor.iDepth--; 78 | 79 | if( scissor.iDepth > 0 ) 80 | { 81 | EngFuncs::PIC_EnableScissor( 82 | scissor.coordStack[scissor.iDepth - 1].x, 83 | scissor.coordStack[scissor.iDepth - 1].y, 84 | scissor.sizeStack[scissor.iDepth - 1].w, 85 | scissor.sizeStack[scissor.iDepth - 1].h ); 86 | } 87 | } 88 | 89 | 90 | -------------------------------------------------------------------------------- /Scissor.h: -------------------------------------------------------------------------------- 1 | /* 2 | Scissor.h -- scissor utils 3 | Copyright (C) 2017 mittorn 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | #pragma once 21 | #ifndef SCISSOR_H 22 | #define SCISSOR_H 23 | 24 | #include "BaseMenu.h" 25 | 26 | namespace UI 27 | { 28 | namespace Scissor 29 | { 30 | void PushScissor( int x, int y, int w, int h ); 31 | inline void PushScissor( Point pt, Size sz ) { PushScissor( pt.x, pt.y, sz.w, sz.h ); } 32 | 33 | void PopScissor(); 34 | } 35 | } 36 | 37 | #endif // SCISSOR_H 38 | -------------------------------------------------------------------------------- /WindowSystem.h: -------------------------------------------------------------------------------- 1 | /* 2 | WindowSystem.h -- window system 3 | Copyright (C) 2019 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #pragma once 17 | #ifndef WINDOWSYSTEM_H 18 | #define WINDOWSYSTEM_H 19 | 20 | #include "utllinkedlist.h" 21 | 22 | class CMenuBaseWindow; 23 | 24 | class CWindowStack 25 | { 26 | public: 27 | CWindowStack() : 28 | active( stack.InvalidIndex() ) 29 | { 30 | 31 | } 32 | 33 | CMenuBaseWindow *Current() const { return stack.IsValidIndex( active ) ? stack[active] : NULL; } 34 | 35 | bool IsActive( void ) { return stack.Count() > 0; } 36 | int Count( void ) { return stack.Count(); } 37 | void Clean( void ) 38 | { 39 | stack.RemoveAll(); 40 | active = stack.InvalidIndex(); 41 | } 42 | void Add( CMenuBaseWindow *menu ); 43 | void Remove( CMenuBaseWindow *menu ); 44 | 45 | bool IsVisible( const CMenuBaseWindow *menu ) const; 46 | 47 | void VidInit( bool firstTime ); 48 | void Update( void ); 49 | void KeyUpEvent( int key ); 50 | void KeyDownEvent( int key ); 51 | void CharEvent( int ch ); 52 | void MouseEvent( int x, int y ); 53 | void InputMethodResized( void ); 54 | private: 55 | CUtlLinkedList stack; 56 | 57 | int active; // current active window 58 | }; 59 | 60 | #endif // WINDOWSYSTEM_H 61 | -------------------------------------------------------------------------------- /controls/Action.h: -------------------------------------------------------------------------------- 1 | /* 2 | Action.h - simple label with background item 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | #ifndef MENU_ACTION_H 17 | #define MENU_ACTION_H 18 | 19 | #include "BaseItem.h" 20 | 21 | class CMenuAction : public CMenuBaseItem 22 | { 23 | public: 24 | typedef CMenuBaseItem BaseClass; 25 | 26 | CMenuAction(); 27 | 28 | void VidInit( void ) override; 29 | bool KeyUp( int key ) override; 30 | bool KeyDown( int key ) override; 31 | void Draw( void ) override; 32 | 33 | void SetBackground( const char *path, unsigned int color = uiColorWhite ); 34 | void SetBackground( unsigned int color, unsigned int focused = 0 ); 35 | 36 | bool m_bLimitBySize; 37 | bool bIgnoreColorstring; 38 | 39 | private: 40 | CColor m_iBackcolor; 41 | CColor m_iBackColorFocused; 42 | CImage m_szBackground; 43 | bool m_bfillBackground; 44 | bool forceCalcW, forceCalcY; 45 | }; 46 | 47 | #endif // MENU_ACTION_H 48 | -------------------------------------------------------------------------------- /controls/AnimatedBanner.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #ifndef ANIMATED_TITLE_H 22 | #define ANIMATED_TITLE_H 23 | 24 | #include "BaseItem.h" 25 | #include "Image.h" 26 | 27 | #define ART_BLIP_NUM 2 28 | #define ART_BLUR_NUM 4 29 | 30 | class CMenuAnimatedBanner : public CMenuBaseItem 31 | { 32 | public: 33 | virtual void VidInit() override; 34 | virtual void Draw() override; 35 | virtual void Think() override; 36 | 37 | virtual bool TryLoad(); 38 | private: 39 | void RandomizeGoalTime( float time ); 40 | void RandomizeSpeed( float initial_speed ); 41 | void RandomizeBlipTime( float time ); 42 | void RandomizeBlip( void ); 43 | 44 | float scale; 45 | 46 | CImage logo; 47 | CImage logoBlip[ART_BLIP_NUM]; 48 | CImage logoBlur[ART_BLUR_NUM]; 49 | CImage logoBlurBlip[ART_BLUR_NUM]; 50 | 51 | int m_nLogoImageXMin; 52 | int m_nLogoImageXMax; 53 | int m_nLogoImageXGoal; 54 | float m_flPrevFrameTime; 55 | float m_flTimeLogoNewGoal; 56 | float m_flTimeLogoNewGoalMin; 57 | float m_flTimeLogoNewGoalMax; 58 | float m_flTimeUntilLogoBlipMin; 59 | float m_flTimeUntilLogoBlipMax; 60 | float m_flTimeLogoBlip; 61 | int m_nLogoBlipType; 62 | int m_nLogoImageY; 63 | float m_fLogoImageX; 64 | float m_fLogoSpeedMin; 65 | float m_fLogoSpeedMax; 66 | float m_fLogoSpeed; 67 | int m_nLogoBGOffsetX; 68 | int m_nLogoBGOffsetY; 69 | 70 | enum LogoBlip_t 71 | { 72 | E_LOGO_BLIP_BOTH, 73 | E_LOGO_BLIP_JUST_LOGO, 74 | E_LOGO_BLIP_JUST_BG, 75 | E_LOGO_BLIP_STAGGER, 76 | E_LOGO_BLIP_BOTH_SHOW_BLIP_LOGO_ONLY 77 | } m_nNextLogoBlipType; 78 | 79 | // not referenced 80 | bool drawBlip[ART_BLIP_NUM]; 81 | bool drawBgBlip; 82 | }; 83 | 84 | #endif // ANIMATED_TITLE_H 85 | -------------------------------------------------------------------------------- /controls/BackgroundBitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | BackgroundBitmap.h -- background menu item 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_BACKGROUNDBITMAP_H 18 | #define MENU_BACKGROUNDBITMAP_H 19 | 20 | #include "Bitmap.h" 21 | #include "utlvector.h" 22 | 23 | #define ART_BACKGROUND "gfx/shell/splash.bmp" 24 | 25 | // Ultimate class that support multiple types of background: fillColor, WON-style, GameUI-style 26 | class CMenuBackgroundBitmap: public CMenuBitmap 27 | { 28 | public: 29 | CMenuBackgroundBitmap(); 30 | 31 | void VidInit( void ) override; 32 | void Draw( void ) override; 33 | void SetInactive(bool) override { } 34 | void ToggleInactive() override { } 35 | 36 | bool bForceColor; // dialogs should set this 37 | 38 | static void LoadBackground(); 39 | static bool ShouldDrawLogoMovie() { return s_bEnableLogoMovie; } 40 | private: 41 | void DrawBackgroundLayout( Point p, int xOffset, int yOffset, float xScale, float yScale ); 42 | void DrawColor(); 43 | void DrawInGameBackground(); 44 | 45 | static bool LoadBackgroundImage( const bool gamedirOnly ); // Steam background loader 46 | static bool CheckBackgroundSplash( const bool gamedirOnly ); // WON background loader 47 | 48 | //========== 49 | // WON-style 50 | //========== 51 | static bool s_bEnableLogoMovie; 52 | static Size s_BackgroundImageSize; 53 | 54 | //============= 55 | // GameUI-style 56 | //============= 57 | typedef struct 58 | { 59 | HIMAGE hImage; 60 | Point coord; 61 | Size size; 62 | } bimage_t; 63 | 64 | static CUtlVector s_Backgrounds; 65 | }; 66 | 67 | #endif // MENU_BACKGROUNDBITMAP_H 68 | -------------------------------------------------------------------------------- /controls/BaseClientWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BaseWindow.h -- base client menu window 3 | Copyright (C) 2018 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "BaseMenu.h" 16 | #include "BaseClientWindow.h" 17 | 18 | CMenuBaseClientWindow::CMenuBaseClientWindow( const char *name ) : 19 | BaseClass( name, &uiStatic.client ) 20 | { 21 | } 22 | 23 | bool CMenuBaseClientWindow::KeyDown( int key ) 24 | { 25 | // copy engine behaviour 26 | if( UI::Key::IsEscape( key )) 27 | { 28 | EngFuncs::KEY_SetDest( KEY_GAME ); // set engine states before "escape" 29 | EngFuncs::ClientCmd( FALSE, "escape\n" ); 30 | return true; 31 | } 32 | else if( UI::Key::IsConsole( key )) 33 | { 34 | EngFuncs::KEY_SetDest( KEY_CONSOLE ); 35 | } 36 | 37 | return BaseClass::KeyDown( key ); 38 | } 39 | 40 | 41 | -------------------------------------------------------------------------------- /controls/BaseClientWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | BaseWindow.h -- base client menu window 3 | Copyright (C) 2018 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef BASECLIENTWINDOW_H 16 | #define BASECLIENTWINDOW_H 17 | 18 | #include "BaseWindow.h" 19 | 20 | class CMenuBaseClientWindow : public CMenuBaseWindow 21 | { 22 | public: 23 | typedef CMenuBaseWindow BaseClass; 24 | CMenuBaseClientWindow( const char *name = "BaseClientWindow" ); 25 | 26 | bool KeyDown( int key ) override; 27 | }; 28 | 29 | #endif // BASECLIENTWINDOW_H 30 | -------------------------------------------------------------------------------- /controls/BaseWindow.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BaseWindow.cpp -- base menu window 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "extdll_menu.h" 16 | #include "BaseMenu.h" 17 | #include "Utils.h" 18 | #include "PicButton.h" 19 | #include "ItemsHolder.h" 20 | #include "BaseWindow.h" 21 | 22 | CMenuBaseWindow::CMenuBaseWindow( const char *name, CWindowStack *pStack ) : BaseClass() 23 | { 24 | bAllowDrag = false; // UNDONE 25 | m_bHolding = false; 26 | szName = name; 27 | m_pStack = pStack; 28 | DisableTransition(); 29 | } 30 | 31 | void CMenuBaseWindow::Show() 32 | { 33 | Init(); 34 | VidInit(); 35 | Reload(); // take a chance to reload info for items 36 | m_pStack->Add( this ); 37 | m_iCursor = 0; 38 | 39 | // Probably not a best way 40 | // but we need to inform new window about cursor position, 41 | // otherwise we will have an invalid cursor until first mouse move event 42 | #if 1 43 | m_iCursorPrev = -1; 44 | MouseMove( uiStatic.cursorX, uiStatic.cursorY ); 45 | #else 46 | m_iCursor = 0; 47 | m_iCursorPrev = 0; 48 | // force first available item to have focus 49 | FOR_EACH_VEC( m_pItems, i ) 50 | { 51 | item = m_pItems[i]; 52 | 53 | if( !item->IsVisible() || item->iFlags & (QMF_GRAYED|QMF_INACTIVE|QMF_MOUSEONLY)) 54 | continue; 55 | 56 | m_iCursorPrev = -1; 57 | SetCursor( i ); 58 | break; 59 | } 60 | #endif 61 | EnableTransition( ANIM_OPENING ); 62 | } 63 | 64 | void CMenuBaseWindow::Hide() 65 | { 66 | if( m_pStack == &uiStatic.menu ) // hack! 67 | { 68 | EngFuncs::PlayLocalSound( uiStatic.sounds[SND_OUT] ); 69 | } 70 | 71 | m_pStack->Remove( this ); 72 | EnableTransition( ANIM_CLOSING ); 73 | } 74 | 75 | bool CMenuBaseWindow::IsVisible() const 76 | { 77 | return m_pStack->IsVisible( this ); 78 | } 79 | 80 | void CMenuBaseWindow::SaveAndPopMenu() 81 | { 82 | EngFuncs::ClientCmd( FALSE, "trysaveconfig\n" ); 83 | Hide(); 84 | } 85 | 86 | void CMenuBaseWindow::DragDrop( int down ) 87 | { 88 | m_bHolding = down; 89 | m_bHoldOffset.x = uiStatic.cursorX; 90 | m_bHoldOffset.y = uiStatic.cursorY; 91 | } 92 | 93 | bool CMenuBaseWindow::KeyDown( int key ) 94 | { 95 | if( UI::Key::IsLeftMouse( key ) && bAllowDrag ) 96 | DragDrop( true ); 97 | 98 | if( UI::Key::IsEscape( key ) ) 99 | { 100 | Hide( ); 101 | return true; 102 | } 103 | 104 | return BaseClass::KeyDown( key ); 105 | } 106 | 107 | bool CMenuBaseWindow::KeyUp( int key ) 108 | { 109 | if( UI::Key::IsLeftMouse( key ) && bAllowDrag ) 110 | DragDrop( false ); 111 | 112 | return BaseClass::KeyUp( key ); 113 | } 114 | 115 | void CMenuBaseWindow::Draw() 116 | { 117 | if( !IsRoot() && m_bHolding && bAllowDrag ) 118 | { 119 | m_scPos.x += uiStatic.cursorX - m_bHoldOffset.x; 120 | m_scPos.y += uiStatic.cursorY - m_bHoldOffset.y; 121 | 122 | m_bHoldOffset.x = uiStatic.cursorX; 123 | m_bHoldOffset.y = uiStatic.cursorY; 124 | // CalcPosition(); 125 | CalcItemsPositions(); 126 | } 127 | CMenuItemsHolder::Draw(); 128 | } 129 | 130 | 131 | bool CMenuBaseWindow::DrawAnimation() 132 | { 133 | float alpha; 134 | 135 | if( eTransitionType == ANIM_OPENING ) 136 | { 137 | alpha = ( uiStatic.realTime - m_iTransitionStartTime ) / TTT_PERIOD; 138 | } 139 | else if( eTransitionType == ANIM_CLOSING ) 140 | { 141 | alpha = 1.0f - ( uiStatic.realTime - m_iTransitionStartTime ) / TTT_PERIOD; 142 | } 143 | 144 | if( ( eTransitionType == ANIM_OPENING && alpha < 1.0f ) 145 | || ( eTransitionType == ANIM_CLOSING && alpha > 0.0f ) ) 146 | { 147 | UI_EnableAlphaFactor( alpha ); 148 | 149 | Draw(); 150 | 151 | UI_DisableAlphaFactor(); 152 | 153 | return false; 154 | } 155 | 156 | return true; 157 | } 158 | 159 | bool CMenuBaseWindow::KeyValueData(const char *key, const char *data) 160 | { 161 | if( !strcmp( key, "enabled" ) || !strcmp( key, "visible" ) ) 162 | return true; 163 | 164 | return CMenuBaseItem::KeyValueData(key, data); 165 | } 166 | 167 | void CMenuBaseWindow::EnableTransition( EAnimation type ) 168 | { 169 | eTransitionType = type; 170 | m_iTransitionStartTime = uiStatic.realTime; 171 | } 172 | -------------------------------------------------------------------------------- /controls/BaseWindow.h: -------------------------------------------------------------------------------- 1 | /* 2 | BaseWindow.h -- base menu window 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef BASEWINDOW_H 16 | #define BASEWINDOW_H 17 | 18 | #include "ItemsHolder.h" 19 | #include "BackgroundBitmap.h" 20 | 21 | // Base class for windows. 22 | // Should be used for message boxes, dialogs, root menus(e.g. frameworks) 23 | class CMenuBaseWindow : public CMenuItemsHolder 24 | { 25 | public: 26 | typedef CMenuItemsHolder BaseClass; 27 | CMenuBaseWindow( const char *name = "Unnamed Window", CWindowStack *pStack = &uiStatic.menu ); 28 | 29 | // Overloaded functions 30 | // Window visibility is switched through window stack 31 | void Hide() override; 32 | void Show() override; 33 | bool IsVisible() const override; 34 | 35 | bool KeyUp( int key ) override; 36 | bool KeyDown( int key ) override; 37 | void Draw() override; 38 | 39 | bool KeyValueData(const char *key, const char *data) override; 40 | 41 | enum EAnimation 42 | { 43 | ANIM_NO = 0, // no animation 44 | ANIM_CLOSING, // window closing animation 45 | ANIM_OPENING, // window showing animation 46 | }; 47 | 48 | // Override this method to draw custom animations 49 | // For example, during transitions 50 | // Return false when animation is still going 51 | // Otherwise return true, so window will be marked as "no animation" 52 | // and this method will not be called anymore(until next menu transition) 53 | virtual bool DrawAnimation(); 54 | 55 | // Check current window is a root 56 | virtual bool IsRoot() const { return false; } 57 | 58 | // Hide current window and save changes 59 | virtual void SaveAndPopMenu(); 60 | 61 | bool IsWindow() override { return true; } 62 | 63 | void EnableTransition( EAnimation type ); 64 | void DisableTransition() { eTransitionType = ANIM_NO; } 65 | 66 | // set parent of window 67 | void Link( CMenuItemsHolder *h ) 68 | { 69 | m_pParent = h; 70 | } 71 | 72 | bool bAllowDrag; 73 | EAnimation eTransitionType; // valid only when in transition 74 | 75 | const CWindowStack *WindowStack() const 76 | { 77 | return m_pStack; 78 | } 79 | 80 | protected: 81 | int m_iTransitionStartTime; 82 | 83 | CWindowStack *m_pStack; 84 | private: 85 | CMenuBaseWindow(); // remove 86 | 87 | friend void UI_DrawMouseCursor( void ); // HACKHACK: Cursor should be set by menu item 88 | friend void UI_UpdateMenu( float flTime ); 89 | 90 | bool IsAbsolutePositioned( void ) const override { return true; } 91 | void DragDrop( int down ); 92 | 93 | bool m_bHolding; 94 | Point m_bHoldOffset; 95 | }; 96 | 97 | #endif // BASEWINDOW_H 98 | -------------------------------------------------------------------------------- /controls/Bitmap.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Bitmap.cpp - bitmap menu item 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #include "extdll_menu.h" 18 | #include "BaseMenu.h" 19 | #include "Bitmap.h" 20 | #include "PicButton.h" // GetTitleTransFraction 21 | #include "Utils.h" 22 | #include "BaseWindow.h" 23 | 24 | CMenuBitmap::CMenuBitmap() : BaseClass() 25 | { 26 | SetRenderMode( QM_DRAWNORMAL ); 27 | } 28 | 29 | /* 30 | ================= 31 | CMenuBitmap::Init 32 | ================= 33 | */ 34 | void CMenuBitmap::VidInit( ) 35 | { 36 | colorBase.SetDefault( uiColorWhite ); 37 | colorFocus.SetDefault( uiColorWhite ); 38 | 39 | BaseClass::VidInit(); 40 | if( !szFocusPic ) 41 | szFocusPic = szPic; 42 | } 43 | 44 | bool CMenuBitmap::KeyUp( int key ) 45 | { 46 | const char *sound = 0; 47 | 48 | if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) ) 49 | sound = uiStatic.sounds[SND_LAUNCH]; 50 | else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) ) 51 | sound = uiStatic.sounds[SND_LAUNCH]; 52 | 53 | if( sound ) 54 | { 55 | _Event( QM_PRESSED ); 56 | PlayLocalSound( sound ); 57 | } 58 | 59 | return sound != NULL; 60 | } 61 | 62 | bool CMenuBitmap::KeyDown( int key ) 63 | { 64 | bool handled = false; 65 | 66 | if( UI::Key::IsEnter( key ) && !(iFlags & QMF_MOUSEONLY) ) 67 | handled = true; 68 | else if( UI::Key::IsLeftMouse( key ) && ( iFlags & QMF_HASMOUSEFOCUS ) ) 69 | handled = true; 70 | 71 | if( handled ) 72 | _Event( QM_RELEASED ); 73 | 74 | return handled; 75 | } 76 | 77 | /* 78 | ================= 79 | CMenuBitmap::Draw 80 | ================= 81 | */ 82 | void CMenuBitmap::Draw( void ) 83 | { 84 | if( !szPic ) 85 | { 86 | UI_FillRect( m_scPos, m_scSize, colorBase ); 87 | return; 88 | } 89 | 90 | if( iFlags & QMF_GRAYED ) 91 | { 92 | UI_DrawPic( m_scPos, m_scSize, uiColorDkGrey, szPic, eRenderMode ); 93 | return; // grayed 94 | } 95 | 96 | if(( iFlags & QMF_MOUSEONLY ) && !( iFlags & QMF_HASMOUSEFOCUS )) 97 | { 98 | UI_DrawPic( m_scPos, m_scSize, colorBase, szPic, eRenderMode ); 99 | return; // no focus 100 | } 101 | 102 | if( this != m_pParent->ItemAtCursor() ) 103 | { 104 | UI_DrawPic( m_scPos, m_scSize, colorBase, szPic, eRenderMode ); 105 | return; // no focus 106 | } 107 | 108 | if( this->m_bPressed ) 109 | { 110 | UI_DrawPic( m_scPos, m_scSize, colorBase, szPressPic, ePressRenderMode ); 111 | } 112 | 113 | switch( eFocusAnimation ) 114 | { 115 | case QM_HIGHLIGHTIFFOCUS: 116 | UI_DrawPic( m_scPos, m_scSize, colorBase, szFocusPic, eFocusRenderMode ); 117 | break; 118 | case QM_PULSEIFFOCUS: 119 | { 120 | int color; 121 | 122 | color = PackAlpha( colorBase, 255 * (0.5f + 0.5f * sin( (float)uiStatic.realTime / UI_PULSE_DIVISOR ))); 123 | UI_DrawPic( m_scPos, m_scSize, color, szFocusPic, eFocusRenderMode ); 124 | break; 125 | } 126 | default: 127 | UI_DrawPic( m_scPos, m_scSize, colorBase, szPic, eRenderMode ); // ignore focus 128 | break; 129 | } 130 | } 131 | -------------------------------------------------------------------------------- /controls/Bitmap.h: -------------------------------------------------------------------------------- 1 | /* 2 | Bitmap.h - bitmap menu item 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_BITMAP_H 18 | #define MENU_BITMAP_H 19 | 20 | #include "BaseItem.h" 21 | 22 | class CMenuBitmap : public CMenuBaseItem 23 | { 24 | public: 25 | typedef CMenuBaseItem BaseClass; 26 | 27 | CMenuBitmap(); 28 | 29 | void VidInit( void ) override; 30 | bool KeyUp( int key ) override; 31 | bool KeyDown( int key ) override; 32 | void Draw( void ) override; 33 | void SetPicture( const char *pic, const char *focusPic = NULL, const char *pressPic = NULL) 34 | { 35 | szPic = pic; 36 | szFocusPic = focusPic; 37 | szPressPic = pressPic; 38 | } 39 | 40 | void SetRenderMode( ERenderMode renderMode, ERenderMode focusRenderMode = QM_DRAWNORMAL, ERenderMode pressRenderMode = QM_DRAWNORMAL ) 41 | { 42 | eRenderMode = renderMode; 43 | eFocusRenderMode = focusRenderMode; 44 | ePressRenderMode = pressRenderMode; 45 | } 46 | 47 | protected: 48 | CImage szPic; 49 | ERenderMode eRenderMode; 50 | 51 | CImage szFocusPic; 52 | ERenderMode eFocusRenderMode; 53 | 54 | CImage szPressPic; 55 | ERenderMode ePressRenderMode; 56 | }; 57 | 58 | #endif // MENU_BITMAP_H 59 | -------------------------------------------------------------------------------- /controls/CheckBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | CheckBox.h - checkbox 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_CHECKBOX_H 18 | #define MENU_CHECKBOX_H 19 | 20 | #include "Editable.h" 21 | 22 | #define UI_CHECKBOX_EMPTY "gfx/shell/cb_empty" 23 | #define UI_CHECKBOX_GRAYED "gfx/shell/cb_disabled" 24 | #define UI_CHECKBOX_FOCUS "gfx/shell/cb_over" 25 | #define UI_CHECKBOX_PRESSED "gfx/shell/cb_down" 26 | #define UI_CHECKBOX_ENABLED "gfx/shell/cb_checked" 27 | 28 | class CMenuCheckBox : public CMenuEditable 29 | { 30 | public: 31 | typedef CMenuEditable BaseClass; 32 | 33 | CMenuCheckBox(); 34 | void VidInit() override; 35 | bool KeyUp( int key ) override; 36 | bool KeyDown( int key ) override; 37 | void Draw( void ) override; 38 | void UpdateEditable() override; 39 | void LinkCvar( const char *name ) override 40 | { 41 | CMenuEditable::LinkCvar( name, CMenuEditable::CVAR_VALUE ); 42 | } 43 | 44 | void SetPicture( const char *empty, const char *focus, const char *press, const char *check, const char *grayed ) 45 | { 46 | szEmptyPic = empty; 47 | szFocusPic = focus; 48 | szPressPic = press; 49 | szCheckPic = check; 50 | szGrayedPic = grayed; 51 | } 52 | 53 | bool bChecked; 54 | bool bInvertMask; 55 | bool bChangeOnPressed; 56 | 57 | CImage szEmptyPic; 58 | CImage szFocusPic; 59 | CImage szPressPic; 60 | CImage szCheckPic; 61 | CImage szGrayedPic; // when QMF_GRAYED is set 62 | 63 | unsigned int iMask; // used only for BitMaskCb 64 | static void BitMaskCb( CMenuBaseItem *pSelf, void *pExtra ) 65 | { 66 | CMenuCheckBox *self = (CMenuCheckBox*)pSelf; 67 | 68 | if( !self->bInvertMask == self->bChecked ) 69 | { 70 | *(unsigned int*)pExtra |= self->iMask; 71 | } 72 | else 73 | { 74 | *(unsigned int*)pExtra &= ~self->iMask; 75 | } 76 | } 77 | 78 | CColor colorText; 79 | private: 80 | Point m_scTextPos; 81 | Size m_scTextSize; 82 | }; 83 | 84 | #endif // MENU_CHECKBOX_H 85 | -------------------------------------------------------------------------------- /controls/Editable.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Editable.cpp - generic item for editables 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #include "Editable.h" 17 | 18 | CMenuEditable::CMenuEditable() : BaseClass(), bUpdateImmediately( false ), 19 | m_szCvarName(), m_eType(), 20 | m_flValue(), m_flOriginalValue() 21 | { 22 | m_szString[0] = m_szOriginalString[0] = 0; 23 | } 24 | 25 | void CMenuEditable::LinkCvar(const char *) 26 | { 27 | assert(("Derivative class does not implement LinkCvar(const char*) method. You need to specify types.")); 28 | } 29 | 30 | void CMenuEditable::LinkCvar(const char *name, cvarType_e type) 31 | { 32 | m_szCvarName = name; 33 | m_eType = type; 34 | 35 | UpdateCvar( true ); 36 | } 37 | 38 | void CMenuEditable::Reload() 39 | { 40 | // editable already initialized, so update 41 | if( m_szCvarName ) 42 | UpdateCvar( true ); 43 | } 44 | 45 | void CMenuEditable::SetCvarValue( float value ) 46 | { 47 | m_flValue = value; 48 | 49 | if( onCvarChange ) onCvarChange( this ); 50 | if( bUpdateImmediately ) WriteCvar(); 51 | } 52 | 53 | void CMenuEditable::SetCvarString( const char *string ) 54 | { 55 | if( string != m_szString ) 56 | Q_strncpy( m_szString, string, sizeof( m_szString )); 57 | 58 | if( onCvarChange ) onCvarChange( this ); 59 | if( bUpdateImmediately ) WriteCvar(); 60 | } 61 | 62 | void CMenuEditable::SetOriginalString( const char *psz ) 63 | { 64 | Q_strncpy( m_szOriginalString, psz, sizeof( m_szOriginalString )); 65 | SetCvarString( m_szOriginalString ); 66 | } 67 | 68 | void CMenuEditable::SetOriginalValue( float val ) 69 | { 70 | m_flOriginalValue = val; 71 | SetCvarValue( m_flOriginalValue ); 72 | } 73 | 74 | void CMenuEditable::UpdateCvar( bool haveUpdate ) 75 | { 76 | if( onCvarGet ) 77 | { 78 | onCvarGet( this ); 79 | haveUpdate = false; // FIXME: add return values to events 80 | } 81 | else if( m_szCvarName ) 82 | { 83 | switch( m_eType ) 84 | { 85 | case CVAR_STRING: 86 | { 87 | const char *str = EngFuncs::GetCvarString( m_szCvarName ); 88 | if( haveUpdate || strcmp( m_szOriginalString, str ) ) 89 | { 90 | SetOriginalString( str ); 91 | haveUpdate = true; 92 | } 93 | break; 94 | } 95 | case CVAR_VALUE: 96 | { 97 | float val = EngFuncs::GetCvarFloat( m_szCvarName ); 98 | if( haveUpdate || m_flOriginalValue != val ) 99 | { 100 | SetOriginalValue( val ); 101 | haveUpdate = true; 102 | } 103 | break; 104 | } 105 | } 106 | } 107 | 108 | if( haveUpdate ) 109 | UpdateEditable(); 110 | } 111 | 112 | void CMenuEditable::ResetCvar() 113 | { 114 | switch( m_eType ) 115 | { 116 | case CVAR_STRING: SetCvarString( m_szOriginalString ); break; 117 | case CVAR_VALUE: SetCvarValue( m_flOriginalValue ); break; 118 | } 119 | } 120 | 121 | void CMenuEditable::DiscardChanges() 122 | { 123 | ResetCvar(); 124 | WriteCvar(); 125 | } 126 | 127 | void CMenuEditable::WriteCvar() 128 | { 129 | if( onCvarWrite ) onCvarWrite( this ); 130 | else if( m_szCvarName ) 131 | { 132 | switch( m_eType ) 133 | { 134 | case CVAR_STRING: EngFuncs::CvarSetString( m_szCvarName, m_szString ); break; 135 | case CVAR_VALUE: EngFuncs::CvarSetValue( m_szCvarName, m_flValue ); break; 136 | } 137 | } 138 | } 139 | 140 | -------------------------------------------------------------------------------- /controls/Editable.h: -------------------------------------------------------------------------------- 1 | /* 2 | Editable.h - generic item for editables 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef MENU_EDITABLE_H 17 | #define MENU_EDITABLE_H 18 | 19 | #include "BaseItem.h" 20 | 21 | class CMenuEditable : public CMenuBaseItem 22 | { 23 | public: 24 | typedef CMenuBaseItem BaseClass; 25 | 26 | CMenuEditable(); 27 | void Reload() override; 28 | 29 | // Every derived class can define how it will work with cvars 30 | virtual void UpdateEditable() = 0; 31 | 32 | // Engine allow only string and value cvars 33 | enum cvarType_e 34 | { 35 | CVAR_STRING = 0, 36 | CVAR_VALUE 37 | }; 38 | 39 | // setup editable 40 | void LinkCvar( const char *name, cvarType_e type ); 41 | 42 | // Getters 43 | inline const char *CvarName() const { return m_szCvarName; } 44 | inline float CvarValue() const { return m_flValue; } 45 | inline const char *CvarString() const { return m_szString; } 46 | inline cvarType_e CvarType() const { return m_eType; } 47 | 48 | // Set cvar value/string and emit an event(does not written to engine) 49 | void SetCvarValue( float value ); 50 | void SetCvarString( const char *string ); 51 | 52 | // Set last got engine cvar values 53 | void SetOriginalValue( float val ); 54 | void SetOriginalString( const char *psz ); 55 | 56 | // Reset editable to last got engine values 57 | void ResetCvar(); 58 | 59 | // Send cvar value/string to engine 60 | void WriteCvar(); 61 | 62 | // Discard any changes and immediately send them to engine 63 | void DiscardChanges(); 64 | 65 | // Update cvar values from engine 66 | void UpdateCvar( bool forceUpdate ); 67 | 68 | CEventCallback onCvarWrite; // called on final writing of cvar value 69 | CEventCallback onCvarChange; // called on internal values changes 70 | CEventCallback onCvarGet; // called on any cvar update 71 | 72 | // events library 73 | DECLARE_EVENT_TO_ITEM_METHOD( CMenuEditable, WriteCvar ) 74 | DECLARE_EVENT_TO_ITEM_METHOD( CMenuEditable, DiscardChanges ) 75 | DECLARE_EVENT_TO_ITEM_METHOD( CMenuEditable, ResetCvar ) 76 | 77 | bool bUpdateImmediately; 78 | 79 | protected: 80 | const char *m_szCvarName; 81 | cvarType_e m_eType; 82 | 83 | char m_szString[CS_SIZE], m_szOriginalString[CS_SIZE]; 84 | float m_flValue, m_flOriginalValue; 85 | 86 | private: 87 | // A possible shortcut for derived class, that support only one cvar type 88 | // derived class can move it to public and implement 89 | virtual void LinkCvar( const char *name ); 90 | }; 91 | 92 | #endif // MENU_EDITABLE_H 93 | -------------------------------------------------------------------------------- /controls/Field.h: -------------------------------------------------------------------------------- 1 | /* 2 | Field.h - edit field 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_FIELD_H 18 | #define MENU_FIELD_H 19 | 20 | #include "Editable.h" 21 | 22 | #define UI_MAX_FIELD_LINE 256 23 | 24 | class CMenuField : public CMenuEditable 25 | { 26 | public: 27 | typedef CMenuEditable BaseClass; 28 | 29 | CMenuField(); 30 | void Init( void ) override; 31 | void VidInit( void ) override; 32 | bool KeyDown( int key ) override; 33 | void Draw( void ) override; 34 | void Char( int key ) override; 35 | void UpdateEditable() override; 36 | 37 | bool KeyValueData(const char *key, const char *data) override; 38 | void LinkCvar(const char *name) override 39 | { 40 | CMenuEditable::LinkCvar( name, CVAR_STRING ); 41 | } 42 | 43 | VGUI_DefaultCursor CursorAction() override 44 | { 45 | return dc_ibeam; 46 | } 47 | 48 | void Paste(); 49 | void Clear(); 50 | 51 | void SetBuffer( const char *buffer ) 52 | { 53 | Q_strncpy( szBuffer, buffer, sizeof( szBuffer )); 54 | iCursor = strlen( szBuffer ); 55 | iScroll = g_FontMgr->CutText( font, szBuffer, m_scChSize, iRealWidth, true ); 56 | SetCvarString( szBuffer ); 57 | } 58 | 59 | const char *GetBuffer() 60 | { 61 | return szBuffer; 62 | } 63 | 64 | bool bAllowColorstrings; 65 | bool bHideInput; 66 | bool bNumbersOnly; 67 | CImage szBackground; 68 | int iMaxLength; // can't be more than UI_MAX_FIELD_LINE 69 | 70 | protected: 71 | void _Event( int ev ) override; 72 | 73 | private: 74 | char szBuffer[UI_MAX_FIELD_LINE]; 75 | int iCursor; 76 | int iScroll; 77 | 78 | int iRealWidth; 79 | 80 | bool m_bOverrideOverstrike; 81 | }; 82 | 83 | #endif // MENU_FIELD_H 84 | -------------------------------------------------------------------------------- /controls/Framework.h: -------------------------------------------------------------------------------- 1 | /* 2 | Framework.h -- base menu fullscreen root window 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef FRAMEWORK_H 16 | #define FRAMEWORK_H 17 | 18 | #include "BaseWindow.h" 19 | #include "PicButton.h" 20 | #include "Primitive.h" 21 | 22 | #define MAX_FRAMEWORK_PICBUTTONS 16 23 | 24 | /* 25 | * WON-style menu framework 26 | */ 27 | class CMenuFramework : public CMenuBaseWindow 28 | { 29 | public: 30 | typedef CMenuBaseWindow BaseClass; 31 | 32 | CMenuFramework( const char *name = "Unnamed Framework" ); 33 | virtual ~CMenuFramework() override; 34 | 35 | void Show() override; 36 | void Draw() override; 37 | void Init() final override; 38 | void VidInit() final override; 39 | void Hide() override; 40 | bool IsRoot() const override { return true; } 41 | 42 | bool KeyDown( int key ) override; 43 | 44 | CMenuPicButton *AddButton( const char *szName, const char *szStatus, 45 | EDefaultBtns iButton, CEventCallback onReleased = CEventCallback(), int iFlags = 0 ); 46 | 47 | CMenuPicButton *AddButton( const char *szName, const char *szStatus, 48 | const char *szButtonPath, CEventCallback onReleased = CEventCallback(), int iFlags = 0, int hotkey = 0 ); 49 | 50 | void RealignButtons(); 51 | 52 | bool DrawAnimation() override; 53 | 54 | void PrepareBannerAnimation( EAnimation direction, CMenuPicButton *initiator ); 55 | 56 | class CMenuBannerBitmap : public CMenuBaseItem 57 | { 58 | public: 59 | CMenuBannerBitmap(); 60 | void Draw() override; 61 | void SetPicture( const char *pic ); 62 | 63 | void Draw( Point pt, Size sz ); 64 | 65 | private: 66 | CImage image; 67 | } banner; 68 | 69 | protected: 70 | EAnimation bannerAnimDirection; 71 | Rect bannerRects[2]; 72 | 73 | CMenuPicButton *m_apBtns[MAX_FRAMEWORK_PICBUTTONS]; 74 | int m_iBtnsNum; 75 | }; 76 | 77 | #endif // FRAMEWORK_H 78 | -------------------------------------------------------------------------------- /controls/ItemsHolder.h: -------------------------------------------------------------------------------- 1 | /* 2 | ItemsHolder.h -- an item that can contain and operate with other items 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef EMBEDITEM_H 16 | #define EMBEDITEM_H 17 | 18 | #include "BaseItem.h" 19 | #include "utlvector.h" 20 | 21 | class CMenuItemsHolder : public CMenuBaseItem 22 | { 23 | public: 24 | typedef CMenuBaseItem BaseClass; 25 | 26 | CMenuItemsHolder(); 27 | 28 | // Overload _Init, _VidInit instead of these methods 29 | void Init() override; 30 | void VidInit() override; 31 | 32 | void Reload() override; 33 | bool KeyUp( int key ) override; 34 | bool KeyDown( int key ) override; 35 | void Char( int key ) override; 36 | void ToggleInactive( void ) override; 37 | void SetInactive( bool visible ) override; 38 | void Draw( void ) override; 39 | void Think( void ) override; 40 | 41 | bool MouseMove( int x, int y ) override; 42 | 43 | bool KeyValueData(const char *key, const char *data) override; 44 | 45 | // returns a position where actual items holder is located 46 | virtual Point GetPositionOffset() const; 47 | virtual bool IsWindow() { return false; } 48 | 49 | void CursorMoved( void ); 50 | void SetCursor( int newCursor, bool notify = true ); 51 | void SetCursorToItem( CMenuBaseItem &item, bool notify = true ); 52 | bool AdjustCursor( int dir ); 53 | 54 | void AddItem( CMenuBaseItem &item ); 55 | void RemoveItem( CMenuBaseItem &item ); 56 | CMenuBaseItem *ItemAtCursor( void ); 57 | CMenuBaseItem *ItemAtCursorPrev( void ); 58 | CMenuBaseItem *FindItemByTag( const char *tag ); 59 | inline CMenuBaseItem *GetItemByIndex( int idx ) 60 | { 61 | if( m_pItems.IsValidIndex( idx )) 62 | return m_pItems[idx]; 63 | return NULL; 64 | } 65 | 66 | void CalcItemsPositions(); 67 | void CalcItemsSizes(); 68 | 69 | inline void AddItem( CMenuBaseItem *item ) { AddItem( *item ); } 70 | inline int GetCursor() const { return m_iCursor; } 71 | inline int GetCursorPrev() const { return m_iCursorPrev; } 72 | inline int ItemCount() const { return m_pItems.Count(); } 73 | inline bool WasInit() const { return m_bInit; } 74 | 75 | void SetResourceFilename( const char *filename ) { m_szResFile = filename; } 76 | 77 | void RegisterNamedEvent( CEventCallback ev, const char *name ); 78 | CEventCallback FindEventByName( const char *name ); 79 | 80 | protected: 81 | virtual void _Init() {} 82 | virtual void _VidInit() {} 83 | void VidInitItems(); 84 | 85 | bool LoadRES( const char *filename ); 86 | 87 | int m_iCursor; 88 | int m_iCursorPrev; 89 | 90 | CUtlVector m_pItems; 91 | 92 | // it's unnecessary to register here, it's only for searching events by res file 93 | CUtlVector m_events; 94 | 95 | bool m_bInit; 96 | bool m_bWrapCursor; 97 | 98 | const char *m_szResFile; 99 | private: 100 | bool Key( const int key, const bool down ); 101 | CMenuBaseItem *m_pItemAtCursorOnDown; 102 | 103 | int m_iHotKeyDown; 104 | }; 105 | 106 | #endif // EMBEDITEM_H 107 | -------------------------------------------------------------------------------- /controls/MessageBox.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | MessageBox.cpp -- simple messagebox with text 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "extdll_menu.h" 16 | #include "BaseMenu.h" 17 | #include "Utils.h" 18 | #include "Action.h" 19 | #include "ItemsHolder.h" 20 | #include "MessageBox.h" 21 | 22 | CMenuMessageBox::CMenuMessageBox(const char *name) : BaseClass( name ) 23 | { 24 | iFlags |= QMF_INACTIVE; 25 | } 26 | 27 | void CMenuMessageBox::_Init() 28 | { 29 | background.bForceColor = true; 30 | background.colorBase = uiPromptBgColor; 31 | 32 | dlgMessage.eTextAlignment = QM_CENTER; // center 33 | dlgMessage.iFlags = QMF_INACTIVE|QMF_DROPSHADOW; 34 | dlgMessage.SetCoord( 0, 0 ); 35 | dlgMessage.size = size; 36 | 37 | AddItem( background ); 38 | AddItem( dlgMessage ); 39 | } 40 | 41 | void CMenuMessageBox::SetMessage( const char *sz ) 42 | { 43 | dlgMessage.szName = sz; 44 | } 45 | -------------------------------------------------------------------------------- /controls/MessageBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | MessageBox.h -- simple messagebox with text 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef MESSAGEBOX_H 16 | #define MESSAGEBOX_H 17 | 18 | #include "BaseWindow.h" 19 | #include "Action.h" 20 | 21 | class CMenuMessageBox : public CMenuBaseWindow 22 | { 23 | public: 24 | typedef CMenuBaseWindow BaseClass; 25 | 26 | CMenuMessageBox( const char *name = "Unnamed MessageBox" ); 27 | 28 | void SetMessage( const char *sz ); 29 | private: 30 | void _Init() override; 31 | 32 | CMenuBackgroundBitmap background; 33 | CMenuAction dlgMessage; 34 | }; 35 | 36 | #endif // MESSAGEBOX_H 37 | -------------------------------------------------------------------------------- /controls/MovieBanner.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | #include "MovieBanner.h" 21 | 22 | void CMenuMovieBanner::VidInit() 23 | { 24 | float scaleX = ScreenWidth / 640.0f; 25 | float scaleY = ScreenHeight / 480.0f; 26 | 27 | m_scPos.x = 0; 28 | m_scPos.y = 70 * scaleY * uiStatic.scaleY; // 70 is empirically determined value (magic number) 29 | 30 | // a1ba: multiply by height scale to look better on wide screens 31 | m_scSize.w = EngFuncs::GetLogoWidth() * scaleX; 32 | m_scSize.h = EngFuncs::GetLogoHeight() * scaleY * uiStatic.scaleY; 33 | } 34 | 35 | void CMenuMovieBanner::Draw() 36 | { 37 | if( EngFuncs::ClientInGame() && EngFuncs::GetCvarFloat( "ui_renderworld" )) 38 | return; 39 | 40 | if( EngFuncs::GetLogoLength() <= 0.05f || EngFuncs::GetLogoWidth() <= 32 ) 41 | return; 42 | 43 | EngFuncs::DrawLogo( "logo.avi", m_scPos.x, m_scPos.y, m_scSize.w, m_scSize.h ); 44 | } 45 | -------------------------------------------------------------------------------- /controls/MovieBanner.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #ifndef MOVIE_BANNER_H 22 | #define MOVIE_BANNER_H 23 | #include "BaseItem.h" 24 | 25 | /* 26 | * WON menu compatible movie banner 27 | * Will position itself 28 | */ 29 | class CMenuMovieBanner : public CMenuBaseItem 30 | { 31 | public: 32 | virtual void VidInit() override; 33 | virtual void Draw() override; 34 | }; 35 | 36 | #endif // MOVIE_BANNER_H 37 | -------------------------------------------------------------------------------- /controls/PicButton.h: -------------------------------------------------------------------------------- 1 | /* 2 | PicButton.h - animated button with picture 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | #ifndef MENU_PICBUTTON_H 17 | #define MENU_PICBUTTON_H 18 | 19 | #include "BtnsBMPTable.h" 20 | #include "BaseWindow.h" 21 | 22 | // Use hover bitmap from btns_main.bmp instead of head_%s.bmp 23 | // #define TA_ALT_MODE 1 24 | 25 | // Use banner for animation 26 | #define TA_ALT_MODE2 1 27 | 28 | // Title Transition Time period 29 | #define TTT_PERIOD 200.0f 30 | 31 | class CMenuPicButton : public CMenuBaseItem 32 | { 33 | public: 34 | typedef CMenuBaseItem BaseClass; 35 | 36 | CMenuPicButton(); 37 | bool KeyUp( int key ) override; 38 | bool KeyDown( int key ) override; 39 | void Draw( void ) override; 40 | bool HotKey( int key ) override; 41 | 42 | void SetPicture( EDefaultBtns ID ); 43 | void SetPicture( const char *filename, int hotkey = 0 ); 44 | 45 | bool bEnableTransitions; 46 | bool bPulse; 47 | private: 48 | bool bRollOver; 49 | 50 | void CheckWindowChanged( void ); 51 | void _Event( int ev ) override; 52 | 53 | void DrawButton( int r, int g, int b, int a, wrect_t *rects, int state ); 54 | 55 | HIMAGE hPic; 56 | int hotkey; 57 | int button_id; 58 | int iFocusStartTime; 59 | int iOldState; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /controls/PlayerModelView.h: -------------------------------------------------------------------------------- 1 | /* 2 | PlayerModelView.cpp -- player model view 3 | Copyright (C) 2018 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef CMENUPLAYERMODELVIEW_H 16 | #define CMENUPLAYERMODELVIEW_H 17 | 18 | // HLSDK includes 19 | #include "mathlib.h" 20 | #include "const.h" 21 | #include "keydefs.h" 22 | #include "ref_params.h" 23 | #include "cl_entity.h" 24 | #include "com_model.h" 25 | #include "entity_types.h" 26 | // HLSDK includes end 27 | #include "BaseItem.h" 28 | 29 | class CMenuPlayerModelView : public CMenuBaseItem 30 | { 31 | public: 32 | CMenuPlayerModelView(); 33 | void VidInit() override; 34 | void Draw() override; 35 | bool KeyDown( int key ) override; 36 | bool KeyUp( int key ) override; 37 | void CalcFov(); 38 | 39 | HIMAGE hPlayerImage; 40 | 41 | ref_viewpass_t refdef; 42 | cl_entity_t *ent; 43 | 44 | bool bDrawAsPlayer; 45 | 46 | enum 47 | { 48 | PMV_DONTCARE = 0, 49 | PMV_SHOWMODEL, 50 | PMV_SHOWIMAGE 51 | } eOverrideMode; 52 | 53 | 54 | CColor backgroundColor; 55 | CColor outlineFocusColor; 56 | private: 57 | bool mouseYawControl; 58 | 59 | int prevCursorX, prevCursorY; 60 | }; 61 | 62 | #endif // CMENUPLAYERMODELVIEW_H 63 | -------------------------------------------------------------------------------- /controls/ProgressBar.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | ProgressBar.cpp -- progress bar 3 | Copyright (C) 2017 mittorn 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #include "extdll_menu.h" 17 | #include "BaseMenu.h" 18 | #include "ProgressBar.h" 19 | 20 | CMenuProgressBar::CMenuProgressBar() : BaseClass() 21 | { 22 | m_flMin = 0.0f; 23 | m_flMax = 100.0f; 24 | m_flValue = 0.0f; 25 | m_szCvarName = NULL; 26 | } 27 | 28 | void CMenuProgressBar::LinkCvar( const char *cvName, float flMin, float flMax ) 29 | { 30 | m_szCvarName = cvName; 31 | 32 | m_flMax = flMax; 33 | m_flMin = flMin; 34 | } 35 | 36 | void CMenuProgressBar::SetValue( float flValue ) 37 | { 38 | if( flValue > 1.0f ) flValue = 1; 39 | if( flValue < 0.0f ) flValue = 0; 40 | m_flValue = flValue; 41 | m_szCvarName = NULL; 42 | } 43 | 44 | void CMenuProgressBar::Draw( void ) 45 | { 46 | float flProgress; 47 | 48 | if( m_szCvarName ) 49 | { 50 | flProgress = bound( m_flMin, EngFuncs::GetCvarFloat( m_szCvarName ), m_flMax ); 51 | flProgress = ( flProgress - m_flMin ) / ( m_flMax - m_flMin ); 52 | } 53 | else 54 | { 55 | flProgress = m_flValue; 56 | } 57 | 58 | // draw the background 59 | UI_FillRect( m_scPos, m_scSize, uiInputBgColor ); 60 | 61 | UI_FillRect( m_scPos.x, m_scPos.y, m_scSize.w * flProgress, m_scSize.h, colorBase ); 62 | 63 | // draw the rectangle 64 | UI_DrawRectangle( m_scPos, m_scSize, uiInputFgColor ); 65 | } 66 | -------------------------------------------------------------------------------- /controls/ProgressBar.h: -------------------------------------------------------------------------------- 1 | /* 2 | ProgressBar.h -- progress bar 3 | Copyright (C) 2017 mittorn 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef CMENUPROGRESSBAR_H 16 | #define CMENUPROGRESSBAR_H 17 | 18 | #include "BaseItem.h" 19 | 20 | class CMenuProgressBar : public CMenuBaseItem 21 | { 22 | public: 23 | typedef CMenuBaseItem BaseClass; 24 | 25 | CMenuProgressBar(); 26 | void Draw( void ) override; 27 | void LinkCvar( const char *cvName, float flMin, float flMax ); 28 | void SetValue( float flValue ); 29 | 30 | private: 31 | float m_flMin, m_flMax, m_flValue; 32 | const char *m_szCvarName; 33 | }; 34 | 35 | #endif // CMENUPROGRESSBAR_H 36 | -------------------------------------------------------------------------------- /controls/ScrollView.cpp: -------------------------------------------------------------------------------- 1 | #include "ScrollView.h" 2 | #include "Scissor.h" 3 | 4 | CMenuScrollView::CMenuScrollView() : CMenuItemsHolder (), 5 | m_bHoldingMouse1( false ) 6 | { 7 | } 8 | 9 | void CMenuScrollView::VidInit() 10 | { 11 | colorStroke.SetDefault( uiInputFgColor ); 12 | 13 | BaseClass::VidInit(); 14 | 15 | m_iMax = 0; 16 | m_iPos = 0; 17 | 18 | FOR_EACH_VEC( m_pItems, i ) 19 | { 20 | Point pt = m_pItems[i]->pos; 21 | Size sz = m_pItems[i]->size; 22 | 23 | m_iMax += pt.y + sz.h; 24 | } 25 | m_bDisableScrolling = (m_iMax < size.h); 26 | 27 | m_iMax *= uiStatic.scaleX; 28 | } 29 | 30 | bool CMenuScrollView::KeyDown( int key ) 31 | { 32 | // act when key is pressed or repeated 33 | if( !m_bDisableScrolling ) 34 | { 35 | int newPos = m_iPos; 36 | if( UI::Key::IsUpArrow( key )) 37 | newPos -= 20; 38 | else if( UI::Key::IsDownArrow( key )) 39 | newPos += 20; 40 | else if( UI::Key::IsPageUp( key )) 41 | newPos -= 100; 42 | else if( UI::Key::IsPageDown( key )) 43 | newPos += 100; 44 | else if( UI::Key::IsLeftMouse( key )) 45 | { 46 | // m_bHoldingMouse1 = down != 0; 47 | // m_HoldingPoint = Point( uiStatic.cursorX, uiStatic.cursorY ); 48 | // drag & drop 49 | // scrollbar 50 | } 51 | 52 | // TODO: overscrolling 53 | newPos = bound( 0, newPos, m_iMax - m_scSize.h ); 54 | 55 | // recalc 56 | if( newPos != m_iPos ) 57 | { 58 | m_iPos = newPos; 59 | FOR_EACH_VEC( m_pItems, i ) 60 | { 61 | CMenuBaseItem *pItem = m_pItems[i]; 62 | 63 | pItem->VidInit(); 64 | } 65 | CMenuItemsHolder::MouseMove( uiStatic.cursorX, uiStatic.cursorY ); 66 | } 67 | } 68 | 69 | return CMenuItemsHolder::KeyDown( key ); 70 | } 71 | 72 | Point CMenuScrollView::GetPositionOffset() const 73 | { 74 | return Point( 0, -m_iPos ) + BaseClass::GetPositionOffset(); 75 | } 76 | 77 | bool CMenuScrollView::MouseMove( int x, int y ) 78 | { 79 | return CMenuItemsHolder::MouseMove( x, y ); 80 | } 81 | 82 | bool CMenuScrollView::IsRectVisible(Point pt, Size sz) 83 | { 84 | bool x = isrange( m_scPos.x, pt.x, m_scPos.x + m_scSize.w ) || 85 | isrange( pt.x, m_scPos.x, pt.x + sz.w ); 86 | 87 | bool y = isrange( m_scPos.y, pt.y, m_scPos.y + m_scSize.h ) || 88 | isrange( pt.y, m_scPos.y, pt.y + sz.h ); 89 | 90 | return x && y; 91 | } 92 | 93 | void CMenuScrollView::Draw() 94 | { 95 | if( EngFuncs::KEY_IsDown( K_MOUSE1 ) ) 96 | { 97 | if( !m_bHoldingMouse1 ) 98 | { 99 | m_bHoldingMouse1 = true; 100 | m_HoldingPoint = Point( uiStatic.cursorX, uiStatic.cursorY ); 101 | } 102 | } 103 | else 104 | { 105 | if( m_bHoldingMouse1 ) m_bHoldingMouse1 = false; 106 | } 107 | 108 | if( m_bHoldingMouse1 && !m_bDisableScrolling ) 109 | { 110 | int newPos = m_iPos; 111 | 112 | newPos -= ( uiStatic.cursorY - m_HoldingPoint.y ) / 2; 113 | 114 | // TODO: overscrolling 115 | newPos = bound( 0, newPos, m_iMax - m_scSize.h ); 116 | 117 | // recalc 118 | if( newPos != m_iPos ) 119 | { 120 | m_iPos = newPos; 121 | FOR_EACH_VEC( m_pItems, i ) 122 | { 123 | CMenuBaseItem *pItem = m_pItems[i]; 124 | 125 | pItem->VidInit(); 126 | } 127 | } 128 | m_HoldingPoint = Point( uiStatic.cursorX, uiStatic.cursorY ); 129 | } 130 | 131 | if( bDrawStroke ) 132 | { 133 | UI_DrawRectangleExt( m_scPos, m_scSize, colorStroke, iStrokeWidth ); 134 | } 135 | 136 | int drawn = 0, skipped = 0; 137 | FOR_EACH_VEC( m_pItems, i ) 138 | { 139 | if( !IsRectVisible( m_pItems[i]->GetRenderPosition(), m_pItems[i]->GetRenderSize() ) ) 140 | { 141 | m_pItems[i]->iFlags |= QMF_HIDDENBYPARENT; 142 | skipped++; 143 | } 144 | else 145 | { 146 | m_pItems[i]->iFlags &= ~QMF_HIDDENBYPARENT; 147 | drawn++; 148 | } 149 | } 150 | 151 | Con_NPrintf( 0, "Drawn: %i Skipped: %i", drawn, skipped ); 152 | 153 | UI::Scissor::PushScissor( m_scPos, m_scSize ); 154 | CMenuItemsHolder::Draw(); 155 | UI::Scissor::PopScissor(); 156 | } 157 | -------------------------------------------------------------------------------- /controls/ScrollView.h: -------------------------------------------------------------------------------- 1 | #ifndef SCROLLVIEW_H 2 | #define SCROLLVIEW_H 3 | 4 | #include "ItemsHolder.h" 5 | 6 | class CMenuScrollView : public CMenuItemsHolder 7 | { 8 | typedef CMenuItemsHolder BaseClass; 9 | public: 10 | CMenuScrollView(); 11 | 12 | void VidInit() override; 13 | void Draw() override; 14 | bool KeyDown( int key ) override; 15 | bool MouseMove( int x, int y ) override; 16 | 17 | Point GetPositionOffset() const override; 18 | 19 | private: 20 | bool IsRectVisible( Point pt, Size sz ); 21 | 22 | Point m_scScrollBarPos; 23 | Size m_scScrollBarSize; 24 | bool m_bScrollBarSliding; 25 | bool m_bDisableScrolling; // can't actually scroll due to item placement 26 | bool m_bHoldingMouse1; 27 | Point m_HoldingPoint; 28 | 29 | int m_iPos; 30 | int m_iMax; 31 | // float m_flOverScrolling; 32 | }; 33 | 34 | #endif // SCROLLVIEW_H 35 | -------------------------------------------------------------------------------- /controls/Slider.h: -------------------------------------------------------------------------------- 1 | /* 2 | Slider.h - slider 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_SLIDER_H 18 | #define MENU_SLIDER_H 19 | #define UI_SLIDER_MAIN "gfx/shell/slider" 20 | 21 | #include "Editable.h" 22 | 23 | class CMenuSlider : public CMenuEditable 24 | { 25 | public: 26 | typedef CMenuEditable BaseClass; 27 | 28 | CMenuSlider(); 29 | void VidInit( void ) override; 30 | bool KeyUp( int key ) override; 31 | bool KeyDown( int key ) override; 32 | void Draw( void ) override; 33 | void UpdateEditable() override; 34 | void LinkCvar(const char *name) override 35 | { 36 | CMenuEditable::LinkCvar(name, CVAR_VALUE); 37 | } 38 | 39 | void Setup( float minValue, float maxValue, float range ) 40 | { 41 | m_flMinValue = minValue; 42 | m_flMaxValue = maxValue; 43 | m_flRange = range; 44 | } 45 | void SetCurrentValue( float curValue ) 46 | { 47 | m_flCurValue = curValue > m_flMaxValue ? m_flMaxValue : 48 | ( curValue < m_flMinValue ? m_flMinValue : curValue ); 49 | } 50 | 51 | float GetCurrentValue() { return m_flCurValue; } 52 | // void SetDrawStep( float drawStep, int numSteps ); 53 | 54 | void SetKeepSlider( int keepSlider ) { m_iKeepSlider = keepSlider; } 55 | 56 | CImage imgSlider; 57 | private: 58 | float m_flMinValue; 59 | float m_flMaxValue; 60 | float m_flCurValue; 61 | float m_flDrawStep; 62 | int m_iNumSteps; 63 | float m_flRange; 64 | int m_iKeepSlider; // when mouse button is holds 65 | 66 | int m_iSliderOutlineWidth; 67 | Size m_scCenterBox; 68 | }; 69 | 70 | #endif // MENU_SLIDER_H 71 | -------------------------------------------------------------------------------- /controls/SpinControl.h: -------------------------------------------------------------------------------- 1 | /* 2 | SpinControl.h - spin selector 3 | Copyright (C) 2010 Uncle Mike 4 | Copyright (C) 2017 a1batross 5 | 6 | This program is free software: you can redistribute it and/or modify 7 | it under the terms of the GNU General Public License as published by 8 | the Free Software Foundation, either version 3 of the License, or 9 | (at your option) any later version. 10 | 11 | This program is distributed in the hope that it will be useful, 12 | but WITHOUT ANY WARRANTY; without even the implied warranty of 13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 | GNU General Public License for more details. 15 | */ 16 | 17 | #ifndef MENU_SPINCONTROL_H 18 | #define MENU_SPINCONTROL_H 19 | 20 | #include "Editable.h" 21 | #include "BaseArrayModel.h" 22 | 23 | class CMenuSpinControl : public CMenuEditable 24 | { 25 | public: 26 | typedef CMenuEditable BaseClass; 27 | 28 | CMenuSpinControl(); 29 | 30 | void VidInit( void ) override; 31 | bool KeyUp( int key ) override; 32 | bool KeyDown( int key ) override; 33 | void Draw( void ) override; 34 | void UpdateEditable() override; 35 | 36 | void Setup( CMenuBaseArrayModel *model ); 37 | void Setup( float minValue, float maxValue, float range ); 38 | 39 | void SetDisplayPrecision( short precision ); 40 | 41 | void SetCurrentValue( const char *stringValue ); 42 | void SetCurrentValue( float curValue ); 43 | 44 | float GetCurrentValue( ) { return m_flCurValue; } 45 | const char *GetCurrentString( ) { return m_pModel ? m_pModel->GetText( (int)m_flCurValue ) : NULL; } 46 | 47 | void ForceDisplayString( const char *display ); 48 | 49 | private: 50 | const char *MoveLeft(); 51 | const char *MoveRight(); 52 | void Display(); 53 | 54 | CImage m_szBackground; 55 | CImage m_szLeftArrow; 56 | CImage m_szRightArrow; 57 | CImage m_szLeftArrowFocus; 58 | CImage m_szRightArrowFocus; 59 | float m_flMinValue; 60 | float m_flMaxValue; 61 | float m_flCurValue; 62 | float m_flRange; 63 | 64 | CMenuBaseArrayModel *m_pModel; 65 | short m_iFloatPrecision; 66 | 67 | char m_szDisplay[CS_SIZE]; 68 | }; 69 | 70 | #endif // MENU_SPINCONTROL_H 71 | -------------------------------------------------------------------------------- /controls/Switch.h: -------------------------------------------------------------------------------- 1 | /* 2 | Switch.h - simple switches, like Android 4.0+ 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | #ifndef SWITCH_H 21 | #define SWITCH_H 22 | 23 | #include "Editable.h" 24 | 25 | class CMenuSwitch : public CMenuEditable 26 | { 27 | public: 28 | typedef CMenuEditable BaseClass; 29 | 30 | CMenuSwitch(); 31 | 32 | bool KeyDown( int key ) override; 33 | bool KeyUp( int key ) override; 34 | void VidInit() override; 35 | void Draw() override; 36 | void UpdateEditable() override; 37 | void LinkCvar( const char *name ) override 38 | { 39 | CMenuEditable::LinkCvar( name, CMenuEditable::CVAR_VALUE ); 40 | } 41 | void AddSwitch( const char *text ); 42 | 43 | int GetState() { return m_iState; } 44 | void SetState( int state ); 45 | 46 | bool bMouseToggle; 47 | bool bKeepToggleWidth; 48 | bool bChangeOnPressed; 49 | 50 | CColor iSelectColor; 51 | CColor iBackgroundColor; 52 | CColor iFgTextColor; 53 | CColor iBgTextColor; 54 | 55 | float fTextOffsetX; 56 | float fTextOffsetY; 57 | private: 58 | int IsNewStateByMouseClick( void ); 59 | int m_iState; 60 | 61 | struct switch_t 62 | { 63 | const char *name; 64 | Point pt; 65 | Size sz; 66 | }; 67 | 68 | CUtlVector m_switches; 69 | Point m_scTextPos; 70 | Size m_scTextSize; 71 | }; 72 | 73 | 74 | #endif // SWITCH_H 75 | -------------------------------------------------------------------------------- /controls/TabView.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | TabView.cpp -- tabbed view 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "TabView.h" 16 | #include "Scissor.h" 17 | 18 | CMenuTabView::CMenuTabView() : BaseClass() 19 | { 20 | m_bWrapCursor = true; 21 | SetCharSize( QM_BOLDFONT ); 22 | eTextAlignment = QM_CENTER; 23 | } 24 | 25 | Point CMenuTabView::GetPositionOffset() const 26 | { 27 | Point ret = m_scPos; 28 | ret.y += m_scChSize * 1.5f; 29 | 30 | return ret; 31 | } 32 | 33 | void CMenuTabView::VidInit() 34 | { 35 | CalcPosition(); 36 | CalcSizes(); 37 | 38 | _VidInit(); 39 | VidInitItems(); 40 | 41 | m_szTab.w = m_scSize.w / m_pItems.Count(); 42 | m_szTab.h = m_scChSize * 1.5f; 43 | } 44 | 45 | void CMenuTabView::DrawTab(Point pt, const char *name, bool isEnd, bool isSelected, bool isHighlighted) 46 | { 47 | uint textColor = uiInputTextColor; 48 | uint fillColor = uiColorBlack; 49 | uint textflags = ( iFlags & QMF_DROPSHADOW ) ? ETF_SHADOW : 0; 50 | 51 | if( isSelected && !isHighlighted ) 52 | { 53 | fillColor = uiInputBgColor; 54 | textColor = uiInputFgColor; 55 | } 56 | else if( isHighlighted ) 57 | { 58 | textColor = uiPromptFocusColor; 59 | } 60 | 61 | UI_FillRect( pt, m_szTab, fillColor ); 62 | UI_DrawString( font, pt, m_szTab, name, textColor, m_scChSize, eTextAlignment, textflags ); 63 | 64 | if( !isEnd ) 65 | { 66 | int x = pt.x + m_szTab.w; 67 | int y = pt.y - UI_OUTLINE_WIDTH; 68 | int w = UI_OUTLINE_WIDTH; 69 | int h = m_szTab.h + UI_OUTLINE_WIDTH + UI_OUTLINE_WIDTH; 70 | 71 | // draw right 72 | UI_FillRect( x, y, w, h, uiColorHelp ); 73 | } 74 | } 75 | 76 | void CMenuTabView::Draw() 77 | { 78 | // draw frame first 79 | UI_DrawRectangle( m_scPos, m_scSize, uiColorHelp ); 80 | 81 | // draw tabs 82 | Point tabOffset = m_scPos; 83 | FOR_EACH_VEC( m_pItems, i ) 84 | { 85 | bool isEnd = i == ( m_pItems.Count() - 1 ); 86 | bool isHighlighted = UI_CursorInRect( tabOffset, m_szTab ); 87 | bool isSelected = i == m_iCursor; 88 | 89 | DrawTab( tabOffset, m_pItems[i]->szName, isEnd, isSelected, isHighlighted ); 90 | tabOffset.x += m_szTab.w; 91 | } 92 | 93 | Point contentOffset = Point( m_scPos.x, m_scPos.y + m_scChSize * 1.5f ); 94 | Size contentSize = Size( m_scSize.w, m_scSize.h - m_scChSize * 1.5f ); 95 | 96 | // draw line after tab 97 | UI_FillRect( contentOffset.x, contentOffset.y, 98 | m_scSize.w, UI_OUTLINE_WIDTH, uiColorHelp ); 99 | 100 | // fill background 101 | UI_FillRect( contentOffset, contentSize, uiColorBlack ); 102 | 103 | // draw contents 104 | if( m_iCursor >= 0 && m_iCursor < m_pItems.Count() ) 105 | { 106 | UI::Scissor::PushScissor( contentOffset, contentSize ); 107 | m_pItems[m_iCursor]->Draw(); 108 | UI::Scissor::PopScissor(); 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /controls/TabView.h: -------------------------------------------------------------------------------- 1 | /* 2 | TabView.cpp -- tabbed view 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef TABWIDGET_H 16 | #define TABWIDGET_H 17 | 18 | #include "ItemsHolder.h" 19 | 20 | class CMenuTabView : public CMenuItemsHolder 21 | { 22 | public: 23 | typedef CMenuItemsHolder BaseClass; 24 | CMenuTabView(); 25 | 26 | void VidInit() override; 27 | void Draw() override; 28 | Point GetPositionOffset() const override; 29 | 30 | inline void SetTabName( int idx, const char *name ) 31 | { 32 | if( m_pItems.IsValidIndex( idx )) 33 | m_pItems[idx]->szName = name; 34 | } 35 | 36 | inline void AddTabItem( CMenuBaseItem &item, const char *name ) 37 | { 38 | AddItem( item ); 39 | SetTabName( m_pItems.Count() - 1, name ); 40 | } 41 | 42 | private: 43 | void DrawTab(Point pt, const char *name, bool isEnd , bool isSelected, bool isHighlighted); 44 | 45 | Size m_szTab; 46 | }; 47 | 48 | #endif // TABWIDGET_H 49 | -------------------------------------------------------------------------------- /controls/YesNoMessageBox.h: -------------------------------------------------------------------------------- 1 | /* 2 | YesNoMessageBox.h - simple generic yes/no message box 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef MENU_GENERICMSGBOX_H 17 | #define MENU_GENERICMSGBOX_H 18 | 19 | #include "PicButton.h" 20 | #include "Action.h" 21 | #include "ItemsHolder.h" 22 | #include "BaseWindow.h" 23 | 24 | class CMenuYesNoMessageBox : public CMenuBaseWindow 25 | { 26 | public: 27 | typedef CMenuBaseWindow BaseClass; 28 | CMenuYesNoMessageBox( bool alert = false ); 29 | 30 | void _Init() override; 31 | void _VidInit() override; 32 | void Draw() override; 33 | bool KeyDown( int key ) override; 34 | void SetMessage( const char *msg ); 35 | void SetPositiveButton( const char *msg, EDefaultBtns buttonPic, int extrawidth = 0 ); 36 | void SetNegativeButton( const char *msg, EDefaultBtns buttonPic, int extrawidth = 0 ); 37 | enum EHighlight 38 | { 39 | NO_HIGHLIGHT = 0, 40 | HIGHLIGHT_YES, 41 | HIGHLIGHT_NO 42 | }; 43 | void HighlightChoice( EHighlight ch ); 44 | 45 | // Pass pointer to messagebox to extra of calling object 46 | CEventCallback MakeOpenEvent(); 47 | 48 | CEventCallback onPositive; 49 | CEventCallback onNegative; 50 | 51 | bool bAutoHide; 52 | CMenuBackgroundBitmap background; 53 | CMenuAction dlgMessage1; 54 | CMenuPicButton yes; 55 | CMenuPicButton no; 56 | 57 | private: 58 | static void OpenCb( CMenuBaseItem *, void *pExtra ); 59 | 60 | bool m_bSetYes, m_bSetNo; 61 | bool m_bIsAlert; 62 | }; 63 | 64 | #endif // MENU_GENERICMSGBOX_H 65 | -------------------------------------------------------------------------------- /exports.txt: -------------------------------------------------------------------------------- 1 | GetMenuAPI 2 | GetExtAPI 3 | -------------------------------------------------------------------------------- /extdll_menu.h: -------------------------------------------------------------------------------- 1 | /* 2 | extdll.h - must be included into the all ui files 3 | Copyright (C) 2010 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef EXTDLL_H 17 | #define EXTDLL_H 18 | 19 | #include "xash3d_types.h" 20 | 21 | #ifndef EXPORT 22 | #ifdef _WIN32 23 | #define EXPORT __declspec(dllexport) 24 | #elif defined(__GNUC__) 25 | #define EXPORT __attribute__((visibility("default"))) 26 | #else 27 | #define EXPORT 28 | #endif 29 | #endif 30 | 31 | // shut-up compiler warnings 32 | #ifdef _MSC_VER 33 | #pragma warning(disable : 4305) // int or float data truncation 34 | #pragma warning(disable : 4201) // nameless struct/union 35 | #pragma warning(disable : 4514) // unreferenced inline function removed 36 | #pragma warning(disable : 4100) // unreferenced formal parameter 37 | #pragma warning(disable : 4244) // conversion from 'float' to 'int', possible loss of data 38 | #pragma warning(disable : 4520) // multiple default constructors specified 39 | #pragma warning(disable : 4996) // This function or variable may be unsafe 40 | // disable c++11 on old msvc 41 | #if _MSC_VER < 1800 && !defined MY_COMPILER_SUCKS 42 | #define MY_COMPILER_SUCKS 43 | #endif 44 | #endif 45 | // Misc C-runtime library headers 46 | #include 47 | #include 48 | #include 49 | #include 50 | #include 51 | #include 52 | 53 | #ifdef MY_COMPILER_SUCKS 54 | // C++11 keywords 55 | #define final 56 | #define constexpr 57 | #define override 58 | #define nullptr NULL 59 | #endif 60 | 61 | #ifdef bound 62 | #undef bound 63 | #endif 64 | 65 | #ifndef FALSE 66 | #define FALSE 0 67 | #endif 68 | 69 | #ifndef TRUE 70 | #define TRUE (!FALSE) 71 | #endif 72 | 73 | #if !defined(_WIN32) && !defined(__MINGW32__) 74 | #define stricmp strcasecmp 75 | #define strnicmp strncasecmp 76 | #else 77 | #define strnicmp _strnicmp 78 | #define stricmp _stricmp 79 | #define snprintf _snprintf 80 | #endif 81 | 82 | typedef int (*cmpfunc)( const void *a, const void *b ); 83 | typedef int BOOL; 84 | typedef int qboolean; 85 | typedef unsigned char byte; 86 | typedef unsigned int uint; 87 | typedef unsigned int uint32; //!!! 88 | 89 | #include "menu_int.h" 90 | 91 | #endif//EXTDLL_H 92 | -------------------------------------------------------------------------------- /font/BaseFontBackend.h: -------------------------------------------------------------------------------- 1 | /* 2 | BaseFontBackend.h - common font renderer backend code 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #ifndef BASEFONT_H 17 | #define BASEFONT_H 18 | 19 | // #include "port.h" // defines XASH_MOBILE_PLATFORM 20 | #include "BaseMenu.h" 21 | #include "utlrbtree.h" 22 | 23 | // #ifdef XASH_MOBILE_PLATFORM 24 | #if defined(__ANDROID__) || TARGET_OS_IPHONE || defined(XASH_SAILFISH) || defined(MAINUI_FONT_SCALE) 25 | #define SCALE_FONTS 26 | #endif 27 | 28 | struct charRange_t 29 | { 30 | int chMin; 31 | int chMax; 32 | const int *sequence; 33 | int size; 34 | 35 | size_t Length() const 36 | { 37 | if( sequence ) 38 | return size; 39 | return chMax - chMin; 40 | } 41 | 42 | int Character( size_t pos ) 43 | { 44 | if( sequence ) 45 | return sequence[pos]; 46 | return chMin + pos; 47 | } 48 | }; 49 | 50 | class CBaseFont 51 | { 52 | public: 53 | CBaseFont(); 54 | virtual ~CBaseFont( ); 55 | 56 | virtual bool Create( 57 | const char *name, 58 | int tall, int weight, 59 | int blur, float brighten, 60 | int outlineSize, 61 | int scanlineOffset, float scanlineScale, 62 | int flags ) = 0; 63 | virtual void GetCharRGBA( int ch, Point pt, Size sz, byte *rgba, Size &drawSize ) = 0; 64 | virtual void GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) = 0; 65 | virtual bool HasChar( int ch ) const = 0; 66 | virtual const char *GetBackendName() const = 0; 67 | virtual void GetCharABCWidths( int ch, int &a, int &b, int &c ); 68 | virtual void UploadGlyphsForRanges( charRange_t *range, int rangeSize ); 69 | virtual int DrawCharacter(int ch, Point pt, int charH, const unsigned int color, bool forceAdditive = false); 70 | 71 | inline int GetHeight() const { return m_iHeight + GetEfxOffset(); } 72 | inline int GetTall() const { return m_iTall; } 73 | inline const char *GetName() const { return m_szName; } 74 | inline int GetAscent() const { return m_iAscent; } 75 | inline int GetMaxCharWidth() const { return m_iMaxCharWidth; } 76 | inline int GetFlags() const { return m_iFlags; } 77 | inline int GetWeight() const { return m_iWeight; } 78 | inline int GetEfxOffset() const { return m_iBlur + m_iOutlineSize; } 79 | 80 | bool IsEqualTo( const char *name, int tall, int weight, int blur, int flags ) const; 81 | 82 | void DebugDraw(); 83 | 84 | void GetTextureName(char *dst, size_t len) const; 85 | 86 | inline int GetEllipsisWide( ) { return m_iEllipsisWide; } 87 | 88 | protected: 89 | void ApplyBlur( Size rgbaSz, byte *rgba ); 90 | void ApplyOutline(Point pt, Size rgbaSz, byte *rgba ); 91 | void ApplyScanline( Size rgbaSz, byte *rgba ); 92 | void ApplyStrikeout( Size rgbaSz, byte *rgba ); 93 | 94 | char m_szName[32]; 95 | int m_iTall, m_iWeight, m_iFlags, m_iHeight, m_iMaxCharWidth; 96 | int m_iAscent; 97 | bool m_bAdditive; 98 | 99 | // blurring 100 | int m_iBlur; 101 | float m_fBrighten; 102 | 103 | // Scanlines 104 | int m_iScanlineOffset; 105 | float m_fScanlineScale; 106 | 107 | // Outlines 108 | int m_iOutlineSize; 109 | int m_iEllipsisWide; 110 | 111 | private: 112 | bool ReadFromCache( const char *filename, charRange_t *range, size_t rangeSize ); 113 | void SaveToCache( const char *filename, charRange_t *range, size_t rangeSize, CBMP *bmp ); 114 | 115 | void GetBlurValueForPixel( double *distribution, const byte *src, Point srcPt, Size srcSz, byte *dest ); 116 | 117 | struct glyph_t 118 | { 119 | glyph_t() : ch( 0 ), texture( 0 ), rect() { } 120 | glyph_t( int ch ) : ch( ch ), texture( 0 ), rect() { } 121 | int ch; 122 | HIMAGE texture; 123 | wrect_t rect; 124 | 125 | bool operator< (const glyph_t &a) const 126 | { 127 | return ch < a.ch; 128 | } 129 | }; 130 | 131 | struct abc_t 132 | { 133 | int ch; 134 | int a, b, c; 135 | 136 | bool operator< ( const abc_t &a ) const 137 | { 138 | return ch < a.ch; 139 | } 140 | }; 141 | 142 | CUtlRBTree m_glyphs; 143 | CUtlRBTree m_ABCCache; 144 | 145 | char m_szTextureName[256]; 146 | friend class CFontManager; 147 | }; 148 | 149 | 150 | #endif // BASEFONT_H 151 | -------------------------------------------------------------------------------- /font/BitmapFont.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | BitmapFont.cpp - bitmap font backend 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #include "BaseMenu.h" 17 | #include "BaseFontBackend.h" 18 | #include "BitmapFont.h" 19 | 20 | CBitmapFont::CBitmapFont() : CBaseFont(), hImage( 0 ) { } 21 | CBitmapFont::~CBitmapFont() { } 22 | #ifndef MAINUI_FORCE_CONSOLE_BITMAP_FONT 23 | #include "menufont.h" 24 | #endif 25 | 26 | #ifndef MAINUI_CONSOLE_FONT_HEIGHT 27 | // redefine in specific ports 28 | #define MAINUI_CONSOLE_FONT_HEIGHT 10 29 | #endif 30 | bool CBitmapFont::Create(const char *name, int tall, int weight, int blur, float brighten, int outlineSize, int scanlineOffset, float scanlineScale, int flags) 31 | { 32 | Q_strncpy( m_szName, name, sizeof( m_szName ) ); 33 | m_iHeight = m_iTall = tall; 34 | m_iWeight = weight; 35 | m_iFlags = flags; 36 | 37 | m_iBlur = blur; 38 | m_fBrighten = brighten; 39 | 40 | m_iOutlineSize = outlineSize; 41 | 42 | m_iScanlineOffset = scanlineOffset; 43 | m_fScanlineScale = scanlineScale; 44 | m_iAscent = 0; 45 | m_iMaxCharWidth = 0; 46 | #ifndef MAINUI_FORCE_CONSOLE_BITMAP_FONT 47 | if( tall > UI_CONSOLE_CHAR_HEIGHT * uiStatic.scaleY ) 48 | { 49 | hImage = EngFuncs::PIC_Load( "#XASH_SYSTEMFONT_001.bmp", menufont_bmp, sizeof( menufont_bmp ), 0 ); 50 | iImageWidth = EngFuncs::PIC_Width( hImage ); 51 | iImageHeight = EngFuncs::PIC_Height( hImage ); 52 | } 53 | else 54 | #endif 55 | m_iHeight = m_iTall = MAINUI_CONSOLE_FONT_HEIGHT; 56 | int a, c; 57 | GetCharABCWidths( '.', a, m_iEllipsisWide, c ); 58 | m_iEllipsisWide *= 3; 59 | 60 | return true; 61 | } 62 | 63 | void CBitmapFont::GetCharRGBA(int ch, Point pt, Size sz, byte *rgba, Size &drawSize) 64 | { 65 | 66 | } 67 | 68 | void CBitmapFont::GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) 69 | { 70 | // static font not uses cache 71 | return; 72 | } 73 | 74 | void CBitmapFont::GetCharABCWidths(int ch, int &a, int &b, int &c) 75 | { 76 | a = c = 0; 77 | if( hImage ) 78 | b = m_iHeight/2-1; 79 | else 80 | { 81 | char str[2] = {(char)ch, 0}; 82 | EngFuncs::engfuncs.pfnDrawConsoleStringLen( str, &b, NULL ); 83 | } 84 | } 85 | 86 | bool CBitmapFont::HasChar(int ch) const 87 | { 88 | if( ( ch >= 33 && ch <= 126 ) // ascii 89 | || ( ch >= 0x0400 && ch <= 0x045F ) ) // cyrillic 90 | return true; 91 | return false; 92 | } 93 | 94 | void CBitmapFont::UploadGlyphsForRanges(charRange_t *range, int rangeSize) 95 | { 96 | 97 | } 98 | 99 | int CBitmapFont::DrawCharacter(int ch, Point pt, int charH, const unsigned int color, bool forceAdditive) 100 | { 101 | // let's say we have twice lower width from height 102 | // cp1251 now 103 | if( ch >= 0x0410 && ch <= 0x042F ) 104 | ch = ch - 0x410 + 0xC0; 105 | if( ch >= 0x0430 && ch <= 0x044F ) 106 | ch = ch - 0x430 + 0xE0; 107 | else 108 | { 109 | int i; 110 | for( i = 0; i < 64; i++ ) 111 | if( table_cp1251[i] == ch ) 112 | ch = i + 0x80; 113 | } 114 | 115 | // Draw character doesn't works with alpha override 116 | // EngFuncs::DrawCharacter( pt.x, pt.y, sz.h / 2, sz.h, ch, (int)iColor, hImage ); 117 | 118 | if( hImage ) 119 | { 120 | EngFuncs::PIC_Set( hImage, Red( color ), Green( color ), Blue( color ), Alpha( color )); 121 | 122 | float row, col, size; 123 | col = (ch & 15) * 0.0625f + (0.5f / 256.0f); 124 | row = (ch >> 4) * 0.0625f + (0.5f / 256.0f); 125 | size = 0.0625f - (1.0f / 256.0f); 126 | 127 | 128 | wrect_t rc; 129 | int w, h; 130 | w = iImageWidth; 131 | h = iImageHeight; 132 | 133 | rc.top = h * row; 134 | rc.left = w * col; 135 | rc.bottom = rc.top + h * size; 136 | rc.right = rc.left + w * size; 137 | 138 | if( forceAdditive ) 139 | EngFuncs::PIC_DrawAdditive( pt.x, pt.y, charH/2, charH, &rc ); 140 | else 141 | EngFuncs::PIC_DrawTrans( pt.x, pt.y, charH/2, charH, &rc ); 142 | 143 | return charH/2-1; 144 | 145 | } 146 | else 147 | { 148 | char str[2] = {(char)ch, 0}; 149 | EngFuncs::engfuncs.pfnDrawSetTextColor( Red( color ), Green( color ), Blue( color ), Alpha( color ) ); 150 | 151 | return EngFuncs::engfuncs.pfnDrawConsoleString( pt.x, pt.y, str ) - pt.x; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /font/BitmapFont.h: -------------------------------------------------------------------------------- 1 | /* 2 | BitmapFont.h - bitmap font backend 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #ifndef BITMAPFONT_H 17 | #define BITMAPFONT_H 18 | 19 | #include "BaseFontBackend.h" 20 | 21 | class CBitmapFont : public CBaseFont 22 | { 23 | public: 24 | CBitmapFont(); 25 | ~CBitmapFont() override; 26 | 27 | bool Create( const char *name, 28 | int tall, int weight, 29 | int blur, float brighten, 30 | int outlineSize, 31 | int scanlineOffset, float scanlineScale, 32 | int flags ) override; 33 | void GetCharRGBA( int ch, Point pt, Size sz, byte *rgba, Size &drawSize ) override; 34 | void GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) override; 35 | void GetCharABCWidths( int ch, int &a, int &b, int &c ) override; 36 | bool HasChar( int ch ) const override; 37 | const char *GetBackendName() const override { return "bitmap"; } 38 | 39 | void UploadGlyphsForRanges( charRange_t *range, int rangeSize ) override; 40 | int DrawCharacter(int ch, Point pt, int charH, const unsigned int color, bool forceAdditive = false) override; 41 | private: 42 | HIMAGE hImage; 43 | int iImageWidth, iImageHeight; 44 | }; 45 | 46 | #endif // BITMAPFONT_H 47 | -------------------------------------------------------------------------------- /font/FontManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | FontManager.h - font manager 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #ifndef FONTMANAGER_H 17 | #define FONTMANAGER_H 18 | 19 | #include "utlvector.h" 20 | #include "utlhashmap.h" 21 | #include "utlstring.h" 22 | #include "Primitive.h" 23 | #include "FontRenderer.h" 24 | 25 | class CBaseFont; 26 | 27 | /* 28 | * Font manager is used for creating and operating with fonts 29 | **/ 30 | class CFontManager 31 | { 32 | public: 33 | CFontManager(); 34 | ~CFontManager(); 35 | 36 | void VidInit(); 37 | 38 | void DeleteAllFonts(); 39 | void DeleteFont( HFont hFont ); 40 | 41 | HFont GetFontByName( const char *name ); 42 | void GetCharABCWide( HFont font, int ch, int &a, int &b, int &c ); 43 | int GetFontTall( HFont font ); 44 | int GetFontAscent( HFont font ); 45 | bool GetFontUnderlined( HFont font ); 46 | 47 | int GetCharacterWidthScaled(HFont font, int ch, int charH ); 48 | 49 | void GetTextSize( HFont font, const char *text, int *wide, int *tall = NULL, int size = -1 ); 50 | 51 | // simplified version, counts only newlines 52 | int GetTextHeight( HFont font, const char *text, int size = -1 ); 53 | int GetTextHeightExt( HFont font, const char *text, int height, int visibleWidth, int size = -1 ); 54 | 55 | /* 56 | * Determine how text should be cut, to fit in "visibleWidth" 57 | * NOTE: this function DOES NOT work with multi-line strings 58 | * 59 | * If reverse is set, return value will indicate starting index, because ending index is always at string index 60 | * If reverse is NOT set, return value will indicate ending index, because starting index is always at 0 61 | */ 62 | int CutText(HFont fontHandle, const char *text, int height, int visibleSize, bool reverse, bool stopAtWhitespace = false, int *width = NULL, bool *remaining = NULL ); 63 | 64 | int GetTextWideScaled( HFont font, const char *text, const int height, int size = -1 ); 65 | 66 | int DrawCharacter( HFont font, int ch, Point pt, int charH, const unsigned int color, bool forceAdditive = false ); 67 | 68 | void DebugDraw( HFont font ); 69 | CBaseFont *GetIFontFromHandle( HFont font ); 70 | 71 | int GetEllipsisWide( HFont font ); // cached wide of "..." 72 | 73 | bool FindFontDataFile( const char *name, int tall, int weight, int flags, char *dataFile, size_t dataFileChars ); 74 | unsigned char *LoadFontDataFile( const char *virtualpath, int *length = nullptr ); 75 | private: 76 | int GetCharacterWidth( HFont font, int ch ); 77 | int GetTextWide( HFont font, const char *text, int size = -1 ); 78 | 79 | void UploadTextureForFont(CBaseFont *font ); 80 | 81 | CUtlVector m_Fonts; 82 | struct font_file 83 | { 84 | int length; 85 | unsigned char *data; 86 | }; 87 | CUtlHashMap m_FontFiles; 88 | 89 | friend class CFontBuilder; 90 | }; 91 | 92 | // lazy to fix code everywhere 93 | #ifndef CLIENT_DLL 94 | extern CFontManager *g_FontMgr; 95 | #endif 96 | 97 | #endif // FONTMANAGER_H 98 | -------------------------------------------------------------------------------- /font/FontRenderer.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef FONT_RENDERER_H 3 | #define FONT_RENDERER_H 4 | 5 | typedef int HFont; // handle to a font 6 | 7 | enum EFontFlags 8 | { 9 | FONT_NONE = 0, 10 | FONT_ITALIC = 1 << 0, 11 | FONT_UNDERLINE = 1 << 1, 12 | FONT_STRIKEOUT = 1 << 2 13 | }; 14 | #ifndef MAINUI_SMALL_SCREEN 15 | #define UI_CONSOLE_CHAR_WIDTH 9 16 | #define UI_CONSOLE_CHAR_HEIGHT 18 17 | 18 | #define UI_SMALL_CHAR_WIDTH 10 19 | #define UI_SMALL_CHAR_HEIGHT 20 20 | 21 | #define UI_MED_CHAR_WIDTH 13 22 | #define UI_MED_CHAR_HEIGHT 26 23 | 24 | #ifdef CS16CLIENT 25 | #define UI_BIG_CHAR_WIDTH 25 26 | #define UI_BIG_CHAR_HEIGHT 50 27 | #else 28 | #define UI_BIG_CHAR_WIDTH 20 29 | #define UI_BIG_CHAR_HEIGHT 40 30 | #endif // CS16CLIENT 31 | #else // MAINUI_SMALL_SCREEN 32 | 33 | #define UI_CONSOLE_CHAR_WIDTH 30 34 | #define UI_CONSOLE_CHAR_HEIGHT 60 35 | 36 | #define UI_SMALL_CHAR_WIDTH 30 37 | #define UI_SMALL_CHAR_HEIGHT 60 38 | 39 | #define UI_MED_CHAR_WIDTH 35 40 | #define UI_MED_CHAR_HEIGHT 70 41 | 42 | #define UI_BIG_CHAR_WIDTH 35 43 | #define UI_BIG_CHAR_HEIGHT 70 44 | #endif 45 | 46 | 47 | enum EFontSizes 48 | { 49 | #ifdef CLIENT_DLL // hack! 50 | QM_DEFAULTFONT = 1, // medium size font 51 | #else 52 | QM_DEFAULTFONT = 0, // medium size font 53 | #endif 54 | QM_SMALLFONT, // small 55 | QM_BIGFONT, // big 56 | QM_BOLDFONT, 57 | }; 58 | 59 | class CFontBuilder 60 | { 61 | public: 62 | CFontBuilder( const char *name, int tall, int weight ) 63 | { 64 | m_szName = name; 65 | m_iTall = tall; 66 | m_iWeight = weight; 67 | 68 | m_iFlags = FONT_NONE; 69 | m_iBlur = m_iScanlineOffset = m_iOutlineSize = 0; 70 | m_hForceHandle = -1; 71 | 72 | m_fScanlineScale = 0.7f; 73 | m_fBrighten = 1.0f; 74 | } 75 | 76 | CFontBuilder &SetBlurParams( int blur, float brighten = 1.0f ) 77 | { 78 | m_iBlur = blur; 79 | m_fBrighten = brighten; 80 | return *this; 81 | } 82 | 83 | CFontBuilder &SetOutlineSize( int outlineSize = 1 ) 84 | { 85 | m_iOutlineSize = outlineSize; 86 | return *this; 87 | } 88 | 89 | CFontBuilder &SetScanlineParams( int offset = 2, float scale = 0.7f ) 90 | { 91 | m_iScanlineOffset = offset; 92 | m_fScanlineScale = scale; 93 | return *this; 94 | } 95 | 96 | CFontBuilder &SetFlags( int flags ) 97 | { 98 | m_iFlags = flags; 99 | return *this; 100 | } 101 | 102 | HFont Create(); 103 | 104 | private: 105 | CFontBuilder &SetHandleNum( HFont num ) // restricted only for FontManager 106 | { 107 | m_hForceHandle = num; 108 | return *this; 109 | } 110 | 111 | const char *m_szName; 112 | int m_iTall, m_iWeight, m_iFlags; 113 | int m_iBlur; 114 | float m_fBrighten; 115 | 116 | int m_iOutlineSize; 117 | 118 | int m_iScanlineOffset; 119 | float m_fScanlineScale; 120 | HFont m_hForceHandle; 121 | friend class CFontManager; 122 | }; 123 | 124 | 125 | #endif // FONT_RENDERER_H 126 | -------------------------------------------------------------------------------- /font/FreeTypeFont.h: -------------------------------------------------------------------------------- 1 | /* 2 | FreeTypeFont.h -- freetype2 font renderer 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #if !defined( _WIN32 ) && !defined( FREETYPEFONT_H ) 17 | #define FREETYPEFONT_H 18 | 19 | #if defined(MAINUI_USE_CUSTOM_FONT_RENDER) && defined(MAINUI_USE_FREETYPE) 20 | 21 | #include "BaseFontBackend.h" 22 | 23 | extern "C" 24 | { 25 | #include 26 | #include FT_FREETYPE_H 27 | } 28 | 29 | #include "utlmemory.h" 30 | #include "utlrbtree.h" 31 | 32 | class CFreeTypeFont : public CBaseFont 33 | { 34 | public: 35 | CFreeTypeFont(); 36 | ~CFreeTypeFont() override; 37 | 38 | bool Create(const char *name, 39 | int tall, int weight, 40 | int blur, float brighten, 41 | int outlineSize, 42 | int scanlineOffset, float scanlineScale, 43 | int flags) override; 44 | void GetCharRGBA(int ch, Point pt, Size sz, unsigned char *rgba, Size &drawSize) override; 45 | void GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) override; 46 | bool HasChar( int ch ) const override; 47 | const char *GetBackendName() const override { return "ft2"; } 48 | private: 49 | FT_Face face; 50 | static FT_Library m_Library; 51 | byte *m_pFontData; 52 | 53 | friend class CFontManager; 54 | }; 55 | 56 | #endif // defined(MAINUI_USE_CUSTOM_FONT_RENDER) && defined(MAINUI_USE_FREETYPE) 57 | 58 | #endif // FREETYPEFONT_H 59 | -------------------------------------------------------------------------------- /font/StbFont.h: -------------------------------------------------------------------------------- 1 | /* 2 | StbFont.h -- stb_truetype font renderer 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | 17 | #if defined(MAINUI_USE_CUSTOM_FONT_RENDER) && defined(MAINUI_USE_STB) 18 | #include "BaseFontBackend.h" 19 | #include "utlmemory.h" 20 | #include "utlrbtree.h" 21 | #include "stb_truetype.h" 22 | 23 | 24 | class CStbFont : public CBaseFont 25 | { 26 | public: 27 | CStbFont(); 28 | ~CStbFont(); 29 | 30 | bool Create(const char *name, 31 | int tall, int weight, 32 | int blur, float brighten, 33 | int outlineSize, 34 | int scanlineOffset, float scanlineScale, 35 | int flags) override; 36 | void GetCharRGBA(int ch, Point pt, Size sz, unsigned char *rgba, Size &drawSize) override; 37 | void GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) override; 38 | bool HasChar( int ch ) const override; 39 | const char *GetBackendName() const override { return "stb"; } 40 | 41 | private: 42 | byte *m_pFontData; 43 | stbtt_fontinfo m_fontInfo; 44 | 45 | double scale; 46 | 47 | friend class CFontManager; 48 | }; 49 | 50 | #endif // defined(MAINUI_USE_CUSTOM_FONT_RENDER) && defined(MAINUI_USE_FREETYPE) 51 | -------------------------------------------------------------------------------- /font/WinAPIFont.h: -------------------------------------------------------------------------------- 1 | /* 2 | WinAPIFont.h - Win32 Font backend 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #pragma once 16 | #if !defined(WINAPIFONT_H) && defined(MAINUI_USE_CUSTOM_FONT_RENDER) && defined(_WIN32) 17 | #define WINAPIFONT_H 18 | 19 | #define WIN32_LEAN_AND_MEAN 20 | #define UNICODE // use unicode fonts 21 | #include 22 | #undef GetCharABCWidths 23 | 24 | #include "BaseFontBackend.h" 25 | #include "FontManager.h" 26 | 27 | #include "utlmemory.h" 28 | #include "utlrbtree.h" 29 | 30 | class CWinAPIFont : public CBaseFont 31 | { 32 | public: 33 | CWinAPIFont( ); 34 | ~CWinAPIFont( ); 35 | 36 | bool Create( const char *name, 37 | int tall, int weight, 38 | int blur, float brighten, 39 | int outlineSize, 40 | int scanlineOffset, float scanlineScale, 41 | int flags ) override; 42 | void GetCharRGBA( int ch, Point pt, Size sz, unsigned char *rgba, Size &drawSize ) override; 43 | void GetCharABCWidthsNoCache( int ch, int &a, int &b, int &c ) override; 44 | bool HasChar( int ch ) const override; 45 | const char *GetBackendName() const override { return "win32"; } 46 | 47 | bool m_bFound; 48 | 49 | private: 50 | HFONT m_hFont; 51 | HDC m_hDC; 52 | HBITMAP m_hDIB; 53 | 54 | int m_rgiBitmapSize[2]; 55 | 56 | // pointer to buffer for use when generated bitmap versions of a texture 57 | unsigned char *m_pBuf; 58 | 59 | friend class CFontManager; 60 | friend int CALLBACK FontEnumProc( const LOGFONT *, const TEXTMETRIC *, DWORD, LPARAM lpParam ); 61 | }; 62 | 63 | #endif // WINAPIFONT_H 64 | -------------------------------------------------------------------------------- /menus/Configuration.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "PicButton.h" 24 | #include "YesNoMessageBox.h" 25 | #include "keydefs.h" 26 | #include "TabView.h" 27 | 28 | #define ART_BANNER "gfx/shell/head_config" 29 | 30 | class CMenuOptions: public CMenuFramework 31 | { 32 | private: 33 | void _Init( void ) override; 34 | 35 | public: 36 | typedef CMenuFramework BaseClass; 37 | CMenuOptions() : CMenuFramework("CMenuOptions") { } 38 | 39 | // update dialog 40 | CMenuYesNoMessageBox msgBox; 41 | }; 42 | 43 | /* 44 | ================= 45 | CMenuOptions::Init 46 | ================= 47 | */ 48 | void CMenuOptions::_Init( void ) 49 | { 50 | banner.SetPicture( ART_BANNER ); 51 | 52 | msgBox.SetMessage( L( "Check the Internet for updates?" ) ); 53 | SET_EVENT( msgBox.onPositive, UI_OpenUpdatePage( false, true ) ); 54 | 55 | msgBox.Link( this ); 56 | 57 | AddItem( banner ); 58 | AddButton( L( "Controls" ), L( "Change keyboard and mouse settings" ), 59 | PC_CONTROLS, UI_Controls_Menu, QMF_NOTIFY ); 60 | AddButton( L( "GameUI_Audio" ), L( "Change sound volume and quality" ), 61 | PC_AUDIO, UI_Audio_Menu, QMF_NOTIFY ); 62 | AddButton( L( "GameUI_Video" ), L( "Change screen size, video mode and gamma" ), 63 | PC_VIDEO, UI_Video_Menu, QMF_NOTIFY ); 64 | AddButton( L( "Touch" ), L( "Change touch settings and buttons" ), 65 | PC_TOUCH, UI_Touch_Menu, QMF_NOTIFY, 't' ); 66 | AddButton( L( "GameUI_Joystick" ), L( "Change gamepad axis and button settings" ), 67 | PC_GAMEPAD, UI_GamePad_Menu, QMF_NOTIFY, 'g' ); 68 | AddButton( L( "Update" ), L( "Check for updates" ), 69 | PC_UPDATE, msgBox.MakeOpenEvent(), QMF_NOTIFY ); 70 | AddButton( L( "Done" ), L( "Go back to the Main menu" ), 71 | PC_DONE, VoidCb( &CMenuOptions::Hide ), QMF_NOTIFY ); 72 | } 73 | 74 | ADD_MENU( menu_options, CMenuOptions, UI_Options_Menu ); 75 | -------------------------------------------------------------------------------- /menus/ConnectionWarning.cpp: -------------------------------------------------------------------------------- 1 | #include "BaseWindow.h" 2 | #include "CheckBox.h" 3 | #include "PicButton.h" 4 | #include "Action.h" 5 | 6 | enum EPresets { EPRESET_NORMAL = 0, EPRESET_DSL, EPRESET_SLOW, EPRESET_LAST }; 7 | 8 | class CMenuConnectionWarning : public CMenuBaseWindow 9 | { 10 | public: 11 | CMenuConnectionWarning() : CMenuBaseWindow( "ConnectionWarning" ) 12 | { 13 | 14 | } 15 | void _Init() override; 16 | void _VidInit() override; 17 | bool KeyDown( int key ) override; 18 | 19 | void WriteSettings(const EPresets preset ); 20 | 21 | CMenuPicButton done; 22 | private: 23 | CMenuBackgroundBitmap background; 24 | CMenuPicButton options; 25 | CMenuCheckBox normal, dsl, slowest; 26 | CMenuAction title, message; 27 | }; 28 | 29 | bool CMenuConnectionWarning::KeyDown( int key ) 30 | { 31 | if( UI::Key::IsEscape( key ) ) 32 | { 33 | return true; // handled 34 | } 35 | 36 | return CMenuBaseWindow::KeyDown( key ); 37 | } 38 | 39 | void CMenuConnectionWarning::_Init() 40 | { 41 | iFlags |= QMF_DIALOG; 42 | 43 | background.bForceColor = true; 44 | background.colorBase = uiPromptBgColor; 45 | 46 | normal.szName = L( "Normal internet connection" ); 47 | normal.SetCoord( 20, 140 ); 48 | SET_EVENT( normal.onChanged, 49 | ((CMenuConnectionWarning*)pSelf->Parent())->WriteSettings( EPRESET_NORMAL ) ); 50 | 51 | dsl.szName = L( "DSL or PPTP with limited packet size" ); 52 | dsl.SetCoord( 20, 200 ); 53 | SET_EVENT( dsl.onChanged, 54 | ((CMenuConnectionWarning*)pSelf->Parent())->WriteSettings( EPRESET_DSL ) ); 55 | 56 | slowest.szName = L( "Slow connection mode (64kbps)" ); 57 | slowest.SetCoord( 20, 260 ); 58 | SET_EVENT( slowest.onChanged, 59 | ((CMenuConnectionWarning*)pSelf->Parent())->WriteSettings( EPRESET_SLOW ) ); 60 | 61 | done.SetPicture( PC_DONE ); 62 | done.szName = L( "Done" ); 63 | done.SetGrayed( true ); 64 | done.SetRect( 410, 320, UI_BUTTONS_WIDTH / 2, UI_BUTTONS_HEIGHT ); 65 | done.onReleased = VoidCb( &CMenuConnectionWarning::Hide ); 66 | done.bEnableTransitions = false; 67 | 68 | options.SetPicture( PC_ADV_OPT ); 69 | options.szName = L( "Adv. Options" ); 70 | SET_EVENT_MULTI( options.onReleased, 71 | { 72 | CMenuConnectionWarning *p = pSelf->GetParent(CMenuConnectionWarning); 73 | UI_GameOptions_Menu(); 74 | p->done.SetGrayed( false ); 75 | }); 76 | options.SetRect( 154, 320, UI_BUTTONS_WIDTH, UI_BUTTONS_HEIGHT ); 77 | options.bEnableTransitions = false; 78 | 79 | title.iFlags = QMF_INACTIVE|QMF_DROPSHADOW; 80 | title.eTextAlignment = QM_CENTER; 81 | title.szName = L( "Connection problem" ); 82 | title.SetRect( 0, 16, 640, 20 ); 83 | 84 | message.iFlags = QMF_INACTIVE; 85 | message.szName = L( "Too many lost packets while connecting!\nPlease select network settings" ); 86 | message.SetRect( 20, 60, 600, 32 ); 87 | 88 | AddItem( background ); 89 | AddItem( done ); 90 | AddItem( options ); 91 | AddItem( normal ); 92 | AddItem( dsl ); 93 | AddItem( slowest ); 94 | AddItem( title ); 95 | AddItem( message ); 96 | } 97 | 98 | void CMenuConnectionWarning::_VidInit() 99 | { 100 | SetRect( DLG_X + 192, 192, 640, 384 ); 101 | pos.x += uiStatic.xOffset; 102 | pos.y += uiStatic.yOffset; 103 | } 104 | 105 | void CMenuConnectionWarning::WriteSettings( const EPresets preset) 106 | { 107 | const struct 108 | { 109 | float cl_cmdrate; 110 | float cl_updaterate; 111 | float rate; 112 | } presets[EPRESET_LAST] = 113 | { 114 | { 30, 60, 25000 }, 115 | { 30, 60, 25000 }, 116 | { 25, 30, 7500 } 117 | }; 118 | 119 | EngFuncs::CvarSetValue( "cl_cmdrate", presets[preset].cl_cmdrate ); 120 | EngFuncs::CvarSetValue( "cl_updaterate", presets[preset].cl_updaterate ); 121 | EngFuncs::CvarSetValue( "rate", presets[preset].rate ); 122 | 123 | normal.bChecked = preset == EPRESET_NORMAL; 124 | dsl.bChecked = preset == EPRESET_DSL; 125 | slowest.bChecked = preset == EPRESET_SLOW; 126 | 127 | done.SetGrayed( false ); 128 | } 129 | 130 | ADD_MENU3( menu_connectionwarning, CMenuConnectionWarning, UI_ConnectionWarning_f ); 131 | void UI_ConnectionWarning_f() 132 | { 133 | if( !UI_IsVisible() ) 134 | UI_Main_Menu(); 135 | menu_connectionwarning->Show(); 136 | } 137 | -------------------------------------------------------------------------------- /menus/FileDialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "Action.h" 24 | #include "Table.h" 25 | #include "StringVectorModel.h" 26 | #include "PicButton.h" 27 | 28 | #define ART_BANNER "gfx/shell/head_touchoptions" 29 | #define ART_GAMMA "gfx/shell/gamma" 30 | 31 | uiFileDialogGlobal_t uiFileDialogGlobal; 32 | 33 | class CMenuFileDialog : public CMenuFramework 34 | { 35 | public: 36 | CMenuFileDialog() : CMenuFramework("CMenuFileDialog") { } 37 | 38 | private: 39 | void _Init( void ) override; 40 | void _VidInit( void ) override; 41 | void SaveAndPopMenu() override; 42 | void RejectChanges(); 43 | void ApplyChanges( const char *fileName ); 44 | void UpdateExtra(); 45 | 46 | class CFileListModel : public CStringVectorModel 47 | { 48 | public: 49 | CFileListModel() : CStringVectorModel() {} 50 | void Update() override; 51 | } model; 52 | 53 | CMenuTable fileList; 54 | 55 | class CPreview : public CMenuAction 56 | { 57 | public: 58 | void Draw() override; 59 | HIMAGE image; 60 | } preview; 61 | }; 62 | 63 | void CMenuFileDialog::CPreview::Draw() 64 | { 65 | UI_FillRect( m_scPos.x - 2, m_scPos.y - 2, m_scSize.w + 4, m_scSize.h + 4, 0xFFC0C0C0 ); 66 | UI_FillRect( m_scPos.x, m_scPos.y, m_scSize.w, m_scSize.h, 0xFF808080 ); 67 | EngFuncs::PIC_Set( image, 255, 255, 255, 255 ); 68 | EngFuncs::PIC_DrawTrans( m_scPos, m_scSize ); 69 | } 70 | 71 | void CMenuFileDialog::CFileListModel::Update( void ) 72 | { 73 | char **filenames; 74 | int i = 0, numFiles, j, k; 75 | 76 | 77 | for( k = 0; k < uiFileDialogGlobal.npatterns; k++) 78 | { 79 | filenames = EngFuncs::GetFilesList( uiFileDialogGlobal.patterns[k], &numFiles, TRUE ); 80 | for ( j = 0; j < numFiles; i++, j++ ) 81 | AddToTail( filenames[j] ); 82 | } 83 | 84 | } 85 | 86 | void CMenuFileDialog::ApplyChanges(const char *fileName) 87 | { 88 | Q_strncpy( uiFileDialogGlobal.result, fileName, sizeof( uiFileDialogGlobal.result ) ); 89 | uiFileDialogGlobal.result[255] = 0; 90 | uiFileDialogGlobal.valid = false; 91 | uiFileDialogGlobal.callback( fileName[0] != 0 ); 92 | } 93 | 94 | void CMenuFileDialog::RejectChanges() 95 | { 96 | ApplyChanges( "" ); 97 | Hide(); 98 | } 99 | 100 | void CMenuFileDialog::SaveAndPopMenu() 101 | { 102 | const char *fileName = model.GetText( fileList.GetCurrentIndex() ); 103 | ApplyChanges( fileName ); 104 | Hide(); 105 | } 106 | 107 | void CMenuFileDialog::UpdateExtra() 108 | { 109 | const char *fileName = model.GetText( fileList.GetCurrentIndex() ); 110 | if( uiFileDialogGlobal.preview ) 111 | preview.image = EngFuncs::PIC_Load( fileName ); 112 | } 113 | 114 | /* 115 | ================= 116 | UI_FileDialog_Init 117 | ================= 118 | */ 119 | void CMenuFileDialog::_Init( void ) 120 | { 121 | // banner.SetPicture( ART_BANNER ); 122 | 123 | fileList.iFlags |= QMF_DROPSHADOW; 124 | fileList.SetModel( &model ); 125 | fileList.onChanged = VoidCb( &CMenuFileDialog::UpdateExtra ); 126 | fileList.SetRect( 360, 230, -20, 465 ); 127 | UpdateExtra(); 128 | 129 | preview.SetRect( 72, 380, 196, 196 ); 130 | 131 | // AddItem( banner ); 132 | AddButton( L( "Done" ), L( "Use selected file" ), PC_DONE, VoidCb( &CMenuFileDialog::SaveAndPopMenu ) ); 133 | AddButton( L( "GameUI_Cancel" ), L( "Cancel file selection" ), PC_CANCEL, VoidCb( &CMenuFileDialog::RejectChanges ) ); 134 | AddItem( preview ); 135 | AddItem( fileList ); 136 | } 137 | 138 | void CMenuFileDialog::_VidInit() 139 | { 140 | preview.SetVisibility( uiFileDialogGlobal.preview ); 141 | } 142 | 143 | ADD_MENU( menu_filedialog, CMenuFileDialog, UI_FileDialog_Menu ); 144 | -------------------------------------------------------------------------------- /menus/InputDevices.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "kbutton.h" 23 | #include "MenuStrings.h" 24 | #include "Bitmap.h" 25 | #include "PicButton.h" 26 | #include "CheckBox.h" 27 | #include "Slider.h" 28 | #include "YesNoMessageBox.h" 29 | 30 | #define ART_BANNER "gfx/shell/head_advanced" 31 | 32 | class CMenuInputDevices : public CMenuFramework 33 | { 34 | private: 35 | void _Init( void ) override; 36 | void _VidInit( void ) override; 37 | bool DrawAnimation() override { return true; } 38 | 39 | void GetConfig( void ); 40 | void SaveAndPopMenu( void ) override; 41 | 42 | public: 43 | CMenuInputDevices() : CMenuFramework("CMenuInputDevices") { } 44 | 45 | CMenuPicButton done, evdev; 46 | CMenuCheckBox mouse, touch, joystick; 47 | }; 48 | 49 | /* 50 | ================= 51 | UI_AdvControls_GetConfig 52 | ================= 53 | */ 54 | void CMenuInputDevices::GetConfig( void ) 55 | { 56 | mouse.LinkCvar( "m_ignore" ); 57 | touch.LinkCvar( "touch_enable" ); 58 | joystick.LinkCvar( "joy_enable" ); 59 | 60 | } 61 | 62 | void CMenuInputDevices::SaveAndPopMenu() 63 | { 64 | mouse.WriteCvar(); 65 | touch.WriteCvar(); 66 | joystick.WriteCvar(); 67 | CMenuFramework::SaveAndPopMenu(); 68 | } 69 | 70 | 71 | /* 72 | ================= 73 | UI_AdvControls_Init 74 | ================= 75 | */ 76 | void CMenuInputDevices::_Init( void ) 77 | { 78 | //banner.SetPicture( ART_BANNER ); 79 | 80 | done.SetNameAndStatus( L( "Done" ), L( "Save changed and go back to the Customize Menu" ) ); 81 | done.SetPicture( PC_DONE ); 82 | done.onReleased = VoidCb( &CMenuInputDevices::SaveAndPopMenu ); 83 | done.SetCoord( 72, 680 ); 84 | 85 | mouse.SetNameAndStatus( L( "Ignore mouse" ), L( "Need for some servers. Will disable mouse in menu too" )); 86 | mouse.iFlags |= QMF_NOTIFY; 87 | #ifndef __ANDROID__ 88 | SET_EVENT_MULTI( mouse.onChanged, 89 | { 90 | if( ((CMenuCheckBox*)pSelf)->bChecked ) 91 | { 92 | static CMenuYesNoMessageBox msgbox(false); 93 | msgbox.SetMessage( L( "If you do not have touchscreen, or joystick, you will not be able to play without mouse.\nAre you sure to disable mouse?" )); 94 | SET_EVENT_MULTI( msgbox.onNegative, 95 | { 96 | pSelf->GetParent(CMenuInputDevices)->mouse.bChecked = false; 97 | }); 98 | msgbox.Link(pSelf->GetParent(CMenuInputDevices)); 99 | msgbox.Show(); 100 | } 101 | }); 102 | #endif 103 | 104 | mouse.SetCoord( 72, 230 ); 105 | 106 | touch.SetNameAndStatus( L( "Enable touch" ), L( "On-screen controls for touchscreen" )); 107 | touch.iFlags |= QMF_NOTIFY; 108 | touch.SetCoord( 72, 280 ); 109 | 110 | joystick.SetNameAndStatus( L( "GameUI_JoystickLabel" ), L( "Enable using game controller in game" )); 111 | joystick.SetCoord( 72, 330 ); 112 | joystick.iFlags |= QMF_NOTIFY; 113 | 114 | evdev.SetNameAndStatus( L( "Evdev input (root)" ), L( "Press this to enable full mouse and keyboard control on Android" )); 115 | evdev.iFlags |= QMF_NOTIFY; 116 | evdev.SetCoord( 72, 380 ); 117 | evdev.onReleased.SetCommand( FALSE, "evdev_autodetect\n" ); 118 | 119 | //AddItem( banner ); 120 | AddItem( done ); 121 | AddItem( mouse ); 122 | AddItem( touch ); 123 | AddItem( joystick ); 124 | #ifdef __ANDROID__ 125 | AddItem( evdev ); 126 | #endif 127 | } 128 | 129 | 130 | void CMenuInputDevices::_VidInit() 131 | { 132 | GetConfig(); 133 | } 134 | 135 | ADD_MENU( menu_inputdevices, CMenuInputDevices, UI_InputDevices_Menu ); 136 | -------------------------------------------------------------------------------- /menus/Multiplayer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "YesNoMessageBox.h" 24 | #include "keydefs.h" 25 | #include "PlayerIntroduceDialog.h" 26 | 27 | #define ART_BANNER "gfx/shell/head_multi" 28 | 29 | class CMenuMultiplayer : public CMenuFramework 30 | { 31 | public: 32 | CMenuMultiplayer() : CMenuFramework( "CMenuMultiplayer" ) { } 33 | 34 | void Show() override 35 | { 36 | CMenuFramework::Show(); 37 | 38 | if( EngFuncs::GetCvarFloat( "menu_mp_firsttime2" ) && EngFuncs::GetCvarFloat( "cl_nopred" ) ) 39 | { 40 | EngFuncs::CvarSetValue( "cl_nopred", 0.0f ); 41 | } 42 | 43 | if( !UI::Names::CheckIsNameValid( EngFuncs::GetCvarString( "name" ) ) ) 44 | { 45 | UI_PlayerIntroduceDialog_Show( this ); 46 | } 47 | } 48 | 49 | private: 50 | void _Init() override; 51 | }; 52 | 53 | /* 54 | ================= 55 | CMenuMultiplayer::Init 56 | ================= 57 | */ 58 | void CMenuMultiplayer::_Init( void ) 59 | { 60 | banner.SetPicture( ART_BANNER ); 61 | AddItem( banner ); 62 | 63 | AddButton( L( "Internet game" ), L( "View list of a game internet servers and join the one of your choice" ), PC_INET_GAME, UI_InternetGames_Menu, QMF_NOTIFY ); 64 | // AddButton( L( "Spectate game" ), L( "Spectate internet games" ), PC_SPECTATE_GAMES, NoopCb, QMF_GRAYED | QMF_NOTIFY ); 65 | AddButton( L( "LAN game" ), L( "Set up the game on the local area network" ), PC_LAN_GAME, UI_LanGame_Menu, QMF_NOTIFY ); 66 | AddButton( L( "GameUI_GameMenu_Customize" ), L( "Choose your player name, and select visual options for your character" ), PC_CUSTOMIZE, UI_PlayerSetup_Menu, QMF_NOTIFY ); 67 | AddButton( L( "Controls" ), L( "Change keyboard and mouse settings" ), PC_CONTROLS, UI_Controls_Menu, QMF_NOTIFY ); 68 | AddButton( L( "Done" ), L( "Go back to the Main menu" ), PC_DONE, VoidCb( &CMenuMultiplayer::Hide ), QMF_NOTIFY ); 69 | } 70 | 71 | ADD_MENU( menu_multiplayer, CMenuMultiplayer, UI_MultiPlayer_Menu ); 72 | -------------------------------------------------------------------------------- /menus/PlayerIntroduceDialog.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 a1batross. 3 | PlayerIntroduceDialog.cpp -- dialog intended to let player introduce themselves: enter nickname 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | */ 21 | 22 | #include "BaseWindow.h" 23 | #include "PicButton.h" 24 | #include "YesNoMessageBox.h" 25 | #include "MessageBox.h" 26 | #include "Field.h" 27 | #include "PlayerIntroduceDialog.h" 28 | 29 | class CMenuPlayerIntroduceDialog : public CMenuYesNoMessageBox 30 | { 31 | public: 32 | CMenuPlayerIntroduceDialog() : CMenuYesNoMessageBox( false ), msgBox( true ) 33 | { 34 | } 35 | 36 | void WriteOrDiscard(); 37 | void _Init() override; 38 | bool KeyDown( int key ) override; 39 | 40 | CMenuBaseWindow *pCaller; 41 | 42 | private: 43 | CMenuField name; 44 | CMenuYesNoMessageBox msgBox; 45 | }; 46 | 47 | void CMenuPlayerIntroduceDialog::WriteOrDiscard() 48 | { 49 | if( !UI::Names::CheckIsNameValid( name.GetBuffer() ) ) 50 | { 51 | msgBox.Show(); 52 | } 53 | else 54 | { 55 | name.WriteCvar(); 56 | SaveAndPopMenu(); 57 | } 58 | } 59 | 60 | bool CMenuPlayerIntroduceDialog::KeyDown( int key ) 61 | { 62 | if( UI::Key::IsEscape( key ) ) 63 | { 64 | return true; // handled 65 | } 66 | 67 | if( UI::Key::IsEnter( key ) && ItemAtCursor() == &name ) 68 | { 69 | WriteOrDiscard(); 70 | } 71 | 72 | return CMenuYesNoMessageBox::KeyDown( key ); 73 | } 74 | 75 | void CMenuPlayerIntroduceDialog::_Init() 76 | { 77 | onPositive = VoidCb( &CMenuPlayerIntroduceDialog::WriteOrDiscard ); 78 | SET_EVENT_MULTI( onNegative, 79 | { 80 | CMenuPlayerIntroduceDialog *self = (CMenuPlayerIntroduceDialog*)pSelf; 81 | self->Hide(); // hide ourselves first 82 | self->pCaller->Hide(); // hide our parent 83 | }); 84 | 85 | SetMessage( L( "GameUI_PlayerName" ) ); 86 | 87 | name.bAllowColorstrings = true; 88 | name.SetRect( 188, 140, 270, 32 ); 89 | name.LinkCvar( "name" ); 90 | name.iMaxLength = MAX_SCOREBOARDNAME; 91 | name.SetBuffer( EngFuncs::GetCvarString( "ui_username" )); 92 | 93 | msgBox.SetMessage( L( "Please, choose another player name" ) ); 94 | msgBox.Link( this ); 95 | 96 | // don't close automatically 97 | bAutoHide = false; 98 | Link( this ); // i am my own son 99 | 100 | CMenuYesNoMessageBox::_Init(); 101 | 102 | AddItem( name ); 103 | } 104 | 105 | ADD_MENU3( menu_playerintroducedialog, CMenuPlayerIntroduceDialog, UI_PlayerIntroduceDialog_Show ); 106 | 107 | void UI_PlayerIntroduceDialog_Show() { } 108 | 109 | void UI_PlayerIntroduceDialog_Show( CMenuBaseWindow *pCaller ) 110 | { 111 | menu_playerintroducedialog->pCaller = pCaller; 112 | menu_playerintroducedialog->Show(); 113 | } 114 | -------------------------------------------------------------------------------- /menus/PlayerIntroduceDialog.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2017 a1batross. 3 | PlayerIntroduceDialog.h -- dialog intended to let player introduce themselves: enter nickname 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | 20 | */ 21 | 22 | // Don't expose class, just few functions 23 | void UI_PlayerIntroduceDialog_Show(CMenuBaseWindow *pCaller ); 24 | -------------------------------------------------------------------------------- /menus/SaveLoad.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "PicButton.h" 24 | #include "Action.h" 25 | 26 | #define ART_BANNER "gfx/shell/head_saveload" 27 | 28 | class CMenuSaveLoad : public CMenuFramework 29 | { 30 | public: 31 | CMenuSaveLoad() : CMenuFramework( "CMenuSaveLoad" ) { } 32 | private: 33 | void _Init(); 34 | 35 | CMenuAction hintMessage; 36 | char hintText[MAX_HINT_TEXT]; 37 | }; 38 | 39 | /* 40 | ================= 41 | UI_SaveLoad_Init 42 | ================= 43 | */ 44 | void CMenuSaveLoad::_Init( void ) 45 | { 46 | snprintf( hintText, sizeof( hintText ), 47 | L( "During play, you can quickly save your game by pressing %s.\nLoad this game again by pressing %s." ), 48 | EngFuncs::KeynumToString( KEY_GetKey( "save quick" ) ), 49 | EngFuncs::KeynumToString( KEY_GetKey( "load quick" ) ) ); 50 | 51 | banner.SetPicture( ART_BANNER ); 52 | 53 | hintMessage.iFlags = QMF_INACTIVE; 54 | hintMessage.colorBase = uiColorHelp; 55 | hintMessage.SetCharSize( QM_SMALLFONT ); 56 | hintMessage.szName = hintText; 57 | hintMessage.SetCoord( 360, 480 ); 58 | 59 | AddItem( banner ); 60 | AddButton( L( "GameUI_LoadGame" ), L( "GameUI_LoadGameHelp" ), PC_LOAD_GAME, UI_LoadGame_Menu, QMF_NOTIFY ); 61 | AddButton( L( "GameUI_SaveGame" ), L( "GameUI_SaveGameHelp" ), PC_SAVE_GAME, UI_SaveGame_Menu, QMF_NOTIFY ); 62 | AddButton( L( "Done" ), L( "Go back to the Main menu" ), PC_DONE, VoidCb( &CMenuSaveLoad::Hide ), QMF_NOTIFY ); 63 | AddItem( hintMessage ); 64 | } 65 | 66 | ADD_MENU( menu_saveload, CMenuSaveLoad, UI_SaveLoad_Menu ); 67 | -------------------------------------------------------------------------------- /menus/Touch.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "PicButton.h" 24 | 25 | #define ART_BANNER "gfx/shell/head_touch" 26 | 27 | class CMenuTouch : public CMenuFramework 28 | { 29 | public: 30 | CMenuTouch() : CMenuFramework ( "CMenuTouch" ) { } 31 | }; 32 | 33 | ADD_MENU3( menu_touch, CMenuTouch, UI_Touch_Menu ); 34 | 35 | /* 36 | ================= 37 | UI_Touch_Menu 38 | ================= 39 | */ 40 | void UI_Touch_Menu( void ) 41 | { 42 | if( !menu_touch->WasInit() ) 43 | { 44 | menu_touch->banner.SetPicture( ART_BANNER ); 45 | menu_touch->AddItem( menu_touch->banner ); 46 | 47 | menu_touch->AddButton( L( "Touch options" ), L( "Touch sensitivity and profile options" ), PC_TOUCH_OPTIONS, 48 | UI_TouchOptions_Menu, QMF_NOTIFY, 'o' ); 49 | 50 | menu_touch->AddButton( L( "Touch buttons" ), L( "Add, remove, edit touch buttons" ), PC_TOUCH_BUTTONS, 51 | UI_TouchButtons_Menu, QMF_NOTIFY, 'b' ); 52 | 53 | menu_touch->AddButton( L( "Done" ), L( "Go back to the previous menu" ), PC_DONE, VoidCb( &CMenuFramework::Hide ), QMF_NOTIFY ); 54 | } 55 | 56 | menu_touch->Show(); 57 | } 58 | -------------------------------------------------------------------------------- /menus/TouchEdit.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | /* 22 | * This is empty menu that allows engine to draw touch editor 23 | */ 24 | 25 | #include "Framework.h" 26 | #include "keydefs.h" 27 | 28 | class CMenuTouchEdit : public CMenuFramework 29 | { 30 | public: 31 | CMenuTouchEdit() : CMenuFramework( "CMenuTouchEdit" ) { } 32 | 33 | void Show() override; 34 | void Hide() override; 35 | void Draw() override; 36 | bool DrawAnimation() override; 37 | bool KeyDown( int key ) override; 38 | private: 39 | float saveTouchEnable; 40 | }; 41 | 42 | void CMenuTouchEdit::Show() 43 | { 44 | saveTouchEnable = EngFuncs::GetCvarFloat( "touch_enable" ); 45 | 46 | EngFuncs::CvarSetValue( "touch_enable", 1 ); 47 | EngFuncs::CvarSetValue( "touch_in_menu", 1 ); 48 | EngFuncs::ClientCmd(FALSE, "touch_enableedit"); 49 | 50 | CMenuFramework::Show(); 51 | } 52 | 53 | void CMenuTouchEdit::Hide() 54 | { 55 | EngFuncs::CvarSetValue( "touch_enable", saveTouchEnable ); 56 | EngFuncs::CvarSetValue( "touch_in_menu", 0 ); 57 | EngFuncs::ClientCmd(FALSE, "touch_disableedit"); 58 | 59 | CMenuFramework::Hide(); 60 | } 61 | 62 | bool CMenuTouchEdit::DrawAnimation() 63 | { 64 | return true; 65 | } 66 | 67 | /* 68 | ================= 69 | UI_TouchEdit_DrawFunc 70 | ================= 71 | */ 72 | void CMenuTouchEdit::Draw( void ) 73 | { 74 | if( !EngFuncs::GetCvarFloat("touch_in_menu") ) 75 | { 76 | Hide(); 77 | UI_TouchButtons_GetButtonList(); 78 | } 79 | } 80 | 81 | /* 82 | ================= 83 | UI_TouchEdit_KeyFunc 84 | ================= 85 | */ 86 | bool CMenuTouchEdit::KeyDown( int key ) 87 | { 88 | if( UI::Key::IsEscape( key ) ) 89 | { 90 | Hide(); 91 | PlayLocalSound( uiStatic.sounds[SND_OUT] ); 92 | return true; 93 | } 94 | return false; 95 | } 96 | 97 | ADD_MENU( menu_touchedit, CMenuTouchEdit, UI_TouchEdit_Menu ); 98 | -------------------------------------------------------------------------------- /menus/Video.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #include "Framework.h" 22 | #include "Bitmap.h" 23 | #include "PicButton.h" 24 | 25 | #define ART_BANNER "gfx/shell/head_video" 26 | 27 | class CMenuVideo : public CMenuFramework 28 | { 29 | public: 30 | CMenuVideo() : CMenuFramework( "CMenuVideo" ) { } 31 | }; 32 | 33 | ADD_MENU3( menu_video, CMenuVideo, UI_Video_Menu ); 34 | 35 | /* 36 | ================= 37 | UI_Video_Menu 38 | ================= 39 | */ 40 | void UI_Video_Menu( void ) 41 | { 42 | if( !menu_video->WasInit() ) 43 | { 44 | menu_video->banner.SetPicture( ART_BANNER ); 45 | 46 | menu_video->AddItem( menu_video->banner ); 47 | menu_video->AddButton( L( "Video options" ), L( "Set video options such as screen size, gamma and image quality." ), PC_VID_OPT, UI_VidOptions_Menu, QMF_NOTIFY ); 48 | menu_video->AddButton( L( "Video modes" ), L( "Set video modes and configure 3D accelerators." ), PC_VID_MODES, UI_VidModes_Menu, QMF_NOTIFY ); 49 | menu_video->AddButton( L( "Done" ), L( "Go back to the previous menu" ), PC_DONE, VoidCb( &CMenuFramework::Hide ), QMF_NOTIFY ); 50 | } 51 | 52 | menu_video->Show(); 53 | } 54 | -------------------------------------------------------------------------------- /menus/Zoo.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | Zoo.cpp -- examples 3 | Copyright (C) 2017 a1batross 4 | 5 | This program is free software; you can redistribute it and/or 6 | modify it under the terms of the GNU General Public License 7 | as published by the Free Software Foundation; either version 2 8 | of the License, or (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 13 | 14 | See the GNU General Public License for more details. 15 | 16 | You should have received a copy of the GNU General Public License 17 | along with this program; if not, write to the Free Software 18 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 19 | */ 20 | #include "Framework.h" 21 | #include "Action.h" 22 | #include "Field.h" 23 | #include "ScrollView.h" 24 | 25 | class CMenuZoo : public CMenuFramework 26 | { 27 | public: 28 | CMenuZoo() : CMenuFramework( "Example" ) { } 29 | 30 | virtual void _Init(); 31 | virtual void _VidInit(); 32 | 33 | static void OKButtonCommand( CMenuBaseItem *pSelf, void *pExtra ) 34 | { 35 | pSelf->Parent()->Hide(); 36 | } 37 | 38 | static void CancelButtonCommand( CMenuBaseItem *pSelf, void *pExtra ) 39 | { 40 | pSelf->Parent()->Hide(); 41 | } 42 | 43 | private: 44 | CMenuAction OKButton; 45 | CMenuAction CancelButton; 46 | CMenuAction Label1; 47 | CMenuAction Label2; 48 | CMenuAction Label3; 49 | CMenuAction Label4; 50 | CMenuField Entry1; 51 | CMenuField Entry2; 52 | CMenuField Entry3; 53 | CMenuField Entry4; 54 | CMenuField Entry5; 55 | 56 | CMenuAction bmp[35]; 57 | CMenuScrollView scrollView; 58 | }; 59 | 60 | #define SET_TAG_BY_MEMBER_NAME( member ) \ 61 | member.szTag = STR( member ); \ 62 | AddItem( member ); 63 | 64 | void CMenuZoo::_Init() 65 | { 66 | /* 67 | szTag = "CDKeyEntryDialog"; 68 | iFlags = QMF_DIALOG; 69 | 70 | RegisterNamedEvent( OKButtonCommand, "Ok" ); 71 | RegisterNamedEvent( CancelButtonCommand, "Cancel" ); 72 | 73 | background.bForceColor = true; 74 | 75 | SET_TAG_BY_MEMBER_NAME( OKButton ); 76 | SET_TAG_BY_MEMBER_NAME( CancelButton ); 77 | SET_TAG_BY_MEMBER_NAME( Label1 ); 78 | SET_TAG_BY_MEMBER_NAME( Label2 ); 79 | SET_TAG_BY_MEMBER_NAME( Label3 ); 80 | SET_TAG_BY_MEMBER_NAME( Label4 ); 81 | SET_TAG_BY_MEMBER_NAME( Entry1 ); 82 | SET_TAG_BY_MEMBER_NAME( Entry2 ); 83 | SET_TAG_BY_MEMBER_NAME( Entry3 ); 84 | //SET_TAG_BY_MEMBER_NAME( Entry4 ); 85 | //SET_TAG_BY_MEMBER_NAME( Entry5 ); 86 | */ 87 | 88 | const char *pics[] = 89 | { 90 | "gfx/shell/head_advanced.tga", 91 | "gfx/shell/head_advoptions.tga", 92 | "gfx/shell/head_audio.tga", 93 | "gfx/shell/head_config.tga", 94 | "gfx/shell/head_controls.tga", 95 | "gfx/shell/head_creategame.tga", 96 | "gfx/shell/head_createroom.tga", 97 | "gfx/shell/head_customize.tga", 98 | "gfx/shell/head_custom.tga", 99 | "gfx/shell/head_filter.tga", 100 | "gfx/shell/head_gameopts.tga", 101 | "gfx/shell/head_gamepad.tga", 102 | "gfx/shell/head_gore.tga", 103 | "gfx/shell/head_inetgames.tga", 104 | "gfx/shell/head_keyboard.tga", 105 | "gfx/shell/head_lan.tga", 106 | "gfx/shell/head_load.tga", 107 | "gfx/shell/head_multi.tga", 108 | "gfx/shell/head_newgame.tga", 109 | "gfx/shell/head_playrec.tga", 110 | "gfx/shell/head_play.tga", 111 | "gfx/shell/head_readme.tga", 112 | "gfx/shell/head_record.tga", 113 | "gfx/shell/head_rooms.tga", 114 | "gfx/shell/head_room.tga", 115 | "gfx/shell/head_saveload.tga", 116 | "gfx/shell/head_save.tga", 117 | "gfx/shell/head_single.tga", 118 | "gfx/shell/head_specgames.tga", 119 | "gfx/shell/head_touch_buttons.tga", 120 | "gfx/shell/head_touch_options.tga", 121 | "gfx/shell/head_touch.tga", 122 | "gfx/shell/head_video.tga", 123 | "gfx/shell/head_vidmodes.tga", 124 | "gfx/shell/head_vidoptions.tga" 125 | }; 126 | 127 | for( int i = 0; i < 35; i++ ) 128 | { 129 | HIMAGE pic = EngFuncs::PIC_Load( pics[i] ); 130 | 131 | bmp[i].SetBackground( pics[i] ); 132 | bmp[i].iFlags |= QMF_DISABLESCAILING; 133 | bmp[i].szName = pics[i]; 134 | bmp[i].eFocusAnimation = QM_HIGHLIGHTIFFOCUS; 135 | bmp[i].colorFocus = PackRGBA( 255, 255, 255, 255 ); 136 | bmp[i].colorBase = PackRGBA( 128, 128, 128, 255 ); 137 | if( i == 0 ) 138 | bmp[i].SetCoord( 0, 0 ); 139 | else 140 | bmp[i].SetCoord( bmp[i-1].pos.x, bmp[i-1].pos.y + EngFuncs::PIC_Height( pic ) ); 141 | scrollView.AddItem( bmp[i] ); 142 | } 143 | 144 | scrollView.SetRect( 0, 0, 1024, 768 ); 145 | 146 | AddItem( scrollView ); 147 | } 148 | 149 | void CMenuZoo::_VidInit() 150 | { 151 | 152 | } 153 | 154 | ADD_MENU( menu_zoo, CMenuZoo, UI_Zoo_Menu ) 155 | -------------------------------------------------------------------------------- /model/BaseArrayModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef BASE_ARRAY_MODEL_H 3 | #define BASE_ARRAY_MODEL_H 4 | 5 | #include "BaseModel.h" 6 | 7 | class CMenuBaseArrayModel : public CMenuBaseModel 8 | { 9 | public: 10 | // every array model must implement these methods 11 | virtual const char *GetText( int line ) = 0; 12 | 13 | // final methods 14 | int GetColumns() const final override 15 | { 16 | return 1; 17 | } 18 | 19 | const char *GetCellText( int line, int ) final override 20 | { 21 | return GetText( line ); 22 | } 23 | }; 24 | 25 | #endif // BASE_ARRAY_MODEL_H 26 | -------------------------------------------------------------------------------- /model/BaseModel.h: -------------------------------------------------------------------------------- 1 | /* 2 | BaseModel.h -- base model for simple MVC 3 | Copyright (C) 2017-2018 a1batross 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef BASE_MODEL_H 16 | #define BASE_MODEL_H 17 | 18 | #include "extdll_menu.h" 19 | 20 | enum ECellType 21 | { 22 | CELL_TEXT = 0, 23 | CELL_IMAGE_DEFAULT, 24 | CELL_IMAGE_ADDITIVE, 25 | CELL_IMAGE_TRANS, 26 | CELL_IMAGE_HOLES, 27 | // CELL_ITEM, 28 | }; 29 | 30 | class CMenuBaseModel 31 | { 32 | public: 33 | virtual ~CMenuBaseModel() { } 34 | 35 | // every model must implement these methods 36 | virtual void Update() = 0; 37 | virtual int GetColumns() const = 0; 38 | virtual int GetRows() const = 0; 39 | virtual const char *GetCellText( int line, int column ) = 0; 40 | 41 | // customization 42 | virtual void OnDeleteEntry( int line ) { } 43 | virtual void OnActivateEntry( int line ) { } 44 | virtual unsigned int GetAlignmentForColumn( int column ) const { return QM_LEFT; } 45 | virtual ECellType GetCellType( int line, int column ) { return CELL_TEXT; } 46 | virtual bool GetLineColor( int line, unsigned int &fillColor, bool &force ) const { return false; } 47 | virtual bool GetCellColors( int line, int column, unsigned int &textColor, bool &force ) const { return false; } 48 | virtual bool IsCellTextWrapped( int line, int column ) { return true; } 49 | // virtual CMenuBaseItem *GetCellItem( int line, int column ) { return NULL; } 50 | 51 | // sorting 52 | virtual bool Sort( int column, bool ascend ) { return false; } // false means no sorting support for column 53 | }; 54 | 55 | #endif // BASE_MODEL_H 56 | -------------------------------------------------------------------------------- /model/StringArrayModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STRINGARRAYMODEL_H 3 | #define STRINGARRAYMODEL_H 4 | 5 | #include "BaseArrayModel.h" 6 | 7 | class CStringArrayModel : public CMenuBaseArrayModel 8 | { 9 | public: 10 | // pointer to array of pointers 11 | CStringArrayModel( const char **ptr, int count ) 12 | { 13 | m_u.m_pArrayOfPtrs = ptr; 14 | m_iCount = count; 15 | m_iOffset = 0; 16 | } 17 | 18 | CStringArrayModel( const char *str, int offset, int count ) 19 | { 20 | m_u.m_pArrayOfChars = str; 21 | m_iOffset = offset; 22 | m_iCount = count; 23 | } 24 | 25 | // by default, there is no need to update 26 | void Update() override { } 27 | 28 | const char *GetText( int line ) final override 29 | { 30 | if( line < 0 || line > m_iCount ) 31 | { 32 | Con_Printf("StringArrayModel: wrong index %d of %d\n", line, m_iCount ); 33 | return ""; 34 | } 35 | if( m_iOffset ) 36 | return m_u.m_pArrayOfChars + m_iOffset * line; 37 | return m_u.m_pArrayOfPtrs[line]; 38 | } 39 | 40 | int GetRows() const final override 41 | { 42 | return m_iCount; 43 | } 44 | 45 | protected: 46 | int m_iCount; 47 | 48 | private: 49 | union 50 | { 51 | const char **m_pArrayOfPtrs; 52 | const char *m_pArrayOfChars; 53 | } m_u; 54 | int m_iOffset; 55 | }; 56 | 57 | #endif // STRINGARRAYMODEL_H 58 | -------------------------------------------------------------------------------- /model/StringVectorModel.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | #ifndef STRINGVECTORMODEL_H 3 | #define STRINGVECTORMODEL_H 4 | 5 | #include "BaseArrayModel.h" 6 | #include "utlvector.h" 7 | #include "utlstring.h" 8 | 9 | class CStringVectorModel : 10 | public CMenuBaseArrayModel, 11 | public CUtlVector 12 | { 13 | public: 14 | CStringVectorModel( int growSize = 0, int initSize = 0 ) : 15 | CUtlVector( growSize, initSize ) 16 | { 17 | 18 | } 19 | 20 | // no need to update 21 | void Update() override {} 22 | 23 | const char *GetText( int line ) final override 24 | { 25 | if( line < 0 ) 26 | return NULL; 27 | 28 | return Element( line ).String(); 29 | } 30 | 31 | int GetRows() const final override 32 | { 33 | return Count(); 34 | } 35 | }; 36 | #endif // STRINGVECTORMODEL_H 37 | -------------------------------------------------------------------------------- /sdk_includes/README.md: -------------------------------------------------------------------------------- 1 | # sdk_includes 2 | 3 | This directory contains minimal set of Xash3D FWGS headers, 4 | so you can include them in your project that may have completely incompatible 5 | set of headers (like halflife-updated, or original HLSDK for example). 6 | 7 | Contents of sdk_includes automatically generated with copy.sh shell script. 8 | Run it from this folder, in context of engine build, to automatically synchronize 9 | selected headers. 10 | 11 | As this contains proprietary Valve headers, the amount of headers needed for menu 12 | must be reduced at some point. 13 | -------------------------------------------------------------------------------- /sdk_includes/common/cl_entity.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef CL_ENTITY_H 17 | #define CL_ENTITY_H 18 | 19 | typedef struct efrag_s 20 | { 21 | struct mleaf_s *leaf; 22 | struct efrag_s *leafnext; 23 | struct cl_entity_s *entity; 24 | struct efrag_s *entnext; 25 | } efrag_t; 26 | 27 | typedef struct 28 | { 29 | byte mouthopen; // 0 = mouth closed, 255 = mouth agape 30 | byte sndcount; // counter for running average 31 | int sndavg; // running average 32 | } mouth_t; 33 | 34 | typedef struct 35 | { 36 | float prevanimtime; 37 | float sequencetime; 38 | byte prevseqblending[2]; 39 | vec3_t prevorigin; 40 | vec3_t prevangles; 41 | 42 | int prevsequence; 43 | float prevframe; 44 | 45 | byte prevcontroller[4]; 46 | byte prevblending[2]; 47 | } latchedvars_t; 48 | 49 | typedef struct 50 | { 51 | // Time stamp for this movement 52 | float animtime; 53 | 54 | vec3_t origin; 55 | vec3_t angles; 56 | } position_history_t; 57 | 58 | typedef struct cl_entity_s cl_entity_t; 59 | 60 | #define HISTORY_MAX 64 // Must be power of 2 61 | #define HISTORY_MASK ( HISTORY_MAX - 1 ) 62 | 63 | #include "entity_state.h" 64 | #include "event_args.h" 65 | 66 | struct cl_entity_s 67 | { 68 | int index; // Index into cl_entities ( should match actual slot, but not necessarily ) 69 | qboolean player; // True if this entity is a "player" 70 | 71 | entity_state_t baseline; // The original state from which to delta during an uncompressed message 72 | entity_state_t prevstate; // The state information from the penultimate message received from the server 73 | entity_state_t curstate; // The state information from the last message received from server 74 | 75 | int current_position; // Last received history update index 76 | position_history_t ph[HISTORY_MAX]; // History of position and angle updates for this player 77 | 78 | mouth_t mouth; // For synchronizing mouth movements. 79 | 80 | latchedvars_t latched; // Variables used by studio model rendering routines 81 | 82 | // Information based on interplocation, extrapolation, prediction, or just copied from last msg received. 83 | // 84 | float lastmove; 85 | 86 | // Actual render position and angles 87 | vec3_t origin; 88 | vec3_t angles; 89 | 90 | // Attachment points 91 | vec3_t attachment[4]; 92 | 93 | // Other entity local information 94 | int trivial_accept; 95 | 96 | struct model_s *model; // cl.model_precache[ curstate.modelindes ]; all visible entities have a model 97 | struct efrag_s *efrag; // linked list of efrags 98 | struct mnode_s *topnode; // for bmodels, first world node that splits bmodel, or NULL if not split 99 | 100 | float syncbase; // for client-side animations -- used by obsolete alias animation system, remove? 101 | int visframe; // last frame this entity was found in an active leaf 102 | colorVec cvFloorColor; 103 | }; 104 | 105 | #endif//CL_ENTITY_H 106 | -------------------------------------------------------------------------------- /sdk_includes/common/con_nprint.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef CON_NPRINT_H 16 | #define CON_NPRINT_H 17 | 18 | typedef struct con_nprint_s 19 | { 20 | int index; // Row # 21 | float time_to_live; // # of seconds before it dissappears 22 | float color[3]; // RGB colors ( 0.0 -> 1.0 scale ) 23 | } con_nprint_t; 24 | 25 | #endif//CON_NPRINT_H 26 | -------------------------------------------------------------------------------- /sdk_includes/common/entity_types.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef ENTITY_TYPES_H 17 | #define ENTITY_TYPES_H 18 | 19 | #define ET_NORMAL 0 20 | #define ET_PLAYER 1 21 | #define ET_TEMPENTITY 2 22 | #define ET_BEAM 3 23 | #define ET_FRAGMENTED 4 // BMODEL or SPRITE that was split across BSP nodes 24 | 25 | #endif//ENTITY_TYPES_H 26 | -------------------------------------------------------------------------------- /sdk_includes/common/event_args.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef EVENT_ARGS_H 16 | #define EVENT_ARGS_H 17 | 18 | // Event was invoked with stated origin 19 | #define FEVENT_ORIGIN ( 1<<0 ) 20 | 21 | // Event was invoked with stated angles 22 | #define FEVENT_ANGLES ( 1<<1 ) 23 | 24 | typedef struct event_args_s 25 | { 26 | int flags; 27 | 28 | // Transmitted 29 | int entindex; 30 | 31 | float origin[3]; 32 | float angles[3]; 33 | float velocity[3]; 34 | 35 | int ducking; 36 | 37 | float fparam1; 38 | float fparam2; 39 | 40 | int iparam1; 41 | int iparam2; 42 | 43 | int bparam1; 44 | int bparam2; 45 | } event_args_t; 46 | 47 | #endif//EVENT_ARGS_H 48 | -------------------------------------------------------------------------------- /sdk_includes/common/gameinfo.h: -------------------------------------------------------------------------------- 1 | /* 2 | gameinfo.h - current game info 3 | Copyright (C) 2010 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef GAMEINFO_H 17 | #define GAMEINFO_H 18 | 19 | #define GFL_NOMODELS (1<<0) 20 | #define GFL_NOSKILLS (1<<1) 21 | #define GFL_RENDER_PICBUTTON_TEXT (1<<2) 22 | #define GFL_HD_BACKGROUND (1<<3) 23 | #define GFL_ANIMATED_TITLE (1<<4) 24 | 25 | /* 26 | ======================================================================== 27 | 28 | GAMEINFO stuff 29 | 30 | internal shared gameinfo structure (readonly for engine parts) 31 | ======================================================================== 32 | */ 33 | typedef struct GAMEINFO_s 34 | { 35 | // filesystem info 36 | char gamefolder[64]; // used for change game '-game x' 37 | char startmap[64]; // map to start singleplayer game 38 | char trainmap[64]; // map to start hazard course (if specified) 39 | char title[64]; // Game Main Title 40 | char version[14]; // game version (optional) 41 | short flags; // game flags 42 | 43 | // about mod info 44 | char game_url[256]; // link to a developer's site 45 | char update_url[256]; // link to updates page 46 | char type[64]; // single, toolkit, multiplayer etc 47 | char date[64]; 48 | char size[64]; // displayed mod size 49 | 50 | int gamemode; 51 | } GAMEINFO; 52 | 53 | /* 54 | ======================================================================== 55 | 56 | Extended GameInfo struct introduced in Xash3D FWGS 57 | 58 | GAMEINFO can't be reliably extended, as nor engine, nor menu can't be 59 | sure about struct size. By adding struct versioning, we can check the 60 | presense for extra fields. 61 | ======================================================================== 62 | */ 63 | 64 | #define GAMEINFO_VERSION 2 65 | 66 | typedef enum gametype_e 67 | { 68 | GAME_NORMAL, 69 | GAME_SINGLEPLAYER_ONLY, 70 | GAME_MULTIPLAYER_ONLY, 71 | } gametype_t; 72 | 73 | typedef struct gameinfo2_s 74 | { 75 | int gi_version; // should be set to desired struct version, e.g. GAMEINFO_VERSION 76 | 77 | // filesystem info 78 | char gamefolder[64]; // used for change game 79 | char startmap[64]; // map to start singleplayer game from 80 | char trainmap[64]; // map to start hazardous course from (if specified) 81 | char demomap[64]; // map to start demo chapter from (if specified) 82 | char title[64]; // game title 83 | char iconpath[64]; // path to game icon 84 | char version[16]; // game version (optional) 85 | uint32_t flags; // gameinfo flags, extended to fit more flags 86 | 87 | // mod info 88 | char game_url[256]; // link to a developer's site 89 | char update_url[256]; // link to updates page 90 | char type[64]; // single, toolkit, multiplayer, etc 91 | char date[64]; // release date 92 | uint64_t size; // size in bytes 93 | 94 | gametype_t gamemode; 95 | } gameinfo2_t; 96 | 97 | #endif//GAMEINFO_H 98 | -------------------------------------------------------------------------------- /sdk_includes/common/kbutton.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1996-1997 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | #ifndef KBUTTON_H 21 | #define KBUTTON_H 22 | 23 | // a1ba: copied from WinQuake/client.h 24 | // 25 | // cl_input 26 | // 27 | typedef struct 28 | { 29 | int down[2]; // key nums holding it down 30 | int state; // low bit is down state 31 | } kbutton_t; 32 | 33 | STATIC_CHECK_SIZEOF( kbutton_t, 12, 12 ); 34 | 35 | #endif // KBUTTON_H 36 | -------------------------------------------------------------------------------- /sdk_includes/common/mathlib.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | // mathlib.h 16 | 17 | #include 18 | 19 | typedef float vec_t; 20 | typedef vec_t vec2_t[2]; 21 | typedef vec_t vec3_t[3]; 22 | typedef vec_t vec4_t[4]; // x,y,z,w 23 | 24 | #ifndef M_PI 25 | #define M_PI 3.14159265358979323846 // matches value in gcc v2 math.h 26 | #endif 27 | 28 | struct mplane_s; 29 | 30 | extern vec3_t vec3_origin; 31 | extern int nanmask; 32 | 33 | #define IS_NAN(x) (((*(int *)&x)&nanmask)==nanmask) 34 | 35 | #ifndef VECTOR_H 36 | #define DotProduct(x,y) ((x)[0]*(y)[0]+(x)[1]*(y)[1]+(x)[2]*(y)[2]) 37 | #endif 38 | 39 | #define VectorSubtract(a,b,c) {(c)[0]=(a)[0]-(b)[0];(c)[1]=(a)[1]-(b)[1];(c)[2]=(a)[2]-(b)[2];} 40 | #define VectorAdd(a,b,c) {(c)[0]=(a)[0]+(b)[0];(c)[1]=(a)[1]+(b)[1];(c)[2]=(a)[2]+(b)[2];} 41 | #define VectorCopy(a,b) {(b)[0]=(a)[0];(b)[1]=(a)[1];(b)[2]=(a)[2];} 42 | #define VectorClear(a) {(a)[0]=0.0;(a)[1]=0.0;(a)[2]=0.0;} 43 | 44 | void VectorMA (const vec3_t veca, float scale, const vec3_t vecb, vec3_t vecc); 45 | 46 | vec_t _DotProduct (vec3_t v1, vec3_t v2); 47 | void _VectorSubtract (vec3_t veca, vec3_t vecb, vec3_t out); 48 | void _VectorAdd (vec3_t veca, vec3_t vecb, vec3_t out); 49 | void _VectorCopy (vec3_t in, vec3_t out); 50 | 51 | int VectorCompare (const vec3_t v1, const vec3_t v2); 52 | float Length (const vec3_t v); 53 | void CrossProduct (const vec3_t v1, const vec3_t v2, vec3_t cross); 54 | float VectorNormalize (vec3_t v); // returns vector length 55 | void VectorInverse (vec3_t v); 56 | void VectorScale (const vec3_t in, vec_t scale, vec3_t out); 57 | 58 | void R_ConcatRotations (float in1[3][3], float in2[3][3], float out[3][3]); 59 | void R_ConcatTransforms (float in1[3][4], float in2[3][4], float out[3][4]); 60 | 61 | void AngleVectors (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); 62 | void AngleVectorsTranspose (const vec3_t angles, vec3_t forward, vec3_t right, vec3_t up); 63 | #define AngleIVectors AngleVectorsTranspose 64 | 65 | void AngleMatrix (const vec3_t angles, float (*matrix)[4] ); 66 | void AngleIMatrix (const vec3_t angles, float (*matrix)[4] ); 67 | void VectorTransform (const vec3_t in1, float in2[3][4], vec3_t out); 68 | 69 | void NormalizeAngles( vec3_t angles ); 70 | void InterpolateAngles( vec3_t start, vec3_t end, vec3_t output, float frac ); 71 | float AngleBetweenVectors( const vec3_t v1, const vec3_t v2 ); 72 | 73 | void VectorMatrix( vec3_t forward, vec3_t right, vec3_t up); 74 | void VectorAngles( const vec3_t forward, vec3_t angles ); 75 | 76 | int InvertMatrix( const float * m, float *out ); 77 | 78 | int BoxOnPlaneSide (vec3_t emins, vec3_t emaxs, struct mplane_s *plane); 79 | float anglemod(float a); 80 | 81 | #define BOX_ON_PLANE_SIDE(emins, emaxs, p) \ 82 | (((p)->type < 3)? \ 83 | ( \ 84 | ((p)->dist <= (emins)[(p)->type])? \ 85 | 1 \ 86 | : \ 87 | ( \ 88 | ((p)->dist >= (emaxs)[(p)->type])?\ 89 | 2 \ 90 | : \ 91 | 3 \ 92 | ) \ 93 | ) \ 94 | : \ 95 | BoxOnPlaneSide( (emins), (emaxs), (p))) 96 | -------------------------------------------------------------------------------- /sdk_includes/common/net_api.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef NET_API_H 17 | #define NET_API_H 18 | 19 | #include "netadr.h" 20 | 21 | #define NETAPI_REQUEST_SERVERLIST ( 0 ) // Doesn't need a remote address 22 | #define NETAPI_REQUEST_PING ( 1 ) 23 | #define NETAPI_REQUEST_RULES ( 2 ) 24 | #define NETAPI_REQUEST_PLAYERS ( 3 ) 25 | #define NETAPI_REQUEST_DETAILS ( 4 ) 26 | 27 | // Set this flag for things like broadcast requests, etc. where the engine should not 28 | // kill the request hook after receiving the first response 29 | #define FNETAPI_MULTIPLE_RESPONSE ( 1<<0 ) 30 | #define FNETAPI_LEGACY_PROTOCOL ( 1<<1 ) // xash3d-fwgs extension 31 | 32 | struct net_response_s; 33 | typedef void (*net_api_response_func_t) ( struct net_response_s *response ); 34 | 35 | #define NET_SUCCESS ( 0 ) 36 | #define NET_ERROR_TIMEOUT ( 1<<0 ) 37 | #define NET_ERROR_PROTO_UNSUPPORTED ( 1<<1 ) 38 | #define NET_ERROR_UNDEFINED ( 1<<2 ) 39 | #define NET_ERROR_FORBIDDEN ( 1<<3 ) // xash3d-fwgs extension 40 | 41 | typedef struct net_adrlist_s 42 | { 43 | struct net_adrlist_s *next; 44 | netadr_t remote_address; 45 | } net_adrlist_t; 46 | 47 | typedef struct net_response_s 48 | { 49 | // NET_SUCCESS or an error code 50 | int error; 51 | // Context ID 52 | int context; 53 | // Type 54 | int type; 55 | // Server that is responding to the request 56 | netadr_t remote_address; 57 | // Response RTT ping time 58 | double ping; 59 | // Key/Value pair string ( separated by backlash \ characters ) 60 | // WARNING: You must copy this buffer in the callback function, because it is freed 61 | // by the engine right after the call!!!! 62 | // ALSO: For NETAPI_REQUEST_SERVERLIST requests, this will be a pointer to a linked list of net_adrlist_t's 63 | void *response; 64 | } net_response_t; 65 | 66 | typedef struct net_status_s 67 | { 68 | // Connected to remote server? 1 == yes, 0 otherwise 69 | int connected; 70 | // Client's IP address 71 | netadr_t local_address; 72 | // Address of remote server 73 | netadr_t remote_address; 74 | // Packet Loss ( as a percentage ) 75 | int packet_loss; 76 | // Latency, in seconds ( multiply by 1000.0 to get milliseconds ) 77 | double latency; 78 | // Connection time, in seconds 79 | double connection_time; 80 | // Rate setting ( for incoming data ) 81 | double rate; 82 | } net_status_t; 83 | 84 | typedef struct net_api_s 85 | { 86 | // APIs 87 | void (*InitNetworking)( void ); 88 | void (*Status )( struct net_status_s *status ); 89 | void (*SendRequest)( int context, int request, int flags, double timeout, struct netadr_s *remote_address, net_api_response_func_t response ); 90 | void (*CancelRequest)( int context ); 91 | void (*CancelAllRequests)( void ); 92 | const char *(*AdrToString)( struct netadr_s *a ); 93 | int ( *CompareAdr)( struct netadr_s *a, struct netadr_s *b ); 94 | int ( *StringToAdr)( char *s, struct netadr_s *a ); 95 | const char *(*ValueForKey)( const char *s, const char *key ); 96 | void (*RemoveKey)( char *s, const char *key ); 97 | void (*SetValueForKey)( char *s, const char *key, const char *value, int maxsize ); 98 | } net_api_t; 99 | 100 | #endif//NET_APIH 101 | -------------------------------------------------------------------------------- /sdk_includes/common/netadr.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 1997-2001 Id Software, Inc. 3 | 4 | This program is free software; you can redistribute it and/or 5 | modify it under the terms of the GNU General Public License 6 | as published by the Free Software Foundation; either version 2 7 | of the License, or (at your option) any later version. 8 | 9 | This program is distributed in the hope that it will be useful, 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 12 | 13 | See the GNU General Public License for more details. 14 | 15 | You should have received a copy of the GNU General Public License 16 | along with this program; if not, write to the Free Software 17 | Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 18 | 19 | */ 20 | 21 | #ifndef NET_ADR_H 22 | #define NET_ADR_H 23 | 24 | #include STDINT_H 25 | 26 | // net.h -- quake's interface to the networking layer 27 | // a1ba: copied from Quake-2/qcommon/qcommon.h and modified to support IPv6 28 | 29 | #define PORT_ANY -1 30 | 31 | typedef enum netadrtype_e 32 | { 33 | NA_UNDEFINED = 0, 34 | NA_LOOPBACK, 35 | NA_BROADCAST, 36 | NA_IP, 37 | NA_IPX, 38 | NA_BROADCAST_IPX, 39 | NA_IP6, 40 | NA_MULTICAST_IP6 41 | } netadrtype_t; 42 | 43 | /* 44 | Original Quake-2 structure: 45 | typedef struct 46 | { 47 | netadrtype_t type; 48 | 49 | byte ip[4]; 50 | byte ipx[10]; 51 | 52 | unsigned short port; 53 | } netadr_t; 54 | */ 55 | 56 | #pragma pack( push, 1 ) 57 | typedef struct netadr_s 58 | { 59 | // the reason we do this evil thing, is that when this struct contains IPv6 60 | // address the `type` is 2-byte wide, but when it doesn't `type` must 4-byte 61 | // wide _and_ ip6_0 must be zeroed, to keep it binary compatible. 62 | #if XASH_LITTLE_ENDIAN 63 | uint16_t type; 64 | uint8_t ip6_0[2]; 65 | #elif XASH_BIG_ENDIAN 66 | uint8_t ip6_0[2]; 67 | uint16_t type; 68 | #else 69 | #error 70 | #endif 71 | 72 | union 73 | { 74 | // IPv6 struct 75 | uint8_t ip6_1[14]; 76 | struct 77 | { 78 | union 79 | { 80 | uint8_t ip[4]; 81 | uint32_t ip4; // for easier conversions 82 | }; 83 | uint8_t ipx[10]; 84 | }; 85 | }; 86 | uint16_t port; 87 | } netadr_t; 88 | #pragma pack( pop ) 89 | 90 | static inline netadrtype_t NET_NetadrType( const netadr_t *a ) 91 | { 92 | if( a->type == NA_IP6 || a->type == NA_MULTICAST_IP6 ) 93 | return (netadrtype_t)a->type; 94 | 95 | if( a->ip6_0[0] || a->ip6_0[1] ) 96 | return NA_UNDEFINED; 97 | 98 | return (netadrtype_t)a->type; 99 | } 100 | 101 | static inline void NET_NetadrSetType( netadr_t *a, netadrtype_t type ) 102 | { 103 | if( type == NA_IP6 || type == NA_MULTICAST_IP6 ) 104 | { 105 | a->type = type; 106 | return; 107 | } 108 | 109 | a->ip6_0[0] = a->ip6_0[1] = 0; 110 | a->type = type; 111 | } 112 | 113 | STATIC_CHECK_SIZEOF( netadr_t, 20, 20 ); 114 | 115 | #endif // NET_ADR_H 116 | -------------------------------------------------------------------------------- /sdk_includes/common/ref_params.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef REF_PARAMS_H 17 | #define REF_PARAMS_H 18 | 19 | typedef struct ref_params_s 20 | { 21 | // output 22 | vec3_t vieworg; 23 | vec3_t viewangles; 24 | 25 | vec3_t forward; 26 | vec3_t right; 27 | vec3_t up; 28 | 29 | // Client frametime; 30 | float frametime; 31 | // Client time 32 | float time; 33 | 34 | // Misc 35 | int intermission; 36 | int paused; 37 | int spectator; 38 | int onground; 39 | int waterlevel; 40 | 41 | vec3_t simvel; 42 | vec3_t simorg; 43 | 44 | vec3_t viewheight; 45 | float idealpitch; 46 | 47 | vec3_t cl_viewangles; 48 | int health; 49 | vec3_t crosshairangle; 50 | float viewsize; 51 | 52 | vec3_t punchangle; 53 | int maxclients; 54 | int viewentity; 55 | int playernum; 56 | int max_entities; 57 | int demoplayback; 58 | int hardware; 59 | int smoothing; 60 | 61 | // Last issued usercmd 62 | struct usercmd_s *cmd; 63 | 64 | // Movevars 65 | struct movevars_s *movevars; 66 | 67 | int viewport[4]; // the viewport coordinates x, y, width, height 68 | int nextView; // the renderer calls ClientDLL_CalcRefdef() and Renderview 69 | // so long in cycles until this value is 0 (multiple views) 70 | int onlyClientDraw; // if !=0 nothing is drawn by the engine except clientDraw functions 71 | } ref_params_t; 72 | 73 | // same as ref_params but for overview mode 74 | typedef struct ref_overview_s 75 | { 76 | vec3_t origin; 77 | qboolean rotated; 78 | 79 | float xLeft; 80 | float xRight; 81 | float yTop; 82 | float yBottom; 83 | float zFar; 84 | float zNear; 85 | float flZoom; 86 | } ref_overview_t; 87 | 88 | // ref_viewpass_t->flags 89 | #define RF_DRAW_WORLD (1<<0) // pass should draw the world (otherwise it's player menu model) 90 | #define RF_DRAW_CUBEMAP (1<<1) // special 6x pass to render cubemap\skybox sides 91 | #define RF_DRAW_OVERVIEW (1<<2) // overview mode is active 92 | #define RF_ONLY_CLIENTDRAW (1<<3) // nothing is drawn by the engine except clientDraw functions 93 | 94 | // intermediate struct for viewpass (or just a single frame) 95 | typedef struct ref_viewpass_s 96 | { 97 | int viewport[4]; // size of new viewport 98 | vec3_t vieworigin; // view origin 99 | vec3_t viewangles; // view angles 100 | int viewentity; // entitynum (P2: Savior uses this) 101 | float fov_x, fov_y; // vertical & horizontal FOV 102 | int flags; // if !=0 nothing is drawn by the engine except clientDraw functions 103 | } ref_viewpass_t; 104 | 105 | #endif//REF_PARAMS_H 106 | -------------------------------------------------------------------------------- /sdk_includes/common/weaponinfo.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef WEAPONINFO_H 17 | #define WEAPONINFO_H 18 | 19 | // Info about weapons player might have in his/her possession 20 | typedef struct weapon_data_s 21 | { 22 | int m_iId; 23 | int m_iClip; 24 | 25 | float m_flNextPrimaryAttack; 26 | float m_flNextSecondaryAttack; 27 | float m_flTimeWeaponIdle; 28 | 29 | int m_fInReload; 30 | int m_fInSpecialReload; 31 | float m_flNextReload; 32 | float m_flPumpTime; 33 | float m_fReloadTime; 34 | 35 | float m_fAimedDamage; 36 | float m_fNextAimBonus; 37 | int m_fInZoom; 38 | int m_iWeaponState; 39 | 40 | int iuser1; 41 | int iuser2; 42 | int iuser3; 43 | int iuser4; 44 | float fuser1; 45 | float fuser2; 46 | float fuser3; 47 | float fuser4; 48 | } weapon_data_t; 49 | 50 | #endif//WEAPONINFO_H 51 | -------------------------------------------------------------------------------- /sdk_includes/common/wrect.h: -------------------------------------------------------------------------------- 1 | /* 2 | wrect.h - rectangle definition 3 | Copyright (C) 2010 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #ifndef WRECT_H 17 | #define WRECT_H 18 | 19 | typedef struct wrect_s 20 | { 21 | int left, right, top, bottom; 22 | } wrect_t; 23 | 24 | #endif//WRECT_H 25 | -------------------------------------------------------------------------------- /sdk_includes/copy.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # DO NOT NEW ADD FILES WITHOUT A REASON 4 | FILES_LIST=" \ 5 | common/bspfile.h \ 6 | common/cl_entity.h \ 7 | common/const.h \ 8 | common/con_nprint.h \ 9 | common/com_model.h \ 10 | common/cvardef.h \ 11 | common/entity_state.h \ 12 | common/entity_types.h \ 13 | common/event_args.h \ 14 | common/gameinfo.h \ 15 | common/kbutton.h \ 16 | common/mathlib.h \ 17 | common/netadr.h \ 18 | common/net_api.h \ 19 | common/ref_params.h \ 20 | common/weaponinfo.h \ 21 | common/wrect.h \ 22 | common/xash3d_types.h \ 23 | engine/custom.h \ 24 | engine/keydefs.h \ 25 | engine/menu_int.h \ 26 | engine/mobility_int.h \ 27 | engine/cursor_type.h \ 28 | public/build.h \ 29 | public/buildenums.h \ 30 | pm_shared/pm_info.h \ 31 | " 32 | 33 | die() 34 | { 35 | echo $@ 36 | exit 1 37 | } 38 | 39 | for i in $FILES_LIST; do 40 | dir=$(dirname $i) 41 | 42 | echo -n "Copying $i... " 43 | mkdir -p $dir || die "Can't create folder $dir" 44 | cp ../../../$i $dir/ || die "Can't copy file $1" 45 | echo "OK" 46 | done 47 | -------------------------------------------------------------------------------- /sdk_includes/engine/cursor_type.h: -------------------------------------------------------------------------------- 1 | /* 2 | cursor_type.h - enumeration of possible mouse cursor types 3 | Copyright (C) 2022 FWGS Team 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | #pragma once 17 | #ifndef CURSOR_TYPE_H 18 | #define CURSOR_TYPE_H 19 | 20 | typedef enum 21 | { 22 | dc_user, 23 | dc_none, 24 | dc_arrow, 25 | dc_ibeam, 26 | dc_hourglass, 27 | dc_crosshair, 28 | dc_up, 29 | dc_sizenwse, 30 | dc_sizenesw, 31 | dc_sizewe, 32 | dc_sizens, 33 | dc_sizeall, 34 | dc_no, 35 | dc_hand, 36 | dc_last 37 | } VGUI_DefaultCursor; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /sdk_includes/engine/custom.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | 16 | #ifndef CUSTOM_H 17 | #define CUSTOM_H 18 | 19 | #include "const.h" 20 | 21 | ///////////////// 22 | // Customization 23 | // passed to pfnPlayerCustomization 24 | // For automatic downloading. 25 | 26 | typedef enum 27 | { 28 | t_sound = 0, 29 | t_skin, 30 | t_model, 31 | t_decal, 32 | t_generic, 33 | t_eventscript, 34 | t_world, // Fake type for world, is really t_model 35 | } resourcetype_t; 36 | 37 | typedef struct 38 | { 39 | int size; 40 | } _resourceinfo_t; 41 | 42 | typedef struct resourceinfo_s 43 | { 44 | _resourceinfo_t info[8]; 45 | } resourceinfo_t; 46 | 47 | #define RES_FATALIFMISSING (1<<0) // Disconnect if we can't get this file. 48 | #define RES_WASMISSING (1<<1) // Do we have the file locally, did we get it ok? 49 | #define RES_CUSTOM (1<<2) // Is this resource one that corresponds to another player's customization 50 | // or is it a server startup resource. 51 | #define RES_REQUESTED (1<<3) // Already requested a download of this one 52 | #define RES_PRECACHED (1<<4) // Already precached 53 | #define RES_ALWAYS (1<<5) // Download always even if available on client 54 | #define RES_CHECKFILE (1<<7) // Check file on client 55 | 56 | // this archive was already mounted after rescan 57 | // only makes sense for archives and on client 58 | #define RES_EXTRA_ARCHIVE_CHECKED BIT( 0 ) 59 | 60 | typedef struct resource_s 61 | { 62 | char szFileName[64]; // File name to download/precache. 63 | resourcetype_t type; // t_sound, t_skin, t_model, t_decal. 64 | int nIndex; // For t_decals 65 | int nDownloadSize; // Size in Bytes if this must be downloaded. 66 | unsigned char ucFlags; 67 | 68 | // for handling client to client resource propagation 69 | unsigned char rgucMD5_hash[16]; // To determine if we already have it. 70 | unsigned char playernum; // Which player index this resource is associated with, 71 | // if it's a custom resource. 72 | 73 | unsigned char rguc_reserved[32]; // For future expansion 74 | unsigned short ucExtraFlags; // fwgs extension, doesn't change the size of struct because of compiler padding 75 | struct resource_s *pNext; // Next in chain. 76 | struct resource_s *pPrev; 77 | } resource_t; 78 | 79 | typedef struct customization_s 80 | { 81 | qboolean bInUse; // Is this customization in use; 82 | resource_t resource; // The resource_t for this customization 83 | qboolean bTranslated; // Has the raw data been translated into a useable format? 84 | // (e.g., raw decal .wad make into texture_t *) 85 | int nUserData1; // Customization specific data 86 | int nUserData2; // Customization specific data 87 | void *pInfo; // Buffer that holds the data structure that references 88 | // the data (e.g., the cachewad_t) 89 | void *pBuffer; // Buffer that holds the data for the customization 90 | // (the raw .wad data) 91 | struct customization_s *pNext; // Next in chain 92 | } customization_t; 93 | 94 | #define FCUST_FROMHPAK ( 1<<0 ) 95 | #define FCUST_WIPEDATA ( 1<<1 ) 96 | #define FCUST_IGNOREINIT ( 1<<2 ) 97 | 98 | STATIC_CHECK_SIZEOF( customization_t, 164, 192 ); 99 | STATIC_CHECK_SIZEOF( resource_t, 136, 144 ); 100 | 101 | #endif // CUSTOM_H 102 | -------------------------------------------------------------------------------- /sdk_includes/engine/mobility_int.h: -------------------------------------------------------------------------------- 1 | /* 2 | mobility_int.h - interface between engine and client for mobile platforms 3 | Copyright (C) 2015 a1batross 4 | 5 | This is free and unencumbered software released into the public domain. 6 | 7 | Anyone is free to copy, modify, publish, use, compile, sell, or 8 | distribute this software, either in source code form or as a compiled 9 | binary, for any purpose, commercial or non-commercial, and by any 10 | means. 11 | 12 | In jurisdictions that recognize copyright laws, the author or authors 13 | of this software dedicate any and all copyright interest in the 14 | software to the public domain. We make this dedication for the benefit 15 | of the public at large and to the detriment of our heirs and 16 | successors. We intend this dedication to be an overt act of 17 | relinquishment in perpetuity of all present and future rights to this 18 | software under copyright law. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR 24 | OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 25 | ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | For more information, please refer to 29 | */ 30 | 31 | #pragma once 32 | #ifndef MOBILITY_INT_H 33 | #define MOBILITY_INT_H 34 | #ifdef __cplusplus 35 | extern "C" { 36 | #endif 37 | 38 | #define MOBILITY_API_VERSION 2 39 | #define MOBILITY_CLIENT_EXPORT "HUD_MobilityInterface" 40 | 41 | #define VIBRATE_NORMAL (1U << 0) // just vibrate for given "life" 42 | 43 | #define TOUCH_FL_HIDE (1U << 0) 44 | #define TOUCH_FL_NOEDIT (1U << 1) 45 | #define TOUCH_FL_CLIENT (1U << 2) 46 | #define TOUCH_FL_MP (1U << 3) 47 | #define TOUCH_FL_SP (1U << 4) 48 | #define TOUCH_FL_DEF_SHOW (1U << 5) 49 | #define TOUCH_FL_DEF_HIDE (1U << 6) 50 | #define TOUCH_FL_DRAW_ADDITIVE (1U << 7) 51 | #define TOUCH_FL_STROKE (1U << 8) 52 | #define TOUCH_FL_PRECISION (1U << 9) 53 | 54 | // flags for COM_ParseFileSafe 55 | #define PFILE_IGNOREBRACKET (1<<0) 56 | #define PFILE_HANDLECOLON (1<<1) 57 | #define PFILE_IGNOREHASHCMT (1<<2) 58 | 59 | typedef struct mobile_engfuncs_s 60 | { 61 | // indicates version of API. Should be equal to MOBILITY_API_VERSION 62 | // version changes when existing functions are changes 63 | int version; 64 | 65 | // vibration control 66 | // life -- time to vibrate in ms 67 | void (*pfnVibrate)( float life, char flags ); 68 | 69 | // enable text input 70 | void (*pfnEnableTextInput)( int enable ); 71 | 72 | // add temporaty button, edit will be disabled 73 | void (*pfnTouchAddClientButton)( const char *name, const char *texture, const char *command, float x1, float y1, float x2, float y2, unsigned char *color, int round, float aspect, int flags ); 74 | 75 | // add button to defaults list. Will be loaded on config generation 76 | void (*pfnTouchAddDefaultButton)( const char *name, const char *texturefile, const char *command, float x1, float y1, float x2, float y2, unsigned char *color, int round, float aspect, int flags ); 77 | 78 | // hide/show buttons by pattern 79 | void (*pfnTouchHideButtons)( const char *name, unsigned char hide ); 80 | 81 | // remove button with given name 82 | void (*pfnTouchRemoveButton)( const char *name ); 83 | 84 | // when enabled, only client buttons shown 85 | void (*pfnTouchSetClientOnly)( unsigned char state ); 86 | 87 | // Clean defaults list 88 | void (*pfnTouchResetDefaultButtons)( void ); 89 | 90 | // Draw scaled font for client 91 | int (*pfnDrawScaledCharacter)( int x, int y, int number, int r, int g, int b, float scale ); 92 | 93 | void (*pfnSys_Warn)( const char *format, ... ); 94 | 95 | // Get native object for current platform. 96 | // Pass NULL to arguments to receive an array of available objects or NULL if nothing 97 | void *(*pfnGetNativeObject)( const char *obj ); 98 | 99 | void (*pfnSetCustomClientID)( const char *id ); 100 | 101 | // COM_ParseFile but with buffer size limit, len reports written size or -1 on overflow 102 | char* (*pfnParseFile)( char *data, char *buf, const int size, unsigned int flags, int *len ); 103 | // To be continued... 104 | } mobile_engfuncs_t; 105 | 106 | // function exported from client 107 | // returns 0 on no error otherwise error 108 | typedef int (*pfnMobilityInterface)( mobile_engfuncs_t *gMobileEngfuncs ); 109 | 110 | #ifdef __cplusplus 111 | } 112 | #endif 113 | #endif 114 | -------------------------------------------------------------------------------- /sdk_includes/pm_shared/pm_info.h: -------------------------------------------------------------------------------- 1 | /*** 2 | * 3 | * Copyright (c) 1996-2002, Valve LLC. All rights reserved. 4 | * 5 | * This product contains software technology licensed from Id 6 | * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc. 7 | * All Rights Reserved. 8 | * 9 | * Use, distribution, and modification of this source code and/or resulting 10 | * object code is restricted to non-commercial enhancements to products from 11 | * Valve LLC. All other use, distribution, or modification is prohibited 12 | * without written permission from Valve LLC. 13 | * 14 | ****/ 15 | #ifndef PM_INFO_H 16 | #define PM_INFO_H 17 | 18 | #define MAX_PHYSINFO_STRING 256 19 | 20 | #endif//PM_INFO_H 21 | -------------------------------------------------------------------------------- /test_dictgen.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # test_dictgen.py -- VGUI2 dictionary generator test 3 | # Copyright(C) 2019 a1batross 4 | # 5 | # This program is free software: you can redistribute it and/or modify 6 | # it under the terms of the GNU General Public License as published by 7 | # the Free Software Foundation, either version 3 of the License, or 8 | # (at your option) any later version. 9 | # 10 | # This program is distributed in the hope that it will be useful, 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | # GNU General Public License for more details. 14 | 15 | import unittest 16 | import dictgen 17 | import filecmp 18 | import os 19 | 20 | VALID_UNPARSED_TOKENS = ['L ("test1")', 'L( "test2" )', 'L("test" "test")'] 21 | INVALID_UNPARSED_TOKENS = ['L( test )', 'L( "multiline"\n"multiline )'] 22 | VALID_TOKENS = ["test1", "test2", "testtest"] 23 | 24 | class DictGenTest(unittest.TestCase): 25 | 26 | def test_parsing_srcs(self): 27 | tokens = dictgen.process_file(os.path.join('tests', 'testfile')) 28 | for i in VALID_UNPARSED_TOKENS: 29 | self.assertTrue(i in tokens) 30 | 31 | for i in INVALID_UNPARSED_TOKENS: 32 | self.assertFalse(i in tokens) 33 | 34 | def test_processing_translables(self): 35 | tokens = dictgen.process_trans(VALID_UNPARSED_TOKENS) 36 | self.assertEqual(tokens, VALID_TOKENS) 37 | 38 | def test_vgui_parser(self): 39 | tokens = dictgen.vgui_translation_parse(os.path.join('tests', 'test_english.txt')) 40 | self.assertEqual(tokens, VALID_TOKENS) 41 | 42 | def test_dictgen(self): 43 | dictgen.create_translations_file('temp.txt', VALID_TOKENS) 44 | tokens = dictgen.vgui_translation_parse('temp.txt') 45 | os.remove('temp.txt') 46 | self.assertEqual(tokens, VALID_TOKENS) 47 | 48 | if __name__ == '__main__': 49 | unittest.main() 50 | 51 | 52 | -------------------------------------------------------------------------------- /tests/test_english.txt: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FWGS/mainui_cpp/b1d006e521a4cfca8e576115a43a7cb8a3dbf79b/tests/test_english.txt -------------------------------------------------------------------------------- /tests/testfile: -------------------------------------------------------------------------------- 1 | L( test ) // don't added 2 | L ("test1") 3 | L( "test2" ) 4 | L("test" "test") 5 | L( "multiline" 6 | "multiline" ) // don't added, yet 7 | -------------------------------------------------------------------------------- /translations/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/FWGS/mainui_cpp/b1d006e521a4cfca8e576115a43a7cb8a3dbf79b/translations/.gitkeep -------------------------------------------------------------------------------- /udll_int.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | dll_int.cpp - dll entry point 3 | Copyright (C) 2010 Uncle Mike 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | 16 | 17 | #include "extdll_menu.h" 18 | #include "BaseMenu.h" 19 | #include "Utils.h" 20 | 21 | ui_enginefuncs_t EngFuncs::engfuncs; 22 | ui_extendedfuncs_t EngFuncs::textfuncs; 23 | ui_globalvars_t *gpGlobals; 24 | CMenu gMenu; 25 | 26 | static UI_FUNCTIONS gFunctionTable = 27 | { 28 | UI_VidInit, 29 | UI_Init, 30 | UI_Shutdown, 31 | UI_UpdateMenu, 32 | UI_KeyEvent, 33 | UI_MouseMove, 34 | UI_SetActiveMenu, 35 | UI_AddServerToList, 36 | UI_GetCursorPos, 37 | UI_SetCursorPos, 38 | UI_ShowCursor, 39 | UI_CharEvent, 40 | UI_MouseInRect, 41 | UI_IsVisible, 42 | UI_CreditsActive, 43 | UI_FinalCredits 44 | }; 45 | 46 | //======================================================================= 47 | // GetApi 48 | //======================================================================= 49 | extern "C" EXPORT int GetMenuAPI(UI_FUNCTIONS *pFunctionTable, ui_enginefuncs_t* pEngfuncsFromEngine, ui_globalvars_t *pGlobals) 50 | { 51 | if( !pFunctionTable || !pEngfuncsFromEngine ) 52 | { 53 | return FALSE; 54 | } 55 | 56 | // copy HUD_FUNCTIONS table to engine, copy engfuncs table from engine 57 | memcpy( pFunctionTable, &gFunctionTable, sizeof( UI_FUNCTIONS )); 58 | memcpy( &EngFuncs::engfuncs, pEngfuncsFromEngine, sizeof( ui_enginefuncs_t )); 59 | memset( &EngFuncs::textfuncs, 0, sizeof( ui_extendedfuncs_t )); 60 | 61 | gpGlobals = pGlobals; 62 | 63 | return TRUE; 64 | } 65 | 66 | static UI_EXTENDED_FUNCTIONS gExtendedTable = 67 | { 68 | AddTouchButtonToList, 69 | UI_MenuResetPing_f, 70 | UI_ConnectionWarning_f, 71 | UI_UpdateDialog, 72 | UI_ShowMessageBox, 73 | UI_ConnectionProgress_Disconnect, 74 | UI_ConnectionProgress_Download, 75 | UI_ConnectionProgress_DownloadEnd, 76 | UI_ConnectionProgress_Precache, 77 | UI_ConnectionProgress_Connect, 78 | UI_ConnectionProgress_ChangeLevel, 79 | UI_ConnectionProgress_ParseServerInfo 80 | }; 81 | 82 | extern "C" EXPORT int GetExtAPI( int version, UI_EXTENDED_FUNCTIONS *pFunctionTable, ui_extendedfuncs_t *pEngfuncsFromEngine ) 83 | { 84 | if( !pFunctionTable || !pEngfuncsFromEngine ) 85 | { 86 | return FALSE; 87 | } 88 | 89 | if( version != MENU_EXTENDED_API_VERSION ) 90 | { 91 | Con_Printf( "Error: failed to initialize extended menu API. Expected by DLL: %d. Got from engine: %d\n", MENU_EXTENDED_API_VERSION, version ); 92 | return FALSE; 93 | } 94 | 95 | memcpy( &EngFuncs::textfuncs, pEngfuncsFromEngine, sizeof( ui_extendedfuncs_t ) ); 96 | memcpy( pFunctionTable, &gExtendedTable, sizeof( UI_EXTENDED_FUNCTIONS )); 97 | 98 | return TRUE; 99 | } 100 | -------------------------------------------------------------------------------- /utflib.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | utflib.c - small unicode conversion library 3 | Copyright (C) 2024 Alibek Omarov 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #include "utflib.h" 16 | #include "xash3d_types.h" 17 | 18 | uint32_t Q_DecodeUTF8( utfstate_t *s, uint32_t in ) 19 | { 20 | // get character length 21 | if( s->len == 0 ) 22 | { 23 | // init state 24 | s->uc = 0; 25 | 26 | // expect ASCII symbols by default 27 | if( likely( in <= 0x7fu )) 28 | return in; 29 | 30 | // invalid sequence 31 | if( unlikely( in >= 0xf8u )) 32 | return 0; 33 | 34 | s->k = 0; 35 | 36 | if( in >= 0xf0u ) 37 | { 38 | s->uc = in & 0x07u; 39 | s->len = 3; 40 | } 41 | else if( in >= 0xe0u ) 42 | { 43 | s->uc = in & 0x0fu; 44 | s->len = 2; 45 | } 46 | else if( in >= 0xc0u ) 47 | { 48 | s->uc = in & 0x1fu; 49 | s->len = 1; 50 | } 51 | 52 | return 0; 53 | } 54 | 55 | // invalid sequence, reset 56 | if( unlikely( in > 0xbfu )) 57 | { 58 | s->len = 0; 59 | return 0; 60 | } 61 | 62 | s->uc <<= 6; 63 | s->uc += in & 0x3fu; 64 | s->k++; 65 | 66 | // sequence complete, reset and return code point 67 | if( likely( s->k == s->len )) 68 | { 69 | s->len = 0; 70 | return s->uc; 71 | } 72 | 73 | // feed more characters 74 | return 0; 75 | } 76 | 77 | uint32_t Q_DecodeUTF16( utfstate_t *s, uint32_t in ) 78 | { 79 | // get character length 80 | if( s->len == 0 ) 81 | { 82 | // init state 83 | s->uc = 0; 84 | 85 | // expect simple case, after all decoding UTF-16 must be easy 86 | if( likely( in < 0xd800u || in > 0xdfffu )) 87 | return in; 88 | 89 | s->uc = (( in - 0xd800u ) << 10 ) + 0x10000u; 90 | s->len = 1; 91 | s->k = 0; 92 | 93 | return 0; 94 | } 95 | 96 | // invalid sequence, reset 97 | if( unlikely( in < 0xdc00u || in > 0xdfffu )) 98 | { 99 | s->len = 0; 100 | return 0; 101 | } 102 | 103 | s->uc |= in - 0xdc00u; 104 | s->k++; 105 | 106 | // sequence complete, reset and return code point 107 | if( likely( s->k == s->len )) 108 | { 109 | s->len = 0; 110 | return s->uc; 111 | } 112 | 113 | // feed more characters (should never happen with UTF-16) 114 | return 0; 115 | } 116 | 117 | size_t Q_EncodeUTF8( char dst[4], uint32_t ch ) 118 | { 119 | if( ch <= 0x7fu ) 120 | { 121 | dst[0] = ch; 122 | return 1; 123 | } 124 | else if( ch <= 0x7ffu ) 125 | { 126 | dst[0] = 0xc0u | (( ch >> 6 ) & 0x1fu ); 127 | dst[1] = 0x80u | (( ch ) & 0x3fu ); 128 | return 2; 129 | } 130 | else if( ch <= 0xffffu ) 131 | { 132 | dst[0] = 0xe0u | (( ch >> 12 ) & 0x0fu ); 133 | dst[1] = 0x80u | (( ch >> 6 ) & 0x3fu ); 134 | dst[2] = 0x80u | (( ch ) & 0x3fu ); 135 | return 3; 136 | } 137 | 138 | dst[0] = 0xf0u | (( ch >> 18 ) & 0x07u ); 139 | dst[1] = 0x80u | (( ch >> 12 ) & 0x3fu ); 140 | dst[2] = 0x80u | (( ch >> 6 ) & 0x3fu ); 141 | dst[3] = 0x80u | (( ch ) & 0x3fu ); 142 | return 4; 143 | } 144 | 145 | size_t Q_UTF8Length( const char *s ) 146 | { 147 | size_t len = 0; 148 | utfstate_t state = { 0 }; 149 | 150 | if( !s ) 151 | return 0; 152 | 153 | for( ; *s; s++ ) 154 | { 155 | uint32_t ch = Q_DecodeUTF8( &state, (uint32_t)*s ); 156 | 157 | if( ch == 0 ) 158 | continue; 159 | 160 | len++; 161 | } 162 | 163 | return len; 164 | } 165 | 166 | static size_t Q_CodepointLength( uint32_t ch ) 167 | { 168 | if( ch <= 0x7fu ) 169 | return 1; 170 | else if( ch <= 0x7ffu ) 171 | return 2; 172 | else if( ch <= 0xffffu ) 173 | return 3; 174 | 175 | return 4; 176 | } 177 | 178 | size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize ) 179 | { 180 | utfstate_t state = { 0 }; 181 | size_t dsti = 0, srci; 182 | 183 | if( !dst || !src || !dstsize || !srcsize ) 184 | return 0; 185 | 186 | for( srci = 0; srci < srcsize && src[srci]; srci++ ) 187 | { 188 | uint32_t ch; 189 | size_t len; 190 | 191 | ch = Q_DecodeUTF16( &state, src[srci] ); 192 | 193 | if( ch == 0 ) 194 | continue; 195 | 196 | len = Q_CodepointLength( ch ); 197 | 198 | if( dsti + len + 1 > dstsize ) 199 | break; 200 | 201 | dsti += Q_EncodeUTF8( &dst[dsti], ch ); 202 | } 203 | 204 | dst[dsti] = 0; 205 | 206 | return dsti; 207 | } 208 | -------------------------------------------------------------------------------- /utflib.h: -------------------------------------------------------------------------------- 1 | /* 2 | utflib.h - small unicode conversion library 3 | Copyright (C) 2024 Alibek Omarov 4 | 5 | This program is free software: you can redistribute it and/or modify 6 | it under the terms of the GNU General Public License as published by 7 | the Free Software Foundation, either version 3 of the License, or 8 | (at your option) any later version. 9 | 10 | This program is distributed in the hope that it will be useful, 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 | GNU General Public License for more details. 14 | */ 15 | #ifndef UTFLIB_H 16 | #define UTFLIB_H 17 | 18 | #include STDINT_H 19 | #include 20 | 21 | typedef struct utfstate_s 22 | { 23 | uint32_t uc; 24 | uint8_t len; 25 | uint8_t k; 26 | } utfstate_t; 27 | 28 | // feed utf8 characters one by one 29 | // if it returns 0, feed more 30 | // utfstate_t must be zero initialized 31 | uint32_t Q_DecodeUTF8( utfstate_t *s, uint32_t ch ); 32 | uint32_t Q_DecodeUTF16( utfstate_t *s, uint32_t ch ); 33 | size_t Q_EncodeUTF8( char dst[4], uint32_t ch ); 34 | 35 | size_t Q_UTF8Length( const char *s ); 36 | 37 | // srcsize in byte pairs 38 | size_t Q_UTF16ToUTF8( char *dst, size_t dstsize, const uint16_t *src, size_t srcsize ); 39 | 40 | #endif // UTFLIB_H 41 | -------------------------------------------------------------------------------- /vs2022/IMPORTANT_NOTE_FOR_MOD_DEVELOPER.txt: -------------------------------------------------------------------------------- 1 | DO NOT replace engine's menu.dll with your freshly built DLL! 2 | 3 | COPY IT ALONGSIDE YOUR MOD CLIENT.DLL, ENGINE WILL FIND IT AUTOMATICALLY! 4 | 5 | FOR 64 BIT BUILDS: LEAVE _amd64 POSTFIX! DO NOT RENAME THE DLL! 6 | 7 | FOR 32 BIT BUILDS: DO NOT USE _amd64 DLL, IT'S INCOMPATIBLE! 8 | 9 | Make Xash3D FWGS happy! 10 | -------------------------------------------------------------------------------- /vs2022/mainui_cpp.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.5.33530.505 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "mainui_cpp", "mainui_cpp.vcxproj", "{84E422A2-9E83-49BF-8107-E84C5DB4236A}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|x64 = Debug|x64 11 | Debug|x86 = Debug|x86 12 | Release|x64 = Release|x64 13 | Release|x86 = Release|x86 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Debug|x64.ActiveCfg = Debug|x64 17 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Debug|x64.Build.0 = Debug|x64 18 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Debug|x86.ActiveCfg = Debug|Win32 19 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Debug|x86.Build.0 = Debug|Win32 20 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Release|x64.ActiveCfg = Release|x64 21 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Release|x64.Build.0 = Release|x64 22 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Release|x86.ActiveCfg = Release|Win32 23 | {84E422A2-9E83-49BF-8107-E84C5DB4236A}.Release|x86.Build.0 = Release|Win32 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | GlobalSection(ExtensibilityGlobals) = postSolution 29 | SolutionGuid = {40563B4A-D8CA-4961-87C3-67F64296FAEF} 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /wscript: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env python 2 | # encoding: utf-8 3 | # a1batross, mittorn, 2018 4 | 5 | from waflib import Logs, Configure 6 | import os 7 | 8 | top = '.' 9 | 10 | FT2_CHECK='''extern "C" { 11 | #include 12 | #include FT_FREETYPE_H 13 | } 14 | 15 | int main() { return FT_Init_FreeType( NULL ); } 16 | ''' 17 | 18 | def options(opt): 19 | grp = opt.add_option_group('MainUI C++ options') 20 | grp.add_option('--enable-stbtt', action = 'store_true', dest = 'USE_STBTT', default = False, 21 | help = 'prefer stb_truetype.h over freetype [default: %(default)s]') 22 | 23 | return 24 | 25 | def configure(conf): 26 | conf.load('fwgslib cxx11') 27 | conf.env.append_unique('DEFINES', 'STDINT_H=') 28 | 29 | if not conf.check_std('cxx11'): 30 | conf.define('MY_COMPILER_SUCKS', 1) 31 | 32 | if conf.env.DEST_OS in ['android', 'darwin', 'nswitch', 'psvita'] or conf.env.MAGX: 33 | conf.options.USE_STBTT = True 34 | 35 | conf.define('MAINUI_USE_CUSTOM_FONT_RENDER', 1) 36 | 37 | nortti = { 38 | 'msvc': ['/GR-'], 39 | 'default': ['-fno-rtti'] 40 | } 41 | 42 | conf.env.append_unique('CXXFLAGS', conf.get_flags_by_compiler(nortti, conf.env.COMPILER_CC)) 43 | 44 | conf.define_cond('MAINUI_USE_STB', conf.options.USE_STBTT) 45 | 46 | if conf.env.DEST_OS == 'android': 47 | conf.define('NO_STL', 1) 48 | conf.env.append_unique('CXXFLAGS', '-fno-exceptions') 49 | 50 | if conf.env.DEST_OS != 'win32' and conf.env.DEST_OS != 'dos': 51 | if not conf.options.USE_STBTT and not conf.options.LOW_MEMORY: 52 | conf.check_pkg('freetype2', 'FT2', FT2_CHECK) 53 | conf.define('MAINUI_USE_FREETYPE', 1) 54 | 55 | def build(bld): 56 | source = bld.path.ant_glob([ 57 | '*.cpp', 58 | 'miniutl/*.cpp', 59 | 'font/*.cpp', 60 | 'menus/*.cpp', 61 | 'menus/dynamic/*.cpp', 62 | 'model/*.cpp', 63 | 'controls/*.cpp' 64 | ]) 65 | 66 | includes = [ 67 | '.', 68 | 'miniutl/', 69 | 'font/', 70 | 'controls/', 71 | 'menus/', 72 | 'model/', 73 | 'sdk_includes/common', 74 | 'sdk_includes/engine', 75 | 'sdk_includes/public', 76 | 'sdk_includes/pm_shared' 77 | ] 78 | 79 | bld.shlib( 80 | source = source, 81 | target = 'menu', 82 | includes = includes, 83 | use = 'werror FT2 GDI32 USER32', 84 | install_path = bld.env.LIBDIR, 85 | cmake_skip = True 86 | ) 87 | --------------------------------------------------------------------------------