//
// TextWrap.c
//
#include "AEEModGen.h" // IModule インターフェイスの定義
#include "AEEAppGen.h" // IApplet インターフェイスの定義
#include "AEEShell.h" // IShell インターフェイスの宣言
#include "AEEStdLib.h" // BREW ヘルパー関数
#include "TextWrap.bid" // TextWrapアプレットのクラスID
// 前方宣言
static boolean TextWrap_HandleEvent(IApplet * pi, AEEEvent eCode,
uint16 wParam, uint32 dwParam);
static void TextWrap_OnAppStart(AEEApplet* app);
//
// TextWrapアプレットを作成するときに呼び出される関数です。
//
int AEEClsCreateInstance(AEECLSID ClsId,IShell * pIShell,IModule * po,void ** ppObj)
{
*ppObj = NULL;
if (ClsId == AEECLSID_TEXTWRAP) {
if (AEEApplet_New(sizeof(AEEApplet), ClsId, pIShell, po, (IApplet**)ppObj,
(AEEHANDLER)TextWrap_HandleEvent, NULL) == TRUE) {
return (AEE_SUCCESS);
}
}
return (EFAILED);
}
//
// TextWrapアプレットのイベント ハンドラ
//
static boolean TextWrap_HandleEvent(IApplet * pi, AEEEvent eCode, uint16 wParam, uint32 dwParam)
{
switch (eCode)
{
case EVT_APP_START:
TextWrap_OnAppStart((AEEApplet*) pi);
return TRUE;
case EVT_APP_STOP:
return TRUE;
default:
break;
}
return FALSE;
}
//
// TextWrapアプレットが開始したときに呼び出される関数です。
//
static void TextWrap_OnAppStart(AEEApplet* app)
{
IShell* shell;
IDisplay* disp;
char* astr_text = "怒りっぽいのであれば,いらつかせてやりなさい。"
"臆病であれば,脅してやりなさい。"
"道楽者であれば,誘惑してやりなさい。";
int astr_text_len;
AECHAR* wstr_text;
int wstr_text_bytes;
int wstr_pos;
int x, y;
AEEFont font = AEE_FONT_NORMAL; // 描画に使用するフォント
int font_ascent, font_descent, font_height;
AEERect rect; // 文字列を描画する枠
// IShell オブジェクトを取得する
shell = app->m_pIShell;
// IDisplay オブジェクトを取得する
disp = app->m_pIDisplay;
// 青い四角形を描画する
rect.x = 14;
rect.y = 14;
rect.dx = 92;
rect.dy = 100;
IDISPLAY_DrawRect(disp, &rect, MAKE_RGB(0, 0, 255),
MAKE_RGB(255, 255, 255), IDF_RECT_FRAME | IDF_RECT_FILL);
// フォント情報を取得する
IDISPLAY_GetFontMetrics(disp, font, &font_ascent, &font_descent);
font_height = font_ascent + font_descent;
// AECHAR文字列のバッファを確保する
astr_text_len = STRLEN(astr_text);
wstr_text_bytes = (astr_text_len + 1) * sizeof(AECHAR);
wstr_text = (AECHAR*) MALLOC(wstr_text_bytes);
// char文字列をAECHAR文字列に変換する
STREXPAND(astr_text, astr_text_len, wstr_text, wstr_text_bytes);
// 文字列を描画する位置を計算
rect.x += 2; // 枠より 2 ピクセル内側に描画
rect.y += 2;
rect.dx -= 4;
rect.dy -= 4;
x = rect.x; // 画面上の文字列の表示位置 (X座標)
y = rect.y; // 画面上の文字列の表示位置 (Y座標)
// 文字列描画ループ
wstr_pos = 0; // AECHAR文字列バッファ内の表示位置
while (1)
{
// 枠の横幅に入る文字数を計算する
int count;
IDISPLAY_MeasureTextEx(disp, font, wstr_text + wstr_pos, -1, rect.dx, &count);
if (count == 0) break;
// 文字列を描画する
IDISPLAY_DrawText(disp, font, wstr_text + wstr_pos, count,
x, y, &rect, 0);
// 次の行を描画するための準備
y += font_height;
wstr_pos += count;
}
// AECHAR文字列を解放する
FREE(wstr_text);
// 実際の画面表示を更新する
IDISPLAY_Update(disp);
}
|