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
|
|
|
|
2002-12-29 06:50:19 +00:00
|
|
|
Licensed under a BSD-style license.
|
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-06-11 05:51:15 +00:00
|
|
|
/*$Id: ZMouseTest.cpp,v 1.13 2003/06/11 05:51:47 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;
|
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
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);
|
2003-01-12 19:00:14 +00:00
|
|
|
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();
|
2002-12-01 07:56:17 +00:00
|
|
|
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;
|
2002-12-01 07:56:17 +00:00
|
|
|
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();
|
2003-01-12 19:00:14 +00:00
|
|
|
|
|
|
|
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]);
|
|
|
|
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);
|
|
|
|
cursor.Draw(engine->MouseX()-8.0f,engine->MouseY()-8.0f);
|
|
|
|
|
|
|
|
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[])
|
|
|
|
{
|
|
|
|
ZEngine *engine = ZEngine::GetInstance();
|
|
|
|
|
2003-01-12 19:00:14 +00:00
|
|
|
if(Initialize())
|
|
|
|
{
|
|
|
|
//engine->InitPhysFS(argv[0]); //remove this line if PhysFS is not available
|
|
|
|
Test();
|
|
|
|
}
|
2002-11-21 05:40:49 +00:00
|
|
|
|
|
|
|
ZEngine::ReleaseInstance(); //release engine instance
|
|
|
|
return 0;
|
|
|
|
}
|