本文整理汇总了C#中SDL2.SDL类的典型用法代码示例。如果您正苦于以下问题:C# SDL类的具体用法?C# SDL怎么用?C# SDL使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
SDL类属于SDL2命名空间,在下文中一共展示了SDL类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: HasIntersection
// http://stackoverflow.com/questions/99353/how-to-test-if-a-line-segment-intersects-an-axis-aligned-rectange-in-2d
public static bool HasIntersection(SDL.SDL_Rect rect, int x1, int y1, int x2, int y2)
{
Func<int, int, double> implicitLineEqn = new Func<int, int, double>((x, y) => { return ((y2 - y1) * x) + ((x1 - x2) * y) + ((x2 * y1) - (x1 * y2)) * 1.0; });
double topLeft = implicitLineEqn(rect.x, rect.y);
double topRight = implicitLineEqn(rect.x + rect.w, rect.y);
double bottomLeft = implicitLineEqn(rect.x, rect.y + rect.h);
double bottomRight = implicitLineEqn(rect.x + rect.w, rect.y + rect.h);
if ((topLeft < 0 && topRight < 0 && bottomLeft < 0 && bottomRight < 0) || (topLeft > 0 && topRight > 0 && bottomLeft > 0 && bottomRight > 0))
{
return false;
}
if ((x1 > rect.x + rect.w) && (x2 > rect.x + rect.w))
{
return false;
}
else if ((x1 < rect.x) && (x2 < rect.x))
{
return false;
}
else if ((y1 < rect.y) && (y2 < rect.y))
{
return false;
}
else if ((y1 > rect.y + rect.h) && (y2 > rect.y + rect.h))
{
return false;
}
else
{
return true;
}
}
示例2: SDL2Window
public SDL2Window(string title, int x, int y, int w, int h, SDL.SDL_WindowFlags flags)
{
Window = SDL.SDL_CreateWindow(title, x, y, w, h, flags);
if (Window == IntPtr.Zero)
{
throw new Exception("SDL_CreateWindow()", new Exception(SDL.SDL_GetError()));
}
}
示例3: SDL2Renderer
public SDL2Renderer(SDL2Window window, int index, SDL.SDL_RendererFlags flags)
{
Renderer = SDL.SDL_CreateRenderer(window.Window, index, (uint)flags);
if (Renderer == IntPtr.Zero)
{
throw new Exception("SDL_CreateRenderer()", new Exception(SDL.SDL_GetError()));
}
}
示例4: WindowEventArgs
public WindowEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
SubEventType = (WindowEventType)rawEvent.window.windowEvent;
Data1 = rawEvent.window.data1;
Data2 = rawEvent.window.data2;
RawTimeStamp = rawEvent.window.timestamp;
WindowID = rawEvent.window.windowID;
}
示例5: MouseWheelEventArgs
public MouseWheelEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
RawTimeStamp = rawEvent.wheel.timestamp;
WindowID = rawEvent.wheel.windowID;
MouseDeviceID = rawEvent.wheel.which;
HorizontalScrollAmount = rawEvent.wheel.x;
VerticalScrollAmount = rawEvent.wheel.y;
}
示例6: KeyboardEventArgs
public KeyboardEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
RawTimeStamp = rawEvent.key.timestamp;
repeat = rawEvent.key.repeat;
KeyInformation = new KeyInformation(rawEvent.key.keysym.scancode, rawEvent.key.keysym.sym, rawEvent.key.keysym.mod);
State = (KeyState)rawEvent.key.state;
WindowID = rawEvent.key.windowID;
}
示例7: MouseButtonEventArgs
public MouseButtonEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
RawTimeStamp = rawEvent.button.timestamp;
WindowID = rawEvent.button.windowID;
MouseDeviceID = rawEvent.button.which;
MouseButton = (MouseButtonCode)rawEvent.button.button;
State = (MouseButtonState)rawEvent.button.state;
RelativeToWindowX = rawEvent.button.x;
RelativeToWindowY = rawEvent.button.y;
}
示例8: Window
public Window(
string title,
Point2d<int> position,
Size2d<int> size,
SDL.SDL_WindowFlags flags)
{
window = SDL.SDL_CreateWindow(
title,
position.X,
position.Y,
size.Width,
size.Height,
flags);
}
示例9: TextInputEventArgs
public TextInputEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
RawTimeStamp = rawEvent.text.timestamp;
WindowID = rawEvent.text.windowID;
byte[] rawBytes = new byte[SDL2.SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE];
// we have an unsafe pointer to a char array from SDL, explicitly marshal this to a byte array of fixed size
unsafe { Marshal.Copy((IntPtr)rawEvent.text.text, rawBytes, 0, SDL2.SDL.SDL_TEXTINPUTEVENT_TEXT_SIZE); }
// look for the index of the first null terminator
int length = Array.IndexOf(rawBytes, (byte)0);
// according to the SDL2 migration guide, TextInputEvent will have a UTF-8 encoded string
Text = System.Text.Encoding.UTF8.GetString(rawBytes, 0, length);
}
示例10: MouseMotionEventArgs
public MouseMotionEventArgs(SDL.SDL_Event rawEvent)
: base(rawEvent)
{
RawTimeStamp = rawEvent.motion.timestamp;
WindowID = rawEvent.motion.windowID;
MouseDeviceID = rawEvent.motion.which;
RelativeToWindowX = rawEvent.motion.x;
RelativeToWindowY = rawEvent.motion.y;
RelativeToLastMotionEventX = rawEvent.motion.xrel;
RelativeToLastMotionEventY = rawEvent.motion.yrel;
List<MouseButtonCode> buttonsPressed = new List<MouseButtonCode>();
if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_LEFT)
buttonsPressed.Add(MouseButtonCode.Left);
if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_MIDDLE)
buttonsPressed.Add(MouseButtonCode.Middle);
if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_RIGHT)
buttonsPressed.Add(MouseButtonCode.Right);
if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_X1)
buttonsPressed.Add(MouseButtonCode.X1);
if (SDL.SDL_BUTTON(rawEvent.motion.state) == SDL.SDL_BUTTON_X2)
buttonsPressed.Add(MouseButtonCode.X2);
MouseButtonsPressed = buttonsPressed;
}
示例11: RenderSetViewport
public void RenderSetViewport(SDL.SDL_Rect rect)
{
if (SDL.SDL_RenderSetViewport(Renderer, ref rect) != 0)
{
throw new Exception("SDL_RenderSetViewport()", new Exception(SDL.SDL_GetError()));
}
}
示例12: RenderFillRects
public void RenderFillRects(SDL.SDL_Rect[] rects)
{
if (SDL.SDL_RenderFillRects(Renderer, rects, rects.Length) != 0)
{
throw new Exception("SDL_RenderFillRects()", new Exception(SDL.SDL_GetError()));
}
}
示例13: RenderReadPixels
public void RenderReadPixels(SDL.SDL_Rect rect, uint format, IntPtr pixels, int pitch)
{
if (SDL.SDL_RenderReadPixels(Renderer, ref rect, format, pixels, pitch) != 0)
{
throw new Exception("SDL_RenderReadPixels()", new Exception(SDL.SDL_GetError()));
}
}
示例14: RenderCopyEx
public void RenderCopyEx(IntPtr texture, SDL.SDL_Rect srcrect, SDL.SDL_Rect dstrect, double angle, SDL.SDL_Point center, SDL.SDL_RendererFlip flip)
{
if (SDL.SDL_RenderCopyEx(Renderer, texture, ref srcrect, ref dstrect, angle, ref center, flip) != 0)
{
throw new Exception("SDL_RenderCopyEx()", new Exception(SDL.SDL_GetError()));
}
}
示例15: RenderDrawPoints
public void RenderDrawPoints(SDL.SDL_Point[] points)
{
if (SDL.SDL_RenderDrawPoints(Renderer, points, points.Length) != 0)
{
throw new Exception("SDL_RenderDrawPoints()", new Exception(SDL.SDL_GetError()));
}
}