Skip to content

Commit

Permalink
Mouse wheel scrolling in research and build menus.
Browse files Browse the repository at this point in the history
Cherry-picked from the 3.0 branch, plus compilation fix.

Commit patch from ticket:2110 "Mousewheel menu patch"
Author: noccy
Thanks for the patch!

Format and additional changes by me.

Close ticket:2110
(cherry picked from commit e979b6a)

Fix missing declaration from
e979b6a
(cherry picked from commit 55cf2a4)
  • Loading branch information
buginator authored and cybersphinx committed Aug 11, 2011
1 parent 5886695 commit 6a41d3f
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/widget/form.c
Expand Up @@ -836,7 +836,7 @@ static BOOL formPickHTab(TAB_POS *psTabPos,
// Also need to check if the TabMultiplier is set or not, if not then it means
// we have not yet added the code to display/handle the tab scroll buttons.
// At this time, I think only the design screen has this limitation of only 8 tabs.
if (number > MAX_TAB_SMALL_SHOWN && psTabPos->TabMultiplier) // of course only do this if we actually need >8 tabs.
if (number > (MAX_TAB_SMALL_SHOWN - 1) && psTabPos->TabMultiplier) // of course only do this if we actually need >8 tabs.
{
number -= (psTabPos->TabMultiplier - 1) * TAB_SEVEN;
if (number > TAB_SEVEN) // is it still > than TAB_SEVEN?
Expand Down Expand Up @@ -1385,7 +1385,7 @@ static void formDisplayTTabs(W_TABFORM *psForm,SDWORD x0, SDWORD y0,
x = x0 + 2;
x1 = x + width - 2;
y1 = y0 + height;
if (number > MAX_TAB_SMALL_SHOWN) //we can display 8 tabs fine with no extra voodoo.
if (number > (MAX_TAB_SMALL_SHOWN - 1)) //we can display 8 tabs fine with no extra voodoo.
{ // We do NOT want to draw all the tabs once we have drawn 7 tabs
// Both selected & hilite are converted from virtual tab range, to a range
// that is seen on the form itself. This would be 0-6 (7 tabs)
Expand Down
15 changes: 15 additions & 0 deletions src/display.c
Expand Up @@ -475,6 +475,8 @@ void resetInput(void)
void processInput(void)
{
BOOL mOverRadar = false;
BOOL mOverConstruction = false;

int WheelZoomIterator;

if (InGameOpUp || isInGamePopupUp)
Expand All @@ -487,6 +489,11 @@ void processInput(void)
mOverRadar = true;
}

if(CoordInBuild(mouseX(), mouseY()))
{
mOverConstruction = true;
}

StartOfLastFrame = currentFrame;
currentFrame = frameGetFrameNumber();

Expand All @@ -509,6 +516,10 @@ void processInput(void)
{
kf_RadarZoomIn();
}
else if (mOverConstruction)
{
kf_BuildPrevPage();
}
else
{
for (WheelZoomIterator = 0; WheelZoomIterator < 10; WheelZoomIterator++)
Expand All @@ -528,6 +539,10 @@ void processInput(void)
{
kf_RadarZoomOut();
}
else if (mOverConstruction)
{
kf_BuildNextPage();
}
else
{
for (WheelZoomIterator = 0; WheelZoomIterator < 10; WheelZoomIterator++)
Expand Down
30 changes: 30 additions & 0 deletions src/hci.c
Expand Up @@ -1508,14 +1508,20 @@ static void intProcessEditStats(UDWORD id)
if (psTForm->TabMultiplier < 1 )
{
psTForm->TabMultiplier = 1; //Must be at least 1.
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
// add routine to update tab widgets now...
temp = psTForm->majorT; //set tab # to previous "page"
temp -=TAB_SEVEN; //7 = 1 "page" of tabs
if ( temp < 0)
{
psTForm->majorT = 0;
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
else
{
psTForm->majorT = temp;
}
#ifdef DEBUG_SCROLLTABS
sprintf(buf,"[debug menu]Clicked LT %d tab #=%d",psTForm->TabMultiplier,psTForm->majorT);
addConsoleMessage(buf,DEFAULT_JUSTIFY,SYSTEM_MESSAGE);
Expand All @@ -1535,6 +1541,7 @@ static void intProcessEditStats(UDWORD id)
if (psTForm->TabMultiplier > numTabs) // add 'Bzzt' sound effect?
{
psTForm->TabMultiplier -= 1; // to signify past max?
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
//add routine to update tab widgets now...
psTForm->majorT += TAB_SEVEN; // set tab # to next "page"
Expand Down Expand Up @@ -3027,6 +3034,7 @@ static void intProcessStats(UDWORD id)
if (psTForm->TabMultiplier < 1)
{
psTForm->TabMultiplier = 1; // Must be at least 1.
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
//add routine to update tab widgets now...
temp = psTForm->majorT; // set tab # to previous "page"
Expand Down Expand Up @@ -3054,6 +3062,7 @@ static void intProcessStats(UDWORD id)
if (psTForm->TabMultiplier > numTabs) //add 'Bzzt' sound effect?
{
psTForm->TabMultiplier -= 1; //to signify past max?
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
//add routine to update tab widgets now...
psTForm->majorT += TAB_SEVEN; // set tab # to next "page"
Expand Down Expand Up @@ -7280,3 +7289,24 @@ BASE_OBJECT * getCurrentSelected(void)
{
return psObjSelected;
}

// Checks if a coordinate is over the build menu
BOOL CoordInBuild(int x, int y)
{
// This measurement is valid for the menu, so the buildmenu_height
// value is used to "nudge" it all upwards from the command menu.
// FIXME: hardcoded value (?)
const int buildmenu_height = 300;
Vector2f pos;

pos.x = x - RET_X;
pos.y = y - RET_Y + buildmenu_height; // guesstimation

if (pos.x < 0 || pos.y < 0 || pos.x >= RET_FORMWIDTH || pos.y >= buildmenu_height)
{
return false;
}

return true;
}

3 changes: 3 additions & 0 deletions src/hci.h
Expand Up @@ -315,6 +315,9 @@ extern BOOL ClosingOrder;
/* Initialise the in game interface */
extern BOOL intInitialise(void);

// Check of coordinate is in the build menu
extern BOOL CoordInBuild(int x, int y);

/* Shut down the in game interface */
extern void interfaceShutDown(void);

Expand Down
105 changes: 105 additions & 0 deletions src/keybind.c
Expand Up @@ -99,6 +99,8 @@
Alex McLean, Pumpkin Studios, EIDOS Interactive.
*/

//#define DEBUG_SCROLLTABS //enable to see tab scroll button info for buttons

#define MAP_ZOOM_RATE (1000)
#define MAP_PITCH_RATE (SPIN_SCALING/SECS_PER_SPIN)

Expand Down Expand Up @@ -2804,3 +2806,106 @@ void kf_NoAssert()
console("Asserts turned off");
debug(LOG_ERROR, "Asserts turned off");
}

// rotuine to decrement the tab-scroll 'buttons'
void kf_BuildPrevPage()
{
W_TABFORM *psTForm;
int temp;
#ifdef DEBUG_SCROLLTABS
int numTabs;
int maxTabs;
#endif
int tabPos;

ASSERT_OR_RETURN( , psWScreen != NULL, " Invalid screen pointer!");
psTForm = (W_TABFORM *)widgGetFromID(psWScreen, IDSTAT_TABFORM); //get our form
if (psTForm == NULL)
{
return;
}

if (psTForm->TabMultiplier < 1)
{
psTForm->TabMultiplier = 1; // 1-based
}

#ifdef DEBUG_SCROLLTABS
numTabs = numForms(psTForm->numStats,psTForm->numButtons);
maxTabs = ((numTabs /TAB_SEVEN) + 1); // (Total tabs needed / 7(max tabs that fit))+1
#endif
temp = psTForm->majorT - 1;
if (temp < 0)
{
temp = 0 ;
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
return;
}

psTForm->majorT = temp;
tabPos = ((psTForm->majorT) % TAB_SEVEN); // The tabs position on the page
if ((tabPos == (TAB_SEVEN - 1)) && (psTForm->TabMultiplier > 1))
{
psTForm->TabMultiplier -= 1;
}
audio_PlayTrack(ID_SOUND_BUTTON_CLICK_5);

#ifdef DEBUG_SCROLLTABS
console("Tabs: %d - MaxTabs: %d - MajorT: %d - numMajor: %d - TabMultiplier: %d",numTabs, maxTabs, psTForm->majorT, psTForm->numMajor, psTForm->TabMultiplier);
#endif
}

// rotuine to advance the tab-scroll 'buttons'
void kf_BuildNextPage()
{
W_TABFORM *psTForm;
int numTabs;
int maxTabs;
int tabPos;

ASSERT_OR_RETURN( , psWScreen != NULL, " Invalid screen pointer!");

psTForm = (W_TABFORM *)widgGetFromID(psWScreen, IDSTAT_TABFORM);
if (psTForm == NULL)
{
return;
}

if (psTForm->TabMultiplier < 1)
{
psTForm->TabMultiplier = 1; // 1-based
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
}
numTabs = numForms(psTForm->numStats,psTForm->numButtons);
maxTabs = ((numTabs /TAB_SEVEN)); // (Total tabs needed / 7(max tabs that fit))+1

if (psTForm->majorT < numTabs - 1)
{
// Increase tab if we are not on the last one
psTForm->majorT += 1; // set tab # to next "page"
}
else
{
// went over max
audio_PlayTrack(ID_SOUND_BUILD_FAIL);
return;
}
tabPos = ((psTForm->majorT) % TAB_SEVEN); // The tabs position on the page
// 7 mod 7 = 0, since we are going forward we can assume it's the next tab
if ((tabPos == 0) && (psTForm->TabMultiplier <= maxTabs))
{
psTForm->TabMultiplier += 1;
}

if (psTForm->majorT >= psTForm->numMajor)
{
psTForm->majorT = psTForm->numMajor - 1;
}
audio_PlayTrack( ID_SOUND_BUTTON_CLICK_5 );

#ifdef DEBUG_SCROLLTABS
console("Tabs: %d - MaxTabs: %d - MajorT: %d - numMajor: %d - TabMultiplier: %d",numTabs, maxTabs, psTForm->majorT, psTForm->numMajor, psTForm->TabMultiplier);
#endif
}


3 changes: 3 additions & 0 deletions src/keybind.h
Expand Up @@ -247,4 +247,7 @@ extern void kf_ToggleWatchWindow( void );

bool runningMultiplayer(void);

void kf_BuildNextPage( void );
void kf_BuildPrevPage( void );

#endif // __INCLUDED_SRC_KEYBIND_H__

0 comments on commit 6a41d3f

Please sign in to comment.