Skip to content

Commit

Permalink
refactor: draw candidate window with Direct2D
Browse files Browse the repository at this point in the history
  • Loading branch information
kanru committed Aug 26, 2024
1 parent b31b352 commit c35bcb9
Show file tree
Hide file tree
Showing 10 changed files with 626 additions and 449 deletions.
2 changes: 2 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
BasedOnStyle: Google
IndentWidth: 4
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,10 @@ add_definitions(
/D_UNICODE=1 /DUNICODE=1 # do Unicode build
/D_CRT_SECURE_NO_WARNINGS # disable warnings about old libc functions
)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF)

set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /utf-8") # set source code encoding to UTF-8
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /GR-") # turn off C++ RTTI
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /utf-8") # set source code encoding to UTF-8
Expand Down
20 changes: 15 additions & 5 deletions ChewingTextService/ChewingTextService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,18 @@
//

#include "ChewingTextService.h"

#include <Shellapi.h>
#include <assert.h>
#include <string>
#include <libIME/Utils.h>
#include <libIME/LangBarButton.h>
#include <libIME/Utils.h>
#include <sys/stat.h>

#include <string>

#include "ChewingImeModule.h"
#include "resource.h"
#include <Shellapi.h>
#include <sys/stat.h>


using namespace std;

Expand Down Expand Up @@ -717,8 +721,11 @@ void TextService::applyConfig() {
font_ = CreateFontIndirect(&lf); // create new font
if(messageWindow_)
messageWindow_->setFont(font_);
if(candidateWindow_)
// messageWindow_->setFontSize(cfg.fontSize);
if(candidateWindow_) {
candidateWindow_->setFont(font_);
candidateWindow_->setFontSize(static_cast<float>(cfg.fontSize));
}
}
}

Expand Down Expand Up @@ -759,6 +766,7 @@ void TextService::updateCandidates(Ime::EditSession* session) {
candidateWindow_->clear();
candidateWindow_->setUseCursor(config().cursorCandList);
candidateWindow_->setCandPerRow(config().candPerRow);
candidateWindow_->setFontSize(static_cast<float>(config().fontSize));

::chewing_cand_Enumerate(chewingContext_);
int* selKeys = ::chewing_get_selKey(chewingContext_); // keys used to select candidates
Expand Down Expand Up @@ -798,6 +806,7 @@ void TextService::showCandidates(Ime::EditSession* session) {
if(!candidateWindow_) {
candidateWindow_ = new Ime::CandidateWindow(this, session);
candidateWindow_->setFont(font_);
candidateWindow_->setFontSize(config().fontSize);
}
updateCandidates(session);
candidateWindow_->show();
Expand All @@ -821,6 +830,7 @@ void TextService::showMessage(Ime::EditSession* session, std::wstring message, i
// FIXME: reuse the window whenever possible
messageWindow_ = new Ime::MessageWindow(this, session);
messageWindow_->setFont(font_);
messageWindow_->setFontSize(config().fontSize);
messageWindow_->setText(message);

int x = 0, y = 0;
Expand Down
7 changes: 6 additions & 1 deletion libIME/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ add_library(libIME_static STATIC
${PROJECT_SOURCE_DIR}/CandidateWindow.cpp
)

target_compile_features(libIME_static PUBLIC cxx_std_17)

target_link_libraries(libIME_static
shlwapi.lib
PUBLIC shlwapi.lib
PUBLIC d2d1.lib
PUBLIC d3d11.lib
PUBLIC dwrite.lib
)
Loading

0 comments on commit c35bcb9

Please sign in to comment.