GaitGeneration by Graph Search
読み取り中…
検索中…
一致する文字列を見つけられません
mouse.cpp
[詳解]
1
3
4// Copyright(c) 2023-2025 Design Engineering Laboratory, Saitama University
5// Released under the MIT license
6// https://opensource.org/licenses/mit-license.php
7
8#include "mouse.h"
9
10#include <cmath>
11
12#include <Dxlib.h>
13
14#include "math_util.h"
15
16
17namespace designlab
18{
19
21 kMouseKeyCodes
22{
23 MOUSE_INPUT_RIGHT,
24 MOUSE_INPUT_LEFT,
25 MOUSE_INPUT_MIDDLE,
26 MOUSE_INPUT_4,
27 MOUSE_INPUT_5,
28 MOUSE_INPUT_6,
29 MOUSE_INPUT_7,
30 MOUSE_INPUT_8
31},
32cursor_pos_x_(0),
33cursor_pos_y_(0),
34cursor_past_pos_x_(0),
35cursor_past_pos_y_(0),
36pushing_counter_({}),
37releasing_counter_({}),
38wheel_rot_(0)
39{
40}
41
43{
44 // マウスの位置取得.
45 cursor_past_pos_x_ = cursor_pos_x_;
46 cursor_past_pos_y_ = cursor_pos_y_;
47 GetMousePoint(&cursor_pos_x_, &cursor_pos_y_);
48
49 // マウスのクリック取得.
50 const int mouse_input = GetMouseInput();
51
52 for (const auto& i : kMouseKeyCodes)
53 {
54 if (mouse_input & i)
55 {
56 // 押されているなら.
57 pushing_counter_[i]++;
58 releasing_counter_[i] = 0;
59 }
60 else
61 {
62 // 離されているなら.
63 pushing_counter_[i] = 0;
64 releasing_counter_[i]++;
65 }
66 }
67
68 // ホイール回転を取得,GetMouseWheelRotVol()は前回の呼び出し以降の回転量を返す.
69 wheel_rot_ = GetMouseWheelRotVol();
70}
71
72int Mouse::GetPressingCount(const int mouse_code) const
73{
74 // std::mapでは find も count も処理速度は同じくらい,
75 // multimap や multiset は find を推奨する.
76 if (releasing_counter_.count(mouse_code) == 0)
77 {
78 return -1;
79 }
80
81 return pushing_counter_.at(mouse_code);
82}
83
84int Mouse::GetReleasingCount(const int mouse_code) const
85{
86 if (releasing_counter_.count(mouse_code) == 0)
87 {
88 return -1;
89 }
90
91 return releasing_counter_.at(mouse_code);
92}
93
95{
96 return cursor_pos_x_ - cursor_past_pos_x_;
97}
98
100{
101 return cursor_pos_y_ - cursor_past_pos_y_;
102}
103
104double Mouse::GetDiffPos() const
105{
106 return sqrt(static_cast<double>(math_util::Squared(GetDiffPosY()) +
108}
109
110} // namespace designlab
int GetDiffPosX() const
マウスカーソルの移動量を取得する. X座標は画面の左端を0として,右向きが正. これは Dxlib の仕様なので変更不能.
Definition mouse.cpp:94
int GetPressingCount(int mouse_code) const
ボタンが押されているフレーム数を取得する.
Definition mouse.cpp:72
int GetReleasingCount(int mouse_code) const
ボタンが離されているフレーム数を取得する.
Definition mouse.cpp:84
void Update()
マウス入力を更新する.これを毎フレーム実行しないと, マウス入力を取得できない.
Definition mouse.cpp:42
int GetDiffPosY() const
マウスカーソルの移動量を取得する. Y座標は画面の上端を0として,下向きが正. これは Dxlib の仕様なので変更不能.
Definition mouse.cpp:99
double GetDiffPos() const
マウスカーソルの移動量を取得する.
Definition mouse.cpp:104
constexpr T Squared(const T num) noexcept
2乗した値を返す関数.
Definition math_util.h:59