diff --git a/tools/apps/hgjson/CDlgMain.cpp b/tools/apps/hgjson/CDlgMain.cpp index 0465a4e..c8835db 100644 --- a/tools/apps/hgjson/CDlgMain.cpp +++ b/tools/apps/hgjson/CDlgMain.cpp @@ -12,6 +12,7 @@ #include "DlgTwain.h" #include "DlgOptJson.h" #include "DlgManualUSB.h" +#include "DlgZk.h" // CDlgMain 对话框 @@ -95,6 +96,10 @@ BOOL CDlgMain::OnInitDialog() page->Create(CDlgManualUSB::IDD, this); insert_page(page, L"USB"); + page = new CDlgZk(this); + page->Create(CDlgZk::IDD, this); + insert_page(page, L"LCD字库"); + tab_.SetCurSel(2); OnTcnSelchangeTab1(NULL, &lret); diff --git a/tools/apps/hgjson/DlgZk.cpp b/tools/apps/hgjson/DlgZk.cpp new file mode 100644 index 0000000..ba952dc --- /dev/null +++ b/tools/apps/hgjson/DlgZk.cpp @@ -0,0 +1,167 @@ +// DlgInput.cpp : implementation file +// + +#include "stdafx.h" +#include "hgjson.h" +#include "DlgZk.h" +#include "afxdialogex.h" +#include "DlgRange.h" +#include "DlgCondition.h" +#include "opt_ui/DlgPage.h" // for local_trans + +#include + + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// known name ... +namespace hz_2_py +{ + std::string getLetter(std::string strText, bool head_only = false); +}; +namespace util +{ + std::wstring a2u(const char* a, bool from_utf8 = false); + std::string u2a(const wchar_t* u, bool to_utf8 = false); +}; + +////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// +// CDlgZk dialog + +IMPLEMENT_DYNAMIC(CDlgZk, CDialogEx) + +CDlgZk::CDlgZk(CWnd* pParent /*=NULL*/) + : CDialogEx(CDlgZk::IDD, pParent) +{ +} + +CDlgZk::~CDlgZk() +{ +} + + +std::wstring CDlgZk::get_item_text(UINT id) +{ + int l = GetDlgItem(id)->GetWindowTextLengthW(); + wchar_t* buf = new wchar_t[l + 4]; + + l = GetDlgItem(id)->GetWindowTextW(buf, l + 2); + buf[l] = 0; + + std::wstring ret(buf); + + delete[] buf; + + return std::move(ret); +} + +void CDlgZk::DoDataExchange(CDataExchange* pDX) +{ + CDialogEx::DoDataExchange(pDX); + DDX_Control(pDX, IDC_COMBO_FONT, font_); + DDX_Control(pDX, IDC_COMBO_SIZE, size_); + DDX_Control(pDX, IDC_COMBO_SIZE2, o_size_); +} +BOOL CDlgZk::OnInitDialog() +{ + CDialogEx::OnInitDialog(); + + // Set the icon for this dialog. The framework does this automatically + // when the application's main window is not a dialog + font_.SetCurSel(0); + size_.SetCurSel(0); + o_size_.SetCurSel(0); + + return TRUE; // return TRUE unless you set the focus to a control +} + +void CDlgZk::regen(void) +{ + std::wstring f(get_item_text(IDC_COMBO_FONT)), + fs(get_item_text(IDC_COMBO_SIZE)), + t(get_item_text(IDC_EDIT_DATA)), + os(get_item_text(IDC_COMBO_SIZE2)), + sep(L""); + SIZE out = { _wtoi(os.c_str()), _wtoi(os.c_str() + os.find(sep) + sep.length()) }; + int h = _wtoi(fs.c_str()); + wchar_t text[40] = { 0 }; + HWND hwnd = GetDlgItem(IDC_STATIC_DRAW)->m_hWnd; + HDC hdc = ::GetDC(hwnd); + char_dc dc(hdc); + uint8_t *ptr = NULL; + + dc.set_font(h, f.c_str()); + sep = L""; + for (int i = 0; i < t.length(); ++i) + { + sep += L"static uint8_t "; + text[0] = t[i]; + text[1] = 0; + ptr = dc.lattice(text[0], out); + + std::string ansi(util::u2a(text)); + ansi = hz_2_py::getLetter(ansi); + std::transform(ansi.begin(), ansi.end(), ansi.begin(), tolower); + sep += util::a2u(ansi.c_str()) + L"[] = {" + std::to_wstring(out.cx) + L", " + std::to_wstring(out.cy) + L"\r\n\t\t"; + swprintf_s(text, L", 0x%02X", ptr[0]); + sep += text; + for (int i = 1; i < out.cx * out.cy / 8; ++i) + { + if (i % 16 == 0) + sep += L"\r\n\t\t"; + else if (i % 8 == 0) + sep += L" "; + + if (i % 8 == 0) + swprintf_s(text, L", 0x%02X", ptr[i]); + else + swprintf_s(text, L", 0x%02X", ptr[i]); + sep += text; + } + delete[] ptr; + sep += L"\r\n\t};\r\n\r\n"; + } + ::ReleaseDC(hwnd, hdc); + + ::SetDlgItemTextW(m_hWnd, IDC_EDIT_STATUS, sep.c_str()); +} + +BEGIN_MESSAGE_MAP(CDlgZk, CDialogEx) + ON_EN_CHANGE(IDC_EDIT_DATA, &CDlgZk::OnEnChangeEditData) + ON_CBN_SELCHANGE(IDC_COMBO_FONT, &CDlgZk::OnCbnSelchangeComboFont) + ON_CBN_SELCHANGE(IDC_COMBO_SIZE, &CDlgZk::OnCbnSelchangeComboSize) + ON_CBN_SELCHANGE(IDC_COMBO_SIZE2, &CDlgZk::OnCbnSelchangeComboSize2) +END_MESSAGE_MAP() + + +// CDlgZk message handlers + + +void CDlgZk::OnEnChangeEditData() +{ + // TODO: ÿؼ RICHEDIT ؼ + // ʹ֪ͨд CDialogEx::OnInitDialog() + // CRichEditCtrl().SetEventMask() + // ͬʱ ENM_CHANGE ־㵽С + + // TODO: ڴӿؼ֪ͨ + regen(); +} + + +void CDlgZk::OnCbnSelchangeComboFont() +{ + // TODO: ڴӿؼ֪ͨ + regen(); +} + +void CDlgZk::OnCbnSelchangeComboSize() +{ + // TODO: ڴӿؼ֪ͨ + regen(); +} + +void CDlgZk::OnCbnSelchangeComboSize2() +{ + // TODO: ڴӿؼ֪ͨ + regen(); +} diff --git a/tools/apps/hgjson/DlgZk.h b/tools/apps/hgjson/DlgZk.h new file mode 100644 index 0000000..ca156db --- /dev/null +++ b/tools/apps/hgjson/DlgZk.h @@ -0,0 +1,149 @@ +#pragma once + + +// CDlgInput dialog +#include +#include + +#include +#include +#include + + +// Group: ;ͼ;ֽʽ;߼; +// +// Cat: ͼ; +// + +class CDlgZk : public CDialogEx +{ + DECLARE_DYNAMIC(CDlgZk) + + CComboBox font_; + CComboBox size_; + CComboBox o_size_; + + std::wstring get_item_text(UINT id); + + + class char_dc + { + HDC hdc_; + HDC src_; + HBITMAP bmp_; + HBITMAP old_; + HFONT font_ = NULL; + HFONT oldf_ = NULL; + SIZE size_; + + public: + char_dc(HDC src) : src_(src) + { + size_.cx = size_.cy = 256; + bmp_ = CreateCompatibleBitmap(src, size_.cx, size_.cy); + hdc_ = CreateCompatibleDC(src); + old_ = (HBITMAP)SelectObject(hdc_, bmp_); + BitBlt(hdc_, 0, 0, size_.cx, size_.cy, src, 0, 0, SRCCOPY); + ::SetBkMode(hdc_, TRANSPARENT); + ::SetTextColor(hdc_, RGB(0, 0, 0)); + } + ~char_dc() + { + if (oldf_) + ::SelectObject(hdc_, oldf_); + SelectObject(hdc_, old_); + DeleteObject(bmp_); + DeleteDC(hdc_); + if (font_) + DeleteObject(font_); + } + + public: + bool set_font(int size = 8, const wchar_t* name = L"") + { + HFONT* old = &oldf_, tmpf = NULL; + + if (font_) + { + DeleteObject(font_); + old = &tmpf; + } + font_ = ::CreateFontW(size, 0, 0, 0, 0, 0, 0, 0, GB2312_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY, DEFAULT_PITCH, name); + if (font_) + *old = (HFONT)::SelectObject(hdc_, font_); + + return font_ != NULL; + } + uint8_t* lattice(wchar_t ch, SIZE size) + { + for (int r = 0; r < size_.cy; ++r) + { + for (int c = 0; c < size_.cx; ++c) + { + ::SetPixel(hdc_, c, r, RGB(255, 255, 255)); + } + } + + wchar_t str[] = { ch, 0 }; + SIZE rsize = { 0 }; + POINT center = { 0 }; + int x = 0, + y = 0; + uint8_t* buf = NULL, *oper = NULL, val = 0; + + ::GetTextExtentPointW(hdc_, str, 1, &rsize); + ::TextOutW(hdc_, x, y, str, 1); + oper = buf = new uint8_t[size.cx * size.cy / 8]; + center.x = x + rsize.cx / 2; + center.y = y + rsize.cy / 2; + + // LCD: 8 lines / unit, from bottom to top, auto increament on x-axis + for (int i = 0; i < size.cx * size.cy / 8; ++i) + { + val = 0; + x = i % size.cx; + y = i / size.cx * 8; + + #define GET_PIXE(r) \ + val <<= 1; \ + val |= ::GetPixel(hdc_, x, r) & 1; \ + ::SetPixel(src_, x, r, ::GetPixel(hdc_, x, r)); + + GET_PIXE(y + 7); + GET_PIXE(y + 6); + GET_PIXE(y + 5); + GET_PIXE(y + 4); + + GET_PIXE(y + 3); + GET_PIXE(y + 2); + GET_PIXE(y + 1); + GET_PIXE(y + 0); + + *oper++ = val ^ 0x0ff; + BitBlt(src_, size.cx * 2, size.cy * 2, size.cx, size.cy, hdc_, 0, 0, SRCCOPY); + } + + return buf; + } + }; + + void regen(void); + +public: + CDlgZk(CWnd* pParent = NULL); // standard constructor + virtual ~CDlgZk(); + +// Dialog Data + enum { IDD = IDD_ZK }; + +protected: + virtual void DoDataExchange(CDataExchange* pDX); // DDX/DDV support + virtual BOOL OnInitDialog(); + + DECLARE_MESSAGE_MAP() +public: + afx_msg void OnEnChangeEditData(); + afx_msg void OnCbnSelchangeComboFont(); + afx_msg void OnCbnSelchangeComboSize(); + afx_msg void OnCbnSelchangeComboSize2(); +}; diff --git a/tools/apps/hgjson/hgjson.rc b/tools/apps/hgjson/hgjson.rc index aef2bf8..ed63822 100644 Binary files a/tools/apps/hgjson/hgjson.rc and b/tools/apps/hgjson/hgjson.rc differ diff --git a/tools/apps/hgjson/hgjson.vcxproj b/tools/apps/hgjson/hgjson.vcxproj index 5084f4e..2fc3f48 100644 --- a/tools/apps/hgjson/hgjson.vcxproj +++ b/tools/apps/hgjson/hgjson.vcxproj @@ -132,6 +132,7 @@ + @@ -183,6 +184,7 @@ + diff --git a/tools/apps/hgjson/hgjson.vcxproj.filters b/tools/apps/hgjson/hgjson.vcxproj.filters index 15762bb..f3108e3 100644 --- a/tools/apps/hgjson/hgjson.vcxproj.filters +++ b/tools/apps/hgjson/hgjson.vcxproj.filters @@ -102,6 +102,9 @@ sane_opt + + Header Files + @@ -173,6 +176,9 @@ sane_opt + + Source Files + diff --git a/tools/apps/hgjson/resource.h b/tools/apps/hgjson/resource.h index 6336a57..9ca9b20 100644 Binary files a/tools/apps/hgjson/resource.h and b/tools/apps/hgjson/resource.h differ diff --git a/tools/solution/Release/hgjson.exe b/tools/solution/Release/hgjson.exe index d58c156..4ff6919 100644 Binary files a/tools/solution/Release/hgjson.exe and b/tools/solution/Release/hgjson.exe differ