zengine/test/ZMouseTest.cpp

99 lines
3.3 KiB
C++
Raw Normal View History

2002-11-21 05:40:49 +00:00
/*******************************************************************************
2002-12-29 06:50:19 +00:00
This file is Part of the ZEngine Library for 2D game development.
Copyright (C) 2002, 2003 James Turk
2002-11-21 05:40:49 +00:00
2003-07-10 20:45:39 +00:00
ZEngine is Licensed under a BSD-style license.
This example file is in the public domain, it may be used with no restrictions.
2002-11-21 05:40:49 +00:00
2002-12-29 06:50:19 +00:00
The maintainer of this library is James Turk (james@conceptofzero.net)
and the home of this Library is http://www.zengine.sourceforge.net
2002-11-21 05:40:49 +00:00
*******************************************************************************/
2002-12-29 07:09:44 +00:00
2003-10-05 19:46:04 +00:00
/*$Id: ZMouseTest.cpp,v 1.18 2003/10/05 19:46:04 cozman Exp $*/
2003-01-04 05:17:56 +00:00
2002-11-21 05:40:49 +00:00
#include <ZEngine.h>
#include <string>
using namespace std;
using namespace ZE;
bool Initialize()
2002-11-21 05:40:49 +00:00
{
ZEngine *engine = ZEngine::GetInstance();
ZConfigFile cfg("tests.zcf");
2003-01-04 05:16:01 +00:00
int w,h,bpp,rate;
2002-11-21 05:40:49 +00:00
bool fs;
2003-06-11 05:51:15 +00:00
std::string title;
2002-11-21 05:40:49 +00:00
w = cfg.GetInt("ZMouseTest","width",800);
h = cfg.GetInt("ZMouseTest","height",600);
bpp = cfg.GetInt("ZMouseTest","bpp",32);
fs = cfg.GetBool("ZMouseTest","fullscreen",false);
title = cfg.GetString("ZMouseTest","title","ZMouse Test");
2003-01-04 05:16:01 +00:00
rate = cfg.GetInt("ZMouseTest","framerate",60);
2002-11-21 05:40:49 +00:00
engine->SetupDisplay(w,h,bpp,fs);
2003-01-04 05:16:01 +00:00
engine->SetDesiredFramerate(rate);
return engine->CreateDisplay(title);
2002-11-21 05:40:49 +00:00
}
void Test()
{
ZEngine *engine = ZEngine::GetInstance();
//Open and Setup all the Images//
ZImage text[3], cursor("data/cursor.bmp");
ZFont font("data/almontew.ttf",30);
SDL_Rect textRect;
engine->HideCursor();
cursor.SetColorKey(255,0,255);
2002-11-21 05:40:49 +00:00
font.SetColor(0,255,0);
font.SetBGColor(0,0,255);
font.DrawText("Mouse Test",text[0]);
font.DrawShadedText("Mouse Test",text[1]);
textRect.x = textRect.y = 100;
textRect.w = font.StringWidth("Mouse Test");
textRect.h = font.StringHeight("Mouse Test");
2002-11-21 05:40:49 +00:00
do
{
//In the active loop, check events first//
engine->CheckEvents();
if(engine->IsActive())
{
if(engine->KeyIsPressed(SDLK_ESCAPE))
engine->RequestQuit();
//show where mouse is (clicked or not)//
if(engine->RButtonPressed())
font.DrawText(FormatStr("Right button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
else if(engine->LButtonPressed())
font.DrawText(FormatStr("Left button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
2003-10-05 19:46:04 +00:00
else if(engine->MButtonPressed())
font.DrawText(FormatStr("Middle button clicked at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
else
font.DrawText(FormatStr("Mouse at %d,%d",engine->MouseX(),engine->MouseY()),text[2]);
engine->Clear(); //clear screen
//draw the images//
text[engine->MouseInRect(&textRect)].Draw(100,100);
text[2].Draw(0,0);
2003-07-05 00:40:44 +00:00
cursor.Draw(engine->MouseX()-8,engine->MouseY()-8);
engine->Update(); //update the screen
}
2002-11-21 05:40:49 +00:00
} while(!engine->QuitRequested()); //quit only when engine has encountered a quit request
}
int main(int argc, char *argv[])
2002-11-21 05:40:49 +00:00
{
if(Initialize())
Test();
ZEngine::ReleaseInstance();
2002-11-21 05:40:49 +00:00
return 0;
}