2.1.3 Mouse Wheel

Most recent mouse have a wheel. The wheel can be turned, but it doesn’t have an absolute position. Esenthel can only tell you how much the wheel was turned since the last update. This distance is called a ’delta’. In general, a delta value indicates the difference between the previous and the current value. There are delta values for time, position changes, mouse wheel changes and so on. For the mouse wheel you will need the function Ms.wheel(). The result is a float value.

The next example shows a dot on the vertical axis, controlled by the mouse wheel. The function Ms.wheel() only returns the change since the previous update, which means it cannot be assigned to the position directly. You will have to add it to the current value. This change is a very small positive number while you move the wheel upwards. While moving down, the value will be negative.

 
Vec2 mousePos; 
 
void InitPre() 
{ 
5   EE_INIT(); 
} 
 
bool Init() 
{ 
10   return true
} 
 
void Shut() {} 
 
15bool Update() 
{ 
   if(Kb.bp(KB_ESC)) return false
   mousePos.y += Ms.wheel() * 0.1; 
   return true
20} 
 
void Draw() 
{ 
   D.clear(BLACK); 
25   mousePos.draw(RED); 
}  

Exercise
Start from the example above. When the left mouse button is held down, you need to control the horizontal dot position. When the right mouse button is held down, you control the vertical position of the dot.