[分享] 硬幹 TextBox 第三版 ctrl-xcv
應該要叫 TextBox 才對,啊嘶~
第三版:http://damody.googlecode.com/files/TextEditor_v3.7z
changelog
修正 s3748679 版友說的問題
加入 Ctrl-C Ctrl-V Ctrl-X Delete 多行單行的功能
第二版:http://damody.googlecode.com/files/TextEditor_v2.7z
縮圖:http://ppt.cc/X6TJ
changelog:
修正 text width 算不準的問題
加入 mouse select 的功能
code: http://damody.googlecode.com/files/TextEditor.7z
縮圖: http://ppt.cc/cCEu
定一個抽象層 EditorConcept
定一個實作層 GdiEditor
定一下要用的資料結構
struct Size
{
Size();
Size(int _w, int _h);
int w, h;
};
拿來存有大小的東西
struct Vec2
{
Vec2();
Vec2(int _x, int _y);
int x, y;
};
存位置
struct Rect
{
Rect();
Rect(int _x, int _y, int _w, int _h);
union
{
struct
{
int x, y, w, h;
};
struct
{
int left, right, top, bottom;
};
};
};
存矩形
struct Color
{
Color();
Color(unsigned char _r, unsigned char _g, unsigned char _b);
unsigned char r, g, b;
};
存顏色
定義外框大小
白邊大小
Size m_Size;
Rect m_MarginSize;
定義一下顏色
Color m_MarginColor;
Color m_BackGroundColor;
定一下字的大小
要不要顯示行號
要不要顯示專注點
愛的閃耀間隔
Size m_FontSize;
bool m_ShowLineNumber;
bool m_ShowFocus;
double m_BlinkTime;
定一下基本拿 size 的函數
Size GetSize();
void SetSize(int w, int h);
Rect GetMarginSize();
void SetMarginSize(const Rect& rc);
定一下繪圖函數
Render();
畫背景函數
RenderBackGround();
用純虛擬函數 定義畫靠右/左字串
virtual void DrawLeftString(int x, int y, const std::wstring& s) = 0;
virtual void DrawRightString(int x, int y, const std::wstring& s) = 0;
用純虛擬函數 定義需要平台支援的函數
virtual void DrawRect(const Rect& area, const Color& c) = 0;
virtual void SetFontSize(const EditorConcept::Size& s) = 0;
virtual Size GetFontSize() = 0;
再把一些業務邏輯加進來
virtual void SetFocusBlinkTime(double v);
virtual double GetFocusBlinkTime();
virtual void UpdateBlink();
virtual bool SafePositon(int x, int y);
virtual void TypeEnter();
virtual void TypeHome();
virtual void TypeEnd();
virtual void TypeDelete();
virtual void TypeBackSpace();
enum MOVE_DIRECTION
{
UP,
DOWN,
LEFT,
RIGHT
};
virtual void MoveFocus(MOVE_DIRECTION md);
實作一下
平台相依函數
virtual void DrawRect(const Rect& area, const Color& c);
virtual void DrawRightString(int x, int y, const std::wstring& s);
virtual void DrawLeftString(int x, int y, const std::wstring& s);
virtual void SetFontSize(const EditorConcept::Size& s);
virtual Size GetFontSize();
protected:
virtual void InterRenderStart();
virtual void InterRenderEnd();
後記:
我是一個虛擬函數一個平台相依函數成對實作的,
這樣可以快速驗證,
後來有用 double buffer 來解決 愛(字)一直閃爍的問題,
就不多說了,因為這是對平台不夠了解的問題,
中間把平台相依函數做完後,
就剩把大量的業務邏輯實作在 EditorConcept 虛擬層的工作,
還有把這些邏輯跟WndProc 接在一起了。
還有 Focus 的閃爍時間是參考 chrono 來實作的~
要感謝的 google 與 blog 太多了,就謝天吧~
--
標題 [閒聊] 寫程式的時候要吃甜食
推 del680202:我寫程式的時候 都想脫光衣服
推 lgzenith:雙腳放到桌上反而容易進入狀況
→ loveme00835:看吉澤明步...
#1Hc6x55S (Soft_Job)
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.118.175.34
推
06/28 16:40, , 1F
06/28 16:40, 1F
→
06/28 17:55, , 2F
06/28 17:55, 2F
推
06/28 22:15, , 3F
06/28 22:15, 3F
→
06/28 22:16, , 4F
06/28 22:16, 4F
→
06/28 22:26, , 5F
06/28 22:26, 5F
→
06/28 23:26, , 6F
06/28 23:26, 6F
→
06/29 01:45, , 7F
06/29 01:45, 7F
→
06/29 05:19, , 8F
06/29 05:19, 8F
※ 編輯: damody 來自: 114.37.89.226 (06/29 09:33)
推
06/29 21:02, , 9F
06/29 21:02, 9F
推
06/29 21:17, , 10F
06/29 21:17, 10F
推
06/30 03:12, , 11F
06/30 03:12, 11F
→
06/30 03:27, , 12F
06/30 03:27, 12F
推
06/30 18:19, , 13F
06/30 18:19, 13F
→
06/30 22:09, , 14F
06/30 22:09, 14F
→
06/30 22:11, , 15F
06/30 22:11, 15F
→
07/01 00:16, , 16F
07/01 00:16, 16F
→
07/01 00:17, , 17F
07/01 00:17, 17F
→
07/01 03:32, , 18F
07/01 03:32, 18F
推
07/01 05:55, , 19F
07/01 05:55, 19F
→
07/01 10:08, , 20F
07/01 10:08, 20F
→
07/01 11:01, , 21F
07/01 11:01, 21F
→
07/01 12:23, , 22F
07/01 12:23, 22F
→
07/01 22:18, , 23F
07/01 22:18, 23F
→
07/01 22:18, , 24F
07/01 22:18, 24F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):