From 4d5babd812f447d5b5087b49a66544b261373de2 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Mon, 15 Jun 2020 21:20:57 +0200 Subject: [PATCH 01/10] * Mission Timer at proper place * Map view dimensions fixed --- code/REDALERT/CREDITS.CPP | 17 ++++++----------- code/REDALERT/DISPLAY.CPP | 27 ++++++--------------------- code/REDALERT/SCENARIO.CPP | 9 +++++++-- code/REDALERT/SIDEBAR.CPP | 3 ++- code/REDALERT/TAB.CPP | 3 +-- code/REDALERT/WINSTUB.CPP | 2 +- 6 files changed, 23 insertions(+), 38 deletions(-) diff --git a/code/REDALERT/CREDITS.CPP b/code/REDALERT/CREDITS.CPP index e81076c..834476e 100644 --- a/code/REDALERT/CREDITS.CPP +++ b/code/REDALERT/CREDITS.CPP @@ -89,14 +89,7 @@ void CreditClass::Graphic_Logic(bool forced) { BStart(BENCH_TABS); - int xx = SeenBuff.Get_Width() - (120 * RESFACTOR); - - /* - ** Adjust the credits display to be above the sidebar for 640x400 - */ -#ifdef WIN32 - xx += 80 * RESFACTOR; -#endif + int xx = SeenBuff.Get_Width() - (120 * RESFACTOR) + ( 80 * RESFACTOR ); /* ** Play a sound effect when the money display changes, but only if a sound @@ -116,7 +109,8 @@ void CreditClass::Graphic_Logic(bool forced) TabClass::Draw_Credits_Tab(); Fancy_Text_Print("%ld", xx, 0, &MetalScheme, TBLACK, TPF_METAL12 | TPF_CENTER | TPF_USE_GRAD_PAL, Current); - if (Scen.MissionTimer.Is_Active()) { + if (Scen.MissionTimer.Is_Active()) + { long secs = Scen.MissionTimer / TICKS_PER_SECOND; long mins = secs / 60; long hours = mins / 60; @@ -141,10 +135,11 @@ void CreditClass::Graphic_Logic(bool forced) Map.FlasherTimer = 7; } + xx = SeenBuff.Get_Width() - (120 * RESFACTOR); if (hours) { - Fancy_Text_Print(TXT_TIME_FORMAT_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, hours, mins, secs); + Fancy_Text_Print(TXT_TIME_FORMAT_HOURS, xx, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, hours, mins, secs); } else { - Fancy_Text_Print(TXT_TIME_FORMAT_NO_HOURS, 200 * RESFACTOR, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, mins, secs); + Fancy_Text_Print(TXT_TIME_FORMAT_NO_HOURS, xx, 0, &MetalScheme, TBLACK, TPF_METAL12|TPF_CENTER|TPF_USE_GRAD_PAL, mins, secs); } } diff --git a/code/REDALERT/DISPLAY.CPP b/code/REDALERT/DISPLAY.CPP index 21cd688..4401a5a 100644 --- a/code/REDALERT/DISPLAY.CPP +++ b/code/REDALERT/DISPLAY.CPP @@ -561,33 +561,18 @@ short const * DisplayClass::Text_Overlap_List(char const * text, int x, int y) c *=============================================================================================*/ void DisplayClass::Set_View_Dimensions(int x, int y, int width, int height) { - //if (width == -1) { - // TacLeptonWidth = Pixel_To_Lepton(SeenBuff.Get_Width()-x); - //} else { - // TacLeptonWidth = width * CELL_LEPTON_W; - //} - TacLeptonWidth = Pixel_To_Lepton(SeenBuff.Get_Width() - x); + if (width == -1) width = SeenBuff.Get_Width(); + TacLeptonWidth = Pixel_To_Lepton( width - x); - // ST - 3/1/2019 12:05PM - // Made the below code more consistent with the width calculation. This is needed if we aren't going to draw the tabs at the top of the screen - // - //if (height == -1) { - // TacLeptonHeight = Pixel_To_Lepton(SeenBuff.Get_Height() - y); - // //height = (SeenBuff.Get_Height()-y) / CELL_PIXEL_H; - //} - //else { - // TacLeptonHeight = height * CELL_LEPTON_H; - //} - //TacLeptonHeight = height * CELL_LEPTON_H; - - TacLeptonHeight = Pixel_To_Lepton(SeenBuff.Get_Height() - y); + if (height == -1) height = SeenBuff.Get_Height(); + TacLeptonHeight = Pixel_To_Lepton(height - y); /* ** Adjust the tactical cell if it is now in an invalid position ** because of the changed dimensions. */ - int xx = 0;// Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W); - int yy = 0;// Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H); + int xx = Coord_X(TacticalCoord) - (MapCellX * CELL_LEPTON_W); + int yy = Coord_Y(TacticalCoord) - (MapCellY * CELL_LEPTON_H); Confine_Rect(&xx, &yy, TacLeptonWidth, TacLeptonHeight, MapCellWidth * CELL_LEPTON_W, MapCellHeight * CELL_LEPTON_H); diff --git a/code/REDALERT/SCENARIO.CPP b/code/REDALERT/SCENARIO.CPP index a523112..0797e76 100644 --- a/code/REDALERT/SCENARIO.CPP +++ b/code/REDALERT/SCENARIO.CPP @@ -571,7 +571,10 @@ bool Read_Scenario(char * name) } #endif Fill_In_Data(); - Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight); + + // BL 2020-06-15 : not needed !! + //Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight); + } else { #if (1) @@ -759,7 +762,9 @@ void Fill_In_Data(void) *=============================================================================================*/ void Post_Load_Game(int load_multi) { - Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight); + // BL 2020-06-15 : not needed !! + //Map.Set_View_Dimensions(0, 0, Map.MapCellWidth, Map.MapCellHeight); + // // Do NOT call Overpass if we're loading a multiplayer game; it calls the // random # generator, which throws the games out of sync if they were diff --git a/code/REDALERT/SIDEBAR.CPP b/code/REDALERT/SIDEBAR.CPP index 916368f..2dc13a1 100644 --- a/code/REDALERT/SIDEBAR.CPP +++ b/code/REDALERT/SIDEBAR.CPP @@ -1030,7 +1030,8 @@ bool SidebarClass::Activate(int control) ** activate it on the left side of the screen. */ if (IsSidebarActive /*&& X*/) { - Set_View_Dimensions(0, 0, (((ScreenWidth/2)-SIDE_WIDTH)/ICON_PIXEL_W) * RESFACTOR); + Set_View_Dimensions( 0, 0, SeenBuff.Get_Width() - ( SIDE_WIDTH * RESFACTOR ) ); + IsToRedraw = true; Help_Text(TXT_NONE); Repair.Zap(); diff --git a/code/REDALERT/TAB.CPP b/code/REDALERT/TAB.CPP index f408886..8527a0e 100644 --- a/code/REDALERT/TAB.CPP +++ b/code/REDALERT/TAB.CPP @@ -139,10 +139,9 @@ void TabClass::Draw_Credits_Tab(void) int width = SeenBuff.Get_Width(); CC_Draw_Shape(TabShape, Map.MoneyFlashTimer > 1 ? 8 : 6, width - (EVA_WIDTH * RESFACTOR), 0, WINDOW_MAIN, SHAPE_NORMAL); - if (Scen.MissionTimer.Is_Active()) { bool light = ((int)Scen.MissionTimer < TICKS_PER_MINUTE * Rule.TimerWarning) || Map.FlasherTimer > 0; - CC_Draw_Shape(TabShape, light ? 4 : 2, 320, 0, WINDOW_MAIN, SHAPE_NORMAL); + CC_Draw_Shape(TabShape, light ? 4 : 2, width - ( ( EVA_WIDTH * 2 ) * RESFACTOR) , 0, WINDOW_MAIN, SHAPE_NORMAL); } } diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 3755f68..419ea13 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -84,7 +84,7 @@ void Show_OldFrameBuffer(bool show) { memset(backbuffer_data, 0, ScreenWidth * ScreenHeight * 4); } -std::vector loaded_images; +std::vector loaded_images; Image_t* Image_LoadImage(const char* name) { // Check to see if the image is already loaded. From 2007adbda391fa4775416583de6f2a0d58683433 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Mon, 15 Jun 2020 21:31:03 +0200 Subject: [PATCH 02/10] * Change font to Arial * Load/save dialog in proper place --- code/REDALERT/GADGET.CPP | 31 ------------------------------- code/REDALERT/LOADDLG.CPP | 5 +++-- code/REDALERT/WINSTUB.CPP | 2 +- 3 files changed, 4 insertions(+), 34 deletions(-) diff --git a/code/REDALERT/GADGET.CPP b/code/REDALERT/GADGET.CPP index ca5a3f6..fa22be4 100644 --- a/code/REDALERT/GADGET.CPP +++ b/code/REDALERT/GADGET.CPP @@ -495,37 +495,6 @@ KeyNumType GadgetClass::Input(void) key = Keyboard->Get(); } -#ifdef WIN32 -#ifdef CHEAT_KEYS - //if (key == KN_K && !Debug_Map && (Debug_Flag || Debug_Playtest)) { - // /* - // ** time to create a screen shot using the PCX code (if it works) - // */ - // if (!Debug_MotionCapture) { - // GraphicBufferClass temp_page( SeenBuff.Get_Width(), - // SeenBuff.Get_Height(), - // NULL, - // SeenBuff.Get_Width() * SeenBuff.Get_Height()); - // CDFileClass file; - // char filename[30]; - // -// // Hide_Mouse(); - // SeenBuff.Blit(temp_page); -// // Show_Mouse(); - // for (int lp = 0; lp < 99; lp ++) { - // sprintf(filename, "scrsht%02d.pcx", lp); - // file.Set_Name(filename); - // if (!file.Is_Available()) break; - // } - // - // file.Cache(200000); - // Write_PCX_File(file, temp_page, & GamePalette); - // Sound_Effect(VOC_BEEP); - // } - //} -#endif -#endif - /* ** For mouse button clicks, the mouse position is actually held in the MouseQ... ** globals rather than their normal Mouse... globals. This is because we need to diff --git a/code/REDALERT/LOADDLG.CPP b/code/REDALERT/LOADDLG.CPP index 76db461..4fced4e 100644 --- a/code/REDALERT/LOADDLG.CPP +++ b/code/REDALERT/LOADDLG.CPP @@ -111,8 +111,9 @@ int LoadOptionsClass::Process(void) */ int d_dialog_w = 250 * RESFACTOR; // dialog width int d_dialog_h = 156 * RESFACTOR; // dialog height - int d_dialog_x = (((320 * RESFACTOR) - d_dialog_w) / 2); // centered x-coord - int d_dialog_y = (((200 * RESFACTOR) - d_dialog_h) / 2); // centered y-coord + + int d_dialog_x = ((SeenBuff.Get_Width() - d_dialog_w) / 2); + int d_dialog_y = ((SeenBuff.Get_Height() - d_dialog_h) / 2); int d_dialog_cx = d_dialog_x + (d_dialog_w / 2); // coord of x-center int d_txt8_h = 11 * RESFACTOR; // ht of 8-pt text diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 419ea13..50851d5 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -450,7 +450,7 @@ void Create_Main_Window ( HANDLE instance , int command_show , int width , int h ImGui_ImplSDL2_InitForD3D(game_window); ImGui_ImplOpenGL3_Init(); - io.Fonts->AddFontFromFileTTF("fonts/Roboto-Medium.ttf", 16.0f); + io.Fonts->AddFontFromFileTTF("fonts/Arial.ttf", 16.0f); ImGui_NewFrame(); } From 7091282433d704e48c6aac19fb1a3cc979d52775 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Tue, 16 Jun 2020 15:11:17 +0200 Subject: [PATCH 03/10] * Handle text input properly from SDL * Removed duplicate keyboard.cpp --- code/REDALERT/EDIT.CPP | 22 +- code/REDALERT/KEY.CPP | 3 +- code/REDALERT/KEY.H | 15 +- code/REDALERT/KEYBOARD.CPP | 466 ------------------------------------- code/REDALERT/WINSTUB.CPP | 39 +++- 5 files changed, 45 insertions(+), 500 deletions(-) delete mode 100644 code/REDALERT/KEYBOARD.CPP diff --git a/code/REDALERT/EDIT.CPP b/code/REDALERT/EDIT.CPP index 5de95fd..45783a9 100644 --- a/code/REDALERT/EDIT.CPP +++ b/code/REDALERT/EDIT.CPP @@ -376,6 +376,8 @@ void EditClass::Draw_Text(char const * text) *=============================================================================================*/ bool EditClass::Handle_Key(KeyASCIIType ascii) { + unsigned char testAscii = (unsigned char)ascii; + switch (ascii) { /* ** Handle the special case of a non-keyboard event. It is possible that this @@ -416,7 +418,7 @@ bool EditClass::Handle_Key(KeyASCIIType ascii) /* ** Don't add a character if the length is greater than edit width. */ - if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(ascii) ) >= (Width-2)) { + if (((int)String_Pixel_Width(String) + (int)Char_Pixel_Width(testAscii) ) >= (Width-2)) { break; } @@ -429,21 +431,21 @@ bool EditClass::Handle_Key(KeyASCIIType ascii) ** Invisible characters are never added to the string. This is ** especially true for spaces at the beginning of the string. */ - if (!isgraph(ascii) && ascii != ' ') break; - if (ascii == ' ' && Length == 0) break; + if (!isgraph(testAscii) && testAscii != ' ') break; + if (testAscii == ' ' && Length == 0) break; /* ** If this is an upper case only edit gadget, then force the alphabetic ** character to upper case. */ - if ((EditFlags & UPPERCASE) && isalpha(ascii)) { - ascii = (KeyASCIIType)toupper(ascii); + if ((EditFlags & UPPERCASE) && isalpha(testAscii)) { + testAscii = (KeyASCIIType)toupper(testAscii); } - if ((!(EditFlags & NUMERIC) || !isdigit(ascii)) && - (!(EditFlags & ALPHA) || !isalpha(ascii)) && - (!(EditFlags & MISC) || isalnum(ascii)) && - ascii != ' ') { + if ((!(EditFlags & NUMERIC) || !isdigit(testAscii)) && + (!(EditFlags & ALPHA) || !isalpha(testAscii)) && + (!(EditFlags & MISC) || isalnum(testAscii)) && + testAscii != ' ') { break; } @@ -453,7 +455,7 @@ bool EditClass::Handle_Key(KeyASCIIType ascii) ** because the event flag has been cleared. This prevents the gadget's ID ** number from being returned just because the gadget has been edited. */ - String[Length++] = ascii; + String[Length++] = testAscii; String[Length] = '\0'; Flag_To_Redraw(); break; diff --git a/code/REDALERT/KEY.CPP b/code/REDALERT/KEY.CPP index eef74e9..582806b 100644 --- a/code/REDALERT/KEY.CPP +++ b/code/REDALERT/KEY.CPP @@ -192,7 +192,6 @@ bool WWKeyboardClass::Put(unsigned short key) return(false); } - /*********************************************************************************************** * WWKeyboardClass::Put_Key_Message -- Translates and inserts wParam into Keyboard Buffer * * * @@ -517,6 +516,7 @@ bool WWKeyboardClass::Is_Buffer_Empty(void) const *=============================================================================================*/ void WWKeyboardClass::Fill_Buffer_From_System(void) { + /* if (!Is_Buffer_Full()) { MSG msg; @@ -528,6 +528,7 @@ void WWKeyboardClass::Fill_Buffer_From_System(void) DispatchMessage(&msg); } } + */ } diff --git a/code/REDALERT/KEY.H b/code/REDALERT/KEY.H index fbaec2c..787238e 100644 --- a/code/REDALERT/KEY.H +++ b/code/REDALERT/KEY.H @@ -33,10 +33,6 @@ #ifndef KEYBOARD_H #define KEYBOARD_H -#ifndef WIN32 -#include "..\wwflat32\include\keyboard.h" -#else - #include /* @@ -44,18 +40,10 @@ ** November of '94. Until the compiler supports this, use the following ** definition. */ -#ifndef __BORLANDC__ -#ifndef TRUE_FALSE_DEFINED -#define TRUE_FALSE_DEFINED -enum {false=0,true=1}; -typedef int bool; -#endif -#endif - #pragma warning(disable : 4005) typedef enum { - WWKEY_SHIFT_BIT = 0x100, + WWKEY_SHIFT_BIT = 0x100, WWKEY_CTRL_BIT = 0x200, WWKEY_ALT_BIT = 0x400, WWKEY_RLS_BIT = 0x800, @@ -656,4 +644,3 @@ typedef enum KeyNumType { //extern WWKeyboardClass *_Kbd; #endif -#endif diff --git a/code/REDALERT/KEYBOARD.CPP b/code/REDALERT/KEYBOARD.CPP deleted file mode 100644 index 116fee4..0000000 --- a/code/REDALERT/KEYBOARD.CPP +++ /dev/null @@ -1,466 +0,0 @@ -// -// Copyright 2020 Electronic Arts Inc. -// -// TiberianDawn.DLL and RedAlert.dll and corresponding source code is free -// software: you can redistribute it and/or modify it under the terms of -// the GNU General Public License as published by the Free Software Foundation, -// either version 3 of the License, or (at your option) any later version. - -// TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed -// in the hope that it will be useful, but with permitted additional restrictions -// under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT -// distributed with this program. You should have received a copy of the -// GNU General Public License along with permitted additional restrictions -// with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection - -/* $Header: F:\projects\c&c0\vcs\code\conquer.cpv 4.74 23 Sep 1996 12:36:00 JOE_BOSTIC $ */ -/*********************************************************************************************** - * * - * Project Name : Westwood Keyboard Library * - * * - * File Name : KEYBOARD.CPP * - * * - * Programmer : Philip W. Gorrow * - * * - * Start Date : 10/16/95 * - * * - * Last Update : September 24, 1996 [JLB] * - * * - *---------------------------------------------------------------------------------------------* - * Functions: * - * WWKeyboardClass::Put -- Logic to insert a key into the keybuffer] * - * WWKeyboardClass::Get -- Logic to get a metakey from the buffer * - * WWKeyboardClass::Check -- Checks to see if a key is in the buffer * - * WWKeyboardClass::Put_Key_Message -- Translates and inserts wParam into Keyboard Buffer * - * WWKeyboardClass::Buff_Get -- Lowlevel function to get a key from key buffer * - * WWKeyboardClass::Get_Mouse_X -- Returns the mouses current x position in pixels * - * WWKeyboardClass::Get_Mouse_Y -- returns the mouses current y position in pixels * - * WWKeyboardClass::Get_Mouse_XY -- Returns the mouses x,y position via reference vars * - * Check_Key -- compatability routine for old 32 bit library * - * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ - -#include "keyboard.h" - -#include "monoc.h" - -//void Message_Loop(void); - -WWKeyboardClass * _Kbd = NULL; - - -#define ARRAY_SIZE(x) int(sizeof(x)/sizeof(x[0])) - - -/*********************************************************************************************** - * WWKeyboardClass::WWKeyBoardClass -- Construction for Westwood Keyboard Class * - * * - * INPUT: none * - * * - * OUTPUT: none * - * * - * HISTORY: * - * 10/16/1995 PWG : Created. * - *=============================================================================================*/ -WWKeyboardClass::WWKeyboardClass(void) : - MouseQX(0), - MouseQY(0), - Head(0), - Tail(0) -// MState(0), -// Conditional(0), -// CurrentCursor(0) -{ - _Kbd = this; - - memset(KeyState, '\0', sizeof(KeyState)); -} - - -/*********************************************************************************************** - * WWKeyboardClass::Buff_Get -- Lowlevel function to get a key from key buffer * - * * - * INPUT: none * - * * - * OUTPUT: int - the key value that was pulled from buffer (includes bits) * * - * * - * WARNINGS: If the key was a mouse event MouseQX and MouseQY will be updated * - * * - * HISTORY: * - * 10/17/1995 PWG : Created. * - *=============================================================================================*/ -unsigned short WWKeyboardClass::Buff_Get(void) -{ - while (!Check()) {} // wait for key in buffer - - unsigned short temp = Fetch_Element(); - if (Is_Mouse_Key(temp)) { - MouseQX = Fetch_Element(); - MouseQY = Fetch_Element(); - } - return(temp); -} - - -bool WWKeyboardClass::Is_Mouse_Key(unsigned short key) -{ - key &= 0xFF; - return (key == VK_LBUTTON || key == VK_MBUTTON || key == VK_RBUTTON); -} - - -/*********************************************************************************************** - * WWKeyboardClass::Check -- Checks to see if a key is in the buffer * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/16/1995 PWG : Created. * - * 09/24/1996 JLB : Converted to new style keyboard system. * - *=============================================================================================*/ -unsigned short WWKeyboardClass::Check(void) const -{ - ((WWKeyboardClass *)this)->Fill_Buffer_From_System(); - if (Is_Buffer_Empty()) return(false); - return(Peek_Element()); -} - - -/*********************************************************************************************** - * WWKeyboardClass::Get -- Logic to get a metakey from the buffer * - * * - * INPUT: none * - * * - * OUTPUT: int - the meta key taken from the buffer. * - * * - * WARNINGS: This routine will not return until a keypress is received * - * * - * HISTORY: * - * 10/16/1995 PWG : Created. * - *=============================================================================================*/ -unsigned short WWKeyboardClass::Get(void) -{ - while (!Check()) {} // wait for key in buffer - return (Buff_Get()); -} - - -/*********************************************************************************************** - * WWKeyboardClass::Put -- Logic to insert a key into the keybuffer] * - * * - * INPUT: int - the key to insert into the buffer * - * * - * OUTPUT: bool - true if key is sucessfuly inserted. * - * * - * WARNINGS: none * - * * - * HISTORY: * - * 10/16/1995 PWG : Created. * - *=============================================================================================*/ -bool WWKeyboardClass::Put(unsigned short key) -{ - if (!Is_Buffer_Full()) { - Put_Element(key); - return(true); - } - return(false); -} - - -/*********************************************************************************************** - * WWKeyboardClass::Put_Key_Message -- Translates and inserts wParam into Keyboard Buffer * - * * - * INPUT: * - * * - * OUTPUT: * - * * - * WARNINGS: * - * * - * HISTORY: * - * 10/16/1995 PWG : Created. * - *=============================================================================================*/ -bool WWKeyboardClass::Put_Key_Message(unsigned short vk_key, bool release) -{ - // - // Get the status of all of the different keyboard modifiers. Note, only pay attention - // to numlock and caps lock if we are dealing with a key that is affected by them. Note - // that we do not want to set the shift, ctrl and alt bits for Mouse keypresses as this - // would be incompatible with the dos version. - // - if (!Is_Mouse_Key(vk_key)) { - if (((GetKeyState(VK_SHIFT) & 0x8000) != 0) || - ((GetKeyState(VK_CAPITAL) & 0x0008) != 0) || - ((GetKeyState(VK_NUMLOCK) & 0x0008) != 0)) { - - vk_key |= WWKEY_SHIFT_BIT; - } - if ((GetKeyState(VK_CONTROL) & 0x8000) != 0) { - vk_key |= WWKEY_CTRL_BIT; - } - if ((GetKeyState(VK_MENU) & 0x8000) != 0) { - vk_key |= WWKEY_ALT_BIT; - } - } - - if (release) { - vk_key |= WWKEY_RLS_BIT; - } - - // - // Finally use the put command to enter the key into the keyboard - // system. - // - return(Put(vk_key)); - - - -} - -#pragma warning (disable : 4065) -char WWKeyboardClass::To_ASCII(unsigned short key) -{ - /* - ** Released keys never translate into an ASCII value. - */ - if (key & WWKEY_RLS_BIT) { - return('\0'); - } - - /* - ** Set the KeyState buffer to reflect the shift bits stored in the key value. - */ - if (key & WWKEY_SHIFT_BIT) { - KeyState[VK_SHIFT] = 0x80; - } - if (key & WWKEY_CTRL_BIT) { - KeyState[VK_CONTROL] = 0x80; - } - if (key & WWKEY_ALT_BIT) { - KeyState[VK_MENU] = 0x80; - } - - /* - ** Ask windows to translate the key into an ASCII equivalent. - */ - char buffer[10]; - int result = 1; - int scancode = 0; - char override = '\0'; - - switch (key & 0xFF) { -// case KN_RETURN: -// override = KA_RETURN; -// break; - -// case KN_BACKSPACE: -// override = KA_BACKSPACE; -// break; - - default: - scancode = MapVirtualKey(key & 0xFF, 0); - result = ToAscii((UINT)(key & 0xFF), (UINT)scancode, (PBYTE)KeyState, (LPWORD)buffer, (UINT)0); - break; - } - - /* - ** Restore the KeyState buffer back to pristine condition. - */ - if (key & WWKEY_SHIFT_BIT) { - KeyState[VK_SHIFT] = 0; - } - if (key & WWKEY_CTRL_BIT) { - KeyState[VK_CONTROL] = 0; - } - if (key & WWKEY_ALT_BIT) { - KeyState[VK_MENU] = 0; - } - - /* - ** If Windows could not perform the translation as expected, then - ** return with a null ASCII value. - */ - if (result != 1) { - return('\0'); - } - - if (override != 0) { - return(override); - } - - return(buffer[0]); -} - - -bool WWKeyboardClass::Down(unsigned short key) -{ - return(GetAsyncKeyState(key & 0xFF) == 0 ? false : true); -} - - -extern "C" { - void __cdecl Stop_Execution (void); -} - - - -unsigned short WWKeyboardClass::Fetch_Element(void) -{ - unsigned short val = 0; - if (Head != Tail) { - val = Buffer[Head]; - - Head = (Head + 1) % ARRAY_SIZE(Buffer); - } - return(val); -} - - -unsigned short WWKeyboardClass::Peek_Element(void) const -{ - if (!Is_Buffer_Empty()) { - return(Buffer[Head]); - } - return(0); -} - - -bool WWKeyboardClass::Put_Element(unsigned short val) -{ - if (!Is_Buffer_Full()) { - int temp = (Tail+1) % ARRAY_SIZE(Buffer); - Buffer[Tail] = val; - Tail = temp; - return(true); - } - return(false); -} - - -bool WWKeyboardClass::Is_Buffer_Full(void) const -{ - if ((Tail + 1) % ARRAY_SIZE(Buffer) == Head) { - return(true); - } - return(false); -} - - -bool WWKeyboardClass::Is_Buffer_Empty(void) const -{ - if (Head == Tail) { - return(true); - } - return(false); -} - - -void WWKeyboardClass::Fill_Buffer_From_System(void) -{ - if (!Is_Buffer_Full()) { - MSG msg; - while (PeekMessage(&msg, NULL, 0, 0, PM_NOREMOVE)) { - if (!GetMessage( &msg, NULL, 0, 0 )) { - return; - } - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } -} - - -void WWKeyboardClass::Clear(void) -{ - Head = Tail; -} - - -void WWKeyboardClass::Message_Handler(HWND , UINT message, UINT wParam, LONG lParam) -{ - switch (message) { - case WM_SYSKEYDOWN: - case WM_KEYDOWN: - if ( wParam==VK_SCROLL ){ - Stop_Execution(); - } else { - Put_Key_Message((unsigned short)wParam); - } - break; - - case WM_SYSKEYUP: - case WM_KEYUP: - Put_Key_Message((unsigned short)wParam, true); - break; - - case WM_LBUTTONDOWN: - Put_Key_Message(VK_LBUTTON); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_LBUTTONUP: - Put_Key_Message(VK_LBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_LBUTTONDBLCLK: - Put_Key_Message(VK_LBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - Put_Key_Message(VK_LBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_MBUTTONDOWN: - Put_Key_Message(VK_MBUTTON); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_MBUTTONUP: - Put_Key_Message(VK_MBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_MBUTTONDBLCLK: - Put_Key_Message(VK_MBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - Put_Key_Message(VK_MBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_RBUTTONDOWN: - Put_Key_Message(VK_RBUTTON); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_RBUTTONUP: - Put_Key_Message(VK_RBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - - case WM_RBUTTONDBLCLK: - Put_Key_Message(VK_RBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - Put_Key_Message(VK_RBUTTON, true); - Put(LOWORD(lParam)); - Put(HIWORD(lParam)); - break; - -// case WM_MOUSEMOVE: -// if (CurrentCursor) -// SetCursor(CurrentCursor); -// break; - } -} diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 50851d5..87fd8a2 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -60,6 +60,8 @@ #include #include +#include +#include GLuint backbuffer_texture = -1; byte* backbuffer_data; @@ -86,6 +88,16 @@ void Show_OldFrameBuffer(bool show) { std::vector loaded_images; +auto utf8_decode = [](const std::string& str) -> std::wstring +{ + if (str.empty()) return std::wstring(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); + return wstrTo; +}; + + Image_t* Image_LoadImage(const char* name) { // Check to see if the image is already loaded. for (int i = 0; i < loaded_images.size(); i++) { @@ -679,7 +691,10 @@ void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { // flags = 0; SDL_Event event; + while (SDL_PollEvent(&event)) { + const Uint8* state = SDL_GetKeyboardState(NULL); + switch (event.type) { case SDL_SYSWMEVENT: @@ -753,16 +768,24 @@ void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { } break; } + + // handle backspace and ENTER + if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) Keyboard->Put_Element( KN_BACKSPACE ); + if (event.key.keysym.scancode == ( SDL_SCANCODE_RETURN || SDL_SCANCODE_KP_ENTER ) ) Keyboard->Put_Element( KN_RETURN ); - const Uint8* state = SDL_GetKeyboardState(NULL); + break; + case SDL_TEXTINPUT: + int keyFlags = 0x00; - if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) + if (state[SDL_SCANCODE_RSHIFT] || state[SDL_SCANCODE_LSHIFT]) keyFlags |= KN_SHIFT_BIT; + if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) keyFlags |= KN_ALT_BIT; + + std::wstring input_utf16 = utf8_decode( std::string( event.text.text ) ); + + if( input_utf16.length() == 1 ) { - Keyboard->Put_Element(event.key.keysym.sym | KN_ALT_BIT); - } - else - { - Keyboard->Put_Element(event.key.keysym.sym); + short vKey = VkKeyScanW( input_utf16[0] ); + Keyboard->Put_Element( vKey | keyFlags ); } break; @@ -783,8 +806,6 @@ void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { Device_Present(); } - - #ifndef NDEBUG /*********************************************************************************************** * Assert_Failure -- display the line and source file where a failed assert occurred * From 829f27c76f78585ee1515f0f1dc030f4ce71d617 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Thu, 18 Jun 2020 16:11:40 +0200 Subject: [PATCH 04/10] Rewrote UserInput <> SDL interaction. --- code/CMakeLists.txt | 9 +- code/REDALERT/CONQUER.CPP | 24 ++--- code/REDALERT/DISPLAY.CPP | 32 +++---- code/REDALERT/ENDING.CPP | 6 +- code/REDALERT/EXTERNS.H | 5 + code/REDALERT/FUNCTION.H | 9 +- code/REDALERT/GADGET.CPP | 8 +- code/REDALERT/GLOBALS.CPP | 6 ++ code/REDALERT/KEY.CPP | 8 +- code/REDALERT/MAPEDDLG.CPP | 1 - code/REDALERT/MAPEDIT.CPP | 6 +- code/REDALERT/MAPSEL.CPP | 10 +- code/REDALERT/MENUS.CPP | 12 +-- code/REDALERT/TECHNO.CPP | 27 ++---- code/REDALERT/WIN32LIB/MOUSEWW.CPP | 25 +++-- code/REDALERT/WINSTUB.CPP | 139 +-------------------------- code/REDALERT/io/UserInput.cpp | 149 +++++++++++++++++++++++++++++ code/REDALERT/io/UserInput.h | 144 ++++++++++++++++++++++++++++ 18 files changed, 386 insertions(+), 234 deletions(-) create mode 100644 code/REDALERT/io/UserInput.cpp create mode 100644 code/REDALERT/io/UserInput.h diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index f8efb95..b794edb 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -8,6 +8,11 @@ set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../) set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/../) set(CMAKE_VERBOSE_MAKEFILE ON) +set(src_io + ./REDALERT/io/UserInput.cpp + ./REDALERT/io/UserInput.h +) + set(src_win32lib ./REDALERT/WIN32LIB/TOBUFF.cpp ./RedAlert/WIN32LIB/ALLOC.CPP @@ -708,8 +713,8 @@ set(src_external add_definitions(-DCHEAT_KEYS -DIMGUI_IMPL_OPENGL_LOADER_GLEW -DSCENARIO_EDITOR -DWINDOWS_IGNORE_PACKING_MISMATCH -DTRUE_FALSE_DEFINED -DWIN32 -DWINDOWS -DENGLISH -D_USRDLL -DREDALERT_EXPORTS) add_compile_options(/permissive+ /Zc:forScope- /Zp1) -add_executable(RedAlert ${src_win32lib} ${src_redalert} ${src_external}) +add_executable(RedAlert ${src_io} ${src_win32lib} ${src_redalert} ${src_external}) set_target_properties(RedAlert PROPERTIES OUTPUT_NAME "RedAlert" LINK_FLAGS "/PDB:\"RedAlert.pdb\" /SUBSYSTEM:WINDOWS" RUNTIME_OUTPUT_DIRECTORY "${CMAKE_SOURCE_DIR}/../../bin" ) -target_include_directories(RedAlert PRIVATE ./external/devil/;./external/;./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include) +target_include_directories(RedAlert PRIVATE ./external/devil/;./external/;./redalert/io;./redalert/win32lib;./external/lua/;./external/imgui;./external/dxsdk/Include;./external/ffmpeg-win32/include;./external/sdl2/include;./win32lib;./external/openal/include) target_link_libraries(RedAlert "opengl32.lib" "winmm.lib" "Ws2_32.lib" "${CMAKE_SOURCE_DIR}/external/devil/DevIL.lib" "${CMAKE_SOURCE_DIR}/external/sdl2/lib/x86/SDL2.lib" "${CMAKE_SOURCE_DIR}/external/openal/out/build/x86-Release/OpenAL32.lib") diff --git a/code/REDALERT/CONQUER.CPP b/code/REDALERT/CONQUER.CPP index a0ae38f..4fec68c 100644 --- a/code/REDALERT/CONQUER.CPP +++ b/code/REDALERT/CONQUER.CPP @@ -891,45 +891,45 @@ void Keyboard_Process(KeyNumType & input) ** state! */ if (input != 0 && (plain == Options.KeyTeam1 || plain == KN_1)) { - Handle_Team(0, action); - input = KN_NONE; - } - if (input != 0 && (plain == Options.KeyTeam2 || plain == KN_2)) { Handle_Team(1, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam3 || plain == KN_3)) { + if (input != 0 && (plain == Options.KeyTeam2 || plain == KN_2)) { Handle_Team(2, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam4 || plain == KN_4)) { + if (input != 0 && (plain == Options.KeyTeam3 || plain == KN_3)) { Handle_Team(3, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam5 || plain == KN_5)) { + if (input != 0 && (plain == Options.KeyTeam4 || plain == KN_4)) { Handle_Team(4, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam6 || plain == KN_6)) { + if (input != 0 && (plain == Options.KeyTeam5 || plain == KN_5)) { Handle_Team(5, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam7 || plain == KN_7)) { + if (input != 0 && (plain == Options.KeyTeam6 || plain == KN_6)) { Handle_Team(6, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam8 || plain == KN_8)) { + if (input != 0 && (plain == Options.KeyTeam7 || plain == KN_7)) { Handle_Team(7, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam9 || plain == KN_9)) { + if (input != 0 && (plain == Options.KeyTeam8 || plain == KN_8)) { Handle_Team(8, action); input = KN_NONE; } - if (input != 0 && (plain == Options.KeyTeam10 || plain == KN_0)) { + if (input != 0 && (plain == Options.KeyTeam9 || plain == KN_9)) { Handle_Team(9, action); input = KN_NONE; } + if (input != 0 && (plain == Options.KeyTeam10 || plain == KN_0)) { + Handle_Team(0, action); + input = KN_NONE; + } /* ** Handle the bookmark hotkeys. diff --git a/code/REDALERT/DISPLAY.CPP b/code/REDALERT/DISPLAY.CPP index 4401a5a..52929de 100644 --- a/code/REDALERT/DISPLAY.CPP +++ b/code/REDALERT/DISPLAY.CPP @@ -3309,16 +3309,15 @@ int DisplayClass::TacticalClass::Selection_At_Mouse(unsigned flags, KeyNumType & { int x, y; // Sub cell pixel coordinates. bool edge = false; - if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) { - x = Keyboard->MouseQX; - y = Keyboard->MouseQY; - } - else { - x = Get_Mouse_X(); - y = Get_Mouse_Y(); + + x = UserInput.Mouse.X; + y = UserInput.Mouse.Y; - if (x == 0 || y == 199 || x == 319) edge = true; + if (x == 0 || y == SeenBuff.Get_Height() || x == SeenBuff.Get_Width()) + { + edge = true; } + COORDINATE coord = Map.Pixel_To_Coord(x, y); CELL cell = Coord_Cell(coord); @@ -3345,7 +3344,7 @@ int DisplayClass::TacticalClass::Selection_At_Mouse(unsigned flags, KeyNumType & if (object != nullptr) { - bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT); + bool shiftdown = UserInput.KeyB.Shift = true; if (shiftdown) { @@ -3387,16 +3386,15 @@ int DisplayClass::TacticalClass::Command_Object(unsigned flags, KeyNumType & key { int x, y; // Sub cell pixel coordinates. bool edge = false; - if (flags & (LEFTPRESS | LEFTRELEASE | RIGHTPRESS | RIGHTRELEASE)) { - x = Keyboard->MouseQX; - y = Keyboard->MouseQY; - } - else { - x = Get_Mouse_X(); - y = Get_Mouse_Y(); - if (x == 0 || y == 199 || x == 319) edge = true; + x = UserInput.Mouse.X; + y = UserInput.Mouse.Y; + + if (x == 0 || y == SeenBuff.Get_Height() || x == SeenBuff.Get_Width()) + { + edge = true; } + COORDINATE coord = Map.Pixel_To_Coord(x, y); CELL cell = Coord_Cell(coord); diff --git a/code/REDALERT/ENDING.CPP b/code/REDALERT/ENDING.CPP index 8f5e10f..f7d0ff9 100644 --- a/code/REDALERT/ENDING.CPP +++ b/code/REDALERT/ENDING.CPP @@ -122,10 +122,10 @@ void Nod_Ending(void) if ((key & 0xFF) == KN_LMOUSE && !(key & KN_RLSE_BIT)) { int mousex = MouseQX; int mousey = MouseQY; - if (mousey >= 22 && mousey <= 177) { + if (mousex >= 22 && mousey <= 177) { done++; - if (mousex < 160 && mousey < 100) selection = 2; - if (mousex < 160 && mousey >= 100) selection = 3; + if (mousex < 160 && mousey < 100) selection = 2; + if (mousex < 160 && mousey >= 100) selection = 3; if (mousex >= 160 && mousey >= 100) selection = 4; } } diff --git a/code/REDALERT/EXTERNS.H b/code/REDALERT/EXTERNS.H index 4526440..4b91e44 100644 --- a/code/REDALERT/EXTERNS.H +++ b/code/REDALERT/EXTERNS.H @@ -91,6 +91,8 @@ extern void const *LightningShapes; extern int NewINIFormat; +extern bool renderConsole; + #ifdef FIXIT_ANTS extern bool AntsEnabled; @@ -158,6 +160,7 @@ extern PKey FastKey; extern PKey SlowKey; extern RulesClass Rule; extern KeyboardClass * Keyboard; +extern UserInputClass UserInput; extern RandomStraw CryptRandom; extern RandomClass NonCriticalRandomNumber; extern CarryoverClass * Carryover; @@ -365,6 +368,8 @@ extern GroundType Ground[LAND_COUNT]; /* ** Constant externs (data is not modified during game play). */ +extern std::map const sdl_keyMapping; + extern char const * Missions[MISSION_COUNT]; extern char const Keys[]; extern char const * const VQName[VQ_COUNT]; diff --git a/code/REDALERT/FUNCTION.H b/code/REDALERT/FUNCTION.H index 89a207a..5db6e4e 100644 --- a/code/REDALERT/FUNCTION.H +++ b/code/REDALERT/FUNCTION.H @@ -199,11 +199,10 @@ struct NoInitClass { #define TIMER_H #endif -#ifdef WIN32 #include "key.h" -#endif +#include "io/UserInput.h" -#include +#include #include "mpu.h" #include "bench.h" #include "rect.h" @@ -212,7 +211,7 @@ struct NoInitClass { #include "face.h" #include "random.h" #include "crc.h" -#include "compat.h" +#include "compat.h" #include "fixed.h" #include "base64.h" #include "pipe.h" @@ -1072,7 +1071,7 @@ extern DynamicVectorClass xxx2; template <>class DynamicVectorClass; extern DynamicVectorClass xxx3; -void WWSDL_ProcessEvents(KeyNumType& key, int& flags); +void WWSDL_ProcessEvents(KeyNumType& key, int& flags, bool presentBuffer = true); void Device_Present(void); /* diff --git a/code/REDALERT/GADGET.CPP b/code/REDALERT/GADGET.CPP index fa22be4..f4207a8 100644 --- a/code/REDALERT/GADGET.CPP +++ b/code/REDALERT/GADGET.CPP @@ -84,8 +84,6 @@ GadgetClass * GadgetClass::Focused = 0; static RemapControlType _GreyScheme = {15}; RemapControlType * GadgetClass::ColorScheme = &_GreyScheme; -int mousex, mousey; - /*********************************************************************************************** * GadgetClass::GadgetClass -- Constructor for gadget object. * * * @@ -569,7 +567,7 @@ KeyNumType GadgetClass::Input(void) if (StuckOn) { StuckOn->Draw_Me(false); GadgetClass * oldstuck = StuckOn; - StuckOn->Clicked_On(key, flags, mousex, mousey); + StuckOn->Clicked_On(key, flags, UserInput.Mouse.X, UserInput.Mouse.Y); if (StuckOn) { StuckOn->Draw_Me(false); } else { @@ -583,7 +581,7 @@ KeyNumType GadgetClass::Input(void) */ if (Focused && (flags & KEYBOARD)) { Focused->Draw_Me(false); - Focused->Clicked_On(key, flags, mousex, mousey); + Focused->Clicked_On(key, flags, UserInput.Mouse.X, UserInput.Mouse.Y); if (Focused) { Focused->Draw_Me(false); } @@ -610,7 +608,7 @@ KeyNumType GadgetClass::Input(void) ** Process this button. If the button was recognized and action was ** performed, then bail from further processing (speed reasons?). */ - if (next_button->Clicked_On(key, flags, mousex, mousey)) { + if (next_button->Clicked_On(key, flags, UserInput.Mouse.X, UserInput.Mouse.Y)) { /* ** Some buttons will require repainting when they perform some action. diff --git a/code/REDALERT/GLOBALS.CPP b/code/REDALERT/GLOBALS.CPP index ac288ad..2e9c522 100644 --- a/code/REDALERT/GLOBALS.CPP +++ b/code/REDALERT/GLOBALS.CPP @@ -252,6 +252,12 @@ CCINIClass AftermathINI; RulesClass Rule; +/*************************************************************************** +** All user input, mouse and keyboard, is routed through the object pointed to by this +** user input class pointer. +*/ +UserInputClass UserInput; + /*************************************************************************** ** All keyboard input is routed through the object pointed to by this ** keyboard class pointer. diff --git a/code/REDALERT/KEY.CPP b/code/REDALERT/KEY.CPP index 582806b..53764ca 100644 --- a/code/REDALERT/KEY.CPP +++ b/code/REDALERT/KEY.CPP @@ -51,7 +51,8 @@ * WWKeyboardClass::Put_Mouse_Message -- Stores a mouse type message into the keyboard buffer* * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ -#include "key.h" +//#include "key.h" +#include "FUNCTION.H" #include "monoc.h" @@ -316,8 +317,9 @@ char WWKeyboardClass::To_ASCII(unsigned short key) int result = 1; int scancode = 0; - scancode = MapVirtualKey(key & 0xFF, 0); - result = ToAscii((UINT)(key & 0xFF), (UINT)scancode, (PBYTE)KeyState, (LPWORD)buffer, (UINT)0); + //scancode = MapVirtualKey(key & 0xFF, 0); + //result = ToAscii((UINT)(key & 0xFF), (UINT)scancode, (PBYTE)KeyState, (LPWORD)buffer, (UINT)0); + buffer[0] = UserInput.KeyB.ASCII; /* ** Restore the KeyState buffer back to pristine condition. diff --git a/code/REDALERT/MAPEDDLG.CPP b/code/REDALERT/MAPEDDLG.CPP index e19b0f6..7d80932 100644 --- a/code/REDALERT/MAPEDDLG.CPP +++ b/code/REDALERT/MAPEDDLG.CPP @@ -719,7 +719,6 @@ static int map_y2; // map coords y2, pixel coords bool sizemap_cancel = false; // true = user cancels bool sizemap_process = true; void Imgui_SizeMap(void) { - extern int mousex, mousey; bool toolActive = false; ImGuiStyle& style = ImGui::GetStyle(); diff --git a/code/REDALERT/MAPEDIT.CPP b/code/REDALERT/MAPEDIT.CPP index d8f7dfe..ff3c30c 100644 --- a/code/REDALERT/MAPEDIT.CPP +++ b/code/REDALERT/MAPEDIT.CPP @@ -1506,7 +1506,6 @@ int mainmenu_x = -1; int mainmenu_y = -1; void Imgui_MapEdit_MainMenu(void) { - extern int mousex, mousey; bool toolActive = false; ImGuiStyle& style = ImGui::GetStyle(); @@ -1559,15 +1558,14 @@ void Imgui_MapEdit_MainMenu(void) { *=========================================================================*/ void MapEditClass::Main_Menu(void) { - extern int mousex, mousey; int selection; // option the user picks bool process; // menu stays up while true int rc; Imgui_Dialog_Function = Imgui_MapEdit_MainMenu; mainmenu_selection = -1; - mainmenu_x = mousex; - mainmenu_y = mousey; + mainmenu_x = UserInput.Mouse.X; + mainmenu_y = UserInput.Mouse.Y; /* ** Main Menu loop diff --git a/code/REDALERT/MAPSEL.CPP b/code/REDALERT/MAPSEL.CPP index d893c50..9d1989a 100644 --- a/code/REDALERT/MAPSEL.CPP +++ b/code/REDALERT/MAPSEL.CPP @@ -326,12 +326,12 @@ int Mouse_Over_Spot(int house, int scenario) { int retval = -1; for (int selection = 0; selection < 3 && MapCoords[house][scenario][selection].x != -1; selection++) { - int mousex = Get_Mouse_X() / RESFACTOR; + int mousex = UserInput.Mouse.X / RESFACTOR; int mousey = Get_Mouse_Y() / RESFACTOR; - if (mousex >= MapCoords[house][scenario][selection].x && - mousey >= MapCoords[house][scenario][selection].y && - mousex <= MapCoords[house][scenario][selection].x+11 && - mousey <= MapCoords[house][scenario][selection].y+9) { + if (UserInput.Mouse.X >= MapCoords[house][scenario][selection].x && + UserInput.Mouse.Y >= MapCoords[house][scenario][selection].y && + UserInput.Mouse.X <= MapCoords[house][scenario][selection].x+11 && + UserInput.Mouse.Y <= MapCoords[house][scenario][selection].y+9) { retval = selection; break; diff --git a/code/REDALERT/MENUS.CPP b/code/REDALERT/MENUS.CPP index d7b0e28..ccdcd9c 100644 --- a/code/REDALERT/MENUS.CPP +++ b/code/REDALERT/MENUS.CPP @@ -267,8 +267,8 @@ int Check_Menu(int menu, char const * text[], char *, long field, int index, Key mx2=mx1+(menuptr[ITEMWIDTH]*FontWidth)-1; /* structure as */ my2=my1+(menuptr[ITEMSHIGH]*menuskip)-1; /* necessary */ - tempy=Get_Mouse_Y(); - if (Coordinates_In_Region(Get_Mouse_X(), tempy, mx1, my1, mx2, my2)&& MenuUpdate) { + tempy=UserInput.Mouse.Y; + if (Coordinates_In_Region(UserInput.Mouse.X, tempy, mx1, my1, mx2, my2)&& MenuUpdate) { newitem=(tempy-my1)/menuskip; } @@ -299,8 +299,8 @@ int Check_Menu(int menu, char const * text[], char *, long field, int index, Key */ case KN_RMOUSE: case KN_LMOUSE: - if (Coordinates_In_Region(Keyboard->MouseQX, Keyboard->MouseQY, mx1, my1, mx2, my2)) { - newitem = (Keyboard->MouseQY - my1) / menuskip; + if (Coordinates_In_Region(UserInput.Mouse.X, UserInput.Mouse.Y, mx1, my1, mx2, my2)) { + newitem = (UserInput.Mouse.Y - my1) / menuskip; } else { UnknownKey = key; // Pass the unprocessed button click back. break; @@ -772,7 +772,7 @@ int Main_Menu(unsigned long ) case KN_LMOUSE: - if (Coordinates_In_Region(Keyboard->MouseQX, Keyboard->MouseQY, + if (Coordinates_In_Region(UserInput.Mouse.X, UserInput.Mouse.Y, 9*RESFACTOR, 10*RESFACTOR, 79*RESFACTOR, 24*RESFACTOR)){ @@ -786,7 +786,7 @@ int Main_Menu(unsigned long ) // secret ANT missions if (Is_Counterstrike_Installed() == true) { - if ((Keyboard->Down(KN_LSHIFT) || Keyboard->Down(KN_RSHIFT)) && Coordinates_In_Region(Keyboard->MouseQX, Keyboard->MouseQY, 260*RESFACTOR, 0, 320*RESFACTOR, 50*RESFACTOR)) { + if ((Keyboard->Down(KN_LSHIFT) || Keyboard->Down(KN_RSHIFT)) && Coordinates_In_Region(UserInput.Mouse.X, UserInput.Mouse.Y, 260*RESFACTOR, 0, 320*RESFACTOR, 50*RESFACTOR)) { AntsEnabled = true; process = false; retval = 2; // To match SEL_START_NEW_GAME diff --git a/code/REDALERT/TECHNO.CPP b/code/REDALERT/TECHNO.CPP index 2a9e3c8..5700235 100644 --- a/code/REDALERT/TECHNO.CPP +++ b/code/REDALERT/TECHNO.CPP @@ -138,11 +138,6 @@ */ #define MAX_UNCLOAK_STAGE 38 -//Added for getting the input for special character keys from the client -// - 6/26/2019 JAS -extern bool DLL_Export_Get_Input_Key_State(KeyNumType key); - - /*************************************************************************** ** These are the pointers to the special shape data that the units may need. */ @@ -3523,14 +3518,9 @@ ActionType TechnoClass::What_Action(ObjectClass const * object) const return(ACTION_SELF); } - //bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2)); - //bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2)); - //bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2)); - //Added for getting the input for special character keys from the client - // - 6/26/2019 JAS - bool altdown = DLL_Export_Get_Input_Key_State(KN_LALT); - bool ctrldown = DLL_Export_Get_Input_Key_State(KN_LCTRL); - bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT); + bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2)); + bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2)); + bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2)); /* ** Special guard area mission is possible if both the control and the @@ -3646,14 +3636,9 @@ ActionType TechnoClass::What_Action(CELL cell) const CellClass const * cellptr = &Map[cell]; OverlayTypeClass const * optr = NULL; - //bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2)); - //bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2)); - //bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2)); - //Added for getting the input for special character keys from the client - // - 6/26/2019 JAS - bool altdown = DLL_Export_Get_Input_Key_State(KN_LALT); - bool ctrldown = DLL_Export_Get_Input_Key_State(KN_LCTRL); - bool shiftdown = DLL_Export_Get_Input_Key_State(KN_LSHIFT); + bool altdown = (Keyboard->Down(Options.KeyForceMove1) || Keyboard->Down(Options.KeyForceMove2)); + bool ctrldown = (Keyboard->Down(Options.KeyForceAttack1) || Keyboard->Down(Options.KeyForceAttack2)); + bool shiftdown = (Keyboard->Down(Options.KeySelect1) || Keyboard->Down(Options.KeySelect2)); /* ** Disable recognizing the key forced fire option when dealing with buildings. diff --git a/code/REDALERT/WIN32LIB/MOUSEWW.CPP b/code/REDALERT/WIN32LIB/MOUSEWW.CPP index 5bf3f2a..dcefb52 100644 --- a/code/REDALERT/WIN32LIB/MOUSEWW.CPP +++ b/code/REDALERT/WIN32LIB/MOUSEWW.CPP @@ -31,15 +31,15 @@ * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */ #include "imgui.h" -#include "mouse.h" +#include "../FUNCTION.H" +#include "MOUSE.H" #include "../image.h" -#include static WWMouseClass *_Mouse=NULL; void CALLBACK Process_Mouse( UINT event_id, UINT res1 , DWORD user, DWORD res2, DWORD res3 ); -extern bool GameInFocus; -extern int mousex, mousey; +extern bool GameInFocus; +extern UserInputClass UserInput; /*********************************************************************************************** * MOUSECLASS::MOUSECLASS -- Constructor for the Mouse Class * @@ -241,8 +241,8 @@ void WWMouseClass::RenderMouse(void) { //ImVec2 size(current_cursor->width, current_cursor->height); //ImGui::Image((ImTextureID)current_cursor->image, size); - int _my = mousey + (current_cursor->height * 0.25); - int xstart = mousex - Get_Hotspot_X(); + int _my = UserInput.Mouse.Y + (current_cursor->height * 0.25); + int xstart = UserInput.Mouse.X - Get_Hotspot_X(); int ystart = _my - Get_Hotspot_Y(); int yend = current_cursor->height + ystart - 1; int xend = current_cursor->width + xstart - 1; @@ -483,7 +483,7 @@ int WWMouseClass::Get_Mouse_State(void) *=============================================================================================*/ int WWMouseClass::Get_Mouse_X(void) { - return mousex; + return UserInput.Mouse.X; } @@ -499,7 +499,7 @@ int WWMouseClass::Get_Mouse_X(void) *=============================================================================================*/ int WWMouseClass::Get_Mouse_Y(void) { - return mousey; + return UserInput.Mouse.Y; } /*********************************************************************************************** @@ -515,8 +515,8 @@ int WWMouseClass::Get_Mouse_Y(void) *=============================================================================================*/ void WWMouseClass::Get_Mouse_XY(int &x, int &y) { - x = mousex; - y = mousey; + x = UserInput.Mouse.X; + y = UserInput.Mouse.Y; } //#pragma off(unreferenced) @@ -575,14 +575,13 @@ void *Set_Mouse_Cursor(int hotx, int hoty, int cursor) extern int DLLForceMouseX; extern int DLLForceMouseY; -extern int mousex, mousey; int Get_Mouse_X(void) { - return mousex; + return UserInput.Mouse.X; } int Get_Mouse_Y(void) { - return mousey; + return UserInput.Mouse.Y; } \ No newline at end of file diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index 87fd8a2..4e60f57 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -88,16 +88,6 @@ void Show_OldFrameBuffer(bool show) { std::vector loaded_images; -auto utf8_decode = [](const std::string& str) -> std::wstring -{ - if (str.empty()) return std::wstring(); - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); - return wstrTo; -}; - - Image_t* Image_LoadImage(const char* name) { // Check to see if the image is already loaded. for (int i = 0; i < loaded_images.size(); i++) { @@ -677,133 +667,8 @@ void __cdecl SetPalette(unsigned char *palette, long, unsigned long) } -void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { - static int numFramesLMouse = 0; - extern int mousex, mousey; - bool leftMouseProcessed = false; - - SDL_GetMouseState(&mousex, &mousey); - - Keyboard->MouseQX = mousex; - Keyboard->MouseQY = mousey; - - // if (flags == LEFTRELEASE || flags == RIGHTRELEASE) - // flags = 0; - - SDL_Event event; - - while (SDL_PollEvent(&event)) { - const Uint8* state = SDL_GetKeyboardState(NULL); - - switch (event.type) - { - case SDL_SYSWMEVENT: - if ( event.syswm.msg->msg.win.msg == WM_DESTROY ) - { - Invalidate_Cached_Icons(); - VisiblePage.Un_Init(); - HiddenPage.Un_Init(); - AllSurfaces.Release(); - if (!InDebugger) Reset_Video_Mode(); - - /* - ** If we are shutting down gracefully than flag that the message loop has finished. - ** If this is a forced shutdown (ReadyToQuit == 0) then try and close down everything - ** before we exit. - */ - PostQuitMessage(0); - - switch (ReadyToQuit) { - case 1: - ReadyToQuit = 2; - break; - case 0: - ExitProcess(0); - break; - } - } - - break; - - case SDL_MOUSEMOTION: - flags = GadgetClass::LEFTUP; - break; - - case SDL_MOUSEBUTTONDOWN: - if (event.button.button == SDL_BUTTON_LEFT) { - flags = GadgetClass::LEFTPRESS; - leftMouseProcessed = true; - numFramesLMouse++; - key = KN_LMOUSE; - } - else if (event.button.button == SDL_BUTTON_RIGHT) { - numFramesLMouse = 0; - flags = GadgetClass::RIGHTPRESS; - key = KN_RMOUSE; - } - break; - - case SDL_MOUSEBUTTONUP: - if (event.button.button == SDL_BUTTON_LEFT) { - flags = GadgetClass::LEFTRELEASE; - numFramesLMouse = 0; - } - else if (event.button.button == SDL_BUTTON_RIGHT) { - flags = GadgetClass::RIGHTRELEASE; - numFramesLMouse = 0; - } - break; - - case SDL_KEYDOWN: - if (event.key.keysym.scancode == SDL_SCANCODE_GRAVE) { - renderConsole = !renderConsole; - - if (renderConsole) { - ShowCursor(TRUE); - Hide_Mouse(); - } - else { - ShowCursor(FALSE); - Show_Mouse(); - } - break; - } - - // handle backspace and ENTER - if (event.key.keysym.scancode == SDL_SCANCODE_BACKSPACE) Keyboard->Put_Element( KN_BACKSPACE ); - if (event.key.keysym.scancode == ( SDL_SCANCODE_RETURN || SDL_SCANCODE_KP_ENTER ) ) Keyboard->Put_Element( KN_RETURN ); - - break; - case SDL_TEXTINPUT: - int keyFlags = 0x00; - - if (state[SDL_SCANCODE_RSHIFT] || state[SDL_SCANCODE_LSHIFT]) keyFlags |= KN_SHIFT_BIT; - if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) keyFlags |= KN_ALT_BIT; - - std::wstring input_utf16 = utf8_decode( std::string( event.text.text ) ); - - if( input_utf16.length() == 1 ) - { - short vKey = VkKeyScanW( input_utf16[0] ); - Keyboard->Put_Element( vKey | keyFlags ); - } - - break; - } - - if (Debug_Map || renderConsole) - { - ImGui_ImplSDL2_ProcessEvent(&event); - } - - } - - if (!leftMouseProcessed && numFramesLMouse != 0) - { - flags = GadgetClass::LEFTHELD; - } - - Device_Present(); +void WWSDL_ProcessEvents(KeyNumType& key, int& flags, bool presentBuffer) { + UserInput.Process_Input(key, flags, presentBuffer); } #ifndef NDEBUG diff --git a/code/REDALERT/io/UserInput.cpp b/code/REDALERT/io/UserInput.cpp new file mode 100644 index 0000000..669291d --- /dev/null +++ b/code/REDALERT/io/UserInput.cpp @@ -0,0 +1,149 @@ +#include "../FUNCTION.H" +#include "UserInput.h" + +extern KeyboardClass * Keyboard; + +/* +auto utf8_decode = [](const std::string& str) -> std::wstring +{ + if (str.empty()) return std::wstring(); + int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); + std::wstring wstrTo(size_needed, 0); + MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); + return wstrTo; +}; +*/ + +void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuffer) +{ + bool leftMouseProcessed = false; + + SDL_GetMouseState(&Mouse.X, &Mouse.Y); + + Keyboard->MouseQX = Mouse.X; + Keyboard->MouseQY = Mouse.Y; + + static SDL_Event event; + memset(&event, 0, sizeof(SDL_Event)); + + while (SDL_PollEvent(&event)) { + const Uint8* state = SDL_GetKeyboardState(NULL); + + switch (event.type) + { + case SDL_SYSWMEVENT: + if (event.syswm.msg->msg.win.msg == WM_DESTROY) + { + Invalidate_Cached_Icons(); + VisiblePage.Un_Init(); + HiddenPage.Un_Init(); + AllSurfaces.Release(); + if (!InDebugger) Reset_Video_Mode(); + + PostQuitMessage(0); + + switch (ReadyToQuit) { + case 1: + ReadyToQuit = 2; + break; + case 0: + ExitProcess(0); + break; + } + } + + break; + + case SDL_MOUSEMOTION: + flags = GadgetClass::LEFTUP; + break; + + case SDL_MOUSEBUTTONDOWN: + if (event.button.button == SDL_BUTTON_LEFT) { + Mouse.Button_Left == MouseButtonState::MOUSE_BUTTON_DOWN; + + flags = GadgetClass::LEFTPRESS; + leftMouseProcessed = true; + numFramesLMouse++; + key = KN_LMOUSE; + } + else if (event.button.button == SDL_BUTTON_RIGHT) { + Mouse.Button_Right == MouseButtonState::MOUSE_BUTTON_DOWN; + + numFramesLMouse = 0; + flags = GadgetClass::RIGHTPRESS; + key = KN_RMOUSE; + } + break; + + case SDL_MOUSEBUTTONUP: + if (event.button.button == SDL_BUTTON_LEFT) { + Mouse.Button_Left == MouseButtonState::MOUSE_BUTTON_RELEASE; + + flags = GadgetClass::LEFTRELEASE; + numFramesLMouse = 0; + } + else if (event.button.button == SDL_BUTTON_RIGHT) { + Mouse.Button_Right == MouseButtonState::MOUSE_BUTTON_RELEASE; + + flags = GadgetClass::RIGHTRELEASE; + numFramesLMouse = 0; + } + break; + + case SDL_KEYDOWN: + { + if (event.key.keysym.scancode == SDL_SCANCODE_GRAVE) { + renderConsole = !renderConsole; + + if (renderConsole) { + ShowCursor(TRUE); + Hide_Mouse(); + } + else { + ShowCursor(FALSE); + Show_Mouse(); + } + break; + } + + int keyFlags = 0x00; + if (state[SDL_SCANCODE_RSHIFT] || state[SDL_SCANCODE_LSHIFT]) keyFlags |= KN_SHIFT_BIT; + if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) keyFlags |= KN_ALT_BIT; + if (state[SDL_SCANCODE_RCTRL] || state[SDL_SCANCODE_LCTRL]) keyFlags |= KN_CTRL_BIT; + + // handle match between SDL and internals (non-text keys) + auto element = sdl_keyMapping.find((SDL_KeyCode)event.key.keysym.sym); + if (element != sdl_keyMapping.end()) + { + Keyboard->Put_Element(element->second | keyFlags); + KeyB.ASCII = element->second; + } + + break; + } + case SDL_TEXTINPUT: + // limit to range 0-255 + if (event.text.text[0] == ( event.text.text[0] & 0xFF ) ) + { + KeyB.ASCII = (char)event.text.text[0]; + } + } + + if (Debug_Map || renderConsole) + { + ImGui_ImplSDL2_ProcessEvent(&event); + } + } + + if (!leftMouseProcessed && numFramesLMouse != 0) + { + Mouse.Button_Left == MouseButtonState::MOUSE_BUTTON_HOLD; + flags = GadgetClass::LEFTHELD; + } + + if (presentBuffer) + { + Device_Present(); + } +} \ No newline at end of file diff --git a/code/REDALERT/io/UserInput.h b/code/REDALERT/io/UserInput.h new file mode 100644 index 0000000..5955353 --- /dev/null +++ b/code/REDALERT/io/UserInput.h @@ -0,0 +1,144 @@ +#ifndef USERINPUT_H +#define USERINPUT_H + +#include +#include +#include + +#include "examples/imgui_impl_sdl.h" + +// Mapping of SDL KeyCode values to internal KeyNumType +std::map const sdl_keyMapping = { + { SDLK_a, KN_A }, + { SDLK_b, KN_B }, + { SDLK_c, KN_C }, + { SDLK_d, KN_D }, + { SDLK_e, KN_E }, + { SDLK_f, KN_F }, + { SDLK_g, KN_G }, + { SDLK_h, KN_H }, + { SDLK_i, KN_I }, + { SDLK_j, KN_J }, + { SDLK_k, KN_K }, + { SDLK_l, KN_N }, + { SDLK_m, KN_M }, + { SDLK_n, KN_N }, + { SDLK_o, KN_O }, + { SDLK_p, KN_P }, + { SDLK_q, KN_Q }, + { SDLK_r, KN_R }, + { SDLK_s, KN_S }, + { SDLK_t, KN_T }, + { SDLK_u, KN_U }, + { SDLK_v, KN_V }, + { SDLK_w, KN_W }, + { SDLK_x, KN_X }, + { SDLK_y, KN_Y }, + { SDLK_z, KN_Z }, + + { SDLK_0, KN_0 }, + { SDLK_1, KN_1 }, + { SDLK_2, KN_2 }, + { SDLK_3, KN_3 }, + { SDLK_4, KN_4 }, + { SDLK_5, KN_5 }, + { SDLK_6, KN_6 }, + { SDLK_7, KN_7 }, + { SDLK_8, KN_8 }, + { SDLK_9, KN_9 }, + + { SDLK_KP_MULTIPLY, KN_KEYPAD_ASTERISK }, + { SDLK_KP_DIVIDE, KN_KEYPAD_SLASH }, + { SDLK_MINUS, KN_MINUS }, + { SDLK_EQUALS, KN_EQUAL }, + + { SDLK_RIGHTBRACKET, KN_RBRACKET }, + { SDLK_LEFTBRACKET, KN_LBRACKET }, + { SDLK_SEMICOLON, KN_SEMICOLON }, + { SDLK_COMMA, KN_COMMA }, + { SDLK_PERIOD, KN_PERIOD }, + { SDLK_SLASH, KN_SLASH }, + { SDLK_BACKSLASH, KN_BACKSLASH }, + + { SDLK_F1, KN_F1 }, + { SDLK_F2, KN_F2 }, + { SDLK_F3, KN_F3 }, + { SDLK_F4, KN_F4 }, + { SDLK_F5, KN_F5 }, + { SDLK_F6, KN_F6 }, + { SDLK_F7, KN_F7 }, + { SDLK_F8, KN_F8 }, + { SDLK_F9, KN_F9 }, + { SDLK_F10, KN_F10 }, + { SDLK_F11, KN_F12 }, + { SDLK_F12, KN_F12 }, + + { SDLK_BACKSPACE, KN_BACKSPACE }, + { SDLK_KP_ENTER, KN_RETURN }, + { SDLK_RETURN, KN_RETURN }, + { SDLK_ESCAPE, KN_ESC }, +}; + +class UserInputClass +{ + public: + typedef enum { + MOUSE_BUTTON_UP, + MOUSE_BUTTON_DOWN, + MOUSE_BUTTON_HOLD, + MOUSE_BUTTON_RELEASE, + } MouseButtonState; + + typedef enum { + INPUT_ACTION_NONE, + INPUT_ACTION_KEYBOARD, + INPUT_ACTION_MOUSE, + } InputAction; + + void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuffer = true); + + InputAction LastAction; + + class KeyboardState { + public: + SDL_KeyCode LastKey; + char ASCII; + + bool Shift; + bool Control; + bool Alt; + + void ResetState() { + this->Shift = false; + this->Control = false; + this->Alt = false; + + LastKey = SDLK_UNKNOWN; + ASCII = 0x0; + } + }; + + KeyboardState KeyB; + + class MouseState { + public: + int X; + int Y; + + MouseButtonState Button_Left; + MouseButtonState Button_Middle; + MouseButtonState Button_Right; + + void ResetState() { + this->Button_Left = MouseButtonState::MOUSE_BUTTON_UP; + this->Button_Middle = MouseButtonState::MOUSE_BUTTON_UP; + this->Button_Right = MouseButtonState::MOUSE_BUTTON_UP; + } + }; + + MouseState Mouse; + private: + int numFramesLMouse = 0; +}; + +#endif \ No newline at end of file From 71007c06d0c7430aaee94a2caf56c7461f1293dc Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Thu, 18 Jun 2020 22:09:37 +0200 Subject: [PATCH 05/10] * Center on player location at Skirmish start --- code/REDALERT/DISPLAY.CPP | 3 +-- code/REDALERT/HOUSE.H | 3 ++- code/REDALERT/KEY.CPP | 2 ++ code/REDALERT/RADAR.CPP | 9 ++------- code/REDALERT/SCENARIO.CPP | 9 +++++++-- code/REDALERT/io/UserInput.cpp | 27 ++++++++++++--------------- code/REDALERT/io/UserInput.h | 3 --- 7 files changed, 26 insertions(+), 30 deletions(-) diff --git a/code/REDALERT/DISPLAY.CPP b/code/REDALERT/DISPLAY.CPP index 52929de..17db919 100644 --- a/code/REDALERT/DISPLAY.CPP +++ b/code/REDALERT/DISPLAY.CPP @@ -3090,7 +3090,6 @@ int DisplayClass::TacticalClass::Action(unsigned flags, KeyNumType & key) x = Get_Mouse_X(); y = Get_Mouse_Y(); - bool edge = (y == 0 || x == 0 || x == SeenBuff.Get_Width()-1 || y == SeenBuff.Get_Height()-1); COORDINATE coord = Map.Pixel_To_Coord(x, y); CELL cell = Coord_Cell(coord); @@ -3344,7 +3343,7 @@ int DisplayClass::TacticalClass::Selection_At_Mouse(unsigned flags, KeyNumType & if (object != nullptr) { - bool shiftdown = UserInput.KeyB.Shift = true; + bool shiftdown = UserInput.KeyB.Shift == true; if (shiftdown) { diff --git a/code/REDALERT/HOUSE.H b/code/REDALERT/HOUSE.H index 9ae63e1..2bdd9d2 100644 --- a/code/REDALERT/HOUSE.H +++ b/code/REDALERT/HOUSE.H @@ -522,7 +522,8 @@ class HouseClass { ** This records information about the location and size of ** the base. */ - COORDINATE Center; // Center of the base. + COORDINATE Center; // Center COORDINATE of the base. + CELL CenterCell; // Center CELL of the base. int Radius; // Average building distance from center (leptons). struct { int AirDefense; diff --git a/code/REDALERT/KEY.CPP b/code/REDALERT/KEY.CPP index 53764ca..3b5db7f 100644 --- a/code/REDALERT/KEY.CPP +++ b/code/REDALERT/KEY.CPP @@ -103,10 +103,12 @@ unsigned short WWKeyboardClass::Buff_Get(void) while (!Check()) {} // wait for key in buffer unsigned short temp = Fetch_Element(); + /* if (Is_Mouse_Key(temp)) { MouseQX = Fetch_Element(); MouseQY = Fetch_Element(); } + */ return(temp); } diff --git a/code/REDALERT/RADAR.CPP b/code/REDALERT/RADAR.CPP index 4c151e3..77ccdaa 100644 --- a/code/REDALERT/RADAR.CPP +++ b/code/REDALERT/RADAR.CPP @@ -1776,13 +1776,8 @@ int RadarClass::RTacticalClass::Action(unsigned flags, KeyNumType & key) ** or release event, special mouse queuing storage variables are used. Other ** events must use the current mouse position globals. */ - if (flags & (LEFTPRESS|LEFTRELEASE|RIGHTPRESS|RIGHTRELEASE)) { - x = Keyboard->MouseQX; - y = Keyboard->MouseQY; - } else { - x = Get_Mouse_X(); - y = Get_Mouse_Y(); - } + x = Get_Mouse_X(); + y = Get_Mouse_Y(); /* ** See if the mouse is over the radar general area, but not yet diff --git a/code/REDALERT/SCENARIO.CPP b/code/REDALERT/SCENARIO.CPP index 0797e76..5d51d33 100644 --- a/code/REDALERT/SCENARIO.CPP +++ b/code/REDALERT/SCENARIO.CPP @@ -644,10 +644,14 @@ void Fill_In_Data(void) */ if (!Debug_Map) { Map.SidebarClass::Activate(1); -// if (Session.Type == GAME_NORMAL) { + if (Session.Type == GAME_NORMAL) { Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = Scen.Waypoint[WAYPT_HOME]; Map.Set_Tactical_Position(Cell_Coord((Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR)) - (5*RESFACTOR))); -// } + } + if (Session.Type == GAME_SKIRMISH) { + Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = PlayerPtr->CenterCell; + Map.Set_Tactical_Position( Cell_Coord( (PlayerPtr->CenterCell - (MAP_CELL_W * 4 * RESFACTOR) ) - (5 * RESFACTOR) ) ); + } } #endif @@ -3240,6 +3244,7 @@ static void Create_Units(bool official) ** Assign the center of this house to the waypoint location. */ hptr->Center = Cell_Coord(centroid); + hptr->CenterCell = centroid; /* ** If Bases are ON, human & computer houses are treated differently diff --git a/code/REDALERT/io/UserInput.cpp b/code/REDALERT/io/UserInput.cpp index 669291d..6fc66d8 100644 --- a/code/REDALERT/io/UserInput.cpp +++ b/code/REDALERT/io/UserInput.cpp @@ -3,21 +3,9 @@ extern KeyboardClass * Keyboard; -/* -auto utf8_decode = [](const std::string& str) -> std::wstring -{ - if (str.empty()) return std::wstring(); - int size_needed = MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), NULL, 0); - std::wstring wstrTo(size_needed, 0); - MultiByteToWideChar(CP_UTF8, 0, &str[0], (int)str.size(), &wstrTo[0], size_needed); - return wstrTo; -}; -*/ - void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuffer) { bool leftMouseProcessed = false; - SDL_GetMouseState(&Mouse.X, &Mouse.Y); Keyboard->MouseQX = Mouse.X; @@ -108,9 +96,18 @@ void UserInputClass::Process_Input(KeyNumType& key, int& flags, bool presentBuff } int keyFlags = 0x00; - if (state[SDL_SCANCODE_RSHIFT] || state[SDL_SCANCODE_LSHIFT]) keyFlags |= KN_SHIFT_BIT; - if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) keyFlags |= KN_ALT_BIT; - if (state[SDL_SCANCODE_RCTRL] || state[SDL_SCANCODE_LCTRL]) keyFlags |= KN_CTRL_BIT; + if (state[SDL_SCANCODE_RSHIFT] || state[SDL_SCANCODE_LSHIFT]) { + KeyB.Shift = true; + keyFlags |= KN_SHIFT_BIT; + } + if (state[SDL_SCANCODE_RALT] || state[SDL_SCANCODE_LALT]) { + keyFlags |= KN_ALT_BIT; + KeyB.Alt = true; + } + if (state[SDL_SCANCODE_RCTRL] || state[SDL_SCANCODE_LCTRL]) { + keyFlags |= KN_CTRL_BIT; + KeyB.Control = true; + } // handle match between SDL and internals (non-text keys) auto element = sdl_keyMapping.find((SDL_KeyCode)event.key.keysym.sym); diff --git a/code/REDALERT/io/UserInput.h b/code/REDALERT/io/UserInput.h index 5955353..50d7c39 100644 --- a/code/REDALERT/io/UserInput.h +++ b/code/REDALERT/io/UserInput.h @@ -112,9 +112,6 @@ class UserInputClass this->Shift = false; this->Control = false; this->Alt = false; - - LastKey = SDLK_UNKNOWN; - ASCII = 0x0; } }; From 720e7064d134fe0f445c8fea978b45525f745c1f Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Thu, 18 Jun 2020 22:26:39 +0200 Subject: [PATCH 06/10] * Center Abort Skirmish game dialog * Savegame compatible centering of skirmish start --- code/REDALERT/HOUSE.H | 2 +- code/REDALERT/MPLAYER.CPP | 19 +++++++++++-------- code/REDALERT/SCENARIO.CPP | 8 ++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/code/REDALERT/HOUSE.H b/code/REDALERT/HOUSE.H index 2bdd9d2..d21a745 100644 --- a/code/REDALERT/HOUSE.H +++ b/code/REDALERT/HOUSE.H @@ -523,7 +523,7 @@ class HouseClass { ** the base. */ COORDINATE Center; // Center COORDINATE of the base. - CELL CenterCell; // Center CELL of the base. + //CELL CenterCell; // Center CELL of the base. int Radius; // Average building distance from center (leptons). struct { int AirDefense; diff --git a/code/REDALERT/MPLAYER.CPP b/code/REDALERT/MPLAYER.CPP index 8fd522d..4eaf64d 100644 --- a/code/REDALERT/MPLAYER.CPP +++ b/code/REDALERT/MPLAYER.CPP @@ -619,10 +619,7 @@ int Surrender_Dialog(int text) //------------------------------------------------------------------------ enum { D_DIALOG_W = 240*RESFACTOR, // dialog width - D_DIALOG_H = 63*RESFACTOR, // dialog height - D_DIALOG_X = ((320*RESFACTOR - D_DIALOG_W) / 2),// centered x-coord - D_DIALOG_Y = ((200*RESFACTOR - D_DIALOG_H) / 2),// centered y-coord - D_DIALOG_CX = D_DIALOG_X + (D_DIALOG_W / 2), // coord of x-center + D_DIALOG_H = 63*RESFACTOR, // dialog height D_TXT6_H = 7*RESFACTOR, // ht of 6-pt text D_MARGIN = 5*RESFACTOR, // margin width/height @@ -630,13 +627,9 @@ int Surrender_Dialog(int text) D_OK_W = 45*RESFACTOR, // OK width D_OK_H = 9*RESFACTOR, // OK height - D_OK_X = D_DIALOG_CX - D_OK_W - 5*RESFACTOR, // OK x - D_OK_Y = D_DIALOG_Y + D_DIALOG_H - D_OK_H - D_MARGIN*2, // OK y D_CANCEL_W = 45*RESFACTOR, // Cancel width D_CANCEL_H = 9*RESFACTOR, // Cancel height - D_CANCEL_X = D_DIALOG_CX + 5*RESFACTOR, // Cancel x - D_CANCEL_Y = D_DIALOG_Y + D_DIALOG_H - D_CANCEL_H - D_MARGIN*2, // Cancel y }; //------------------------------------------------------------------------ @@ -647,6 +640,16 @@ int Surrender_Dialog(int text) BUTTON_CANCEL, }; + int D_DIALOG_X = (SeenBuff.Get_Width() - D_DIALOG_W) / 2; // centered x-coord + int D_DIALOG_Y = (SeenBuff.Get_Height() - D_DIALOG_H) / 2; // centered y-coord + int D_DIALOG_CX = D_DIALOG_X + (D_DIALOG_W / 2); // coord of x-center + + int D_OK_X = D_DIALOG_CX - D_OK_W - 5 * RESFACTOR; // OK x + int D_OK_Y = D_DIALOG_Y + D_DIALOG_H - D_OK_H - D_MARGIN * 2; // OK y + + int D_CANCEL_X = D_DIALOG_CX + 5 * RESFACTOR; // Cancel x + int D_CANCEL_Y = D_DIALOG_Y + D_DIALOG_H - D_CANCEL_H - D_MARGIN * 2; // Cancel y + //------------------------------------------------------------------------ // Buttons //------------------------------------------------------------------------ diff --git a/code/REDALERT/SCENARIO.CPP b/code/REDALERT/SCENARIO.CPP index 5d51d33..8a257e8 100644 --- a/code/REDALERT/SCENARIO.CPP +++ b/code/REDALERT/SCENARIO.CPP @@ -400,7 +400,7 @@ bool Start_Scenario(char * name, bool briefing) if (Scen.BriefMovie != VQ_NONE) { sprintf(buffer, "%s.VQA", VQName[Scen.BriefMovie]); } - if (Session.Type == GAME_NORMAL && Scen.BriefMovie == VQ_NONE || !CCFileClass(buffer).Is_Available()) { + if (Session.Type == GAME_NORMAL && ( Scen.BriefMovie == VQ_NONE || !CCFileClass(buffer).Is_Available() ) ) { /* ** Make sure the mouse is visible before showing the restatement. */ @@ -649,8 +649,9 @@ void Fill_In_Data(void) Map.Set_Tactical_Position(Cell_Coord((Scen.Waypoint[WAYPT_HOME] - (MAP_CELL_W * 4 * RESFACTOR)) - (5*RESFACTOR))); } if (Session.Type == GAME_SKIRMISH) { - Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = PlayerPtr->CenterCell; - Map.Set_Tactical_Position( Cell_Coord( (PlayerPtr->CenterCell - (MAP_CELL_W * 4 * RESFACTOR) ) - (5 * RESFACTOR) ) ); + CELL PlayerCenterCell = XY_Cell( Coord_XCell(PlayerPtr->Center), Coord_YCell( PlayerPtr->Center) ); + Scen.Views[0] = Scen.Views[1] = Scen.Views[2] = Scen.Views[3] = PlayerCenterCell; + Map.Set_Tactical_Position( Cell_Coord( (PlayerCenterCell - (MAP_CELL_W * 4 * RESFACTOR) ) - (5 * RESFACTOR) ) ); } } #endif @@ -3244,7 +3245,6 @@ static void Create_Units(bool official) ** Assign the center of this house to the waypoint location. */ hptr->Center = Cell_Coord(centroid); - hptr->CenterCell = centroid; /* ** If Bases are ON, human & computer houses are treated differently From 9d5eb0ac1e7a4563118da2310e86bc03d988bd34 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Sat, 20 Jun 2020 10:27:17 +0200 Subject: [PATCH 07/10] * Centering of mission accomplished * Added 8 px next to the Options bar * TEMP: everything costs $50 --- code/REDALERT/DISPLAY.CPP | 2 +- code/REDALERT/POWER.CPP | 3 +++ code/REDALERT/SCENARIO.CPP | 7 +------ code/REDALERT/SIDEBAR.CPP | 2 +- code/REDALERT/TECHNO.CPP | 2 +- code/REDALERT/io/UserInput.h | 1 + 6 files changed, 8 insertions(+), 9 deletions(-) diff --git a/code/REDALERT/DISPLAY.CPP b/code/REDALERT/DISPLAY.CPP index 17db919..85c4438 100644 --- a/code/REDALERT/DISPLAY.CPP +++ b/code/REDALERT/DISPLAY.CPP @@ -188,7 +188,7 @@ DisplayClass::DisplayClass(void) : ShadowShapes = 0; TransIconset = 0; - Set_View_Dimensions(0, 0, ScreenWidth, ScreenHeight); + Set_View_Dimensions(0, 8 * RESFACTOR, ScreenWidth, ScreenHeight); } diff --git a/code/REDALERT/POWER.CPP b/code/REDALERT/POWER.CPP index 5e1fc0d..7987686 100644 --- a/code/REDALERT/POWER.CPP +++ b/code/REDALERT/POWER.CPP @@ -204,6 +204,8 @@ void PowerClass::Draw_It(bool complete) power_height = Bound(power_height, 0, PowerButton.Height - 2); drain_height = Bound(drain_height, 0, PowerButton.Height - 2); + bottom -= (15 * RESFACTOR); + /* ** Draw the power output graphic on top of the power bar framework. */ @@ -245,6 +247,7 @@ void PowerClass::Draw_It(bool complete) } BEnd(BENCH_POWER); } + RadarClass::Draw_It(complete); } diff --git a/code/REDALERT/SCENARIO.CPP b/code/REDALERT/SCENARIO.CPP index 8a257e8..3eabd81 100644 --- a/code/REDALERT/SCENARIO.CPP +++ b/code/REDALERT/SCENARIO.CPP @@ -922,11 +922,6 @@ void Do_Win(void) Session.GameName[0] = 0; } - /* - ** Determine a cosmetic center point for the text. - */ - int x = Map.TacPixelX + (Lepton_To_Pixel(Map.TacLeptonWidth)/2); - /* ** Hack section. If it's allied scenario 10, variation A, then skip the ** score and map selection, don't increment scenario, and set it to @@ -945,7 +940,7 @@ void Do_Win(void) Map.Flag_To_Redraw (true); Map.Render(); #ifdef WIN32 - Fancy_Text_Print(TXT_SCENARIO_WON, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW); + Fancy_Text_Print(TXT_SCENARIO_WON, (SeenBuff.Get_Width() / 2), 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW); #else Fancy_Text_Print(TXT_MISSION, x, 90*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW); Fancy_Text_Print(TXT_HACKHACK, x, 110*RESFACTOR, &ColorRemaps[PCOLOR_RED], TBLACK, TPF_CENTER|TPF_VCR|TPF_USE_GRAD_PAL|TPF_DROPSHADOW); diff --git a/code/REDALERT/SIDEBAR.CPP b/code/REDALERT/SIDEBAR.CPP index 2dc13a1..212c1a1 100644 --- a/code/REDALERT/SIDEBAR.CPP +++ b/code/REDALERT/SIDEBAR.CPP @@ -1030,7 +1030,7 @@ bool SidebarClass::Activate(int control) ** activate it on the left side of the screen. */ if (IsSidebarActive /*&& X*/) { - Set_View_Dimensions( 0, 0, SeenBuff.Get_Width() - ( SIDE_WIDTH * RESFACTOR ) ); + Set_View_Dimensions( 0, 8 * RESFACTOR, SeenBuff.Get_Width() - ( SIDE_WIDTH * RESFACTOR ) ); IsToRedraw = true; Help_Text(TXT_NONE); diff --git a/code/REDALERT/TECHNO.CPP b/code/REDALERT/TECHNO.CPP index 5700235..fc768bf 100644 --- a/code/REDALERT/TECHNO.CPP +++ b/code/REDALERT/TECHNO.CPP @@ -6705,7 +6705,7 @@ bool TechnoTypeClass::Read_INI(CCINIClass & ini) SightRange = ini.Get_Int(Name(), "Sight", SightRange); Level = ini.Get_Int(Name(), "TechLevel", Level); MaxSpeed = MPHType(_Scale_To_256(ini.Get_Int(Name(), "Speed", fixed(MaxSpeed, 256) * 100))); - Cost = ini.Get_Int(Name(), "Cost", Cost); + Cost = 50; // ini.Get_Int(Name(), "Cost", Cost); MaxAmmo = ini.Get_Int(Name(), "Ammo", MaxAmmo); Risk = Reward = Points = ini.Get_Int(Name(), "Points", Points); Ownable = ini.Get_Owners(Name(), "Owner", Ownable); diff --git a/code/REDALERT/io/UserInput.h b/code/REDALERT/io/UserInput.h index 50d7c39..c98ff8a 100644 --- a/code/REDALERT/io/UserInput.h +++ b/code/REDALERT/io/UserInput.h @@ -74,6 +74,7 @@ std::map const sdl_keyMapping = { { SDLK_F12, KN_F12 }, { SDLK_BACKSPACE, KN_BACKSPACE }, + { SDLK_SPACE, KN_SPACE }, { SDLK_KP_ENTER, KN_RETURN }, { SDLK_RETURN, KN_RETURN }, { SDLK_ESCAPE, KN_ESC }, From b6dba2d56384c547f132f831e76ef35908b7f3d6 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Sat, 20 Jun 2020 11:22:05 +0200 Subject: [PATCH 08/10] Updated git ignore --- .gitignore | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 6b0ff60..4b893ed 100644 --- a/.gitignore +++ b/.gitignore @@ -4,4 +4,15 @@ /.vs/ /out/ -/code/out/ \ No newline at end of file +/code/out/ +/fonts +/sound +/ui +/*.mix +/*.pal +/*.ini +/*.exe +/*.ilk +/*.dat +/savegame* + From 28e98329b6e9a25530da20c05771be97a7374e91 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Sat, 20 Jun 2020 11:44:21 +0200 Subject: [PATCH 09/10] Mouse X/Y-reversal --- code/REDALERT/WIN32LIB/MOUSEWW.CPP | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/code/REDALERT/WIN32LIB/MOUSEWW.CPP b/code/REDALERT/WIN32LIB/MOUSEWW.CPP index b42097b..91c07fb 100644 --- a/code/REDALERT/WIN32LIB/MOUSEWW.CPP +++ b/code/REDALERT/WIN32LIB/MOUSEWW.CPP @@ -241,8 +241,8 @@ void WWMouseClass::RenderMouse(void) { //ImVec2 size(current_cursor->width, current_cursor->height); // Image((ImTextureID)current_cursor->image, size); - int _my = UserInput.Mouse.X + (current_cursor->height * 0.25); - int xstart = UserInput.Mouse.Y - Get_Hotspot_X(); + int _my = UserInput.Mouse.Y + (current_cursor->height * 0.25); + int xstart = UserInput.Mouse.X - Get_Hotspot_X(); int ystart = _my - Get_Hotspot_Y(); int yend = current_cursor->height + ystart - 1; int xend = current_cursor->width + xstart - 1; From 09197ee12fc70cfd85a830afc5a6a42a0edb6052 Mon Sep 17 00:00:00 2001 From: Ben Lankamp Date: Sat, 20 Jun 2020 11:48:49 +0200 Subject: [PATCH 10/10] * Added arrow keys * Fixed position of radar button --- code/REDALERT/RADAR.CPP | 30 +++++++++--------------------- code/REDALERT/SIDEBAR.CPP | 2 +- code/REDALERT/io/UserInput.h | 5 +++++ 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/code/REDALERT/RADAR.CPP b/code/REDALERT/RADAR.CPP index a8dd0d4..2c40ad3 100644 --- a/code/REDALERT/RADAR.CPP +++ b/code/REDALERT/RADAR.CPP @@ -148,35 +148,23 @@ RadarClass::RadarClass(void) : void RadarClass::One_Time(void) { RadWidth = 80 * RESFACTOR; - RadHeight = 70 * RESFACTOR; + RadHeight = 70 * RESFACTOR; RadX = SeenBuff.Get_Width() - RadWidth; RadY = 7 * RESFACTOR; - RadPWidth = 64 * RESFACTOR; - RadPHeight = 64 * RESFACTOR; - #ifdef WIN32 - RadOffX = 6; - RadOffY = 7; - RadIWidth = 128+18;//************ - RadIHeight = 128+2;//************ - #else - RadOffX = 4; - RadOffY = 1; - RadIWidth = 72; - RadIHeight = 69; - #endif + RadPWidth = 64 * RESFACTOR; + RadPHeight = 64 * RESFACTOR; + + RadOffX = 6; + RadOffY = 7; + RadIWidth = 128+18;//************ + RadIHeight = 128+2;//************ DisplayClass::One_Time(); -#ifdef OBSOLETE - RadarButton.X = RadX+RadOffX; - RadarButton.Y = RadY+RadOffY; - RadarButton.Width = RadIWidth; - RadarButton.Height = RadIHeight; -#else + RadarButton.X = RadX; RadarButton.Y = RadY; RadarButton.Width = RadWidth; RadarButton.Height = RadHeight; -#endif } diff --git a/code/REDALERT/SIDEBAR.CPP b/code/REDALERT/SIDEBAR.CPP index 212c1a1..f3db0df 100644 --- a/code/REDALERT/SIDEBAR.CPP +++ b/code/REDALERT/SIDEBAR.CPP @@ -325,7 +325,7 @@ void SidebarClass::Init_IO(void) Zoom.IsSticky = true; Zoom.ID = BUTTON_ZOOM; - Zoom.X = 1024 - (640 - ((0x24c/2)*RESFACTOR)); + Zoom.X = ScreenWidth - (640 - ((0x24c/2)*RESFACTOR)); Zoom.Y = (0x96/2)*RESFACTOR; Zoom.IsPressed = false; Zoom.Set_Shape(MFCD::Retrieve("MAP.SHP")); diff --git a/code/REDALERT/io/UserInput.h b/code/REDALERT/io/UserInput.h index c98ff8a..7f405e2 100644 --- a/code/REDALERT/io/UserInput.h +++ b/code/REDALERT/io/UserInput.h @@ -78,6 +78,11 @@ std::map const sdl_keyMapping = { { SDLK_KP_ENTER, KN_RETURN }, { SDLK_RETURN, KN_RETURN }, { SDLK_ESCAPE, KN_ESC }, + + { SDLK_UP, KN_UP }, + { SDLK_DOWN, KN_DOWN }, + { SDLK_LEFT, KN_LEFT }, + { SDLK_RIGHT, KN_RIGHT }, }; class UserInputClass