?? object.cpp
字號:
/*******************************************************************************
模 塊: 圖形對象模塊.
功 能: 能夠定義一個圖形方塊為對象并顯示和隱藏,是所有圖形對象的基類.
程序員: 雷中南.
版 本: v1.1
時 間: 1999-05-05
*******************************************************************************/
#include <graphics.h>
#include "han.h"
#include "object.h"
//構造函數,派生自 ScrKeep 類.
Object::Object(struct RECT R) : ScrKeep(R)
{
//對象的位置.
Rect = R;
//背景顏色.
BackColor = 0;
//邊框顏色.
FrameColor = 7;
//默認控件為可顯示的.
Visible = L_OK;
//在顯示之前,先將現場保存起來.
ScrKeep::Save();
//注意,雖然對象產生了卻未顯示,這是有必要的.
// clearviewport();
}
//析構函數,在對象被刪除之前先隱藏起來.
Object::~Object()
{
Hide();
}
//隱藏對象,其實就是將保存的背景恢復出來.
void
Object::Hide()
{
//如果object不具備可見屬性則返回.
if(Visible==L_ERROR) return;
ScrKeep::Restore();
}
//將對象畫出來.
void
Object::Show()
{
//如果object不具備可見屬性則返回.
if(Visible==L_ERROR) return;
//視口變化太多了,重定義視口是有必要.
setviewport(0,0,639,479,1);
setviewport(Rect.Left,Rect.Top,Rect.Left+Rect.Width,Rect.Top+Rect.Height,1);
//清除視口.
clearviewport();
//畫對象.
Draw();
}
//畫對象.
void
Object::Draw()
{
//用背景色添滿對象所在位置.
setfillstyle(SOLID_FILL, BackColor);
bar(0,0,Rect.Width,Rect.Height);
//畫邊框.
setcolor(FrameColor);
rectangle(0,0,Rect.Width,Rect.Height);
}
//在對象中輸出文本。
void
Object::OutText(int X, int Y, char *Text)
{
if(Visible==L_ERROR) return;
setviewport(0,0,639,479,1);
setviewport(Rect.Left,Rect.Top,Rect.Left+Rect.Width,Rect.Top+Rect.Height,1);
han.Color = Color;
han.Out(X, Y, Text);
}
//把自己從內存中刪掉.
void
Object::Close()
{
delete this;
}
//背景顏色.
void
Object::SetBkColor(int color)
{
BackColor = color;
}
//設置前景顏色.
void
Object::SetColor(int color)
{
Color = color;
}
//設置邊框顏色.
void
Object::SetFrameColor(int color)
{
FrameColor = color;
}
//運行對象.
void
Object::Run()
{
DoIt();
}
//運行代碼段.
void
Object::DoIt()
{
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -