2021SC@SDUSC
布局ScreenLayout
FullScreenLayout.h文件
FullScreenLayout.h
#pragma once
#include "StandardLayout.h"
namespace weasel
{
class FullScreenLayout: public StandardLayout
{
public:
FullScreenLayout(const UIStyle &style, const Context &context, const Status &status, const CRect& inputPos, Layout* layout);
virtual ~FullScreenLayout();
virtual void DoLayout(CDCHandle dc);
private:
bool AdjustFontPoint(CDCHandle dc, const CRect& workArea, int& fontPoint, int& step);
const CRect& mr_inputPos;
Layout* m_layout;
};
};
weasel命名空间
namespace
- 命名空间,指标识符的可见范围。C++标准库中的所有标识符都被定义在一个名为 std 的namespace 中。
- namesapce简单来说就是用来控制标志符(如变量,函数,类等)的名字冲突的。C++中namespace关键字定义了一个declarative region,所以在一个namespace中声明的标志符和其他namespace中声明的同名标志符是没有名字冲突的。
基本语法
- 定义命名空间
//举例
namespace zhen{
int pal;
void fetch(){
...
}
//声明一些变量、函数、类等
}
- 访问namespace中的成员
* 方法一:using declaration
* 方法二:using directive
// 方法一:using declaration
namespace zhen{
int pal;
void fetch(){
...
}
char pal;// global variable
int main(){
using zhen::pal;// 一个 using declaration; 它将pal放到了当前的block declarative region,相当于声明了一个局部变量pal
cin>>pal;//读入局部变量pal
//double pal; //会报错!因为上条语句已经相当于声明了一个局部变量,这里再声明一个同名的局部变量就会报错
cin>>::pal;// 读入全局变量pal
}
// 方法二:using directive
namespace zhen{
int pal;
void fetch(){
...
}
char pal;// global variable
int main(){
using namespace zhen;// 就跟平时最常见的“using namespace std;”一样
double pal;//这里不会报错,而且会覆盖掉zhen::pal
cin>>pal;//读入局部变量pal
cin>>zhen::pal;//读入zhen中的pal
cin>>::pal;//读入全局变量pal
}
类的继承关系
class FullScreenLayout: public StandardLayout
//FullScreenLayout继承自StandardLayout类
class StandardLayout: public Layout
//StandLayout类又继承自Layout类
- Layout类
namespace weasel
{
class Layout
{
public:
Layout(const UIStyle &style, const Context &context, const Status &status);
virtual void DoLayout(CDCHandle dc) = 0;
/* All points in this class is based on the content area */
/* The top-left corner of the content area is always (0, 0) */
virtual CSize GetContentSize() const = 0;
virtual CRect GetPreeditRect() const = 0;
virtual CRect GetAuxiliaryRect() const = 0;
virtual CRect GetHighlightRect() const = 0;
virtual CRect GetCandidateLabelRect(int id) const = 0;
virtual CRect GetCandidateTextRect(int id) const = 0;
virtual CRect GetCandidateCommentRect(int id) const = 0;
virtual CRect GetStatusIconRect() const = 0;
virtual std::wstring GetLabelText(const std::vector<Text> &labels, int id, const wchar_t *format) const = 0;
virtual bool IsInlinePreedit() const = 0;
virtual bool ShouldDisplayStatusIcon() const = 0;
protected:
const UIStyle &_style;
const Context &_context;
const Status &_status;
};
};
- StandardLayout类
namespace weasel
{
const int MAX_CANDIDATES_COUNT = 10;
const int STATUS_ICON_SIZE = GetSystemMetrics(SM_CXICON);
class StandardLayout: public Layout
{
public:
StandardLayout(const UIStyle &style, const Context &context, const Status &status);
/* Layout */
virtual CSize GetContentSize() const { return _contentSize; }
virtual CRect GetPreeditRect() const { return _preeditRect; }
virtual CRect GetAuxiliaryRect() const { return _auxiliaryRect; }
virtual CRect GetHighlightRect() const { return _highlightRect; }
virtual CRect GetCandidateLabelRect(int id) const { return _candidateLabelRects[id]; }
virtual CRect GetCandidateTextRect(int id) const { return _candidateTextRects[id]; }
virtual CRect GetCandidateCommentRect(int id) const { return _candidateCommentRects[id]; }
virtual CRect GetStatusIconRect() const { return _statusIconRect; }
virtual std::wstring GetLabelText(const std::vector<Text> &labels, int id, const wchar_t *format) const;
virtual bool IsInlinePreedit() const;
virtual bool ShouldDisplayStatusIcon() const;
protected:
/* Utility functions */
CSize GetPreeditSize(CDCHandle dc) const;
void UpdateStatusIconLayout(int* width, int* height);
CSize _contentSize;
CRect _preeditRect, _auxiliaryRect, _highlightRect;
CRect _candidateLabelRects[MAX_CANDIDATES_COUNT];
CRect _candidateTextRects[MAX_CANDIDATES_COUNT];
CRect _candidateCommentRects[MAX_CANDIDATES_COUNT];
CRect _statusIconRect;
};
};