本文整理汇总了C++中Viewport::IncrementInBounds方法的典型用法代码示例。如果您正苦于以下问题:C++ Viewport::IncrementInBounds方法的具体用法?C++ Viewport::IncrementInBounds怎么用?C++ Viewport::IncrementInBounds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Viewport
的用法示例。
在下文中一共展示了Viewport::IncrementInBounds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: WordByWordSelection
// Routine Description:
// - Modifies the given selection point to the edge of the next (or previous) word.
// - By default operates in a left-to-right fashion.
// Arguments:
// - fReverse: Specifies that this function should operate in reverse. E.g. Right-to-left.
// - bufferSize: The dimensions of the screen buffer.
// - coordAnchor: The point within the buffer (inside the edges) where this selection started.
// - coordSelPoint: Defines selection region from coordAnchor to this point. Modified to define the new selection region.
// Return Value:
// - <none>
COORD Selection::WordByWordSelection(const bool fReverse,
const Viewport& bufferSize,
const COORD coordAnchor,
const COORD coordSelPoint) const
{
const CONSOLE_INFORMATION& gci = ServiceLocator::LocateGlobals().getConsoleInformation();
const SCREEN_INFORMATION& screenInfo = gci.GetActiveOutputBuffer();
COORD outCoord = coordSelPoint;
// first move one character in the requested direction
if (!fReverse)
{
bufferSize.IncrementInBounds(outCoord);
}
else
{
bufferSize.DecrementInBounds(outCoord);
}
// get the character at the new position
auto charData = *screenInfo.GetTextDataAt(outCoord);
// we want to go until the state change from delim to non-delim
bool fCurrIsDelim = IsWordDelim(charData);
bool fPrevIsDelim;
// find the edit-line boundaries that we can highlight
COORD coordMaxLeft;
COORD coordMaxRight;
const bool fSuccess = s_GetInputLineBoundaries(&coordMaxLeft, &coordMaxRight);
// if line boundaries fail, then set them to the buffer corners so they don't restrict anything.
if (!fSuccess)
{
coordMaxLeft.X = bufferSize.Left();
coordMaxLeft.Y = bufferSize.Top();
coordMaxRight.X = bufferSize.RightInclusive();
coordMaxRight.Y = bufferSize.BottomInclusive();
}
// track whether we failed to move during an operation
// if we failed to move, we hit the end of the buffer and should just highlight to there and be done.
bool fMoveSucceeded = false;
// determine if we're highlighting more text or unhighlighting already selected text.
bool fUnhighlighting;
if (!fReverse)
{
// if the selection point is left of the anchor, then we're unhighlighting when moving right
fUnhighlighting = Utils::s_CompareCoords(outCoord, coordAnchor) < 0;
}
else
{
// if the selection point is right of the anchor, then we're unhighlighting when moving left
fUnhighlighting = Utils::s_CompareCoords(outCoord, coordAnchor) > 0;
}
do
{
// store previous state
fPrevIsDelim = fCurrIsDelim;
// to make us "sticky" within the edit line, stop moving once we've reached a given max position left/right
// users can repeat the command to move past the line and continue word selecting
// if we're at the max position left, stop moving
if (Utils::s_CompareCoords(outCoord, coordMaxLeft) == 0)
{
// set move succeeded to false as we can't move any further
fMoveSucceeded = false;
break;
}
// if we're at the max position right, stop moving.
// we don't want them to "word select" past the end of the edit line as there's likely nothing there.
// (thus >= and not == like left)
if (Utils::s_CompareCoords(outCoord, coordMaxRight) >= 0)
{
// set move succeeded to false as we can't move any further.
fMoveSucceeded = false;
break;
}
if (!fReverse)
{
fMoveSucceeded = bufferSize.IncrementInBounds(outCoord);
}
else
{
fMoveSucceeded = bufferSize.DecrementInBounds(outCoord);
//.........这里部分代码省略.........