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 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133
|
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers, whose names
* are too numerous to list here. Please refer to the COPYRIGHT
* file distributed with this source distribution.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* aint32 with this program; if not, write to the Free Software
*
*
* Based on the original sources
* Faery Tale II -- The Halls of the Dead
* (c) 1993-1996 The Wyrmkeep Entertainment Co.
*/
#include "common/events.h"
#include "saga2/saga2.h"
#include "saga2/panel.h"
#include "saga2/detection.h"
#include "saga2/fontlib.h"
#include "saga2/floating.h"
#include "saga2/display.h"
#include "saga2/gbevel.h"
namespace Saga2 {
//extern vDisplayPage *drawPage;
extern char iniFile[];
// Function to enable/disable user interface keys
extern bool enableUIKeys(bool _enabled);
/* ======================================================================= *
global dispatcher base
* ======================================================================= */
gDisplayPort *globalPort;
gFont *mainFont;
// UI locking feature, currently kludged it could get better later.
int lockUINest = 0;
/* ======================================================================= *
gPanel member functions
* ======================================================================= */
gPanel::gPanel(gWindow &win, const Rect16 &box, AppFunc *cmd)
: _window(win), _extent(box), _command(cmd) {
_enabled = 1;
_ghosted = 0;
_selected = 0;
_imageLabel = 0;
_title = nullptr;
_id = 0;
_wantMousePoll = 0;
_userData = nullptr;
}
gPanel::gPanel(gPanelList &list, const Rect16 &box,
const char *newTitle, uint16 ident, AppFunc *cmd)
: _window(list._window) {
_title = newTitle;
_extent = box;
_enabled = 1;
_ghosted = 0;
_selected = 0;
_imageLabel = 0;
_command = cmd;
_id = ident;
_wantMousePoll = 0;
_userData = nullptr;
}
gPanel::gPanel(gPanelList &list, const Rect16 &box,
gPixelMap &pic, uint16 ident, AppFunc *cmd)
: _window(list._window) {
_title = (char *)&pic;
_extent = box;
_enabled = 1;
_ghosted = 0;
_selected = 0;
_imageLabel = 1;
_command = cmd;
_id = ident;
_wantMousePoll = 0;
_userData = nullptr;
}
gPanel::gPanel(gPanelList &list, const StaticRect &box,
const char *newTitle, uint16 ident, AppFunc *cmd)
: _window(list._window) {
_title = newTitle;
_extent = Rect16(box);
_enabled = 1;
_ghosted = 0;
_selected = 0;
_imageLabel = 0;
_command = cmd;
_id = ident;
_wantMousePoll = 0;
_userData = nullptr;
}
// Dummy virtual functions
gPanel::~gPanel() {
if (this == g_vm->_toolBase->_mousePanel)
g_vm->_toolBase->_mousePanel = nullptr;
if (this == g_vm->_toolBase->_activePanel)
g_vm->_toolBase->_activePanel = nullptr;
}
void gPanel::draw() {}
void gPanel::drawClipped(gPort &, const Point16 &, const Rect16 &) {}
void gPanel::pointerMove(gPanelMessage &) {}
bool gPanel::pointerHit(gPanelMessage &) {
return false;
}
bool gPanel::pointerRHit(gPanelMessage &) {
return false;
}
void gPanel::pointerDrag(gPanelMessage &) {}
void gPanel::pointerRelease(gPanelMessage &) {}
bool gPanel::keyStroke(gPanelMessage &) {
return false;
}
void gPanel::timerTick(gPanelMessage &) {}
void gPanel::onMouseHintDelay() {}
void gPanel::enable(bool abled) {
_enabled = abled ? 1 : 0;
}
void gPanel::select(uint16 sel) {
_selected = sel ? 1 : 0;
}
void gPanel::ghost(bool b) {
_ghosted = b ? 1 : 0;
}
bool gPanel::isActive() {
return (this == g_vm->_toolBase->_activePanel);
}
void gPanel::notify(gEventType type, int32 value) {
gEvent ev;
ev.panel = this;
ev.eventType = type;
ev.value = value;
ev.mouse.x = g_vm->_toolBase->_pickPos.x - _extent.x;
ev.mouse.y = g_vm->_toolBase->_pickPos.y - _extent.y;
ev.window = &_window;
if (_command) _command(ev);
else if (this != &_window) _window.notify(ev);
}
bool gPanel::activate(gEventType) {
return false;
}
void gPanel::deactivate() {
if (isActive()) g_vm->_toolBase->_activePanel = nullptr;
}
void gPanel::makeActive() {
g_vm->_toolBase->setActive(this);
}
void gPanel::invalidate(Rect16 *) {
assert(displayEnabled());
_window.update(_extent);
}
void gPanel::drawTitle(TextPositions placement) {
gPort &port = _window._windowPort;
Rect16 r = _extent;
const gPixelMap *img = nullptr;
if (_title == nullptr)
return;
if (_imageLabel) {
img = (const gPixelMap *)_title;
r.width = img->_size.x;
r.height = img->_size.y;
} else {
r.width = TextWidth(mainFont, _title, -1, kTextStyleUnderBar);
r.height = mainFont->height;
}
switch (placement) {
case kTextPosLeft:
r.x -= r.width + 2;
r.y += (_extent.height - r.height) / 2 + 1;
break;
case kTextPosRight:
r.x += _extent.width + 3;
r.y += (_extent.height - r.height) / 2 + 1;
break;
case kTextPosHigh:
r.x += (_extent.width - r.width) / 2;
r.y -= r.height + 1;
break;
case kTextPosLow:
r.x += (_extent.width - r.width) / 2;
r.y += _extent.height + 2;
break;
default:
r.x += (_extent.width - r.width) / 2;
r.y += (_extent.height - r.height) / 2;
break;
}
SAVE_GPORT_STATE(port); // save pen color, etc.
if (_imageLabel) {
port.setIndirectColor(kBlackPen); // pen color black
port.setMode(kDrawModeColor); // draw as glyph
port.bltPixels(*img, 0, 0, r.x, r.y, r.width, r.height);
} else {
port.setMode(kDrawModeMatte); // draw as glyph
port.setIndirectColor(kBlackPen); // pen color black
port.setStyle(kTextStyleUnderBar); // set style to do underbars
port.moveTo(r.x, r.y); // move to new text pos
g_vm->_pointer->hide(*globalPort, r); // hide the pointer
port.drawText(_title, -1); // draw the text
g_vm->_pointer->show(*globalPort, r); // hide the pointer
}
}
gPanel *gPanel::hitTest(const Point16 &p) {
return _enabled && !_ghosted && _extent.ptInside(p) ? this : nullptr;
}
gPanel *gPanel::keyTest(int16) {
return nullptr;
}
/* ===================================================================== *
gPanelList class: A context for holding panels.
* ===================================================================== */
// Constructor which is called from window subclass
gPanelList::gPanelList(gWindow &win, const Rect16 &box, char *newTitle,
uint16 ident, AppFunc *cmd)
: gPanel(win, box, cmd) {
_title = newTitle;
_id = ident;
}
// Constructor for standalone panels..
gPanelList::gPanelList(gPanelList &list)
: gPanel(list, list._window.getExtent(), nullptr, 0, nullptr) {
_window._contents.push_back(this);
}
gPanelList::~gPanelList() {
removeControls();
_window._contents.remove(this);
}
void gPanelList::removeControls() {
gPanel *ctl;
// Delete all sub-panels.
while (_contents.size()) {
ctl = _contents.front();
_contents.remove(ctl);
delete ctl;
}
}
// enable/disable gPanelList and all it's children
void gPanelList::enable(bool abled) {
gPanel::enable(abled);
}
void gPanelList::invalidate(Rect16 *) {
gPanel *ctl;
Rect16 invArea;
assert(displayEnabled());
if (displayEnabled())
if (_contents.size()) {
ctl = _contents.back();
invArea = ctl->getExtent();
for (Common::List<gPanel *>::iterator it = _contents.reverse_begin(); it != _contents.end(); --it) {
ctl = *it;
invArea = bound(invArea, ctl->getExtent());
}
_window.update(invArea);
}
}
void gPanelList::draw() {
gPanel *ctl;
if (displayEnabled())
if (_enabled) {
for (Common::List<gPanel *>::iterator it = _contents.reverse_begin(); it != _contents.end(); --it) {
ctl = *it;
if (ctl->getEnabled())
ctl->draw();
}
}
}
void gPanelList::drawClipped(
gPort &port,
const Point16 &offset,
const Rect16 &r) {
gPanel *ctl;
Point16 tmpOffset = offset - Point16(_extent.x, _extent.y);
Rect16 tmpR = r - Point16(_extent.x, _extent.y);
if (displayEnabled())
if (_enabled) {
for (Common::List<gPanel *>::iterator it = _contents.reverse_begin(); it != _contents.end(); --it) {
ctl = *it;
if (ctl->getEnabled())
ctl->drawClipped(port, tmpOffset, tmpR);
}
}
}
gPanel *gPanelList::hitTest(const Point16 &p) {
gPanel *ctl;
gPanel *result;
if (_enabled && !_ghosted) {
for (Common::List<gPanel *>::iterator it = _contents.begin(); it != _contents.end(); ++it) {
ctl = *it;
if ((result = ctl->hitTest(p)) != nullptr)
return result;
}
}
return nullptr;
}
gPanel *gPanelList::keyTest(int16 key) {
gPanel *ctl;
gPanel *result;
if (_enabled && !_ghosted) {
for (Common::List<gPanel *>::iterator it = _contents.reverse_begin(); it != _contents.end(); --it) {
ctl = *it;
if ((result = ctl->keyTest(key)) != nullptr)
return result;
}
}
return nullptr;
}
/* ===================================================================== *
gWindow class: A panel list plus a drawing port.
* ===================================================================== */
// gWindow static variables
int gWindow::_dragMode = 0; // current dragging mode
StaticRect gWindow::_dragExtent = {0, 0, 0, 0}; // dragging extent
StaticPoint16 gWindow::_dragOffset = {0, 0}; // offset to window origin
gWindow::gWindow(const Rect16 &box, uint16 ident, const char saveName[], AppFunc *cmd)
: gPanelList(*this, box, nullptr, ident, cmd) {
//, saver(WIIFF_POS|WIIFS_NORMAL|WIIFE_ONEXIT,iniFile,saveName,box,this)
_openFlag = false;
// pointerImage = &arrowPtr;
// pointerOffset = Point16( 0, 0 );
// Set up the window feature bits
// windowFeatures = features;
// Set up the window's gPort
_windowPort.setFont(mainFont);
_windowPort.setPenMap(globalPort->_penMap);
/* if (windowFeatures & windowBackSaved) // backsave data under window
{
backSave = NEW_UI gBackSave( box );
// rem: if backsave fails, then what?
}
else backSave = NULL;
*/
// Set the window position.
setPos(Point16(box.x, box.y));
}
gWindow::~gWindow() {
// gControl *ctl;
if (isOpen()) close();
// Delete all sub-panels.
// while ( (ctl = (gControl *)contents.remHead()) != NULL )
// delete ctl;
// delete backSave;
}
bool gWindow::open() {
if (isOpen()) return true;
// Send a "pointer-leave" message to mouse panel.
g_vm->_toolBase->leavePanel();
g_vm->_toolBase->_windowList.push_front(this);
g_vm->_toolBase->_activeWindow = this;
g_vm->_toolBase->setActive(nullptr);
// g_vm->_pointer->hide();
// if (backSave) backSave->save( *globalPort );
// g_vm->_pointer->setImage( *pointerImage, pointerOffset.x, pointerOffset.y );
// g_vm->_pointer->show();
_openFlag = true;
draw();
return true;
}
void gWindow::close() {
//saver.onExit(this);
if (!isOpen()) return;
// If any panels on this window are active, then deactivate them.
if (g_vm->_toolBase->_activePanel && g_vm->_toolBase->_activePanel->getWindow() == this)
g_vm->_toolBase->_activePanel->deactivate();
// Don't close a window that is being dragged (should never happen,
// but just in case).
if (DragBar::_dragWindow == (FloatingWindow *)this)
return;
_openFlag = false;
// remove this window from the window list.
g_vm->_toolBase->_windowList.remove(this);
g_vm->_toolBase->_mouseWindow = g_vm->_toolBase->_activeWindow = g_vm->_toolBase->_windowList.front();
g_vm->_toolBase->_mousePanel = g_vm->_toolBase->_activePanel = nullptr;
}
// Move the window to the front...
void gWindow::toFront() { // re-order the windows
if (!isOpen()) return;
g_vm->_toolBase->_windowList.remove(this);
g_vm->_toolBase->_windowList.push_front(this);
g_vm->_toolBase->_activePanel = nullptr;
g_vm->_toolBase->_activeWindow = this;
// redraw the window
update(_extent);
}
bool gWindow::isModal() {
return false;
}
void gWindow::setPos(Point16 pos) {
Rect16 newClip;
_extent.x = pos.x;
_extent.y = pos.y;
// int16 titleHeight = mainFont->height + 5;
// We also need to set up the window's port in a similar fashion.
_windowPort._origin.x = _extent.x;
_windowPort._origin.y = _extent.y;
// set port's clip
newClip = intersect(_extent, g_vm->_mainPort._clip);
newClip.x -= _extent.x;
newClip.y -= _extent.y;
_windowPort.setClip(newClip);
//saver.onMove(this);
// if (backSave) backSave->setPos( pos );
}
void gWindow::setExtent(const Rect16 &r) {
_extent.width = r.width;
_extent.height = r.height;
//saver.onSize(this);
setPos(Point16(r.x, r.y));
}
// insert window into window list
void gWindow::insert() {
g_vm->_toolBase->_windowList.push_front(this);
}
// REM: Need to either adjuct coords when we draw OR
// redefine the address of the pixel map.
void gWindow::deactivate() {
_selected = 0;
gPanel::deactivate();
}
bool gWindow::activate(gEventType why) {
if (why == kEventMouseDown) { // momentarily depress
_selected = 1;
notify(why, 0); // notify App of successful hit
return true;
}
return false;
}
void gWindow::pointerMove(gPanelMessage &) {
notify(kEventMouseMove, 0);
}
bool gWindow::pointerHit(gPanelMessage &) {
activate(kEventMouseDown);
return true;
}
void gWindow::pointerDrag(gPanelMessage &) {
if (_selected) {
notify(kEventMouseDrag, 0);
}
}
void gWindow::pointerRelease(gPanelMessage &) {
if (_selected) notify(kEventMouseUp, 0); // notify App of successful hit
deactivate();
}
void gWindow::draw() {
if (displayEnabled())
gPanelList::draw();
}
void gWindow::drawClipped(
gPort &port,
const Point16 &offset,
const Rect16 &r) {
if (displayEnabled())
gPanelList::drawClipped(port, offset, r);
}
void gWindow::enable(bool abled) {
gPanel::enable(abled);
draw();
}
void gWindow::select(uint16 sel) {
gPanel::select(sel);
draw();
}
/*
void gWindow::setPointer( gPixelMap &map, int x, int y )
{
pointerImage = ↦
pointerOffset.x = x;
pointerOffset.y = y;
if (this == g_vm->_toolBase->_activeWindow)
{
g_vm->_pointer->hide();
g_vm->_pointer->setImage( *pointerImage, pointerOffset.x, pointerOffset.y );
g_vm->_pointer->show();
}
}
*/
/* ===================================================================== *
gControl class: The basis for buttons and other controls.
* ===================================================================== */
gControl::gControl(gPanelList &list, const Rect16 &box, const char *title_, uint16 ident,
AppFunc *cmd) : gPanel(list, box, title_, ident, cmd) {
_accelKey = 0;
// Add control to the window's control list.
_list = &list;
list._contents.push_back(this);
}
gControl::gControl(gPanelList &list, const Rect16 &box, gPixelMap &img, uint16 ident,
AppFunc *cmd) : gPanel(list, box, img, ident, cmd) {
_accelKey = 0;
// Add control to the window's control list.
_list = &list;
list._contents.push_back(this);
}
gControl::~gControl() {
_list->_contents.remove(this);
}
gControl::gControl(gPanelList &list, const StaticRect &box, const char *title_, uint16 ident,
AppFunc *cmd) : gPanel(list, box, title_, ident, cmd) {
_accelKey = 0;
// Add control to the window's control list.
_list = &list;
list._contents.push_back(this);
}
void gControl::enable(bool abled) {
if (!abled != !getEnabled()) { // Use '!' to insure boolean-ness
gPanel::enable(abled);
invalidate();
}
}
void gControl::select(uint16 sel) {
if (!sel != !isSelected()) { // Use '!' to insure boolean-ness
gPanel::select(sel);
invalidate();
}
}
void gControl::ghost(bool sel) {
if (!sel != !isGhosted()) { // Use '!' to insure boolean-ness
gPanel::ghost(sel);
invalidate();
}
}
gPanel *gControl::keyTest(int16 key) {
return _accelKey == key ? this : nullptr;
}
// For many controls, the only drawing routine we need is the
// "clipped" one, and the normal draw routine just calls
// drawClipped with the main port.
void gControl::draw() {
g_vm->_pointer->hide(_window._windowPort, _extent);
if (displayEnabled())
drawClipped(*globalPort,
Point16(-_window._extent.x, -_window._extent.y),
_window._extent);
g_vm->_pointer->show(_window._windowPort, _extent);
}
/* ===================================================================== *
gGenericControl class: A generic button that notifies everything
* ===================================================================== */
gGenericControl::gGenericControl(gPanelList &list, const Rect16 &box,
uint16 ident, AppFunc *cmd)
: gControl(list, box, nullptr, ident, cmd) {
_dblClickFlag = false;
}
bool gGenericControl::activate(gEventType) {
_selected = 1;
return true;
}
void gGenericControl::deactivate() {
_selected = 0;
gPanel::deactivate();
}
void gGenericControl::pointerMove(gPanelMessage &msg) {
notify(kEventMouseMove, (msg._pointerEnter ? kCVEnter : 0) | (msg._pointerLeave ? kCVLeave : 0));
}
bool gGenericControl::pointerHit(gPanelMessage &msg) {
if (msg._rightButton)
notify(kEventRMouseDown, 0);
else if (msg._doubleClick && !_dblClickFlag) {
_dblClickFlag = true;
notify(kEventDoubleClick, 0);
} else {
_dblClickFlag = false;
notify(kEventMouseDown, 0);
}
return true;
}
void gGenericControl::pointerDrag(gPanelMessage &) {
notify(kEventMouseDrag, 0);
}
void gGenericControl::pointerRelease(gPanelMessage &) {
notify(kEventMouseUp, 0);
deactivate();
}
// Generic control has no rendering code.
void gGenericControl::draw() {
}
/* ===================================================================== *
class gToolBase: Global dispatcher for events
* ===================================================================== */
void gToolBase::setActive(gPanel *ctl) {
if (_activePanel && _activePanel == ctl) return;
if (_activePanel) _activePanel->deactivate();
if (ctl == nullptr || ctl->activate(kEventNone)) _activePanel = ctl;
}
void gToolBase::handleMouse(Common::Event &event, uint32 time) {
gWindow *w = _activeWindow;
gPanel *ctl,
*pickPanel = nullptr;
static gMouseState prevState;
static int32 lastClickTime = 0x8000;
static Point16 lastClickPos;
// Emulate mouse state for now
switch (event.type) {
case Common::EVENT_LBUTTONDOWN:
_curMouseState.left = true;
break;
case Common::EVENT_RBUTTONDOWN:
_curMouseState.right = true;
break;
case Common::EVENT_LBUTTONUP:
_curMouseState.left = false;
break;
case Common::EVENT_RBUTTONUP:
_curMouseState.right = false;
break;
case Common::EVENT_MOUSEMOVE:
_curMouseState.pos.x = event.mouse.x;
_curMouseState.pos.y = event.mouse.y;
g_vm->_pointer->move(Point16(_curMouseState.pos.x, _curMouseState.pos.y));
break;
default:
break;
}
// Do nothing if UI locked.
if (lockUINest > 0)
return;
if (g_vm->getGameId() == GID_DINO && _curMouseState.right) {
cycleCursor();
return;
}
// Code for "Tool tip delay"
if (prevState.pos != _curMouseState.pos
&& prevState.left != _curMouseState.left
&& prevState.right != _curMouseState.right) {
_lastMouseMoveTime = _msg._timeStamp;
if (_mouseHintSet)
setMouseTextF(nullptr);
}
// If there is no active window, then do nothing.
if (w == nullptr) {
prevState = _curMouseState;
return;
}
// Set up the pick position relative to the window
if (_activePanel) {
_pickPos.x = _curMouseState.pos.x - _activePanel->_window._extent.x;
_pickPos.y = _curMouseState.pos.y - _activePanel->_window._extent.y;
} else {
_pickPos.x = _curMouseState.pos.x - w->_extent.x;
_pickPos.y = _curMouseState.pos.y - w->_extent.y;
}
// Fill in the message to be sent to the various panels
_msg._pickAbsPos = _pickPos;
_msg._leftButton = _curMouseState.left ? 1 : 0;
_msg._rightButton = _curMouseState.right ? 1 : 0;
_msg._pointerEnter = 0;
_msg._pointerLeave = 0;
_msg._doubleClick = 0;
_msg._timeStamp = time;
if (((_curMouseState.left && !_leftDrag) // if left button hit
|| (_curMouseState.right && !_rightDrag)) // or right button hit
&& _activePanel != nullptr) { // and a panel is active
// Then we have a button hit event. If the button hit
// is occurring outside the panel, then it should be
// de_selected.
if (_activePanel->_extent.ptInside(_pickPos) == false)
_activePanel->deactivate();
}
if (prevState.pos == _curMouseState.pos) ; // don't do anything if same pos
else if (_activePanel) { // if control active
_mousePanel = _activePanel; // assume mouse over active panel
if (_leftDrag || _rightDrag) {
setMsg(_msg, _activePanel); // set up gPanelMessage
_activePanel->pointerDrag(_msg); // send panel a mouse movement
} else {
setMsg(_msg, _activePanel); // set up gPanelMessage
_activePanel->pointerMove(_msg); // send panel a mouse movement
}
}
if (!_activePanel /* && !ms.right */) {
// If the point is within the window
Common::List<gWindow *>::iterator it;
for (it = _windowList.begin(); it != _windowList.end(); ++it) {
w = *it;
if (w->_extent.ptInside(_curMouseState.pos) || w->isModal()) {
// Set up the pick position relative to the window
_pickPos.x = _curMouseState.pos.x - w->_extent.x;
_pickPos.y = _curMouseState.pos.y - w->_extent.y;
if ((ctl = w->hitTest(_pickPos)) != nullptr)
pickPanel = ctl;
else
pickPanel = w;
break;
}
}
if (it == _windowList.end()) {
prevState = _curMouseState;
return;
}
_mouseWindow = w;
// If the mouse is not over the control any more, tell it so.
if (_mousePanel && _mousePanel != pickPanel) {
if (&_mousePanel->_window != w) {
// Temporarily adjust _pickPos to be relative to the old panel's window
// instead of the new panel's window.
_pickPos.x = _curMouseState.pos.x - _mousePanel->_window._extent.x;
_pickPos.y = _curMouseState.pos.y - _mousePanel->_window._extent.y;
setMsgQ(_msg, _mousePanel); // set up gPanelMessage
_pickPos.x = _curMouseState.pos.x - w->_extent.x;
_pickPos.y = _curMouseState.pos.y - w->_extent.y;
} else {
setMsgQ(_msg, _mousePanel); // set up gPanelMessage
}
// _msg._pickPos.x = _pickPos.x - _mousePanel->extent.x;
// _msg._pickPos.y = _pickPos.y - _mousePanel->extent.y;
_msg._inPanel = 0;
_msg._pointerEnter = 0;
_msg._pointerLeave = 1;
_mousePanel->pointerMove(_msg);
}
// If the mouse is over a new control, make that the current
// mouse control.
if (pickPanel) {
setMsg(_msg, pickPanel); // set up gPanelMessage
// _msg._pickPos.x = _pickPos.x - pickPanel->extent.x;
// _msg._pickPos.y = _pickPos.y - pickPanel->extent.y;
_msg._leftButton = _curMouseState.left ? 1 : 0;
// _msg._inPanel = pickPanel->extent.ptInside(_pickPos);
_msg._pointerEnter = (_mousePanel == pickPanel) ? 0 : 1;
_msg._pointerLeave = 0;
_mousePanel = pickPanel;
_mousePanel->pointerMove(_msg);
} else
_mousePanel = nullptr;
}
// Fix up flags because earlier code may have changed them
_msg._pointerEnter = 0;
_msg._pointerLeave = 0;
// Send appropriate button-press messages to the panels
if (prevState.left != _curMouseState.left // if buttons changed state
|| prevState.right != _curMouseState.right) {
// If both buttons were previously up, then a mouse
// hit must have occurred.
if (prevState.left == 0 && prevState.right == 0) {
// Check for mouse double-click. Check to see that
// the elapsed time from the last click is less than
// 1/3 of a second, and that the mouse ptr hasn't moved
// very much.
if (((uint32)(_msg._timeStamp - lastClickTime) < 333)
|| _curMouseState.left > 1
|| _curMouseState.right > 1) {
Point16 diff = lastClickPos - _curMouseState.pos;
if (ABS(diff.x) + ABS(diff.y) < 6)
_msg._doubleClick = 1;
}
// Record the last mouse time and position for
// future double-click checks.
lastClickTime = _msg._timeStamp;
lastClickPos = _curMouseState.pos;
if (_mousePanel) { // if over a control
setMsgQ(_msg, _mousePanel); // set up gPanelMessage
// _msg._pickPos.x = _pickPos.x - _mousePanel->extent.x;
// _msg._pickPos.y = _pickPos.y - _mousePanel->extent.y;
_msg._inPanel = 1;
if (_activeWindow && _activeWindow->isModal()) {
_mouseWindow = _activeWindow;
} else if (_mouseWindow == nullptr) {
_mouseWindow = &_mousePanel->_window;
}
if (_mouseWindow && _mouseWindow != _activeWindow) {
_msg._pickAbsPos = _pickPos;
// Re-order the windows.
_mouseWindow->toFront();
}
// send it a hit message
if (_mousePanel->pointerHit(_msg)) {
_activePanel = _mousePanel;
if (_curMouseState.left)
_leftDrag = true;
else
_rightDrag = true;
}
}
} else if ((_leftDrag && _curMouseState.left == false) // check for release
|| (_rightDrag && _curMouseState.right == false)) {
if (_activePanel && _mousePanel) { // if a control is active
setMsg(_msg, _mousePanel); // send it a release message
_mousePanel->pointerRelease(_msg);
}
_leftDrag = _rightDrag = false;
}
}
prevState = _curMouseState;
}
void gToolBase::leavePanel() {
_msg._timeStamp = g_system->getMillis();
if (_mousePanel) {
_msg._inPanel = 0;
_msg._pointerEnter = 0;
_msg._pointerLeave = 1;
_mousePanel->pointerMove(_msg);
_mousePanel = nullptr;
}
if (_activePanel) _activePanel->deactivate();
}
void gToolBase::handleKeyStroke(Common::Event &event) {
gWindow *w = _activeWindow;
gPanel *ctl;
uint16 key = event.kbd.ascii; // FIXME
uint16 qualifier = 0;
if (event.kbd.flags & Common::KBD_SHIFT)
qualifier |= kQualifierShift;
if (event.kbd.flags & Common::KBD_CTRL)
qualifier |= kQualifierControl;
if (event.kbd.flags & Common::KBD_ALT)
qualifier |= kQualifierAlt;
_msg._pickAbsPos = _pickPos;
_msg._pointerEnter = 0;
_msg._pointerLeave = 0;
_msg._key = key;
_msg._qualifier = qualifier;
_msg._timeStamp = g_system->getMillis();
if (_activePanel) { // send keystroke to active panel
setMsg(_msg, _activePanel); // set up gPanelMessage
if (_activePanel->keyStroke(_msg))
return;
}
// Now, search the contents of the window for a control with
// the correct accelerator key
if (w) {
uint16 k = key;
//uint8 k = key & 0xff;
if (k != 0) {
k = toupper(k);
if ((ctl = w->keyTest(k)) != nullptr) {
if (_activePanel == ctl) return;
if (_activePanel) _activePanel->deactivate();
if (ctl->activate(kEventKeyDown)) {
_activePanel = ctl;
return;
}
}
}
// Try sending the message to the window
if (w->keyStroke(_msg))
return;
// else send the message to the app.
w->notify(kEventKeyDown, (qualifier << 16) | key);
}
}
void gToolBase::handleTimerTick(int32 tick) {
_msg._pickAbsPos = _pickPos;
_msg._pointerEnter = 0;
_msg._pointerLeave = 0;
_msg._timeStamp = tick;
if (_activePanel) { // send keystroke to active panel
setMsg(_msg, _activePanel); // set up gPanelMessage
_activePanel->timerTick(_msg);
} else if (_mousePanel) {
if (_mousePanel->_wantMousePoll) {
setMsg(_msg, _mousePanel); // set up gPanelMessage
_mousePanel->pointerMove(_msg);
} else if (!_mouseHintSet
&& ((uint32)(tick - _lastMouseMoveTime) > 500)) {
_mousePanel->onMouseHintDelay();
}
}
}
void HandleTimerTick(long tick) {
static int32 lastTick;
if (tick - lastTick > 1) {
lastTick = tick;
g_vm->_toolBase->handleTimerTick(tick);
}
}
/* ===================================================================== *
Code to initialize the panel system
* ===================================================================== */
void initPanels(gDisplayPort &port) {
globalPort = &port;
mainFont = &Helv11Font;
}
void cleanupPanels() {
}
int16 leftButtonState() {
return g_vm->_toolBase->_msg._leftButton;
}
int16 rightButtonState() {
return g_vm->_toolBase->_msg._rightButton;
}
void LockUI(bool state) {
if (state == true) {
if (lockUINest <= 0) {
g_vm->_pointer->hide();
enableUIKeys(false);
g_vm->_toolBase->setActive(nullptr);
}
lockUINest++;
} else {
lockUINest--;
assert(lockUINest >= 0);
if (lockUINest <= 0) {
enableUIKeys(true);
g_vm->_pointer->show();
}
}
}
void dumpGBASE(char *msg) {
}
} // end of namespace Saga2
|