| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- /*
- ** Command & Conquer Generals Zero Hour(tm)
- ** Copyright 2025 Electronic Arts Inc.
- **
- ** 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
- ** along with this program. If not, see <http://www.gnu.org/licenses/>.
- */
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // (c) 2001-2003 Electronic Arts Inc. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- // FILE: VerticalSlider.cpp ///////////////////////////////////////////////////
- //-----------------------------------------------------------------------------
- //
- // Westwood Studios Pacific.
- //
- // Confidential Information
- // Copyright (C) 2001 - All Rights Reserved
- //
- //-----------------------------------------------------------------------------
- //
- // Project: RTS3
- //
- // File name: VerticalSlider.cpp
- //
- // Created: Colin Day, June 2001
- //
- // Desc: Vertical slider gui control
- //
- //-----------------------------------------------------------------------------
- ///////////////////////////////////////////////////////////////////////////////
- // SYSTEM INCLUDES ////////////////////////////////////////////////////////////
- #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
- // USER INCLUDES //////////////////////////////////////////////////////////////
- #include "Common/Language.h"
- #include "Gameclient/GameWindowManager.h"
- #include "GameClient/Gadget.h"
- // DEFINES ////////////////////////////////////////////////////////////////////
- // PRIVATE TYPES //////////////////////////////////////////////////////////////
- // PRIVATE DATA ///////////////////////////////////////////////////////////////
- // PUBLIC DATA ////////////////////////////////////////////////////////////////
- // PRIVATE PROTOTYPES /////////////////////////////////////////////////////////
- // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
- ///////////////////////////////////////////////////////////////////////////////
- #ifdef _INTERNAL
- // for occasional debugging...
- //#pragma optimize("", off)
- //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
- #endif
- // GadgetVerticlaSliderInput ==================================================
- /** Handle input for vertical slider */
- //=============================================================================
- WindowMsgHandledType GadgetVerticalSliderInput( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- SliderData *s = (SliderData *)window->winGetUserData();
- WinInstanceData *instData = window->winGetInstanceData();
- switch( msg )
- {
- // ------------------------------------------------------------------------
- case GWM_MOUSE_ENTERING:
- if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
- {
- BitSet( instData->m_state, WIN_STATE_HILITED );
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GBM_MOUSE_ENTERING,
- (WindowMsgData)window,
- 0 );
- //TheWindowManager->winSetFocus( window );
- }
- break;
- // ------------------------------------------------------------------------
- case GWM_MOUSE_LEAVING:
- if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
- {
- BitClear( instData->m_state, WIN_STATE_HILITED );
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GBM_MOUSE_LEAVING,
- (WindowMsgData)window,
- 0 );
- }
- break;
- // ------------------------------------------------------------------------
- case GWM_LEFT_DRAG:
- if( BitTest( instData->getStyle(), GWS_MOUSE_TRACK ) )
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GGM_LEFT_DRAG,
- (WindowMsgData)window,
- mData1 );
- break;
- // ------------------------------------------------------------------------
- case GWM_LEFT_DOWN:
- break;
- // ------------------------------------------------------------------------
- case GWM_LEFT_UP:
- {
- Int x, y;
- // Int mousex = mData1 & 0xFFFF;
- Int mousey = mData1 >> 16;
- ICoord2D size, childSize, childCenter;
- GameWindow *child = window->winGetChild();
- Int pageClickSize, clickPos;
- window->winGetScreenPosition( &x, &y );
- window->winGetSize( &size.x, &size.y );
- child->winGetSize( &childSize.x, &childSize.y );
- child->winGetPosition( &childCenter.x, &childCenter.y );
- childCenter.x += childSize.x / 2;
- childCenter.y += childSize.y / 2;
- //
- // when you click on the slider, but not the button, we will jump
- // the slider position up/down by this much
- //
- pageClickSize = size.y / 5;
- clickPos = mousey - y;
- if( clickPos >= childCenter.y )
- {
- clickPos = childCenter.y + pageClickSize;
- if( clickPos > mousey - y )
- clickPos = mousey - y;
- } // end if
- else
- {
- clickPos = childCenter.y - pageClickSize;
- if( clickPos < mousey - y )
- clickPos = mousey - y;
- } // end else
- // keep pos valid on window
- if( clickPos > y + size.y - childSize.y / 2 )
- clickPos = y + size.y - childSize.y / 2;
- if( clickPos < childSize.y / 2 )
- clickPos = childSize.y / 2;
- child->winSetPosition( 0, clickPos - childSize.y / 2 );
- TheWindowManager->winSendSystemMsg( window, GGM_LEFT_DRAG, 0, mData1 );
- break;
- }
- // ------------------------------------------------------------------------
- case GWM_CHAR:
- {
- switch (mData1)
- {
- // --------------------------------------------------------------------
- case KEY_UP:
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- {
- if( s->position < s->maxVal - 1)
- {
- GameWindow *child = window->winGetChild();
- s->position += 2;
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_TRACK,
- (WindowMsgData)window,
- s->position );
- // Translate to window coords
- child->winSetPosition( 0, (Int)((s->maxVal - s->position) * s->numTicks) );
- }
- }
- break;
- // --------------------------------------------------------------------
- case KEY_DOWN:
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- {
- if( s->position > s->minVal + 1 )
- {
- GameWindow *child = window->winGetChild();
- s->position -= 2;
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_TRACK,
- (WindowMsgData)window,
- s->position );
- // Translate to window coords
- child->winSetPosition( 0, (Int)((s->maxVal - s->position) * s->numTicks) );
- }
- }
- break;
- // --------------------------------------------------------------------
- case KEY_RIGHT:
- case KEY_TAB:
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- window->winNextTab();
- break;
- // --------------------------------------------------------------------
- case KEY_LEFT:
- if( BitTest( mData2, KEY_STATE_DOWN ) )
- window->winPrevTab();
- break;
- default:
- return MSG_IGNORED;
- } // end switch( mData1 )
- break;
- } // end char
- default:
- return MSG_IGNORED;
- } // end switch( msg )
- return MSG_HANDLED;
- } // end GadgetVerticalSliderInput
- // GadgetVerticalSliderSystem =================================================
- /** Handle system messages for vertical slider */
- //=============================================================================
- WindowMsgHandledType GadgetVerticalSliderSystem( GameWindow *window, UnsignedInt msg,
- WindowMsgData mData1, WindowMsgData mData2 )
- {
- SliderData *s = (SliderData *)window->winGetUserData();
- WinInstanceData *instData = window->winGetInstanceData();
- switch( msg )
- {
- // ------------------------------------------------------------------------
- case GBM_SELECTED:
- {
- // tell owner I've finished moving
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_DONE,
- (WindowMsgData)window,
- s->position );
- break;
- }
- // ------------------------------------------------------------------------
- case GGM_LEFT_DRAG:
- {
- // Int mousex = mData2 & 0xFFFF;
- Int mousey = mData2 >> 16;
- Int x, y, delta;
- ICoord2D size, childSize, childCenter;
- GameWindow *child = window->winGetChild();
- window->winGetScreenPosition( &x, &y );
- window->winGetSize( &size.x, &size.y );
- child->winGetSize( &childSize.x, &childSize.y );
- child->winGetScreenPosition( &childCenter.x, &childCenter.y );
- childCenter.x += childSize.x / 2;
- childCenter.y += childSize.y / 2;
- //
- // ignore drag attempts when the mouse is below or above the slider totally
- // and put the dragging thumb back at the slider pos
- //
- if( mousey > y + size.y )
- {
- //s->position = s->minVal;
- TheWindowManager->winSendSystemMsg( window, GSM_SET_SLIDER,
- s->minVal, 0 );
- // tell owner i moved
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_TRACK,
- (WindowMsgData)window,
- s->position );
- break;
-
- } // end if
- else if( mousey < y )
- {
- //s->position = s->maxVal;
- TheWindowManager->winSendSystemMsg( window, GSM_SET_SLIDER,
- s->maxVal, 0 );
- // tell owner i moved
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_TRACK,
- (WindowMsgData)window,
- s->position );
- break;
- } // end else if
- if( childCenter.y <= y + childSize.y / 2 )
- {
- child->winSetPosition( 0, 0 );
- s->position = s->maxVal;
- }
- else if( childCenter.y >= y + size.y - childSize.y / 2 )
- {
- child->winSetPosition( 0, size.y - childSize.y );
- s->position = s->minVal;
- }
- else
- {
- delta = childCenter.y - y - childSize.y/2;
- // Calc slider position
- s->position = (Int)(delta / s->numTicks) ;
- /*
- s->position += s->minVal;
- */
- if( s->position > s->maxVal )
- s->position = s->maxVal;
- // Invert slider position so that maxval is at the top
- s->position = s->maxVal - s->position;
-
- }
- // tell owner i moved
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GSM_SLIDER_TRACK,
- (WindowMsgData)window,
- s->position );
- break;
- }
- // ------------------------------------------------------------------------
- case GSM_SET_SLIDER:
- {
- Int newPos = (Int)mData1;
- GameWindow *child = window->winGetChild();
- if (newPos < s->minVal || newPos > s->maxVal)
- break;
- s->position = newPos;
- // Translate to window coords
- newPos = (Int)((s->maxVal - newPos) * s->numTicks);
- child->winSetPosition( 0, newPos );
- break;
- }
- // ------------------------------------------------------------------------
- case GSM_SET_MIN_MAX:
- {
- Int newPos;
- ICoord2D size;
- GameWindow *child = window->winGetChild();
- window->winGetSize( &size.x, &size.y );
- s->minVal = (Int)mData1;
- s->maxVal = (Int)mData2;
- s->numTicks = (Real)( size.y-GADGET_SIZE)/(Real)(s->maxVal - s->minVal);
- s->position = s->minVal;
- // Translate to window coords
- newPos = (Int)((s->maxVal - s->minVal) * s->numTicks);
- child->winSetPosition( 0, newPos );
- break;
- }
- // ------------------------------------------------------------------------
- case GWM_CREATE:
- break;
- // ------------------------------------------------------------------------
- case GWM_DESTROY:
- delete( (SliderData *)window->winGetUserData() );
- break;
- // ------------------------------------------------------------------------
- case GWM_INPUT_FOCUS:
- // If we're losing focus
- if( mData1 == FALSE )
- {
- BitClear( instData->m_state, WIN_STATE_HILITED );
- } else {
- BitSet( instData->m_state, WIN_STATE_HILITED );
- }
- TheWindowManager->winSendSystemMsg( window->winGetOwner(),
- GGM_FOCUS_CHANGE,
- mData1,
- window->winGetWindowId() );
- *(Bool*)mData2 = TRUE;
- break;
- // ------------------------------------------------------------------------
- case GGM_RESIZED:
- {
- Int width = (Int)mData1;
- // Int height = (Int)mData2;
- GameWindow *thumb = window->winGetChild();
- if( thumb )
- thumb->winSetSize( width, GADGET_SIZE );
- break;
- } // end resized
- default:
- return MSG_IGNORED;
- } // end switch( msg )
- return MSG_HANDLED;
- } // end GadgetVerticalSliderSystem
|