Fix windows compilation.

This commit is contained in:
jmsgrogan 2022-11-30 20:53:17 +00:00
parent b45385e8c7
commit b17ba8b3a7
23 changed files with 85 additions and 53 deletions

View file

@ -31,7 +31,7 @@ void initializeCommandLineArgs(CommandLineArgs* args)
}
LocalFree(szArglist);
args->Process(windowsArgs);
args->process(windowsArgs);
}
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine, int nCmdShow)
@ -39,9 +39,9 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
std::ofstream out("out.txt");
std::cout.rdbuf(out.rdbuf());
auto args = CommandLineArgs::CreateUnique();
auto args = CommandLineArgs::Create();
initializeCommandLineArgs(args.get());
args->RecordLaunchPath();
args->recordLaunchPath();
// Start the main app
auto main_app = MainApplication::Create();
@ -50,18 +50,18 @@ int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, PWSTR pCmdLine
applicationContext->hInstance = reinterpret_cast<void*>(hInstance);
applicationContext->nCmdShow = nCmdShow;
main_app->Initialize(std::move(args), std::move(applicationContext));
main_app->initialize(std::move(args), std::move(applicationContext));
MLOG_INFO("Creating GUI Application");
// Start the gui application
auto gui_app = GuiApplication();
gui_app.SetMainApplication(main_app);
//gui_app.setMainApplication(main_app);
MLOG_INFO("Running GUI Application");
gui_app.Run();
gui_app.run();
main_app->ShutDown();
main_app->shutDown();
return 0;
}

View file

@ -48,7 +48,7 @@ void Lz77Encoder::populateSearchBuffer(const Hit& hit)
int difference = int(length) - distance;
if (difference > 0)
{
for(unsigned idx=0; idx<difference; idx++)
for(unsigned idx=0; idx<unsigned(difference); idx++)
{
mSearchBuffer.addItem(mLookaheadBuffer.getItem(idx));
}
@ -64,7 +64,7 @@ unsigned char Lz77Encoder::getSearchBufferItem(unsigned index) const
unsigned Lz77Encoder::lookAheadForMatchingChars(unsigned distance)
{
unsigned length{0};
for(unsigned idx=0; idx<mMaxLookAheadBufferIndex + 1; idx++)
for(unsigned idx=0; idx<unsigned(mMaxLookAheadBufferIndex + 1); idx++)
{
int search_offset = int(distance-1) - idx;
unsigned char search_char{0};
@ -112,7 +112,7 @@ bool Lz77Encoder::lookAheadSourceEmpty() const
return true;
}
if (mMaxLookAheadBufferIndex < mLookAheadBufferSize - 1)
if (mMaxLookAheadBufferIndex < int(mLookAheadBufferSize) - 1)
{
return true;
}

View file

@ -57,7 +57,7 @@ void ZlibEncoder::parseCompressionMethod(unsigned char method)
if (mCompressionMethod == CompressionMethod::DEFLATE)
{
mWindowSize = pow(2, compression_info + 8);
mWindowSize = static_cast<unsigned>(pow(2, compression_info + 8));
}
}

View file

@ -25,7 +25,6 @@ bool DeflateEncoder::encode()
std::unique_ptr<DeflateBlock> working_block = std::make_unique<DeflateBlock>(&stream, mOutputStream);
working_block->setCompressionMethod(mCompressionMethod);
AbstractChecksumCalculator* checksum_calc;
if (mChecksumCalculators.size() > 0)
{
//std::cout << "Setting checksum calculator " << std::endl;

View file

@ -120,7 +120,7 @@ void HuffmanStream::readCodeLengths()
mInputStream->readNextNBits(2, num_reps);
//std::cout << "Got val 16 doing " << 3 + num_reps << std::endl;
for(unsigned idx=0; idx< 3 + num_reps; idx++)
for(unsigned char idx=0; idx< 3 + num_reps; idx++)
{
addValue(last_value, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
}
@ -131,7 +131,7 @@ void HuffmanStream::readCodeLengths()
mInputStream->readNextNBits(3, num_reps);
//std::cout << "Got val 17 doing " << 3 + num_reps << std::endl;
for(unsigned idx=0; idx< 3 + num_reps; idx++)
for(unsigned char idx=0; idx< 3 + num_reps; idx++)
{
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
}
@ -142,7 +142,7 @@ void HuffmanStream::readCodeLengths()
mInputStream->readNextNBits(7, num_reps);
//std::cout << "Got val 18 doing " << 11 + num_reps << std::endl;
for(unsigned idx=0; idx< 11 + num_reps; idx++)
for(unsigned idx=0; idx< 11 + unsigned(num_reps); idx++)
{
addValue(0, count, last_value, literal_lengths, mNumLiterals, distance_lengths);
}
@ -172,7 +172,7 @@ void HuffmanStream::readCodeLengths()
void HuffmanStream::copyFromBuffer(unsigned length, unsigned distance)
{
unsigned offset = mBuffer.size() - 1 - distance;
std::size_t offset = mBuffer.size() - 1 - distance;
for(unsigned idx=0; idx<length; idx++)
{
auto symbol = mBuffer[offset + idx];
@ -327,7 +327,7 @@ void HuffmanStream::readCodingsTable()
unsigned char h_clen{0};
mInputStream->readNextNBits(4, h_clen);
auto num_code_lengths = h_clen + 4;
unsigned num_code_lengths = h_clen + 4;
//std::cout << "Got HCLEN " << num_code_lengths << std::endl;
auto sequence = std::vector<unsigned char>(num_code_lengths, 0);

View file

@ -18,7 +18,7 @@ ByteUtils::Word ByteUtils::GetWordLastByte(const Word word)
unsigned char ByteUtils::getHigherNBits(unsigned char input, unsigned num)
{
return input >> 8 - num;
return input >> (8 - num);
}
unsigned char ByteUtils::getByteN(uint32_t input, unsigned n)

View file

@ -78,7 +78,7 @@ void BitStream::writeNBits(uint32_t data, unsigned length)
writeByte(mCurrentByte, false);
auto num_bytes = overshoot / 8;
unsigned num_bytes = overshoot / 8;
for (unsigned idx=0; idx< num_bytes; idx++)
{
mCurrentByte = ByteUtils::getMBitsAtN(data, overshoot, idx*8 + num_left);

View file

@ -3,6 +3,7 @@
#include "BitStream.h"
#include <vector>
#include <iterator>
class BufferBitStream : public BitStream
{

View file

@ -20,7 +20,7 @@ list(APPEND graphics_HEADERS
RasterPainter.h
PainterFactory.h
)
if(UNIX)
set(OpenGL_GL_PREFERENCE "GLVND")
find_package(OpenGL QUIET)
if (OpenGL_FOUND)
@ -42,6 +42,7 @@ if (OpenGL_FOUND)
else()
message(STATUS "OpenGL not found - skipping support")
endif()
endif()
add_library(${MODULE_NAME} SHARED
${graphics_LIB_INCLUDES}

View file

@ -120,9 +120,9 @@ void PngWriter::writeDataChunks(const BufferBitStream& buffer)
auto num_bytes = buffer.getBuffer().size();
auto max_bytes{32000};
unsigned num_dat_chunks = num_bytes/max_bytes + 1;
auto num_dat_chunks = num_bytes/max_bytes + 1;
unsigned offset = 0;
for(unsigned idx=0;idx<num_dat_chunks;idx++)
for(std::size_t idx=0;idx<num_dat_chunks;idx++)
{
auto length = max_bytes;
if (idx == num_dat_chunks - 1)

View file

@ -60,7 +60,7 @@ public:
unsigned getNumNodes() const
{
return mNodes.size();
return unsigned(mNodes.size());
}
protected:

View file

@ -2,6 +2,7 @@
#include "MeshBuilder.h"
#define _USE_MATH_DEFINES
#include <math.h>
#include <iostream>

View file

@ -49,6 +49,11 @@ void NetworkManager::RunHttpClient()
Initialize();
}
if (!mSocketInterface)
{
return;
}
auto socket = Socket::Create();
mSocketInterface->InitializeSocket(socket, "127.0.0.1");
mSocketInterface->Write(socket, "Hello Friend");

View file

@ -40,7 +40,7 @@ void TextBox::appendContent(const std::string& text)
bool TextBox::onMyKeyboardEvent(const KeyboardEvent* event)
{
if(!event or !mVisible) return false;
if(!event || !mVisible) return false;
if(event->isFunctionKey())
{

View file

@ -82,7 +82,9 @@ target_include_directories(windows PUBLIC
)
target_compile_definitions(${MODULE_NAME} PRIVATE ${DEFINES})
if(UNIX)
target_compile_options(${MODULE_NAME} PRIVATE -Wno-attributes) # From xdg shell autogen code
endif()
target_link_libraries(${MODULE_NAME} PUBLIC ${platform_LIBS} core geometry graphics ui_elements)
set_property(TARGET ${MODULE_NAME} PROPERTY FOLDER src)

View file

@ -44,6 +44,6 @@ std::unique_ptr<AbstractUIInterface> UiInterfaceFactory::create(DesktopManager*
#endif
}
#else
return std::make_unique<Win32UiInterface>();
return std::make_unique<Win32UIInterface>(desktopManager, std::move(fonts_manager));
#endif
}

View file

@ -2,18 +2,19 @@
#include <Windows.h>
Win32UIInterface::Win32UIInterface()
: mWindowInterface(std::make_unique<Win32WindowInterface>())
Win32UIInterface::Win32UIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware)
: AbstractUIInterface(desktopManager, std::move(fontsManager), useHardware),
mWindowInterface(std::make_unique<Win32WindowInterface>())
{
}
void Win32UIInterface::Initialize(DesktopManager* desktopManager)
void Win32UIInterface::initialize()
{
}
void Win32UIInterface::Loop(DesktopManager* desktopManager)
void Win32UIInterface::loop()
{
// Run the message loop.
MSG msg = { };
@ -24,17 +25,17 @@ void Win32UIInterface::Loop(DesktopManager* desktopManager)
}
}
void Win32UIInterface::ShutDown()
void Win32UIInterface::shutDown()
{
}
void Win32UIInterface::ShowWindow(mt::Window* window)
void Win32UIInterface::showWindow(mt::Window* window)
{
mWindowInterface->Show(window);
}
void Win32UIInterface::AddWindow(mt::Window* window, DesktopManager* desktopManager)
void Win32UIInterface::addWindow(mt::Window* window)
{
mWindowInterface->Add(window, desktopManager);
mWindowInterface->Add(window, mDesktopManager);
}

View file

@ -3,25 +3,26 @@
#include "Window.h"
#include "Win32WindowInterface.h"
#include "AbstractUiInterface.h"
class DesktopManager;
class Win32UIInterface
class Win32UIInterface : public AbstractUIInterface
{
public:
Win32UIInterface();
Win32UIInterface(DesktopManager* desktopManager, std::unique_ptr<FontsManager> fontsManager, bool useHardware = false);
~Win32UIInterface() = default;
void Initialize(DesktopManager* desktopManager);
void initialize() override;
void Loop(DesktopManager* desktopManager);
void loop() override;
void ShutDown();
void shutDown() override;
void ShowWindow(mt::Window* window);
void showWindow(mt::Window* window) override;
void AddWindow(mt::Window* window, DesktopManager* desktopManager);
void addWindow(mt::Window* window) override;
private:

View file

@ -11,14 +11,15 @@
LRESULT CALLBACK FreeWindowProc(HWND hwnd, UINT uMsg, WPARAM wParam, LPARAM lParam);
Win32Window::Win32Window()
Win32Window::Win32Window(mt::Window* window)
: IPlatformWindow(window)
{
}
std::unique_ptr<Win32Window> Win32Window::Create()
std::unique_ptr<Win32Window> Win32Window::Create(mt::Window* window)
{
return std::make_unique<Win32Window>();
return std::make_unique<Win32Window>(window);
}
HWND Win32Window::GetHandle() const
@ -85,11 +86,11 @@ LRESULT CALLBACK Win32Window::WindowProc(UINT message, WPARAM wParam, LPARAM lPa
case WM_CHAR:
{
auto key_event = std::make_unique<KeyboardEvent>();
key_event->SetAction(KeyboardEvent::Action::Pressed);
key_event->setAction(KeyboardEvent::Action::Pressed);
auto keyChar = (wchar_t)wParam;
key_event->SetKeyString(StringUtils::convert(std::wstring(1, keyChar)));
mDesktopManager->OnUiEvent(std::move(key_event));
key_event->setKeyString(StringUtils::convert(std::wstring(1, keyChar)));
mDesktopManager->onUiEvent(std::move(key_event));
}
case WM_PAINT:

View file

@ -9,10 +9,10 @@ class DesktopManager;
class Win32Window : public IPlatformWindow
{
public:
Win32Window();
Win32Window(mt::Window* window);
virtual ~Win32Window() = default;
static std::unique_ptr<Win32Window> Create();
static std::unique_ptr<Win32Window> Create(mt::Window* window);
LRESULT WindowProc(UINT message, WPARAM wParam, LPARAM lParam);
@ -35,6 +35,24 @@ public:
void CreateNative(Win32ApplicationContext* context, DesktopManager* desktopManager);
void show() {};
void map() {};
void clear() {};
void onResize(unsigned width, unsigned height) {};
void beforePaint(mt::Screen* screen)
{
}
void afterPaint(mt::Screen* screen)
{
}
private:
HWND mHandle{ 0 };
int mCmdShow{ 0 };

View file

@ -5,6 +5,7 @@
#include <Windows.h>
#include "DesktopManager.h"
#include "DrawingContext.h"
#include "FileLogger.h"
@ -15,18 +16,18 @@ Win32WindowInterface::Win32WindowInterface()
void Win32WindowInterface::Show(mt::Window* window)
{
auto platformWindow = dynamic_cast<Win32Window*>(window->GetPlatformWindow());
auto platformWindow = dynamic_cast<Win32Window*>(window->getPlatformWindow());
MLOG_INFO("Showing platform window: " << platformWindow->GetHandle());
::ShowWindow(platformWindow->GetHandle(), platformWindow->GetCmdShow());
}
void Win32WindowInterface::Add(mt::Window* window, DesktopManager* desktopManager)
{
auto context = dynamic_cast<Win32ApplicationContext*>(desktopManager->GetMainApp()->GetApplicationContext());
auto context = dynamic_cast<Win32ApplicationContext*>(desktopManager->getMainApp()->GetApplicationContext());
auto win32_window = Win32Window::Create();
auto win32_window = Win32Window::Create(window);
win32_window->CreateNative(context, desktopManager);
win32_window->SetCmdShow(context->nCmdShow);
window->SetPlatformWindow(std::move(win32_window));
window->setPlatformWindow(std::move(win32_window), nullptr, DrawingMode::GRAPH);
}

View file

@ -8,6 +8,7 @@
#include <memory>
class DesktopManager;
class FontsManager;
class Win32ApplicationContext : public IApplicationContext
{

View file

@ -1,4 +1,4 @@
add_library(test_utils SHARED
add_library(test_utils STATIC
TestCase.h
TestCaseRunner.cpp
)