📄 guitest.cpp
字号:
/*
** Haaf's Game Engine 1.5
** Copyright (C) 2003-2005, Relish Games
** hge.relishgames.com
**
** hge_tut01 - Minimal HGE application
*/
#include <stdio.h>
#include "hgeguictrls.h"
#include "hge.h"
#include "hgegui.h"
#include "hgefont.h"
// GUI
#include "guiapp.h"
#include "guiappwindow.h"
#include "guiapplabel.h"
#include "guiappbutton.h"
#include "guiappimage.h"
#include "guiappedit.h"
#include "guiapppassword.h"
#include "guiappscrollbar.h"
#include "guiapplistbox.h"
class OtherWindow : public GUIAppWindow {
GUIAppLabel *label;
GUIAppLabel *label1;
GUIAppButton *button;
GUIAppEdit *edit;
GUIAppListBox *listbox;
GUIAppScrollBar *scroll;
hgeFont *font;
int clickCnt;
public:
enum {
BTN1 = 10, BTN2, BTN3, BTN4, LBL1 = 20, LBL2, EDIT1 = 40, LISTBOX = 50, SCROLL=60
};
OtherWindow( GUIApp *parentApp, int _id, float x, float y ) : GUIAppWindow(parentApp,_id, x,y, 350, 250 ) {
font = parentapp->CreateFont("font2.fnt");
clickCnt = 0;
label = new GUIAppLabel(LBL1, 10, 10, font, "hello!", ARGB(0xFF,0xff,0xff,0xff));
AddCtrl(label);
label1 = new GUIAppLabel(LBL2, 10, 25, font, "", ARGB(0xFF,0xff,0xff,0xff));
AddCtrl(label1);
button = new GUIAppButton(BTN1, 10, 70, "btn-send.png" );
button->SetParent(this);
AddCtrl(button);
edit = new GUIAppEdit(EDIT1,120, 10, 100, font, "" );
edit->SetTextColor(ARGB(0xff,0,0,0));
edit->SetParent(this);
listbox = new GUIAppListBox(LISTBOX, 120,40,200,150,
"btn-up-arrow.png", "btn-down-arrow.png", "btn-clear-arrow.png",
"btn-left-arrow.png", "btn-right-arrow.png", "btn-clear-arrow.png" );
listbox->SetSepSize(4);
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 1"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 2"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 3"));
listbox->AddItem(new GUIAppImage(0,0,0,"common_logo.png"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 4"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 5"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 6"));
listbox->AddItem(new GUIAppImage(0,0,0,"info_butattack_common.png"));
listbox->AddItem(edit);
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 7"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 8"));
listbox->AddItem(new GUIAppImage(0,0,0,"info_butchange_common.png"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 9"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 10"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 11"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 12"));
listbox->AddItem(new GUIAppImage(0,0,0,"info_butbuy_common.png"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 13"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 14"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 15"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 16"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 17"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 18"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 19"));
listbox->AddItem(new GUIAppLabel(0,0,0,font,"item 20"));
AddCtrl(listbox);
scroll = new GUIAppScrollBar(SCROLL,GUIAppScrollBar::H_SCROLL, 120, 220, 100, "btn-left-arrow.png", "btn-right-arrow.png", "btn-clear-arrow.png" );
scroll->SetLimits(0,100,10);
AddCtrl(scroll);
}
virtual void OnEvent ( int obj_id ) {
switch (obj_id) {
case BTN1:
{
char buf[64];
sprintf ( buf, "Click %d", clickCnt ++);
label->SetText(buf);
listbox->SetSelection(listbox->ItemCount()-1);
}
break;
default:
break;
}
}
virtual bool MouseMove(float x, float y) {
char buf[256];
sprintf ( buf, "X=%.1f Y=%.1f", x, y );
label1->SetText(buf);
return GUIAppWindow::MouseMove(x,y);
}
};
// window
class LoginWindow : public GUIAppWindow {
GUIAppLabel *label;
GUIAppButton *button;
GUIAppImage *img;
GUIAppImage *frameImage;
GUIAppEdit *edit1;
GUIAppPassword *edit2;
hgeFont *font;
int clickCnt;
public:
enum {
BTN1 = 10, LBL1 = 20,IMG1 = 30, EDIT1 = 40, EDIT2 = 50
};
LoginWindow( GUIApp *parentApp, int _id, float x, float y ) : GUIAppWindow(parentApp,_id, x,y, 550, 333 ) {
font = parentapp->CreateFont("font2.fnt");
clickCnt = 0;
// passive elements first
label = new GUIAppLabel(LBL1, 10, 10, font, "hello!", ARGB(0xFF,0xff,0xff,0xff));
AddCtrl(label);
img = new GUIAppImage(IMG1,30,120,"common_logo.png");
AddCtrl(img);
frameImage = new GUIAppImage(IMG1,-14,-14,"world_frame.PNG");
AddCtrl(frameImage);
// active elements
button = new GUIAppButton(BTN1, 10, 30, "btn-send.png" );
AddCtrl(button);
edit1 = new GUIAppEdit(EDIT1,120, 10, 100, font, "" );
AddCtrl(edit1);
edit2 = new GUIAppPassword(EDIT2,120, 30, 100, font, "" );
AddCtrl(edit2);
}
virtual void OnEvent ( int obj_id ) {
switch (obj_id) {
case BTN1:
{
char buf[64];
sprintf ( buf, "Click %d", clickCnt ++);
label->SetText(buf);
}
break;
default:
break;
}
}
};
// APP
class TestApp : public GUIApp {
hgeFont *font;
public:
TestApp (HGE *hge) : GUIApp(hge) {
}
void Init () {
LoginWindow *window = new LoginWindow(this,0, 10,10 );
AddCtrl(window);
window->SetBGColor(ARGB(0xaf,0x10,0x10,0xf0));
OtherWindow *other = new OtherWindow(this, 1, 200, 200 );
other->SetBGColor(ARGB(0xaf,0xAf,0x10,0x10));
AddCtrl(other);
}
};
TestApp *app;
bool FrameFunc() {
if (app->Input_GetKeyState(HGEK_ESCAPE)) return true;
return app->FrameFunc();
}
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, int)
{
HGE * hge = hgeCreate(HGE_VERSION);
hge->System_SetState((hgeState)14, 0xFACE0FF);
hge->System_SetState(HGE_FRAMEFUNC, FrameFunc);
hge->System_SetState(HGE_TITLE, "DOMES component test");
hge->System_SetState(HGE_LOGFILE, "hgetest.log");
hge->System_SetState(HGE_USESOUND, false);
// Set up video mode
hge->System_SetState(HGE_SCREENWIDTH, 800);
hge->System_SetState(HGE_SCREENHEIGHT, 600);
hge->System_SetState(HGE_SCREENBPP, 24);
hge->System_SetState(HGE_FPS, 50 );
if(hge->Ini_GetInt("HGE", "FullScreen",0)) {
hge->System_SetState(HGE_WINDOWED, false);
} else {
hge->System_SetState(HGE_WINDOWED, true);
}
if(hge->System_Initiate()) {
app = new TestApp(hge);
app->LoadCursor("cursor.png");
app->Init();
app->SetNavMode(HGEGUI_NONAVKEYS);
hge->System_Start();
} else {
MessageBox(NULL, hge->System_GetErrorMessage(), "Error", MB_OK | MB_ICONERROR | MB_SYSTEMMODAL);
}
hge->System_Shutdown();
hge->Release();
return 0;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -