diff --git a/DDrawCompat/DDrawCompat.vcxproj b/DDrawCompat/DDrawCompat.vcxproj index 3c72da4..d37c2af 100644 --- a/DDrawCompat/DDrawCompat.vcxproj +++ b/DDrawCompat/DDrawCompat.vcxproj @@ -273,6 +273,7 @@ + @@ -383,6 +384,7 @@ + diff --git a/DDrawCompat/DDrawCompat.vcxproj.filters b/DDrawCompat/DDrawCompat.vcxproj.filters index cdd92e1..a987fa1 100644 --- a/DDrawCompat/DDrawCompat.vcxproj.filters +++ b/DDrawCompat/DDrawCompat.vcxproj.filters @@ -567,6 +567,9 @@ Header Files\Config\Settings + + Header Files\Overlay + @@ -893,6 +896,9 @@ Source Files\Win32 + + Source Files\Overlay + diff --git a/DDrawCompat/Overlay/ButtonControl.cpp b/DDrawCompat/Overlay/ButtonControl.cpp new file mode 100644 index 0000000..f2ab0b8 --- /dev/null +++ b/DDrawCompat/Overlay/ButtonControl.cpp @@ -0,0 +1,48 @@ +#include +#include +#include + +namespace Overlay +{ + ButtonControl::ButtonControl(Control& parent, const RECT& rect, const std::string& label, ClickHandler clickHandler) + : Control(&parent, rect, WS_BORDER | WS_TABSTOP | WS_VISIBLE) + , m_clickHandler(clickHandler) + , m_label(*this, rect, label, DT_CENTER) + { + } + + void ButtonControl::onLButtonDown(POINT pos) + { + Input::setCapture(this); + onMouseMove(pos); + } + + void ButtonControl::onLButtonUp(POINT pos) + { + if (Input::getCapture() == this) + { + Input::setCapture(m_parent); + m_label.setColor(FOREGROUND_COLOR); + if (PtInRect(&m_rect, pos)) + { + m_clickHandler(*this); + } + else + { + m_parent->onMouseMove(pos); + } + } + } + + void ButtonControl::onMouseMove(POINT pos) + { + if (Input::getCapture() == this) + { + m_label.setColor(PtInRect(&m_rect, pos) ? HIGHLIGHT_COLOR : FOREGROUND_COLOR); + } + else + { + Control::onMouseMove(pos); + } + } +} diff --git a/DDrawCompat/Overlay/ButtonControl.h b/DDrawCompat/Overlay/ButtonControl.h new file mode 100644 index 0000000..6fad58d --- /dev/null +++ b/DDrawCompat/Overlay/ButtonControl.h @@ -0,0 +1,26 @@ +#pragma once + +#include + +#include + +#include + +namespace Overlay +{ + class ButtonControl : public Control + { + public: + typedef void (*ClickHandler)(Control&); + + ButtonControl(Control& parent, const RECT& rect, const std::string& label, ClickHandler clickHandler); + + virtual void onLButtonDown(POINT pos) override; + virtual void onLButtonUp(POINT pos) override; + virtual void onMouseMove(POINT pos) override; + + private: + ClickHandler m_clickHandler; + LabelControl m_label; + }; +} diff --git a/DDrawCompat/Overlay/ConfigWindow.cpp b/DDrawCompat/Overlay/ConfigWindow.cpp index 71cf70f..f296ca0 100644 --- a/DDrawCompat/Overlay/ConfigWindow.cpp +++ b/DDrawCompat/Overlay/ConfigWindow.cpp @@ -5,10 +5,20 @@ #include #include +namespace +{ + const int CAPTION_HEIGHT = 22; +} + namespace Overlay { ConfigWindow::ConfigWindow() - : Window(nullptr, { 0, 0, SettingControl::TOTAL_WIDTH, 300 }, Config::configHotKey.get()) + : Window(nullptr, { 0, 0, SettingControl::TOTAL_WIDTH, 330 }, Config::configHotKey.get()) + , m_caption(*this, { 0, 0, SettingControl::TOTAL_WIDTH - CAPTION_HEIGHT + 1, CAPTION_HEIGHT }, + "DDrawCompat Config Overlay", 0, WS_BORDER | WS_VISIBLE) + , m_closeButton(*this, + { SettingControl::TOTAL_WIDTH - CAPTION_HEIGHT, 0, SettingControl::TOTAL_WIDTH, CAPTION_HEIGHT }, + "X", onClose) , m_focus(nullptr) { addControl(Config::alternatePixelCenter); @@ -30,6 +40,7 @@ namespace Overlay const int rowHeight = 25; RECT rect = { 0, index * rowHeight + BORDER / 2, m_rect.right, (index + 1) * rowHeight + BORDER / 2 }; + OffsetRect(&rect, 0, m_caption.getRect().bottom); m_controls.emplace_back(*this, rect, setting); } @@ -41,6 +52,11 @@ namespace Overlay return r; } + void ConfigWindow::onClose(Control& control) + { + static_cast(control.getParent())->setVisible(false); + } + void ConfigWindow::setFocus(SettingControl* control) { if (m_focus == control) diff --git a/DDrawCompat/Overlay/ConfigWindow.h b/DDrawCompat/Overlay/ConfigWindow.h index 1990cf5..753fcfc 100644 --- a/DDrawCompat/Overlay/ConfigWindow.h +++ b/DDrawCompat/Overlay/ConfigWindow.h @@ -2,6 +2,8 @@ #include +#include +#include #include #include @@ -17,10 +19,14 @@ namespace Overlay void setFocus(SettingControl* control); private: + static void onClose(Control& control); + virtual RECT calculateRect(const RECT& monitorRect) const override; void addControl(Config::Setting& setting); + LabelControl m_caption; + ButtonControl m_closeButton; std::list m_controls; SettingControl* m_focus; }; diff --git a/DDrawCompat/Overlay/LabelControl.cpp b/DDrawCompat/Overlay/LabelControl.cpp index ede4f04..75c43b3 100644 --- a/DDrawCompat/Overlay/LabelControl.cpp +++ b/DDrawCompat/Overlay/LabelControl.cpp @@ -27,7 +27,10 @@ namespace Overlay void LabelControl::setColor(COLORREF color) { - m_color = color; - invalidate(); + if (m_color != color) + { + m_color = color; + invalidate(); + } } }