1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748
|
/***********************************************************************
created: 9/7/2012
author: Lukas E Meindl
*************************************************************************/
/***************************************************************************
* Copyright (C) 2004 - 2012 Paul D Turner & The CEGUI Development Team
*
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to deal in the Software without restriction, including
* without limitation the rights to use, copy, modify, merge, publish,
* distribute, sublicense, and/or sell copies of the Software, and to
* permit persons to whom the Software is furnished to do so, subject to
* the following conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
***************************************************************************/
#include "EffectsDemo.h"
#include "CEGUI/CEGUI.h"
#include "CEGUI/RenderingWindow.h"
#include <cstdlib>
//----------------------------------------------------------------------------//
WobblyWindowEffect::WobblyWindowEffect(CEGUI::Window* window) :
d_initialised(false),
d_window(dynamic_cast<CEGUI::FrameWindow*>(window))
{
if (!d_window)
CEGUI_THROW(CEGUI::InvalidRequestException("This effect is only applicable to FrameWindows!"));
}
//----------------------------------------------------------------------------//
int WobblyWindowEffect::getPassCount() const
{
return 1;
}
//----------------------------------------------------------------------------//
void WobblyWindowEffect::performPreRenderFunctions(const int /*pass*/)
{
// nothing we need here
}
//----------------------------------------------------------------------------//
void WobblyWindowEffect::performPostRenderFunctions()
{
// nothing we need here
}
void WobblyWindowEffect::syncPivots(CEGUI::RenderingWindow& window)
{
const CEGUI::Rectf pixelRect = CEGUI::Rectf(window.getPosition(), window.getSize());
for (int y = 0; y < ds_yPivotCount; ++y)
{
for (int x = 0; x < ds_xPivotCount; ++x)
{
const float factorMinX = static_cast<float>(ds_xPivotCount - x) / (ds_xPivotCount - 1);
const float factorMaxX = static_cast<float>(x) / (ds_xPivotCount - 1);
const float factorMinY = static_cast<float>(ds_yPivotCount - y) / (ds_yPivotCount - 1);
const float factorMaxY = static_cast<float>(y) / (ds_yPivotCount - 1);
d_pivots[x][y] = CEGUI::Vector2f(
factorMinX * pixelRect.d_min.d_x + factorMaxX * pixelRect.d_max.d_x,
factorMinY * pixelRect.d_min.d_y + factorMaxY * pixelRect.d_max.d_y);
d_pivotVelocities[x][y] = CEGUI::Vector2f(
0.0f,
0.0f);
}
}
}
//----------------------------------------------------------------------------//
bool WobblyWindowEffect::realiseGeometry(CEGUI::RenderingWindow& window,
CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
Texture& tex = window.getTextureTarget().getTexture();
static const CEGUI::Colour c(1, 1, 1, 1);
// qw is the width of one subdivision "box", qh is the height of it
const float qw = window.getSize().d_width / (ds_xPivotCount - 1);
const float qh = window.getSize().d_height / (ds_yPivotCount - 1);
const float tcx = qw * tex.getTexelScaling().d_x;
const float tcy =
(window.getTextureTarget().isRenderingInverted() ? -qh : qh) *
tex.getTexelScaling().d_y;
const Vector3f windowPosition = Vector3f(window.getPosition(), 0.0f);
for (size_t y = 0; y < ds_yPivotCount - 1; ++y)
{
for (size_t x = 0; x < ds_xPivotCount - 1; ++x)
{
// index of the first vertex of the quad we will construct with
// this iteration
const size_t idx = (y * (ds_xPivotCount - 1) + x) * 6;
// first triangle
// vertex 0 - top left
d_vertices[idx + 0].position = Vector3f(d_pivots[x][y], 0.0f) - windowPosition;
d_vertices[idx + 0].colour_val = c;
d_vertices[idx + 0].tex_coords = Vector2f(x * tcx, y * tcy);
// vertex 1 - bottom left
d_vertices[idx + 1].position = Vector3f(d_pivots[x][y + 1], 0.0f) - windowPosition;
d_vertices[idx + 1].colour_val = c;
d_vertices[idx + 1].tex_coords = Vector2f(x * tcx, (y + 1) * tcy);
// vertex 2 - bottom right
d_vertices[idx + 2].position = Vector3f(d_pivots[x + 1][y + 1], 0.0f) - windowPosition;
d_vertices[idx + 2].colour_val = c;
d_vertices[idx + 2].tex_coords = Vector2f((x + 1) * tcx, (y + 1) * tcy);
// second triangle
// vertex 3 - bottom right
d_vertices[idx + 3].position = Vector3f(d_pivots[x + 1][y + 1], 0.0f) - windowPosition;
d_vertices[idx + 3].colour_val = c;
d_vertices[idx + 3].tex_coords = Vector2f((x + 1) * tcx, (y + 1) * tcy);
// vertex 4 - top right
d_vertices[idx + 4].position = Vector3f(d_pivots[x + 1][y], 0.0f) - windowPosition;
d_vertices[idx + 4].colour_val = c;
d_vertices[idx + 4].tex_coords = Vector2f((x + 1) * tcx, y * tcy);
// vertex 5 - top left
d_vertices[idx + 5].position = Vector3f(d_pivots[x][y], 0.0f) - windowPosition;
d_vertices[idx + 5].colour_val = c;
d_vertices[idx + 5].tex_coords = Vector2f(x * tcx, y * tcy);
}
}
geometry.setActiveTexture(&tex);
geometry.appendGeometry(d_vertices, ds_vertexCount);
// false, because we do not want the default geometry added!
return false;
}
//----------------------------------------------------------------------------//
bool WobblyWindowEffect::update(const float elapsed, CEGUI::RenderingWindow& window)
{
using namespace CEGUI;
// initialise ourself upon the first update call.
if (!d_initialised)
{
syncPivots(window);
d_initialised = true;
return true;
}
const CEGUI::Rectf pixelRect = CEGUI::Rectf(window.getPosition(), window.getSize());
bool changed = false;
for (int y = 0; y < ds_yPivotCount; ++y)
{
for (int
x = 0; x < ds_xPivotCount; ++x)
{
const float factorMinX = static_cast<float>(ds_xPivotCount - 1- x) / (ds_xPivotCount - 1);
const float factorMaxX = static_cast<float>(x) / (ds_xPivotCount - 1);
const float factorMinY = static_cast<float>(ds_yPivotCount - 1 - y) / (ds_yPivotCount - 1);
const float factorMaxY = static_cast<float>(y) / (ds_yPivotCount - 1);
const Vector2f desiredPos = Vector2f(
factorMinX * pixelRect.d_min.d_x + factorMaxX * pixelRect.d_max.d_x,
factorMinY * pixelRect.d_min.d_y + factorMaxY * pixelRect.d_max.d_y);
const Vector2f delta = desiredPos - d_pivots[x][y];
float speed = 300.0f;
const Vector2f cursorDelta = d_window->getTitlebar()->isDragged() ? window.getPosition() + d_window->getTitlebar()->getDragPoint() - d_pivots[x][y] : Vector2f(0.0f, 0.0f);
const float cursorDeltaLength = sqrtf(cursorDelta.d_x * cursorDelta.d_x + cursorDelta.d_y * cursorDelta.d_y);
speed /= cursorDeltaLength > 64 ? sqrtf(cursorDeltaLength) * 0.125f : 1;
d_pivotVelocities[x][y] *= pow(0.00001f, elapsed);
d_pivotVelocities[x][y] += delta * (speed * elapsed);
const Vector2f old_pivot(d_pivots[x][y]);
d_pivots[x][y] += d_pivotVelocities[x][y] * elapsed;
changed |= (old_pivot != d_pivots[x][y]);
}
}
// note we just need system to redraw the geometry; we do not need a
// full redraw of all window/widget content - which is unchanged.
if (changed)
d_window->getGUIContext().markAsDirty();
return false;
}
//----------------------------------------------------------------------------//
// The following are related to the RenderEffect
//
// Note: This be the land of magic numbers and compound hacks upon hacks :-p
// Any final version of this we might provide will likely be cleaned up
// considerably.
//----------------------------------------------------------------------------//
const float OldWobblyWindowEffect::tess_x = 8;
const float OldWobblyWindowEffect::tess_y = 8;
//----------------------------------------------------------------------------//
OldWobblyWindowEffect::OldWobblyWindowEffect(CEGUI::Window* window) :
initialised(false),
dragX(0), dragY(0),
elasX(0), elasY(0),
d_window(window)
{
}
//----------------------------------------------------------------------------//
int OldWobblyWindowEffect::getPassCount() const
{
return 1;
}
//----------------------------------------------------------------------------//
void OldWobblyWindowEffect::performPreRenderFunctions(const int /*pass*/)
{
// nothing we need here
}
//----------------------------------------------------------------------------//
void OldWobblyWindowEffect::performPostRenderFunctions()
{
// nothing we need here
}
//----------------------------------------------------------------------------//
bool OldWobblyWindowEffect::realiseGeometry(CEGUI::RenderingWindow& window,
CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
Texture& tex = window.getTextureTarget().getTexture();
static const CEGUI::Colour c(1, 1, 1, 1);
const float qw = window.getSize().d_width / tess_x;
const float qh = window.getSize().d_height / tess_y;
const float tcx = qw * tex.getTexelScaling().d_x;
const float tcy =
(window.getTextureTarget().isRenderingInverted() ? -qh : qh) *
tex.getTexelScaling().d_y;
for (int j = 0; j < tess_y; ++j)
{
for (int i = 0; i < tess_x; ++i)
{
int idx = static_cast<int>( (j * tess_x + i) * 6 );
float top_adj = dragX * ((1.0f / tess_x) * j);
float bot_adj = dragX * ((1.0f / tess_x) * (j+1));
top_adj = ((top_adj*top_adj) / 3) * (dragX < 0 ? -1 : 1);
bot_adj = ((bot_adj*bot_adj) / 3) * (dragX < 0 ? -1 : 1);
float lef_adj = dragY * ((1.0f / tess_y) * i);
float rig_adj = dragY * ((1.0f / tess_y) * (i+1));
lef_adj = ((lef_adj*lef_adj) / 3) * (dragY < 0 ? -1 : 1);
rig_adj = ((rig_adj*rig_adj) / 3) * (dragY < 0 ? -1 : 1);
// vertex 0
vb[idx + 0].position = Vector3f(i * qw - top_adj, j * qh - lef_adj, 0.0f);
vb[idx + 0].colour_val = c;
vb[idx + 0].tex_coords = Vector2f(i * tcx, j*tcy);
// vertex 1
vb[idx + 1].position = Vector3f(i * qw - bot_adj, j * qh + qh - lef_adj, 0.0f);
vb[idx + 1].colour_val = c;
vb[idx + 1].tex_coords = Vector2f(i*tcx, j*tcy+tcy);
// vertex 2
vb[idx + 2].position = Vector3f(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);
vb[idx + 2].colour_val = c;
vb[idx + 2].tex_coords = Vector2f(i*tcx+tcx, j*tcy+tcy);
// vertex 3
vb[idx + 3].position = Vector3f(i * qw + qw - bot_adj, j * qh + qh - rig_adj, 0.0f);
vb[idx + 3].colour_val = c;
vb[idx + 3].tex_coords = Vector2f(i*tcx+tcx, j*tcy+tcy);
// vertex 4
vb[idx + 4].position = Vector3f(i * qw + qw - top_adj, j * qh - rig_adj, 0.0f);
vb[idx + 4].colour_val = c;
vb[idx + 4].tex_coords = Vector2f(i*tcx+tcx, j*tcy);
// vertex 5
vb[idx + 5].position = Vector3f(i * qw - top_adj, j * qh - lef_adj, 0.0f);
vb[idx + 5].colour_val = c;
vb[idx + 5].tex_coords = Vector2f(i * tcx, j*tcy);
}
}
geometry.setActiveTexture(&tex);
geometry.appendGeometry(vb, buffsize);
// false, because we do not want the default geometry added!
return false;
}
//----------------------------------------------------------------------------//
bool OldWobblyWindowEffect::update(const float elapsed, CEGUI::RenderingWindow& window)
{
using namespace CEGUI;
// initialise ourself upon the first update call.
if (!initialised)
{
initialised=true;
lastX = window.getPosition().d_x;
lastY = window.getPosition().d_y;
return true;
}
const Vector2f pos(window.getPosition());
//
// Set up for X axis animation.
//
if (pos.d_x != lastX)
{
dragX += (pos.d_x - lastX) * 0.2f;
elasX = 0.05f;
lastX = pos.d_x;
if (dragX > 25)
dragX = 25;
else if (dragX < -25)
dragX = -25;
}
//
// Set up for y axis animation
//
if (pos.d_y != lastY)
{
dragY += (pos.d_y - lastY) * 0.2f;
elasY = 0.05f;
lastY = pos.d_y;
if (dragY > 25)
dragY = 25;
else if (dragY < -25)
dragY = -25;
}
//
// Perform required animation steps
//
if ((dragX != 0) || (dragY != 0))
{
if (dragX < 0)
{
dragX += (elasX * 800 * elapsed);
elasX += 0.075f * elapsed;
if (dragX >0)
dragX = 0;
}
else
{
dragX -= (elasX * 800 * elapsed);
elasX += 0.075f * elapsed;
if (dragX < 0)
dragX = 0;
}
if (dragY < 0)
{
dragY += elasY * 800 * elapsed;
elasY += 0.075f * elapsed;
if (dragY >0)
dragY = 0;
}
else
{
dragY -= elasY * 800 * elapsed;
elasY += 0.075f * elapsed;
if (dragY < 0)
dragY = 0;
}
// note we just need system to redraw the geometry; we do not need a
// full redraw of all window/widget content - which is unchanged.
d_window->getGUIContext().markAsDirty();
return false;
}
return true;
}
//----------------------------------------------------------------------------//
ElasticWindowEffect::ElasticWindowEffect(CEGUI::Window* window) :
d_initialised(false),
d_window(window)
{}
//----------------------------------------------------------------------------//
int ElasticWindowEffect::getPassCount() const
{
return 1;
}
//----------------------------------------------------------------------------//
void ElasticWindowEffect::performPreRenderFunctions(const int /*pass*/)
{
// nothing we need here
}
//----------------------------------------------------------------------------//
void ElasticWindowEffect::performPostRenderFunctions()
{
// nothing we need here
}
//----------------------------------------------------------------------------//
bool ElasticWindowEffect::realiseGeometry(CEGUI::RenderingWindow& window,
CEGUI::GeometryBuffer& geometry)
{
using namespace CEGUI;
Texture& tex = window.getTextureTarget().getTexture();
static const CEGUI::Colour c(1, 1, 1, 1);
float uvTop = window.getTextureTarget().isRenderingInverted() ? 1.0f : 0.0f;
float uvBot = window.getTextureTarget().isRenderingInverted() ? 0.0f : 1.0f;
const Vector3f windowPosition = Vector3f(window.getPosition(), 0.0f);
const Vector2f& currentTopLeft = d_currentPosition ;
const Vector2f currentBottomRight = d_currentPosition +
Vector2f(window.getSize().d_width, window.getSize().d_height);
{
// first triangle
// vertex 0 - top left
d_vertices[0].position = Vector3f(currentTopLeft, 0.0f) - windowPosition;
d_vertices[0].colour_val = c;
d_vertices[0].tex_coords = Vector2f(0.0f, uvTop);
// vertex 1 - bottom left
d_vertices[1].position = Vector3f(currentTopLeft.d_x, currentBottomRight.d_y, 0.0f) - windowPosition;
d_vertices[1].colour_val = c;
d_vertices[1].tex_coords = Vector2f(0.0f, uvBot);
// vertex 2 - bottom right
d_vertices[2].position = Vector3f(currentBottomRight, 0.0f) - windowPosition;
d_vertices[2].colour_val = c;
d_vertices[2].tex_coords = Vector2f(1.0f, uvBot);
// second triangle
// vertex 3 - bottom right
d_vertices[3].position = Vector3f(currentBottomRight, 0.0f) - windowPosition;
d_vertices[3].colour_val = c;
d_vertices[3].tex_coords = Vector2f(1.0f, uvBot);
// vertex 4 - top right
d_vertices[4].position = Vector3f(currentBottomRight.d_x, currentTopLeft.d_y, 0.0f) - windowPosition;
d_vertices[4].colour_val = c;
d_vertices[4].tex_coords = Vector2f(1.0f, uvTop);
// vertex 5 - top left
d_vertices[5].position = Vector3f(currentTopLeft, 0.0f) - windowPosition;
d_vertices[5].colour_val = c;
d_vertices[5].tex_coords = Vector2f(0.0f, uvTop);
}
geometry.setActiveTexture(&tex);
geometry.appendGeometry(d_vertices, ds_vertexCount);
// false, because we do not want the default geometry added!
return false;
}
//----------------------------------------------------------------------------//
bool ElasticWindowEffect::update(const float elapsed, CEGUI::RenderingWindow& window)
{
using namespace CEGUI;
// initialise ourself upon the first update call.
if (!d_initialised)
{
d_currentPosition = window.getPosition();
d_currentVelocity = Vector2f(0, 0);
d_initialised = true;
return true;
}
const Vector2f delta = window.getPosition() - d_currentPosition;
const float speed = 300.0f;
d_currentVelocity *= pow(0.00001f, elapsed);
d_currentVelocity += delta * (speed * elapsed);
const Vector2f old_position(d_currentPosition);
d_currentPosition += d_currentVelocity * elapsed;
const bool changed = d_currentPosition != old_position;
// note we just need system to redraw the geometry; we do not need a
// full redraw of all window/widget content - which is unchanged.
if (changed)
d_window->getGUIContext().markAsDirty();
return false;
}
//----------------------------------------------------------------------------//
// The following are for the main EffectsDemo class.
//----------------------------------------------------------------------------//
const CEGUI::String EffectsDemo::s_effectNameElastic = "ElasticWindow";
const CEGUI::String EffectsDemo::s_effectNameWobblyNew = "WobblyWindow";
const CEGUI::String EffectsDemo::s_effectNameWobblyOld = "OldWobblyWindow";
/*************************************************************************
Sample specific initialisation goes here.
*************************************************************************/
bool EffectsDemo::initialise(CEGUI::GUIContext* guiContext)
{
using namespace CEGUI;
d_usedFiles = CEGUI::String(__FILE__);
d_guiContext = guiContext;
// Register our effects with the system
RenderEffectManager::getSingleton().addEffect<ElasticWindowEffect>(s_effectNameElastic);
RenderEffectManager::getSingleton().addEffect<WobblyWindowEffect>(s_effectNameWobblyNew);
RenderEffectManager::getSingleton().addEffect<OldWobblyWindowEffect>(s_effectNameWobblyOld);
// Now we make a Falagard mapping for a frame window that uses this effect.
// We create a type "Vanilla/WobblyFrameWindow". Note that it would be
// more usual for this mapping to be specified in the scheme xml file,
// though here we are doing in manually to save from needing either multiple
// versions of the schemes or from having demo specific definitions in
// the schemes.
WindowFactoryManager::getSingleton().addFalagardWindowMapping(
"Vanilla/WobblyFrameWindow", // type to create
"CEGUI/FrameWindow", // 'base' widget type
"Vanilla/FrameWindow", // WidgetLook to use.
"Core/FrameWindow", // WindowRenderer to use.
s_effectNameWobblyNew); // effect to use.
// Since we want to be able to load the EffectsDemo.layout in the editor
// tools (where the above mapping is not available), we now alias the
// new window type onto the original TaharezLook/FrameWindow. This has
// the effect that - after the alias is added - any time a window of
// type "TaharezLook/FrameWindow" is requested, the system will create a
// "TaharezLook/WobblyFrameWindow" instead.
WindowFactoryManager::getSingleton().addWindowTypeAlias(
"Vanilla/FrameWindow", // alias name - can shadow existing types
"Vanilla/WobblyFrameWindow"); // target type to create.
// we will use of the WindowManager.
WindowManager& winMgr = WindowManager::getSingleton();
// load scheme and set up defaults
SchemeManager::getSingleton().createFromFile("TaharezLook.scheme");
SchemeManager::getSingleton().createFromFile("VanillaSkin.scheme");
guiContext->getMouseCursor().setDefaultImage("TaharezLook/MouseArrow");
// load font and setup default if not loaded via scheme
Font& defaultFont = FontManager::getSingleton().createFromFile("DejaVuSans-12.font");
// Set default font for the gui context
guiContext->setDefaultFont(&defaultFont);
// load an image to use as a background
if( !ImageManager::getSingleton().isDefined("SpaceBackgroundImage") )
ImageManager::getSingleton().addFromImageFile("SpaceBackgroundImage", "SpaceBackground.jpg");
if( !ImageManager::getSingleton().isDefined("AliasingTestImage") )
ImageManager::getSingleton().addFromImageFile("AliasingTestImage", "Aliasing.jpg");
// here we will use a StaticImage as the root, then we can use it to place a background image
Window* background = winMgr.createWindow("TaharezLook/StaticImage", "background_wnd");
// set position and size
background->setPosition(UVector2(cegui_reldim(0), cegui_reldim( 0)));
background->setSize(USize(cegui_reldim(1), cegui_reldim( 1)));
// disable frame and standard background
background->setProperty("FrameEnabled", "false");
background->setProperty("BackgroundEnabled", "false");
// set the background image
background->setProperty("Image", "SpaceBackgroundImage");
// set the background window as the root window for our GUIContext
guiContext->setRootWindow(background);
// load the windows for the EffectsDemo from the layout file.
Window* sheet = winMgr.loadLayoutFromFile("EffectsDemo.layout");
// Get the combobox created from within the layout
CEGUI::Combobox* effectsCombobox = static_cast<CEGUI::Combobox*>(sheet->getChild("EffectsFrameWindow/EffectsCombobox"));
// attach this to the 'real' root
background->addChild(sheet);
//Initialise the render effects
initialiseEffects(effectsCombobox->getParent());
// Initialise the items and subscribe the event for the combobox
initialiseEffectsCombobox(effectsCombobox);
// We can switch the automatic effects mapping off now
WindowFactoryManager::getSingleton().removeWindowTypeAlias(
"Vanilla/FrameWindow", // alias name - can shadow existing types
"Vanilla/WobblyFrameWindow"); // target type to create.
// We create a mapping for the elastic windows effect too,
// and we will apply it to a window we create from code
WindowFactoryManager::getSingleton().addFalagardWindowMapping(
"Vanilla/ElasticFrameWindow", // type to create
"CEGUI/FrameWindow", // 'base' widget type
"Vanilla/FrameWindow", // WidgetLook to use.
"Core/FrameWindow", // WindowRenderer to use.
s_effectNameElastic); // effect to use.
// We will create another window using the effects-mapping we created before, this time directly from code
CEGUI::FrameWindow* aliasingFrameWnd = static_cast<CEGUI::FrameWindow*>(
WindowManager::getSingleton().createWindow("Vanilla/ElasticFrameWindow", "AliasingTestWindow") );
// Add it to the layout root
sheet->addChild(aliasingFrameWnd);
// We will add an image to it using a StaticImage window
Window* aliasingWnd = WindowManager::getSingleton().createWindow("Vanilla/StaticImage", "AliasingTestImage");
aliasingFrameWnd->addChild(aliasingWnd);
aliasingFrameWnd->setPosition(CEGUI::UVector2(cegui_reldim(0.05f), cegui_reldim(0.15f)));
aliasingFrameWnd->setSize(CEGUI::USize(cegui_reldim(0.2f), cegui_reldim(0.28f)));
aliasingFrameWnd->setSizingEnabled(true);
aliasingFrameWnd->setCloseButtonEnabled(false);
aliasingFrameWnd->setTitleBarEnabled(true);
aliasingFrameWnd->setText("Elastic Window - Aliasing Testimage");
// Image window setup
aliasingWnd->setSize(CEGUI::USize(cegui_reldim(1.0f), cegui_reldim(1.0f)));
aliasingWnd->setProperty("FrameEnabled", "false");
aliasingWnd->setProperty("BackgroundEnabled", "false");
aliasingWnd->setProperty("Image", "AliasingTestImage");
// success!
return true;
}
/*************************************************************************
Cleans up resources allocated in the initialiseSample call.
*************************************************************************/
void EffectsDemo::deinitialise()
{
// nothing to do here!
}
/*************************************************************************
Initialises the effects ListItems for the Combobox.
*************************************************************************/
void EffectsDemo::initialiseEffectsCombobox(CEGUI::Combobox* effectsCombobox)
{
d_listItemEffectWobblyNew = new MyListItem("Wobbly Window Effect");
d_listItemEffectElastic = new MyListItem("Elastic Window Effect");
d_listItemEffectWobblyOld = new MyListItem("Old Wobbly Window Effect");
d_listItemEffectNone = new MyListItem("None");
effectsCombobox->addItem(d_listItemEffectWobblyNew);
effectsCombobox->addItem(d_listItemEffectElastic);
effectsCombobox->addItem(d_listItemEffectWobblyOld);
effectsCombobox->addItem(d_listItemEffectNone);
effectsCombobox->setItemSelectState(d_listItemEffectWobblyNew, true);
effectsCombobox->subscribeEvent(CEGUI::Combobox::EventListSelectionAccepted, CEGUI::Event::Subscriber(&EffectsDemo::handleEffectsComboboxSelectionChanged, this));
}
/*************************************************************************
Selection EventHandler for the effects Combobox.
*************************************************************************/
bool EffectsDemo::handleEffectsComboboxSelectionChanged(const CEGUI::EventArgs& args)
{
const CEGUI::WindowEventArgs& winArgs(static_cast<const CEGUI::WindowEventArgs&>(args));
CEGUI::Combobox* effectsCombobox = static_cast<CEGUI::Combobox*>(winArgs.window);
CEGUI::ListboxItem* selectionItem = effectsCombobox->getSelectedItem();
CEGUI::FrameWindow* effectsWindow = static_cast<CEGUI::FrameWindow*>(effectsCombobox->getParent());
CEGUI::RenderingWindow* effectsWindowRenderingWnd = static_cast<CEGUI::RenderingWindow*>(effectsWindow->getRenderingSurface());
if(selectionItem == d_listItemEffectElastic)
{
effectsWindowRenderingWnd->setRenderEffect(d_renderEffectElastic);
}
else if(selectionItem == d_listItemEffectWobblyNew)
{
effectsWindowRenderingWnd->setRenderEffect(d_renderEffectWobblyNew);
}
else if(selectionItem == d_listItemEffectWobblyOld)
{
effectsWindowRenderingWnd->setRenderEffect(d_renderEffectWobblyOld);
}
else
{
effectsWindowRenderingWnd->setRenderEffect(0);
}
return true;
}
void EffectsDemo::initialiseEffects(CEGUI::Window* effectsWindow)
{
d_renderEffectElastic = &CEGUI::RenderEffectManager::getSingleton().create(
s_effectNameElastic,
effectsWindow);
d_renderEffectWobblyNew = &CEGUI::RenderEffectManager::getSingleton().create(
s_effectNameWobblyNew,
effectsWindow);
d_renderEffectWobblyOld = &CEGUI::RenderEffectManager::getSingleton().create(
s_effectNameWobblyOld,
effectsWindow);
}
/*************************************************************************
Define the module function that returns an instance of the sample
*************************************************************************/
extern "C" SAMPLE_EXPORT Sample& getSampleInstance()
{
static EffectsDemo sample;
return sample;
}
|