Example #1
0
void LineBrush::DrawLine(int xpos, int ypos, int color){

    int ix = getDirection (xpos, lastX);
    int iy = getDirection (ypos, lastY);
    //std::cout <<" Last X " << lastX <<" ix" << xIterator;
    int delta_x = GetDelta(xpos , lastX);
    int delta_y = GetDelta(ypos , lastY);


    int saveXpos = xpos;
    int saveYpos = ypos;
    if (delta_x >= delta_y)
    {
        // error may go below zero
        int error(delta_y - (delta_x >> 1));

        while (xpos != lastX)
        {
            if ((error >= 0) && (error || (ix > 0)))
            {
                error -= delta_x;
                ypos += iy;
            }
            // else do nothing

            error += delta_y;
            xpos += ix;

            Emit(xpos,ypos, color);
        }
    }
Example #2
0
Tcl_UniChar Tcl_UniCharToLower(int ch)
{
    int info = GetUniCharInfo(ch);

    if (GetCaseType(info) & 0x02) {
        return (Tcl_UniChar) (ch + GetDelta(info));
    } else {
        return ch;
    }
}
virtual bool WriteInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsWritten) const override
{
	if(Global->Opt->WindowMode && Buffer->EventType==MOUSE_EVENT)
	{
		Buffer->Event.MouseEvent.dwMousePosition.Y+=GetDelta();
	}
	DWORD dwNumberOfEventsWritten = 0;
	bool Result = WriteConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsWritten)!=FALSE;
	NumberOfEventsWritten = dwNumberOfEventsWritten;
	return Result;
}
Example #4
0
	bool console::ReadOutput(matrix<FAR_CHAR_INFO>& Buffer, COORD BufferCoord, const SMALL_RECT& ReadRegionRelative) const
	{
		if (ExternalConsole.Imports.pReadOutput)
		{
			const COORD SizeCoord = { static_cast<SHORT>(Buffer.width()), static_cast<SHORT>(Buffer.height()) };
			auto ReadRegion = ReadRegionRelative;
			return ExternalConsole.Imports.pReadOutput(Buffer.data(), SizeCoord, BufferCoord, &ReadRegion) != FALSE;
		}

		const int Delta = sWindowMode? GetDelta() : 0;
		auto ReadRegion = ReadRegionRelative;
		ReadRegion.Top += Delta;
		ReadRegion.Bottom += Delta;

		const rectangle SubRect{ BufferCoord.X, BufferCoord.Y, BufferCoord.X + (ReadRegion.Right - ReadRegion.Left + 1) - 1, BufferCoord.Y + (ReadRegion.Bottom - ReadRegion.Top + 1) - 1 };

		std::vector<CHAR_INFO> ConsoleBuffer(SubRect.width() * SubRect.height());

		const COORD BufferSize{ static_cast<SHORT>(SubRect.width()), static_cast<SHORT>(SubRect.height()) };

		if (BufferSize.X * BufferSize.Y * sizeof(CHAR_INFO) > MAXSIZE)
		{
			const auto HeightStep = std::max(MAXSIZE / (BufferSize.X * sizeof(CHAR_INFO)), size_t(1));

			const size_t Height = ReadRegion.Bottom - ReadRegion.Top + 1;

			for (size_t i = 0; i < Height; i += HeightStep)
			{
				auto PartialReadRegion = ReadRegion;
				PartialReadRegion.Top += static_cast<SHORT>(i);
				PartialReadRegion.Bottom = std::min(ReadRegion.Bottom, static_cast<SHORT>(PartialReadRegion.Top + HeightStep - 1));
				const COORD PartialBufferSize{ BufferSize.X, static_cast<SHORT>(PartialReadRegion.Bottom - PartialReadRegion.Top + 1) };
				if (!ReadOutputImpl(ConsoleBuffer.data() + i * PartialBufferSize.X, PartialBufferSize, PartialReadRegion))
					return false;
			}
		}
		else
		{
			auto ReadRegionCopy = ReadRegion;
			if (!ReadOutputImpl(ConsoleBuffer.data(), BufferSize, ReadRegionCopy))
				return false;
		}

		auto ConsoleBufferIterator = ConsoleBuffer.cbegin();
		for_submatrix(Buffer, SubRect, [&](FAR_CHAR_INFO& i)
		{
			const auto& Cell = *ConsoleBufferIterator++;
			i = { Cell.Char.UnicodeChar, colors::ConsoleColorToFarColor(Cell.Attributes) };
		});

		return true;
	}
Example #5
0
	bool console::PeekInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsRead) const
	{
		DWORD dwNumberOfEventsRead = 0;
		bool Result = PeekConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsRead) != FALSE;
		NumberOfEventsRead = dwNumberOfEventsRead;
		if (sWindowMode)
		{
			COORD Size = {};
			GetSize(Size);
			AdjustMouseEvents(Buffer, NumberOfEventsRead, GetDelta(), Size.X - 1);
		}
		return Result;
	}
Example #6
0
void QmitkRenderWindow::wheelEvent(QWheelEvent *we)
{
  mitk::Point2D displayPos = GetMousePosition(we);
  mitk::MouseWheelEvent::Pointer mWheelEvent = mitk::MouseWheelEvent::New(m_Renderer, displayPos, GetButtonState(we),
      GetModifiers(we), GetDelta(we));

  if (!this->HandleEvent(mWheelEvent.GetPointer()))
  {
    QVTKWidget::wheelEvent(we);
  }

  if (m_ResendQtEvents)
    we->ignore();
}
Example #7
0
bool ChessMove::IsValidMovePawn(const ChessBoard& board) const{
    ChessPiece* pawn = board.GetPiece(startX, startY);
    ChessColor color = pawn->GetColor();
    int delta = GetDelta(color);
    int startingRow = GetStartingRow(color);
    ChessPiece* occupyingPiece = board.GetPiece(endX, endY);
    if (occupyingPiece){
        return abs(startX-endX)==1 && startY+delta==endY;
    } else if (endX==startX){
        if (startingRow==startY){
            return endY==startingRow+delta || (!board.GetPiece(endX, startingRow+delta) && endY==startingRow+delta*2);
        } else {
            return endY==startY+delta;
        }
    }
    return false;
}
Example #8
0
Tcl_UniChar Tcl_UniCharToTitle(int ch)
{
    int info = GetUniCharInfo(ch);
    int mode = GetCaseType(info);

    if (mode & 0x1) {
        /*
         * Subtract or add one depending on the original case.
         */

        return (Tcl_UniChar) (ch + ((mode & 0x4) ? -1 : 1));
    } else if (mode == 0x4) {
        return (Tcl_UniChar) (ch - GetDelta(info));
    } else {
        return ch;
    }
}
Example #9
0
	bool console::ReadInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsRead) const
	{
		DWORD dwNumberOfEventsRead = 0;
		if (!ReadConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsRead))
			return false;

		NumberOfEventsRead = dwNumberOfEventsRead;

		if (sWindowMode)
		{
			COORD Size = {};
			GetSize(Size);
			AdjustMouseEvents(Buffer, NumberOfEventsRead, GetDelta(), Size.X - 1);
		}

		return true;
	}
Example #10
0
void QmitkRenderWindow::wheelEvent(QWheelEvent *we)
{
  mitk::Point2D displayPos = GetMousePosition(we);
  mitk::Point3D worldPos = m_Renderer->Map2DRendererPositionTo3DWorldPosition(GetMousePosition(we));

  mitk::MouseWheelEvent::Pointer mWheelEvent = mitk::MouseWheelEvent::New(m_Renderer, displayPos,worldPos, GetButtonState(we),
      GetModifiers(we), GetDelta(we));

  if (!this->HandleEvent(mWheelEvent.GetPointer()))
  { // TODO: INTERACTION_LEGACY
    mitk::WheelEvent myevent(QmitkEventAdapter::AdaptWheelEvent(m_Renderer, we));
    this->wheelMitkEvent(&myevent);
    QVTKWidget::wheelEvent(we);
  }

  if (m_ResendQtEvents)
    we->ignore();
}
Example #11
0
void GamepadController::UpdateFacing() {
  facing_.Update();
  up_.Update();

  up_.SetValue(kCameraUp);

  vec2 delta = GetDelta();
  delta *= input_config_->gamepad_sensitivity();
  if (input_config_->invert_x()) {
    delta.x() *= -1.0f;
  }
  if (input_config_->invert_y()) {
    delta.y() *= -1.0f;
  }

  // We assume that the player is looking along the x axis, before
  // camera transformations are applied:
  vec3 facing_vector = facing_.Value();
  vec3 side_vector =
      quat::FromAngleAxis(-static_cast<float>(M_PI_2), kCameraUp) *
      facing_vector;

  quat pitch_adjustment = quat::FromAngleAxis(delta.y(), side_vector);
  quat yaw_adjustment = quat::FromAngleAxis(delta.x(), kCameraUp);

  facing_vector = pitch_adjustment * yaw_adjustment * facing_vector;

  // Restrict rotation down so that the user doesn't end up just looking at the
  // raft or river.  Restrict rotation up so the user doesn't end up just
  // looking at the sky, missing the action.
  // The unit is in the range -1.0 ... 1.0 where -1.0 is straight down and
  // 1.0 is straight up.  The yaw angle can be defined as yaw = tan(value).
  static const vec2 kUpDownRotationLimit(-0.2f, 0.5f);
  // Clamp the degrees of freedom to "PI / 2 * kUpRotationLimit" when rotating
  // around kCameraSide to avoid gimbal lock.
  facing_vector =
      (facing_vector * (kCameraForward + kCameraSide)) +
      (mathfu::Clamp(mathfu::vec3::DotProduct(facing_vector, kCameraUp),
                     kUpDownRotationLimit[0], kUpDownRotationLimit[1]) *
       kCameraUp);
  facing_vector.Normalize();

  facing_.SetValue(facing_vector);
}
Example #12
0
	bool console::WriteInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsWritten) const
	{
		if (sWindowMode)
		{
			const auto Delta = GetDelta();

			for (auto& i : span(Buffer, Length))
			{
				if (i.EventType == MOUSE_EVENT)
				{
					i.Event.MouseEvent.dwMousePosition.Y += Delta;
				}
			}
		}
		DWORD dwNumberOfEventsWritten = 0;
		bool Result = WriteConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsWritten) != FALSE;
		NumberOfEventsWritten = dwNumberOfEventsWritten;
		return Result;
	}
virtual bool ReadOutput(matrix<FAR_CHAR_INFO>& Buffer, COORD BufferCoord, SMALL_RECT& ReadRegion) const override
{
	bool Result=false;
	int Delta=Global->Opt->WindowMode?GetDelta():0;
	ReadRegion.Top+=Delta;
	ReadRegion.Bottom+=Delta;

	COORD BufferSize = { static_cast<SHORT>(Buffer.width()), static_cast<SHORT>(Buffer.height()) };

	// skip unused region
	const size_t Offset = BufferCoord.Y * BufferSize.X;
	matrix<CHAR_INFO> ConsoleBuffer(BufferSize.Y - BufferCoord.Y, BufferSize.X);
	
	BufferSize.Y-=BufferCoord.Y;
	BufferCoord.Y=0;

	if(BufferSize.X*BufferSize.Y*sizeof(CHAR_INFO)>MAXSIZE)
	{
		auto SavedY = BufferSize.Y;
		BufferSize.Y = std::max(static_cast<int>(MAXSIZE/(BufferSize.X*sizeof(CHAR_INFO))),1);
		size_t Height = ReadRegion.Bottom - ReadRegion.Top + 1;
		int Start=ReadRegion.Top;
		SMALL_RECT SavedReadRegion=ReadRegion;
		for(size_t i = 0; i < Height; i += BufferSize.Y)
		{
			ReadRegion=SavedReadRegion;
			ReadRegion.Top = static_cast<SHORT>(Start+i);
			Result = ReadConsoleOutput(GetOutputHandle(), ConsoleBuffer[i].data(), BufferSize, BufferCoord, &ReadRegion) != FALSE;
		}
		BufferSize.Y = SavedY;
	}
	else
	{
		Result=ReadConsoleOutput(GetOutputHandle(), ConsoleBuffer.data(), BufferSize, BufferCoord, &ReadRegion)!=FALSE;
	}

	auto& ConsoleBufferVector = ConsoleBuffer.vector();
	std::transform(ConsoleBufferVector.cbegin(), ConsoleBufferVector.cend(), Buffer.data() + Offset, [](CONST_REFERENCE(ConsoleBufferVector) i)
	{
		return FAR_CHAR_INFO::make(i.Char.UnicodeChar, colors::ConsoleColorToFarColor(i.Attributes));
	});
Example #14
0
bool ChessMove::IsValidMove(const ChessBoard& board) const{
    if (endX < 0 || endX > 7 || endY < 0 || endY > 7)
        return false;
    ChessPiece* startPiece = board.GetPiece(startX, startY);
    ChessPiece* occupyingPiece = board.GetPiece(endX, endY);
    ChessColor color = startPiece->GetColor();
    if (occupyingPiece && occupyingPiece->GetColor() == color)
        return false;
    switch (startPiece->GetRank()){
    case PAWN:
        return IsValidMovePawn(board) || IsValidEnPassantMove(board, GetDelta(color), GetStartingRow(color));
    case ROOK:
        return IsValidMoveRook(board);
    case KNIGHT:
        return IsValidMoveKnight();
    case BISHOP:
        return IsValidMoveBishop(board);
    case QUEEN:
        return IsValidMoveBishop(board) || IsValidMoveRook(board);
    case KING:
        return IsValidMoveKing() || IsValidCastleMove(board);
    }
    return false;
}
	__int64 CTimeZones::UTCTime2LocalTime(__int64 time, const CGeoPoint& pt)
	{
		__int64 delta = GetDelta(time, pt);
		return time + delta;
	}
Example #16
0
static int stringprep_erl_control(ErlDrvData drv_data,
				  unsigned int command,
				  char *buf, int len,
				  char **rbuf, int rlen)
{
   int i, j, pos=1;
   unsigned char c;
   int bad = 0;
   int uc = 0, ruc;
   int size;
   int info;
   int prohibit = 0, tolower = 0;
   char *rstring;
   int *mc;
   int *str32;
   int str32len, str32pos = 0;
   int decomp_len, decomp_shift;
   int comp_pos, comp_starter_pos;
   int cclass_prev, cclass2;
   int ch1, ch2;
   int first_ral, last_ral, have_ral, have_l;

   size = len + 1;

   rstring = driver_alloc(size);
   rstring[0] = 0;

   str32len = len + 1;

   str32 = driver_alloc(str32len * sizeof(int));

   switch (command)
   {
      case 0:
	 prohibit = ACMask;
	 tolower = 1;
	 break;

      case NAMEPREP_COMMAND:
	 prohibit = ACMask;
	 tolower = 1;
	 break;

      case NODEPREP_COMMAND:
	 prohibit = ACMask | C11Mask | C21Mask | XNPMask;
	 tolower = 1;
	 break;

      case RESOURCEPREP_COMMAND:
	 prohibit = ACMask | C21Mask;
	 tolower = 0;
	 break;
   }

   for (i = 0; i < len; i++)
   {
      c = buf[i];
      if (c < 0x80) {
	 uc = c;
      } else if (c < 0xC0) {
	 bad = 1;
      } else if (c < 0xE0) {
	 if (i+1 < len && (buf[i+1] & 0xC0) == 0x80) {
	    uc = ((c & 0x1F) << 6) | (buf[i+1] & 0x3F);
	    i++;
	 } else {
	    bad = 1;
	 }
      } else if (c < 0xF0) {
	 if (i+2 < len && (buf[i+1] & 0xC0) == 0x80 &&
	     (buf[i+2] & 0xC0) == 0x80) {
	    uc = ((c & 0x0F) << 12)
	       | ((buf[i+1] & 0x3F) << 6)
	       | (buf[i+2] & 0x3F);
	    i += 2;
	 } else {
	    bad = 1;
	 }
      } else if (c < 0xF8) {
	 if (i+3 < len &&
	     (buf[i+1] & 0xC0) == 0x80 &&
	     (buf[i+2] & 0xC0) == 0x80 &&
	     (buf[i+3] & 0xC0) == 0x80) {
	    uc = ((c & 0x07) << 18)
	       | ((buf[i+1] & 0x3F) << 12)
	       | ((buf[i+2] & 0x3F) << 6)
	       | (buf[i+3] & 0x3F);
	    i += 3;
	    if (uc > 0x10FFFF)
	       bad = 1;
	 } else {
	    bad = 1;
	 }
      } else {
	 bad = 1;
      }

      if (bad) {
	 *rbuf = rstring;
	 driver_free(str32);
	 return 1;
      }
      
      info = GetUniCharInfo(uc);

      if (!(info & B1Mask)) 
      {
	 if (tolower) {
	    if (!(info & MCMask)) 
	    {
	       ruc = uc + GetDelta(info);
	       ADD_DECOMP(ruc);
	    } else {
	       mc = GetMC(info);
	       for (j = 1; j <= mc[0]; j++) {
		  ruc = mc[j];
		  ADD_DECOMP(ruc);
	       }
	    }
	 } else {
	    ruc = uc;
	    ADD_DECOMP(ruc);
	 }
      }
   }

   if (str32pos == 0) {
      rstring[0] = 1;
      *rbuf = rstring;
      driver_free(str32);
      return 1;
   }

   canonical_ordering(str32, str32pos);

   comp_pos = 1;
   comp_starter_pos = 0;
   ch1 = str32[0];
   cclass_prev = GetUniCharCClass(ch1);
   for (i = 1; i < str32pos; i++)
   {
      ch2 = str32[i];
      cclass2 = GetUniCharCClass(ch2);
      if ((cclass_prev == 0 || cclass2 > cclass_prev) &&
	  (ruc = compose(ch1, ch2))) {
	 ch1 = ruc;
      } else {
	 if (cclass2 == 0) {
	    str32[comp_starter_pos] = ch1;
	    comp_starter_pos = comp_pos++;
	    ch1 = ch2;
	    cclass_prev = 0;
	 } else {
	    str32[comp_pos++] = ch2;
	    cclass_prev = cclass2;
	 }
      }
   }
   str32[comp_starter_pos] = ch1;
   str32pos = comp_pos;
   
   last_ral = have_ral = have_l = 0;
   info = GetUniCharInfo(str32[0]);
   first_ral = info & D1Mask;
   for (i = 0; i < str32pos; i++)
   {
      ruc = str32[i];
      info = GetUniCharInfo(ruc);
      if (info & prohibit) {
	 *rbuf = rstring;
	 driver_free(str32);
	 return 1;
      }
      last_ral = info & D1Mask;
      have_ral = have_ral || last_ral;
      have_l = info & D2Mask;
      ADD_UCHAR(ruc);
   }

   if (have_ral && (!first_ral || !last_ral || have_l)) {
      *rbuf = rstring;
      driver_free(str32);
      return 1;
   }

   rstring[0] = 1;
   *rbuf = rstring;
   driver_free(str32);
   
   return pos;
}
Example #17
0
void dng_hue_sat_map::SetDelta (uint32 hueDiv,
								uint32 satDiv,
								uint32 valDiv,
								const HSBModify &modify)
	{

	if (hueDiv >= fHueDivisions ||
		satDiv >= fSatDivisions ||
		valDiv >= fValDivisions ||
		fDeltas.Buffer () == NULL)
		{
		
		DNG_REPORT ("Bad parameters to dng_hue_sat_map::SetDelta");
		
		ThrowProgramError ();
		
		}
		
	// Set this entry.
		
	int32 offset = valDiv * fValStep +
				   hueDiv * fHueStep +
				   satDiv;

	GetDeltas () [offset] = modify;
	
	// The zero saturation entry is required to have a value scale
	// of 1.0f.
	
	if (satDiv == 0)
		{
		
		if (modify.fValScale != 1.0f)
			{
			
			#if qDNGValidate
		
			ReportWarning ("Value scale for zero saturation entries must be 1.0");
						 
			#endif
			
			GetDeltas () [offset] . fValScale = 1.0f;
		
			}
		
		}
		
	// If we are settings the first saturation entry and we have not
	// set the zero saturation entry yet, fill in the zero saturation entry
	// by extrapolating first saturation entry.
	
	if (satDiv == 1)
		{
		
		HSBModify zeroSatModify;
		
		GetDelta (hueDiv, 0, valDiv, zeroSatModify);
		
		if (zeroSatModify.fValScale != 1.0f)
			{
			
			zeroSatModify.fHueShift = modify.fHueShift;
			zeroSatModify.fSatScale = modify.fSatScale;
			zeroSatModify.fValScale = 1.0f;
			
			SetDelta (hueDiv, 0, valDiv, zeroSatModify);
			
			}
		
		}

	}
virtual bool ReadInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsRead) const override
{
	DWORD dwNumberOfEventsRead = 0;
	bool Result=ReadConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsRead)!=FALSE;
	if (Result)
	{
		NumberOfEventsRead = dwNumberOfEventsRead;
		if (Global->Opt->WindowMode && Buffer->EventType == MOUSE_EVENT)
		{
			Buffer->Event.MouseEvent.dwMousePosition.Y=std::max(0, Buffer->Event.MouseEvent.dwMousePosition.Y-GetDelta());
			COORD Size={};
			GetSize(Size);
			Buffer->Event.MouseEvent.dwMousePosition.X=std::min(Buffer->Event.MouseEvent.dwMousePosition.X, static_cast<SHORT>(Size.X-1));
		}
	}
	return Result;
}
	CTRef CTimeZones::UTCTRef2LocalTRef(CTRef TRef, const CGeoPoint& pt)
	{
		__int64 delta = GetDelta(TRef, pt);
		return TRef + int(delta/3600);
		
	}
virtual bool PeekInput(INPUT_RECORD* Buffer, size_t Length, size_t& NumberOfEventsRead) const override
{
	DWORD dwNumberOfEventsRead = 0;
	#ifdef DEBUG_PEEK_INPUT
	//Maximus: для отладки
	//_ASSERTE(Length==1);
	bool Result=PeekConsoleInput(GetInputHandle(), gPeek, (DWORD)min(Length,ARRAYSIZE(gPeek)), &dwNumberOfEventsRead)!=FALSE;
	if (Result && dwNumberOfEventsRead)
	{
		memmove(Buffer, gPeek, dwNumberOfEventsRead*sizeof(*gPeek));
		if (gPeek->EventType == MOUSE_EVENT)
			gnLastPeekButtons = gPeek->Event.MouseEvent.dwButtonState;
	}
	#else
	bool Result=PeekConsoleInput(GetInputHandle(), Buffer, static_cast<DWORD>(Length), &dwNumberOfEventsRead)!=FALSE;
	#endif
	NumberOfEventsRead = dwNumberOfEventsRead;
	if(Global->Opt->WindowMode && Buffer->EventType==MOUSE_EVENT)
	{
		Buffer->Event.MouseEvent.dwMousePosition.Y=std::max(0, Buffer->Event.MouseEvent.dwMousePosition.Y-GetDelta());
		COORD Size={};
		GetSize(Size);
		Buffer->Event.MouseEvent.dwMousePosition.X=std::min(Buffer->Event.MouseEvent.dwMousePosition.X, static_cast<SHORT>(Size.X-1));
	}
	return Result;
}