Because coding is fun!

mouse wheel input

Example "mouse wheel input" in Python

This example uses python 3 with a Raylib (https://www.raylib.com) wrapper (https://pypi.org/project/raylib/) that uses CFFI API static bindings (this is the fastest approach, and keeps the code as close as possible to the original C, which I feel is the best approach when using a C library).

https://www.raylib.com/examples/web/core/loader.html?name=core_input_mouse_wheel

The original C example, edited for easier comparison:


#include "raylib.h"

int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;

InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");

int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels

SetTargetFPS(60); // Set our game to run at 60 frames-per-second

while (!WindowShouldClose()) // Detect window close button or ESC key
{
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);

BeginDrawing();

ClearBackground(RAYWHITE);

DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);

DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);

EndDrawing();
}

CloseWindow(); // Close window and OpenGL context

return 0;
}



The Python version:



from raylib.static import *

screenWidth = 800
screenHeight = 450

InitWindow(screenWidth, screenHeight, b"raylib [core] example - input mouse wheel")

boxPositionX = screenWidth/2 - 40
boxPositionY = screenHeight/2 - 40
scrollSpeed = 4


SetTargetFPS(60)


while not WindowShouldClose():
boxPositionY -= GetMouseWheelMove()*scrollSpeed

BeginDrawing()
ClearBackground(RAYWHITE)
DrawRectangle(int(boxPositionX), int(boxPositionY), 80, 80, MAROON)

DrawText(b"Use mouse wheel to move the cube up and down!", 10, 10, 20, LIGHTGRAY)

yCoord="Box position Y: {}".format(int(boxPositionY))
DrawText(yCoord.encode('ascii'), 10, 40, 20, LIGHTGRAY)

EndDrawing()
CloseWindow()

Example "mouse wheel input" in Rust


https://www.raylib.com/examples/web/core/loader.html?name=core_input_mouse_wheel

The original C example, edited for easier comparison:


#include "raylib.h"

int main(void)
{
const int screenWidth = 800;
const int screenHeight = 450;

InitWindow(screenWidth, screenHeight, "raylib [core] example - input mouse wheel");

int boxPositionY = screenHeight/2 - 40;
int scrollSpeed = 4; // Scrolling speed in pixels

SetTargetFPS(60); // Set our game to run at 60 frames-per-second

while (!WindowShouldClose()) // Detect window close button or ESC key
{
boxPositionY -= (GetMouseWheelMove()*scrollSpeed);

BeginDrawing();

ClearBackground(RAYWHITE);

DrawRectangle(screenWidth/2 - 40, boxPositionY, 80, 80, MAROON);

DrawText("Use mouse wheel to move the cube up and down!", 10, 10, 20, GRAY);
DrawText(FormatText("Box position Y: %03i", boxPositionY), 10, 40, 20, LIGHTGRAY);

EndDrawing();
}

CloseWindow(); // Close window and OpenGL context

return 0;
}



The Rust version:



use raylib::prelude::*;

fn main() {
let screen_width = 800;
let screen_height = 450;

let (mut rl, thread) = raylib::init()
.size(screen_width, screen_height)
.title("raylib [core] example - input mouse wheel")
.build();

let mut box_position_y = screen_height / 2 - 40;
let scroll_speed = 4;

rl.set_target_fps(60); // Set our game to run at 60 frames-per-second

while !rl.window_should_close() {
box_position_y -= rl.get_mouse_wheel_move() * scroll_speed;

let mut d = rl.begin_drawing(&thread);

d.clear_background(Color::RAYWHITE);

d.draw_rectangle(screen_width / 2 - 40, box_position_y, 80, 80, Color::MAROON);

d.draw_text(
"Use mouse wheel to move the cube up and down!",
10,
10,
20,
Color::DARKGRAY,
);

d.draw_text(
&format!("Box position Y: {}", box_position_y), // this is the rust equivalent to FormatText()
10,
40,
20,
Color::LIGHTGRAY,
);
}
}