Skip to content

Commit

Permalink
Merge branch 'for-referctering'
Browse files Browse the repository at this point in the history
  • Loading branch information
pit-ray committed Feb 21, 2021
2 parents dea7e13 + 827de79 commit f573de3
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 318 deletions.
4 changes: 2 additions & 2 deletions core/include/gui_bindings/window_ctrl.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

namespace WindowCtrl
{
bool is_valid_hwnd(HWND hwnd) ;
bool is_valid_rect(HWND hwnd, RECT& rect) ;
bool is_visible_hwnd(HWND hwnd) ;
bool is_window_mode(HWND hwnd, RECT& rect) ;
}

struct OpenNewCurrentWindow : public BindedFuncWithCreator<OpenNewCurrentWindow>
Expand Down
27 changes: 13 additions & 14 deletions core/include/screen_metrics.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ namespace ScreenMetrics {
lhs.bottom == rhs.bottom ;
}

inline auto is_bigger_tran(const RECT& lhs, const RECT& rhs) noexcept {
inline auto is_bigger_than(const RECT& lhs, const RECT& rhs) noexcept {
return lhs.left <= rhs.left && lhs.top <= rhs.top &&
lhs.right >= rhs.right && lhs.bottom >= rhs.bottom ;
}
Expand All @@ -103,22 +103,21 @@ namespace ScreenMetrics {
copy(*rect, minfo.rcMonitor) ;
}

inline void get_monitor_metrics(HWND hwnd, RECT* const rect, RECT* const work_rect=NULL, HMONITOR* monitor=NULL) {
const auto hmonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST) ;
MONITORINFO minfo ;
minfo.cbSize = sizeof(MONITORINFO) ;
if(!GetMonitorInfo(hmonitor, &minfo)) {
struct MonitorInfo {
RECT rect = {0, 0, 0, 0} ;
RECT work_rect = {0, 0, 0, 0} ;
HMONITOR hmonitor = NULL ;
} ;
inline void get_monitor_metrics(HWND hwnd, MonitorInfo& minfo) {
minfo.hmonitor = MonitorFromWindow(hwnd, MONITOR_DEFAULTTONEAREST) ;
MONITORINFO native_minfo ;
native_minfo.cbSize = sizeof(MONITORINFO) ;
if(!GetMonitorInfo(minfo.hmonitor, &native_minfo)) {
throw RUNTIME_EXCEPT("Could not get monitor infomation.") ;
}

copy(*rect, minfo.rcMonitor) ;

if(work_rect != NULL) {
copy(*work_rect, minfo.rcWork) ;
}
if(monitor != NULL) {
*monitor = hmonitor ;
}
copy(minfo.rect, native_minfo.rcMonitor) ;
copy(minfo.work_rect, native_minfo.rcWork) ;
}

namespace Debug {
Expand Down
43 changes: 27 additions & 16 deletions core/src/gui_bindings/easy_click.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,15 @@ namespace EsyClk
}
} ;

static std::vector<Point2D> g_objpos ;
static std::vector<Point2D> g_obj_points ;

inline static auto& get_cache_req() {
static auto g_cache_req = UIA::make_SmartCacheReq(nullptr) ;
return g_cache_req ;
}

void initialize() {
g_objpos.reserve(2048) ;
g_obj_points.reserve(2048) ;

decltype(auto) cuia = UIA::get_global_cuia() ;

Expand Down Expand Up @@ -136,7 +136,7 @@ namespace EsyClk
if(LONG* ppvdata ; SUCCEEDED(SafeArrayAccessData(val.parray,
reinterpret_cast<void**>(&ppvdata)))) {

g_objpos.emplace_back(ppvdata[0], ppvdata[1]) ;
g_obj_points.emplace_back(ppvdata[0], ppvdata[1]) ;
SafeArrayUnaccessData(val.parray) ;
}
}
Expand All @@ -149,6 +149,7 @@ namespace EsyClk
UIA::SmartElement& elem,
const RECT& window_rect,
const BOOL parent_is_focasuable=FALSE) {

if(!parent_is_focasuable) {
BOOL flag ;
if(FAILED(elem->get_CachedIsKeyboardFocusable(&flag))) {
Expand All @@ -159,6 +160,7 @@ namespace EsyClk
return ;
}
}

RECT rect ;
if(FAILED(elem->get_CachedBoundingRectangle(&rect))) {
return ;
Expand All @@ -168,7 +170,7 @@ namespace EsyClk
return ;
}

g_objpos.emplace_back(
g_obj_points.emplace_back(
rect.left + (rect.right - rect.left) / 2,
rect.top + (rect.bottom - rect.top) / 2) ;
}
Expand Down Expand Up @@ -283,7 +285,7 @@ namespace EsyClk
return TRUE ;
}

g_objpos.emplace_back(
g_obj_points.emplace_back(
rect.left + (rect.right - rect.left) / 2,
rect.top + (rect.bottom - rect.top) / 2) ;
return TRUE ;
Expand Down Expand Up @@ -317,10 +319,10 @@ namespace EsyClk

EnumWindows(EnumWindowsProc, static_cast<LPARAM>(procid)) ;

Utility::remove_deplication(EsyClk::g_objpos) ;
Utility::remove_deplication(EsyClk::g_obj_points) ;
}

static HWND g_prehwnd = nullptr ;
static HWND g_prehwnd = NULL ;
static RECT g_prerect = {0, 0, 0, 0} ;

inline static bool need_update(HWND hwnd) {
Expand Down Expand Up @@ -476,6 +478,7 @@ namespace EsyClk
const std::vector<unsigned char>& matched_list,
const bool exist) {

//Handles
auto delete_hdc = [] (HDC h) {
if(h != nullptr) DeleteDC(h) ;
} ;
Expand All @@ -496,6 +499,7 @@ namespace EsyClk
throw RUNTIME_EXCEPT("SelectObject") ;
}

//Colors
auto [bk_r, bk_g, bk_b] = Utility::hex2rgb(iParams::get_s("easy_click_font_bkcolor")) ;
auto bkcolor = RGB(bk_r, bk_g, bk_b) ;

Expand All @@ -522,6 +526,7 @@ namespace EsyClk
throw RUNTIME_EXCEPT("SetTextColor") ;
}

//Drawing
auto draw = [&hdc, &delta] (auto&& str, auto&& point) {
if(SetTextCharacterExtra(hdc.get(), 1) == static_cast<int>(0x80000000)) {
throw RUNTIME_EXCEPT("SetTextCharacterExtra") ;
Expand Down Expand Up @@ -554,13 +559,17 @@ namespace EsyClk
throw RUNTIME_EXCEPT("SetTextColor") ;
}

//overdraw with the weak text color.
for(std::size_t i = 0 ; i < hints_str.size() ; i ++) {
if(matched_list[i] == 0) continue ;
draw(" " + hints_str[i].substr(0, matched_list[i]), points[i]) ;
}
}
}

// [Return value]
// >= 0 : matched something
// < 0 : matched nothing
inline static long match_with_hints(
const KeyLogger& lgr,
const std::vector<hint_t>& hints,
Expand Down Expand Up @@ -619,6 +628,8 @@ namespace EsyClk
static constexpr auto DRAW_INTERVAL_TIME = 600ms ;

while(win_vind::update_background()) {

// The drawing process is very heavy, so draw in the interval.
if(system_clock::now() - drawn_point > DRAW_INTERVAL_TIME) {
EsyClk::draw_identifiers(points, hints_str, matched_num_list, at_least_exist) ;
drawn_point = system_clock::now() ;
Expand Down Expand Up @@ -650,7 +661,7 @@ namespace EsyClk
}
remove_from_back(lgr, 2) ;
KeyAbsorber::release_virtually(VKC_BKSPACE) ;
match_with_hints(lgr, hints, matched_num_list, at_least_exist) ;
match_with_hints(lgr, hints, matched_num_list, at_least_exist) ; //update matching list
continue ;
}

Expand All @@ -660,7 +671,7 @@ namespace EsyClk
}


long full_match_idx = match_with_hints(lgr, hints, matched_num_list, at_least_exist) ;
const auto full_match_idx = match_with_hints(lgr, hints, matched_num_list, at_least_exist) ;
if(full_match_idx >= 0) {
SetCursorPos(points[full_match_idx].x(), points[full_match_idx].y()) ;
if(sendkey != VKC_UNDEFINED) {
Expand All @@ -685,18 +696,19 @@ namespace EsyClk

inline static void common_process(const unsigned char sendkey) {
if(need_update(GetForegroundWindow())) {
g_objpos.clear() ;
g_obj_points.clear() ;
scan_gui_objects() ;

g_hints = assign_identifiers_label(g_objpos.size()) ;
g_hints = assign_identifiers_label(g_obj_points.size()) ;
g_hints_str = convert_hints_to_str(g_hints) ;
}

if(!g_objpos.empty()) {
if(!g_obj_points.empty()) {
update_font() ;
loop_for_key_matching(g_objpos, g_hints, g_hints_str, sendkey) ;
loop_for_key_matching(g_obj_points, g_hints, g_hints_str, sendkey) ;
}

//release all keys
for(auto& key : KeyAbsorber::get_pressed_list()) {
KeyAbsorber::release_virtually(key) ;
}
Expand Down Expand Up @@ -782,11 +794,10 @@ void UpdateEasyClick::sprocess(
return ;
}


g_objpos.clear() ;
g_obj_points.clear() ;
scan_gui_objects() ;

g_hints = assign_identifiers_label(g_objpos.size()) ;
g_hints = assign_identifiers_label(g_obj_points.size()) ;
g_hints_str = convert_hints_to_str(g_hints) ;
}

Expand Down
Loading

0 comments on commit f573de3

Please sign in to comment.