DieHard Wolfers Forum Index DieHard Wolfers
A Wolfenstein 3d Fan Community


  Hosted by: MCS & Areyep.com - Designed by: BrotherTank

Original Yahoo Forum - Die Hard Archives

AReyeP HomepageAreyep Homepage DieHard Wolfenstein BunkerDieHard Wolfenstein Bunker Log inLog in RegisterRegister Banlist FAQFAQ Search ForumsSearch

  Username:    Password:      Remember me       

[Tutorial]Adding mousewheel support
Page 1 of 1
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page BottomView Next Topic
Post new topicReply to topic
Author Message
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 27 Aug 2018

Topics: 22
Posts: 1284
Location: Rauma - Finland
finland.gif

PostPosted: Sat Mar 03, 2012 12:00 am
   Subject: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Next PostGoto Bottom of Posts

In this tutorial I will show you how to add mousewheel support to your mod.

In id_in.h make the following modification.

::: CODE :::
extern int JoyNumButtons;
extern  volatile int32_t    WheelPos;


Then open up id_in.cpp and make the following modification

::: CODE :::
int JoyNumButtons;
volatile int32_t WheelPos=0;


Still in id_in.cpp, find "processEvent" and modify the beginning to this:
And you now have the mouse wheel position in WheelPos variable.

::: CODE :::
static void processEvent(SDL_Event *event)
{
    switch (event->type)
    {
        // exit if the window is closed
        case SDL_QUIT:
            Quit(NULL);

        case SDL_MOUSEBUTTONDOWN:
            if (event->button.button == 4)
                WheelPos++;
            if (event->button.button == 5)
                WheelPos--;
        break;


Enjoy! Mr Green

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:39 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Sat Mar 03, 2012 3:19 pm
   Subject: Re: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Hmmm, I tried implementing this, and it didn't seem to do anything. Perhaps it's just because of my mouse (which only has 2 buttons aside from the mousewheel), but rolling or clicking the mousewheel didn't seem to do anything for me.

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Tricob
Moderator
<B>Moderator</B>


Joined: 14 Mar 2005
Last Visit: 6:27 ago.

Topics: 165
Posts: 8252
Location: Neo-traditions, Inc.
usa.gif

PostPosted: Sat Mar 03, 2012 3:57 pm
   Subject: Re: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

I do appreciate that you've posted this code Codetech, but I'd like you to tell us where in the EXE that the mouse wheel is used, so we can try it out. I've thought more than once about applying the use of the mouse wheel in the Main Menu, but I didn't even know where to start; I'm not very good with Windows coding. Embarassed
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 27 Aug 2018

Topics: 22
Posts: 1284
Location: Rauma - Finland
finland.gif

PostPosted: Sun Mar 04, 2012 12:35 am
   Subject: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

@Metalor: Well that's odd, it should work, unless you expected the above code to have some functionality, it was just to give more freedom to modders. Try the weapon select example and see if that works.


Ok you could use MouseWheel to select weapons for example. I did it a bit differently in Klooni and I haven't tested the following, but it should work.

In wl_play.c, make the following changes to PollMouseButtons:

::: CODE :::
int32_t LastWheelPos=0;

void PollMouseButtons (void)
{
    int buttons = IN_MouseButtons ();
   
    if (WheelPos < LastWheelPos)
        buttonstate[bt_prevweapon] = true;
    if (WheelPos > LastWheelPos)
        buttonstate[bt_nextweapon] = true;
    LastWheelPos = WheelPos;


    if (buttons & 1)
        buttonstate[buttonmouse[0]] = true;
    if (buttons & 2)
        buttonstate[buttonmouse[1]] = true;
    if (buttons & 4)
        buttonstate[buttonmouse[2]] = true;
}


In similar fasion, you could also use it in conjunction with the zoom tutorial, to give snipers a more controllable zoom
http://diehardwolfers.areyep.com/viewtopic.php?t=5010

Again something from the top of my head, so I haven't tested this, but you could apply something like this to T_Player():

::: CODE :::
int32_t ZoomLevel = 0;
int32_t LastWheelPos = 0;

void SniperZoom (void)
{
    if (gamestate.weapon != wp_sniper)
        return;

    if (WheelPos == LastWheelPos)
        return;

    if (WheelPos < LastWheelPos)
        ZoomLevel -= 25;
    if (WheelPos > LastWheelPos)
        ZoomLevel += 25;
    LastWheelPos = WheelPos;

    if (ZoomLevel < 0)
        ZoomLevel = 0;
    if (ZoomLevel > 100)
        ZoomLevel = 100;

    BasicZoom ((int16_t) ZoomLevel);
}

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
Metalor
DieHard Mutant
DieHard Mutant


Joined: 24 Aug 2005
Last Visit: 1:39 ago.

Topics: 95
Posts: 914
Location: California
usa.gif

PostPosted: Sun Mar 04, 2012 12:36 pm
   Subject: Re: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Next PostGoto Bottom of Posts

Well, I guess I was expecting it to have some sort of functionality already set up just from the above. It must have been a reflex.

_________________
- Taking a hiatus from Wolfenstein for a while...

...But I'll be back, you can count on it!
Codetech84
Code Master
Code Master


Joined: 12 Mar 2003
Last Visit: 27 Aug 2018

Topics: 22
Posts: 1284
Location: Rauma - Finland
finland.gif

PostPosted: Sun Mar 04, 2012 3:10 pm
   Subject: Re: [Tutorial]Adding mousewheel support
   [ IP : Logged ]
Reply with quote
Goto Top of PostsGoto Previous PostGoto Bottom of Posts

Metalor wrote:
Well, I guess I was expecting it to have some sort of functionality already set up just from the above. It must have been a reflex.
Yes, sorry about that, that's usually the point of tutorials and you were right to expect something to happen.

My idea for this tutorial was basically to add a variable called WheelPos and save the mouse wheel position to it so people can get creative with it, I meant to give some examples but I really didn't have anything simple to hand out at the time.

But I added two examples, I went on and tested the weapon change example and it works like I expected it too. The second one requires the installation of TexZK's zoom tutorial so I couldn't really give any step by step tutorial, but the code should work in theory. Mr Green

_________________
Click here to visit KFH Games website!
*UPDATED* Spear of Destiny Reloaded
KFH Games on Facebook
Display posts from previous:   
Post new topicReply to topic Time synchronized with the forum server time
DieHard Wolfers Forum Index -> SDL Code Crackers View Previous TopicRefresh this PageAdd Topic to your Browser FavoritesSearch ForumsPrint this TopicE-mail TopicGoto Page TopView Next Topic
Page 1 of 1
Jump to:  

Related topics
 Topics   Replies   Views   Last Post 
No new posts Sticky: [Tutorial] Compiling Wolf4SDL with Code::Blocks
Author: dcbasic
90 27517 Wed May 24, 2017 7:53 pm
Falcon*93 View latest post
No new posts [help] Adding teleporters in wolf4sdl
Author: Mortimer
35 11726 Fri May 26, 2017 8:19 am
Military View latest post
No new posts Remaking released mod into SDL
Author: Dean
14 4418 Thu Aug 14, 2008 4:58 pm
Dean View latest post
No new posts [IDEA] Introducing the new "Haasboy Engine"
Author: Haasboy
2 1373 Fri Aug 01, 2008 10:37 am
dcbasic View latest post
No new posts [Help] Adding a weapon problem
Author: Zombie_Plan
10 2266 Thu Jul 24, 2008 4:26 pm
RichterBelmont12 View latest post
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
   You cannot delete your posts in this forum
You cannot vote in polls in this forum


Copyright ©2003-2008 DieHard Wolfers
A Modified subBunker Theme by BrotherTank
Powered by phpBB © 2001, 2005 phpBB Group