// filename: IRenderTarget.h
// author: enic
// date: 2014-02-12
#pragma once
#include "import_std.h"
namespace elib
{
class IRenerTarget
{
public:
virtual ~IRenerTarget(){}
// !!!這里原先的名字和Windows sdk中的DrawText,結果上當了。表現在基類定義的DrawText接口,派生類始終調用不到
// 正確的class,感覺是虛函數表查的不對,后來發現泥馬明明函數名字都是DrawText結果派生類調用DrawTextW編譯器都不
// 報錯誤,然后把基類的改了還居然就正常了,,,
// 最后發現是被windows sdk的UNICODE模式那些×××W ***A的宏忽悠了,然后編譯器這邊也沒能報錯出來,導致運行期間找
// 不到正確的虛函數然后傻逼了。
// 解決方案有兩個:1.在基類中也引入Windows的頭文件,這樣大家一起被宏定義,始終是一致的名字。但是感覺不太好,仿
// 佛被綁架了一樣,我不喜歡這個感覺。而且不利于跨平臺(總覺得編譯器不夠給力,應該報出來的)。或者是undefine,
// 或者把導致問題的依賴文件移動到cpp中,這樣應該報錯會明顯一點不至于到最后崩潰了無法分析(宏展開才能發現代碼問題)
// 2.該名字,果斷改了,,,以后windows api中有×××W ***A兩個版本的,果斷要記得危險,,,
virtual bool DrawString(const estl::u16string& strText, int iX, int iY) = 0;
};
class CBaseRenderTarget : public IRenerTarget
{
public:
virtual bool DrawString(const estl::u16string& strText, int iX, int iY)
{
return false;
}
};
/*
class IRenderTexture
{};*/
}; //~ end of namespace elib
// filename: CDcRenderTarget.h
// author: enic
// date: 2014-02-13
// note:
// @2014-02-14:現在最糾結的事情是,怎么在PaintEvent的時候獲取到RenderTarget,目前只能確定一件事:
// 只有從NativeWnd才能獲取到DC,才可能創建出真實的RenderTarget,那么創建就只交給NativeWnd
// 然后通過Paint事件傳遞出去.
// 仔細想想,發現上面說的方式也不行,上面的方式限制了paint的時機,也就是只有發生Paint事件
// 的時候才有可能得到Target然后繪圖,貌似不夠合理?下午想想有沒有別的辦法。
#pragma once
#include "../IRenderTarget.h"
#include "CDCT.hpp"
namespace elib
{
// DC渲染目標
class CDcRenerTarget : public CBaseRenderTarget
{
public:
explicit CDcRenerTarget(CDCHandle dc);
virtual ~CDcRenerTarget();
public:
virtual bool DrawString(const estl::u16string& strText, int iX, int iY);
private:
CDCHandle m_dcHandle;
};
}; //~ end of namespace elib