From 0a1ef9aa840b396743805f2d491ddf4f06428268 Mon Sep 17 00:00:00 2001 From: Justin Marshall Date: Sun, 14 Jun 2020 09:20:39 -0700 Subject: [PATCH] Initial checkin of the new UI blit code(there are issues and will be fixed one by one). --- code/CMakeLists.txt | 1 + code/REDALERT/DIALOG.CPP | 5 +++- code/REDALERT/EXPAND.CPP | 2 +- code/REDALERT/FUNCTION.H | 3 +-- code/REDALERT/GAMEDLG.CPP | 4 +-- code/REDALERT/GOPTIONS.CPP | 4 +-- code/REDALERT/LOADDLG.CPP | 6 ++--- code/REDALERT/MENUS.CPP | 2 +- code/REDALERT/MPLAYER.CPP | 8 +++--- code/REDALERT/MSGBOX.CPP | 3 --- code/REDALERT/NEWBLIT.CPP | 40 ++++++++++++++++++++++++++++++ code/REDALERT/NEWBLIT.H | 8 ++++++ code/REDALERT/NULLDLG.CPP | 13 +++++----- code/REDALERT/SCENARIO.CPP | 2 +- code/REDALERT/SPECIAL.CPP | 2 +- code/REDALERT/TXTPRNT.CPP | 3 ++- code/REDALERT/WIN32LIB/GBUFFER.H | 15 ++++++++--- code/REDALERT/WIN32LIB/MOUSEWW.CPP | 2 +- code/REDALERT/WINSTUB.CPP | 6 +++-- 19 files changed, 92 insertions(+), 37 deletions(-) create mode 100644 code/REDALERT/NEWBLIT.CPP create mode 100644 code/REDALERT/NEWBLIT.H diff --git a/code/CMakeLists.txt b/code/CMakeLists.txt index 948f462..86aa182 100644 --- a/code/CMakeLists.txt +++ b/code/CMakeLists.txt @@ -505,6 +505,7 @@ set(src_redalert ./RedAlert/SOUNDDLG.H ./RedAlert/SPECIAL.CPP ./RedAlert/SPECIAL.H + ./RedAlert/NewBlit.cpp ./RedAlert/SPRITE.CPP ./RedAlert/STAGE.H ./RedAlert/STARTUP.CPP diff --git a/code/REDALERT/DIALOG.CPP b/code/REDALERT/DIALOG.CPP index d92474d..fa15f3e 100644 --- a/code/REDALERT/DIALOG.CPP +++ b/code/REDALERT/DIALOG.CPP @@ -207,7 +207,10 @@ void Draw_Box(int x, int y, int w, int h, BoxStyleEnum up, bool filled) BoxStyleType const &style = ButtonColors[up]; if (filled) { - LogicPage->Fill_Rect( x, y, x+w, y+h, style.Filler); +// jmarshall + //LogicPage->Fill_Rect( x, y, x+w, y+h, style.Filler); + GL_FillRect(style.Filler, x, y, w, h); +// jmarshall end } switch (up) { diff --git a/code/REDALERT/EXPAND.CPP b/code/REDALERT/EXPAND.CPP index bec3242..69a3b67 100644 --- a/code/REDALERT/EXPAND.CPP +++ b/code/REDALERT/EXPAND.CPP @@ -497,7 +497,7 @@ bool Expansion_Dialog(void) Call_Back(); - if (display) { + { display = false; Hide_Mouse(); diff --git a/code/REDALERT/FUNCTION.H b/code/REDALERT/FUNCTION.H index 7398f03..e8bc46e 100644 --- a/code/REDALERT/FUNCTION.H +++ b/code/REDALERT/FUNCTION.H @@ -1074,7 +1074,7 @@ extern DynamicVectorClass xxx3; template <>class DynamicVectorClass; extern DynamicVectorClass whatever; -void WWSDL_ProcessEvents(KeyNumType& key, int& flags); +void WWSDL_ProcessEvents(KeyNumType& key, int& flags, bool presentBuffer = true); void Device_Present(void); /* @@ -1154,5 +1154,4 @@ extern const int NUM_EDIT_MISSIONS; extern void (*Imgui_Dialog_Function)(void); - #endif \ No newline at end of file diff --git a/code/REDALERT/GAMEDLG.CPP b/code/REDALERT/GAMEDLG.CPP index bd3564b..e45ec58 100644 --- a/code/REDALERT/GAMEDLG.CPP +++ b/code/REDALERT/GAMEDLG.CPP @@ -260,7 +260,7 @@ void GameControlsClass::Process(void) /* ** Refresh display if needed. */ - if (display) { + { Hide_Mouse(); Map.Flag_To_Redraw(true); @@ -273,7 +273,7 @@ void GameControlsClass::Process(void) refresh = true; } - if (refresh) { + { Hide_Mouse(); /* diff --git a/code/REDALERT/GOPTIONS.CPP b/code/REDALERT/GOPTIONS.CPP index a43fe14..1a6fb4b 100644 --- a/code/REDALERT/GOPTIONS.CPP +++ b/code/REDALERT/GOPTIONS.CPP @@ -265,7 +265,7 @@ void GameOptionsClass::Process(void) bool process = true; pressed = false; while (process) { - Device_Present(); + //Device_Present(); /* ** Invoke game callback. @@ -292,7 +292,7 @@ void GameOptionsClass::Process(void) /* ** Refresh display if needed. */ - if (display || RedrawOptionsMenu) { + { /* ** Redraw the map. diff --git a/code/REDALERT/LOADDLG.CPP b/code/REDALERT/LOADDLG.CPP index 76db461..f85bde4 100644 --- a/code/REDALERT/LOADDLG.CPP +++ b/code/REDALERT/LOADDLG.CPP @@ -285,13 +285,13 @@ int LoadOptionsClass::Process(void) /* ** Refresh display if needed. */ - if (display) { + { /* ** Display the dialog box. */ Hide_Mouse(); - if (display) { + { Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h); Draw_Caption(caption, d_dialog_x, d_dialog_y, d_dialog_w); @@ -304,7 +304,7 @@ int LoadOptionsClass::Process(void) /* ** Redraw the buttons. */ - if (display) { + { commands->Flag_List_To_Redraw(); } Show_Mouse(); diff --git a/code/REDALERT/MENUS.CPP b/code/REDALERT/MENUS.CPP index 524d4e7..d3a3f01 100644 --- a/code/REDALERT/MENUS.CPP +++ b/code/REDALERT/MENUS.CPP @@ -1032,7 +1032,7 @@ int Main_Menu(unsigned long ) break; } - Device_Present(); + //Device_Present(); } Options.Set_Score_Volume(oldvolume, false); diff --git a/code/REDALERT/MPLAYER.CPP b/code/REDALERT/MPLAYER.CPP index bbc8ab1..e71da39 100644 --- a/code/REDALERT/MPLAYER.CPP +++ b/code/REDALERT/MPLAYER.CPP @@ -252,8 +252,6 @@ GameType Select_MPlayer_Game (void) process = true; pressed = false; while (process) { - Device_Present(); - #ifdef WIN32 /* ** If we have just received input focus again after running in the background then @@ -274,9 +272,9 @@ GameType Select_MPlayer_Game (void) //..................................................................... // Refresh display if needed //..................................................................... - if (display) { + { Hide_Mouse(); - if (display >= REDRAW_BACKGROUND) { + { //............................................................... // Refresh the backdrop @@ -294,7 +292,7 @@ GameType Select_MPlayer_Game (void) //.................................................................. // Redraw buttons //.................................................................. - if (display >= REDRAW_BUTTONS) { + { commands->Flag_List_To_Redraw(); } Show_Mouse(); diff --git a/code/REDALERT/MSGBOX.CPP b/code/REDALERT/MSGBOX.CPP index f05a1fe..fa0a29d 100644 --- a/code/REDALERT/MSGBOX.CPP +++ b/code/REDALERT/MSGBOX.CPP @@ -258,9 +258,6 @@ int WWMessageBox::Process(const char * msg, const char * b1txt, const char * b2t process = true; pressed = false; while (process) { - - Device_Present(); - #ifdef WIN32 /* ** If we have just received input focus again after running in the background then diff --git a/code/REDALERT/NEWBLIT.CPP b/code/REDALERT/NEWBLIT.CPP new file mode 100644 index 0000000..b8704e5 --- /dev/null +++ b/code/REDALERT/NEWBLIT.CPP @@ -0,0 +1,40 @@ +// NEWBLIT.CPP +// + +#include +#include "FUNCTION.H" +#include "Image.h" + +extern byte backbuffer_palette[768]; + +void GL_RenderImage(Image_t* image, int x, int y, int width, int height) { + ImVec2 mi(x, y); + ImVec2 ma(x + width, y + height); + ImGui::GetForegroundDrawList()->AddImage((ImTextureID)image->image, mi, ma); +} + +void GL_FillRect(int color, int x, int y, int width, int height) { + ImVec2 mi(x, y); + ImVec2 ma(x + width, y + height); + float r = backbuffer_palette[(color * 3) + 0] / 255.0f; + float g = backbuffer_palette[(color * 3) + 1] / 255.0f; + float b = backbuffer_palette[(color * 3) + 2] / 255.0f; + ImGui::GetForegroundDrawList()->AddRectFilled(mi, ma, ImGui::ColorConvertFloat4ToU32(ImVec4(r, g, b, 1))); +} + +void GL_DrawText(int color, int x, int y, char* text) { + ImVec2 pos(x, y); + float r = backbuffer_palette[(color * 3) + 0] / 255.0f; + float g = backbuffer_palette[(color * 3) + 1] / 255.0f; + float b = backbuffer_palette[(color * 3) + 2] / 255.0f; + ImGui::GetForegroundDrawList()->AddText(pos, ImGui::ColorConvertFloat4ToU32(ImVec4(r, g, b, 1)), text); +} + +void GL_DrawLine(int color, int x, int y, int dx, int dy) { + ImVec2 pos(x, y); + ImVec2 pos2(dx, dy); + float r = backbuffer_palette[(color * 3) + 0] / 255.0f; + float g = backbuffer_palette[(color * 3) + 1] / 255.0f; + float b = backbuffer_palette[(color * 3) + 2] / 255.0f; + ImGui::GetForegroundDrawList()->AddLine(pos, pos2, ImGui::ColorConvertFloat4ToU32(ImVec4(r, g, b, 1))); +} \ No newline at end of file diff --git a/code/REDALERT/NEWBLIT.H b/code/REDALERT/NEWBLIT.H new file mode 100644 index 0000000..67aa378 --- /dev/null +++ b/code/REDALERT/NEWBLIT.H @@ -0,0 +1,8 @@ +// NewBlit.h +// + +struct Image_t; +void GL_RenderImage(Image_t* image, int x, int y, int width, int height); +void GL_DrawText(int color, int x, int y, char* text); +void GL_FillRect(int color, int x, int y, int width, int height); +void GL_DrawLine(int color, int x, int y, int dx, int dy); \ No newline at end of file diff --git a/code/REDALERT/NULLDLG.CPP b/code/REDALERT/NULLDLG.CPP index 5f50671..61c51fb 100644 --- a/code/REDALERT/NULLDLG.CPP +++ b/code/REDALERT/NULLDLG.CPP @@ -617,7 +617,6 @@ int Com_Scenario_Dialog(bool skirmish) oh_dear_its_a_label: while (process) { - Device_Present(); #if(SHOW_MONO) if (!skirmish) { NullModem.Mono_Debug_Print(0); @@ -683,7 +682,7 @@ oh_dear_its_a_label: /* ...................... Refresh display if needed ...................... */ - if (display) { + { if (housebtn.IsDropped) { housebtn.Collapse(); display = REDRAW_BACKGROUND; @@ -693,7 +692,7 @@ oh_dear_its_a_label: /* .................. Redraw backgound & dialog box ................... */ - if (display >= REDRAW_BACKGROUND) { + { Dialog_Box(d_dialog_x, d_dialog_y, d_dialog_w, d_dialog_h); // init font variables @@ -728,7 +727,7 @@ oh_dear_its_a_label: /*.................................................................. Draw the color boxes ..................................................................*/ - if (display >= REDRAW_COLORS) { + { for (i = 0; i < MAX_MPLAYER_COLORS; i++) { LogicPage->Fill_Rect(cbox_x[i] + 1, d_color_y + 1, cbox_x[i] + 1 + d_color_w - 2, d_color_y + 1 + d_color_h - 2, @@ -756,7 +755,7 @@ oh_dear_its_a_label: //.................................................................. // Update game parameter labels //.................................................................. - if (display >= REDRAW_PARMS) { + { // LogicPage->Fill_Rect(d_count_x + d_count_w + 2, d_count_y, d_count_x + d_count_w + 35 * RESFACTOR, d_aiplayers_y + d_aiplayers_h+RESFACTOR, BLACK); @@ -789,13 +788,13 @@ oh_dear_its_a_label: /* .......................... Redraw buttons .......................... */ - if (display >= REDRAW_BUTTONS) { + { commands->Flag_List_To_Redraw(); commands->Draw_All(); } Show_Mouse(); - display = REDRAW_NONE; + //display = REDRAW_NONE; } /* diff --git a/code/REDALERT/SCENARIO.CPP b/code/REDALERT/SCENARIO.CPP index 14f6b06..05e3442 100644 --- a/code/REDALERT/SCENARIO.CPP +++ b/code/REDALERT/SCENARIO.CPP @@ -1707,7 +1707,7 @@ int BGMessageBox(char const * msg, int btn1, int btn2) } #endif - if (display) { + { display = false; Hide_Mouse(); diff --git a/code/REDALERT/SPECIAL.CPP b/code/REDALERT/SPECIAL.CPP index 091b0cf..e28e8e6 100644 --- a/code/REDALERT/SPECIAL.CPP +++ b/code/REDALERT/SPECIAL.CPP @@ -567,7 +567,7 @@ int Fetch_Difficulty(void) */ Call_Back(); - Device_Present(); + // Device_Present(); #ifdef WIN32 /* diff --git a/code/REDALERT/TXTPRNT.CPP b/code/REDALERT/TXTPRNT.CPP index 8e0ee7d..d08ef7f 100644 --- a/code/REDALERT/TXTPRNT.CPP +++ b/code/REDALERT/TXTPRNT.CPP @@ -286,6 +286,7 @@ int __cdecl Buffer_Print2(GraphicViewPortClass& vp, const char* string, int x, i extern "C" LONG __cdecl Buffer_Print(void* thisptr, const char* str, int x, int y, int fcolor, int bcolor) { - Buffer_Print2(*(GraphicViewPortClass*)thisptr, str, x, y, fcolor, bcolor); + //Buffer_Print2(*(GraphicViewPortClass*)thisptr, str, x, y, fcolor, bcolor); + GL_DrawText(fcolor, x, y, (char *)str); return 0; } diff --git a/code/REDALERT/WIN32LIB/GBUFFER.H b/code/REDALERT/WIN32LIB/GBUFFER.H index 6aad38d..a95db68 100644 --- a/code/REDALERT/WIN32LIB/GBUFFER.H +++ b/code/REDALERT/WIN32LIB/GBUFFER.H @@ -136,6 +136,7 @@ #include #include #include "iconcach.h" +#include "../NEWBLIT.H" extern unsigned char* backbuffer_data_raw; @@ -1109,10 +1110,12 @@ inline void GraphicViewPortClass::Draw_Stamp(void const * icondata, int icon, in *=========================================================================*/ inline VOID GraphicViewPortClass::Draw_Line(int sx, int sy, int dx, int dy, unsigned char color) { - if (Lock()){ - Buffer_Draw_Line(this, sx, sy, dx, dy, color); - } - Unlock(); + //if (Lock()){ + // Buffer_Draw_Line(this, sx, sy, dx, dy, color); + //} + //Unlock(); + + GL_DrawLine(color, sx, sy, dx, dy); } /*************************************************************************** @@ -1129,10 +1132,14 @@ inline VOID GraphicViewPortClass::Draw_Line(int sx, int sy, int dx, int dy, unsi *=========================================================================*/ inline VOID GraphicViewPortClass::Fill_Rect(int sx, int sy, int dx, int dy, unsigned char color) { +// jmarshall + // Still needed for gameplay. if (Lock()) { Buffer_Fill_Rect(this, sx, sy, dx, dy, color); Unlock(); } + //GL_FillRect(color, sx, sy, dx - sx, dy - sy); +// jmarshall end } diff --git a/code/REDALERT/WIN32LIB/MOUSEWW.CPP b/code/REDALERT/WIN32LIB/MOUSEWW.CPP index d2a27a1..d16c3ad 100644 --- a/code/REDALERT/WIN32LIB/MOUSEWW.CPP +++ b/code/REDALERT/WIN32LIB/MOUSEWW.CPP @@ -240,7 +240,7 @@ void WWMouseClass::RenderMouse(void) { return; //ImVec2 size(current_cursor->width, current_cursor->height); - //ImGui::Image((ImTextureID)current_cursor->image, size); + // Image((ImTextureID)current_cursor->image, size); int _my = mousey + (current_cursor->height * 0.25); int xstart = mousex - Get_Hotspot_X(); int ystart = _my - Get_Hotspot_Y(); diff --git a/code/REDALERT/WINSTUB.CPP b/code/REDALERT/WINSTUB.CPP index e8ee53e..af30ba5 100644 --- a/code/REDALERT/WINSTUB.CPP +++ b/code/REDALERT/WINSTUB.CPP @@ -823,7 +823,7 @@ void __cdecl SetPalette(unsigned char *palette, long, unsigned long) } -void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { +void WWSDL_ProcessEvents(KeyNumType& key, int& flags, bool presentBuffer) { static int numFramesLMouse = 0; extern int mousex, mousey; bool leftMouseProcessed = false; @@ -910,7 +910,9 @@ void WWSDL_ProcessEvents(KeyNumType& key, int& flags) { flags = GadgetClass::LEFTHELD; } - Device_Present(); + if (presentBuffer) { + Device_Present(); + } }