-
Notifications
You must be signed in to change notification settings - Fork 295
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- New tablet configurations: Wacom CTL-4100 (USB only model), XP-Pen G540 Pro, XP-Pen Deco 01 and Huion osu!tablet - Added `ResetDistance` command - Code refactoring.
- Loading branch information
Showing
17 changed files
with
436 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
#include "stdafx.h" | ||
#include "PositionRingBuffer.h" | ||
|
||
|
||
// | ||
// Constructor | ||
// | ||
PositionRingBuffer::PositionRingBuffer() { | ||
maxLength = sizeof(buffer) / sizeof(Vector2D); | ||
length = 0; | ||
count = 0; | ||
index = 0; | ||
isValid = false; | ||
} | ||
|
||
|
||
// | ||
// Destructor | ||
// | ||
PositionRingBuffer::~PositionRingBuffer() { | ||
} | ||
|
||
|
||
// | ||
// Set buffer length | ||
// | ||
void PositionRingBuffer::SetLength(int len) { | ||
if(len > maxLength) { | ||
length = maxLength; | ||
} else { | ||
length = len; | ||
} | ||
} | ||
|
||
|
||
// | ||
// Add position to buffer | ||
// | ||
void PositionRingBuffer::Add(Vector2D vector) { | ||
buffer[index].x = vector.x; | ||
buffer[index].y = vector.y; | ||
index++; | ||
count++; | ||
if(count > length) { | ||
count = length; | ||
} | ||
if(index >= length) { | ||
index = 0; | ||
} | ||
isValid = true; | ||
} | ||
|
||
|
||
// | ||
// Get position history from the buffer | ||
// | ||
bool PositionRingBuffer::GetLatest(Vector2D *output, int delta) { | ||
int newIndex; | ||
|
||
// Buffer empty? | ||
if(count == 0) return false; | ||
|
||
// Valid delta? | ||
if(delta > 0 || delta <= -count) return false; | ||
|
||
newIndex = index - 1 + delta; | ||
|
||
// Limits | ||
if(newIndex < 0) newIndex = count + newIndex; | ||
|
||
if(newIndex < 0 || newIndex >= count) { | ||
return false; | ||
} | ||
|
||
output->x = buffer[newIndex].x; | ||
output->y = buffer[newIndex].y; | ||
return true; | ||
} | ||
|
||
|
||
// | ||
// Reset buffer | ||
// | ||
void PositionRingBuffer::Reset() { | ||
count = 0; | ||
index = 0; | ||
isValid = false; | ||
} | ||
|
||
|
||
|
||
// | ||
// [] operator | ||
// | ||
Vector2D *PositionRingBuffer::operator[](std::size_t index) { | ||
return &(buffer[index]); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#pragma once | ||
|
||
#include "Vector2D.h" | ||
|
||
class PositionRingBuffer { | ||
public: | ||
Vector2D buffer[100]; | ||
int maxLength; | ||
int length; | ||
int count; | ||
int index; | ||
bool isValid; | ||
|
||
void SetLength(int length); | ||
void Add(Vector2D vector); | ||
bool GetLatest(Vector2D *output, int delta); | ||
void Reset(); | ||
|
||
Vector2D *operator[](std::size_t index); | ||
|
||
|
||
PositionRingBuffer(); | ||
~PositionRingBuffer(); | ||
}; | ||
|
Oops, something went wrong.