Skip to content

Commit

Permalink
add an option and some parameters for simple block style caret (#12, #31
Browse files Browse the repository at this point in the history
)
  • Loading branch information
pit-ray committed Aug 24, 2021
1 parent 2c74004 commit 7667661
Show file tree
Hide file tree
Showing 18 changed files with 358 additions and 158 deletions.
22 changes: 0 additions & 22 deletions core/include/io/display_text_painter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,31 +13,9 @@ namespace vind
struct Impl ;
std::unique_ptr<Impl> pimpl ;

static void delete_hdc(HDC h) noexcept {
if(h != nullptr) DeleteDC(h) ;
}
static void delete_obj(HGDIOBJ f) noexcept {
if(f != nullptr) DeleteObject(f) ;
}

using HDCSPtr = std::shared_ptr<HDC__> ;
using HDCUPtr = std::unique_ptr<HDC__, decltype(&delete_hdc)> ;
using HBitmapUPtr = std::unique_ptr<HBITMAP__, decltype(&delete_obj)> ;
using HFontUPtr = std::unique_ptr<HFONT__, decltype(&delete_obj)> ;

static HDCUPtr create_display_dc() ;

static void set_dc_text_color(HDCSPtr& hdc, const COLORREF& color) ;
static void set_dc_back_color(HDCSPtr& hdc, const COLORREF& color) ;

void initialize_dc(bool enable_double_buffering) ;
void copy(const DisplayTextPainter& rhs) ;

static HFontUPtr create_font(const LOGFONTA& logfont) ;

static void select_obj(HDCSPtr& hdc, const HBitmapUPtr& bitmap) ;
static void select_obj(HDCSPtr& hdc, const HFontUPtr& font) ;

public:
explicit DisplayTextPainter(
LONG font_size,
Expand Down
5 changes: 5 additions & 0 deletions core/include/opt/blockstyle_caret.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#include "option_creator.hpp"


namespace vind
{
class BlockStyleCaret : public OptionCreator<BlockStyleCaret>
Expand All @@ -25,6 +26,10 @@ namespace vind

BlockStyleCaret(const BlockStyleCaret&) = delete ;
BlockStyleCaret& operator=(const BlockStyleCaret&) = delete ;

void restore_caret_style(const std::string& mode) const ;

void make_caret_block_style(const std::string& mode) const ;
} ;
}

Expand Down
4 changes: 2 additions & 2 deletions core/include/util/box_2d.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@ namespace vind
bool is_not_same(const Box2D& rhs) const noexcept ;

bool is_bigger_than(const Box2D& rhs) const noexcept ;
bool is_bigger_equel(const Box2D& rhs) const noexcept ;
bool is_bigger_equal(const Box2D& rhs) const noexcept ;

bool is_smaller_than(const Box2D& rhs) const noexcept ;
bool is_smaller_equel(const Box2D& rhs) const noexcept ;
bool is_smaller_equal(const Box2D& rhs) const noexcept ;

// Area-based comparison
//
Expand Down
2 changes: 1 addition & 1 deletion core/include/util/rect.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ namespace vind
(target.bottom <= range.bottom && target.bottom >= range.top) ;
}

inline auto is_equel(const RECT& lhs, const RECT& rhs) noexcept {
inline auto is_equal(const RECT& lhs, const RECT& rhs) noexcept {
return lhs.left == rhs.left && \
lhs.top == rhs.top && \
lhs.right == rhs.right && \
Expand Down
38 changes: 38 additions & 0 deletions core/include/util/winwrap.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@

#include <windows.h>

#include <memory>
#include <string>

#include "def.hpp"
#include "point_2d.hpp"
#include "string.hpp"

#if defined(DEBUG)
Expand Down Expand Up @@ -70,6 +72,42 @@ namespace vind
}

bool is_failed(HRESULT result) noexcept ;


inline void delete_hdc(HDC h) noexcept {
if(h != nullptr) {
DeleteDC(h) ;
}
}
inline void delete_obj(HGDIOBJ f) noexcept {
if(f != nullptr) {
DeleteObject(f) ;
}
}

using HDCSPtr = std::shared_ptr<HDC__> ;
using HDCUPtr = std::unique_ptr<HDC__, decltype(&delete_hdc)> ;
using HBitmapUPtr = std::unique_ptr<HBITMAP__, decltype(&delete_obj)> ;
using HFontUPtr = std::unique_ptr<HFONT__, decltype(&delete_obj)> ;

HDCUPtr create_display_dc() ;

void set_dc_text_color(HDCSPtr& hdc, const COLORREF& color) ;
void set_dc_back_color(HDCSPtr& hdc, const COLORREF& color) ;

HFontUPtr create_font(const LOGFONTA& logfont) ;

template <typename SmartPtr>
inline void select_obj(HDCSPtr& hdc, const SmartPtr& obj) {
if(!SelectObject(hdc.get(), obj.get())) {
throw RUNTIME_EXCEPT("The device context could not select an object.") ;
}
}

void attach_thread_input(HWND hwnd) ;
void detach_thread_input(HWND hwnd) ;

Point2D get_caret_pos(HWND hwnd) ;
}
}

Expand Down
5 changes: 3 additions & 2 deletions core/src/bind/easyclick/easy_click_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,9 @@ namespace vind
util::refresh_display(NULL) ;

if(auto pos = ft.get()) {
SetCursorPos(pos->x(), pos->y()) ;
mouse::click(sendkey) ;
if(SetCursorPos(pos->x(), pos->y())) {
mouse::click(sendkey) ;
}
}

//Release all keys in order to avoid the next matching right after.
Expand Down
2 changes: 1 addition & 1 deletion core/src/bind/window/min_max_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ namespace vind
}

//If not changed, regard it as a full screen and deal with it.
if(util::is_equel(before_rect, after_rect)) {
if(util::is_equal(before_rect, after_rect)) {
keybrd::pushup(KEYCODE_LWIN, KEYCODE_DOWN) ;
keybrd::pushup(KEYCODE_LWIN, KEYCODE_UP) ;
}
Expand Down
2 changes: 1 addition & 1 deletion core/src/bind/window/window_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ namespace vind
if(!GetClientRect(hwnd, &client_rect)) {
return false ;
}
if(util::is_equel(rect, client_rect)) {
if(util::is_equal(rect, client_rect)) {
return false ;
}

Expand Down
86 changes: 21 additions & 65 deletions core/src/io/display_text_painter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,35 +5,36 @@
#include "util/def.hpp"
#include "util/rect.hpp"
#include "util/rect.hpp"
#include "util/winwrap.hpp"

#include <cstring>
#include <memory>

namespace vind
{
struct DisplayTextPainter::Impl {
HDCSPtr hdc ; //device context for actual use
util::HDCSPtr hdc ; //device context for actual use

HDCSPtr display_dc ;
HDCSPtr compatible_dc ;
util::HDCSPtr display_dc ;
util::HDCSPtr compatible_dc ;

HBitmapUPtr compatible_bitmap ;
util::HBitmapUPtr compatible_bitmap ;

COLORREF fg_color ;
COLORREF bg_color ;

LOGFONTA logfont ; //infomation struct for creation of font
HFontUPtr hfont ; //font handle
util::HFontUPtr hfont ; //font handle

explicit Impl()
: hdc(nullptr, delete_hdc),
display_dc(nullptr, delete_hdc),
compatible_dc(nullptr, delete_hdc),
compatible_bitmap(nullptr, delete_obj),
: hdc(nullptr, util::delete_hdc),
display_dc(nullptr, util::delete_hdc),
compatible_dc(nullptr, util::delete_hdc),
compatible_bitmap(nullptr, util::delete_obj),
fg_color(RGB(0, 0, 0)),
bg_color(RGB(0, 0, 0)),
logfont(),
hfont(nullptr, delete_obj)
hfont(nullptr, util::delete_obj)
{
logfont.lfHeight = 0 ;
logfont.lfWidth = 0 ;
Expand Down Expand Up @@ -65,7 +66,7 @@ namespace vind
} ;

void DisplayTextPainter::initialize_dc(bool enable_double_buffering) {
pimpl->display_dc = create_display_dc() ;
pimpl->display_dc = util::create_display_dc() ;

if(enable_double_buffering) {
auto box = screenmetrics::get_conbined_metrics() ;
Expand All @@ -85,7 +86,7 @@ namespace vind
}
pimpl->compatible_dc.reset(raw_compatible_dc) ;

select_obj(pimpl->compatible_dc, pimpl->compatible_bitmap) ;
util::select_obj(pimpl->compatible_dc, pimpl->compatible_bitmap) ;

if(!BitBlt(pimpl->compatible_dc.get(), 0, 0,
width, height,
Expand Down Expand Up @@ -118,11 +119,11 @@ namespace vind

initialize_dc(rhs.pimpl->compatible_dc != nullptr) ;

pimpl->hfont = create_font(rhs.pimpl->logfont) ;
select_obj(pimpl->hdc, pimpl->hfont) ;
pimpl->hfont = util::create_font(rhs.pimpl->logfont) ;
util::select_obj(pimpl->hdc, pimpl->hfont) ;

set_dc_text_color(pimpl->hdc, rhs.pimpl->fg_color) ;
set_dc_back_color(pimpl->hdc, rhs.pimpl->bg_color) ;
util::set_dc_text_color(pimpl->hdc, rhs.pimpl->fg_color) ;
util::set_dc_back_color(pimpl->hdc, rhs.pimpl->bg_color) ;
}

DisplayTextPainter::~DisplayTextPainter() noexcept = default ;
Expand Down Expand Up @@ -164,14 +165,14 @@ namespace vind
}
}

pimpl->hfont = create_font(pimpl->logfont) ;
select_obj(pimpl->hdc, pimpl->hfont) ;
pimpl->hfont = util::create_font(pimpl->logfont) ;
util::select_obj(pimpl->hdc, pimpl->hfont) ;
}

//foreground color
void DisplayTextPainter::set_text_color(COLORREF color) {
pimpl->fg_color = std::move(color) ;
set_dc_text_color(pimpl->hdc, pimpl->fg_color) ;
util::set_dc_text_color(pimpl->hdc, pimpl->fg_color) ;
}
void DisplayTextPainter::set_text_color(
unsigned char r,
Expand All @@ -186,7 +187,7 @@ namespace vind
//background color
void DisplayTextPainter::set_back_color(COLORREF color) {
pimpl->bg_color = std::move(color) ;
set_dc_back_color(pimpl->hdc, pimpl->bg_color) ;
util::set_dc_back_color(pimpl->hdc, pimpl->bg_color) ;
}
void DisplayTextPainter::set_back_color(
unsigned char r,
Expand Down Expand Up @@ -222,49 +223,4 @@ namespace vind
draw("", 0, 0, 0) ;
}
}

//static utility functions
DisplayTextPainter::HDCUPtr DisplayTextPainter::create_display_dc() {
auto raw_hdc = CreateDCA("DISPLAY", NULL, NULL, NULL) ;
if(!raw_hdc) {
throw RUNTIME_EXCEPT("Could not create HDC of DISPLAY.") ;
}
return HDCUPtr(raw_hdc, delete_hdc) ;
}

void DisplayTextPainter::set_dc_text_color(
std::shared_ptr<HDC__>& hdc,
const COLORREF& color) {
if(SetTextColor(hdc.get(), color) == CLR_INVALID) {
throw RUNTIME_EXCEPT("Could not set a text color.") ;
}
}

void DisplayTextPainter::set_dc_back_color(
std::shared_ptr<HDC__>& hdc,
const COLORREF& color) {
if(SetBkColor(hdc.get(), color) == CLR_INVALID) {
throw RUNTIME_EXCEPT("Could not set a background color.") ;
}
}

DisplayTextPainter::HFontUPtr DisplayTextPainter::create_font(const LOGFONTA& logfont) {
auto raw_font = CreateFontIndirectA(&logfont) ;
if(!raw_font) {
throw RUNTIME_EXCEPT("Could not create a font.") ;
}
return HFontUPtr(raw_font, delete_obj) ;
}

void DisplayTextPainter::select_obj(HDCSPtr& hdc, const HBitmapUPtr& bitmap) {
if(!SelectObject(hdc.get(), bitmap.get())) {
throw RUNTIME_EXCEPT("The device context could not select a bitmap object.") ;
}
}

void DisplayTextPainter::select_obj(HDCSPtr& hdc, const HFontUPtr& font) {
if(!SelectObject(hdc.get(), font.get())) {
throw RUNTIME_EXCEPT("The device context could not select a font object.") ;
}
}
}
4 changes: 2 additions & 2 deletions core/src/key/key_log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ namespace vind
return pimpl->log_.find(key) != pimpl->log_.end() ;
}

//equel
//equal
bool KeyLog::operator==(const KeyLog& rhs) const {
if(!(rhs.pimpl)) return false ;
return pimpl->log_ == rhs.pimpl->log_ ;
Expand All @@ -129,7 +129,7 @@ namespace vind
return pimpl->log_ == rhs ;
}

//not equel
//not equal
bool KeyLog::operator!=(const KeyLog& rhs) const {
if(!(rhs.pimpl)) return false ; //moved
return pimpl->log_ != rhs.pimpl->log_ ;
Expand Down
2 changes: 1 addition & 1 deletion core/src/opt/autotrack_popup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ namespace
vind::util::system_parameters_info(
SPI_SETSNAPTODEFBUTTON,
val, 0,
SPIF_SENDCHANGE) ;
SPIF_UPDATEINIFILE | SPIF_SENDCHANGE) ;
}
}

Expand Down

0 comments on commit 7667661

Please sign in to comment.