Package de.vatrasoft.vatralib.gfx
Interface GfxBinding
-
- All Superinterfaces:
Binding
public interface GfxBinding extends Binding
AGfxBinding(Graphics Binding) is a component that translates abstract graphics operations to concrete, framework-specific operations in order to manipulate the screen. Examples for such operations are "create a window with a certain title and a certain size" and "draw the pixels of a certain image at a certain position within the window".This interface describes these abstract graphics operations, i.e. it contains all methods that a concrete
GfxBindingmust implement.Apart from graphics operations, a
GfxBindingalso deals with handling user input.
-
-
Field Summary
Fields Modifier and Type Field Description static intMAX_OPACITYThe maximum allowed opacity (i.e. all objects will be fully opaque)static intMIN_OPACITYThe minimum allowed opacity (i.e. all objects will be fully transparent)
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description voidbeginFrame()Prepares for the next frame to be drawn, e.g. clears the screen or internal buffer.voidclear()Clears the screen and ensures that no previously cached objects (i.e. images) are subsequently displayed (i.e.voidcreateWindow(java.lang.String windowTitle, int width, int height, Color backgroundColor, boolean fullscreen)Creates a window with the given title and dimensions, using the given color as background.voiddrawFilledArea(long id, java.lang.String filepath, int x, int y, int z, int width, int height, int opacity)Draws the pixels of the given image file repeatedly onto the screen (starting at the specified position within the active window) until the rectangular area denoted bywidthandheightis covered.voiddrawImage(long id, java.lang.String filepath, int x, int y, int z, int opacity)Draws the pixels of the given image file onto the screen (at the specified position within the active window).voiddrawImageSection(long id, java.lang.String filepath, Rectangle imageSection, int x, int y, int z, int opacity, boolean flipX, boolean flipY)Draws the pixels of the given rectangular section of the given image file onto the screen (at the specified position within the active window).voidfinishFrame()Finalizes the frame that is currently being drawn, e.g. copies buffer contents onto the screen.booleanisAnyKeyPressed()Indicates if any key is currently being pressed on the keyboard.booleanisKeyPressed(Key key)Indicates if the givenKeyis currently being pressed on the keyboard.voidremoveObject(long id)Removes the object with the given ID from the screen and ensures that it will not be displayed until a new call todrawImage(long, String, int, int, int, int),drawImageSection(long, String, Rectangle, int, int, int, int, boolean, boolean)ordrawFilledArea(long, String, int, int, int, int, int, int)is made for the same object ID.DimensionsretrieveImageDimensions(java.lang.String filepath)Retrieves the dimensions, i.e. width and height, of the image denoted by the given filepath.voidsetBackgroundColor(Color color)Sets the desired background color for the active window.voidsetFullscreen(boolean fullscreenMode)Enables or disables fullscreen mode.voidsetTotalOpacity(int opacity)Sets the desired opacity for all objects.booleansupportsZOrdering()Indicates if thisGfxBindingcan take care of drawing some objects on top of others depending on their z coordinate.-
Methods inherited from interface de.vatrasoft.vatralib.Binding
getSupportedFileFormats, isFileFormatSupported
-
-
-
-
Field Detail
-
MIN_OPACITY
static final int MIN_OPACITY
The minimum allowed opacity (i.e. all objects will be fully transparent)- See Also:
- Constant Field Values
-
MAX_OPACITY
static final int MAX_OPACITY
The maximum allowed opacity (i.e. all objects will be fully opaque)- See Also:
- Constant Field Values
-
-
Method Detail
-
createWindow
void createWindow(java.lang.String windowTitle, int width, int height, Color backgroundColor, boolean fullscreen)Creates a window with the given title and dimensions, using the given color as background.- Parameters:
windowTitle- the desired window titlewidth- the desired width in pixelsheight- the desired height in pixelsbackgroundColor- theColorto use as backgroundfullscreen-truemeans that the application should start in fullscreen mode
-
setBackgroundColor
void setBackgroundColor(Color color)
Sets the desired background color for the active window.- Parameters:
color- the desiredColor
-
setFullscreen
void setFullscreen(boolean fullscreenMode)
Enables or disables fullscreen mode.- Parameters:
fullscreenMode-truemeans fullscreen mode,falsemeans windowed mode
-
setTotalOpacity
void setTotalOpacity(int opacity)
Sets the desired opacity for all objects. An opacity ofMIN_OPACITYmeans that all objects are fully transparent (i.e. invisible) and that only the background color (seesetBackgroundColor(Color)) will be shown, an opacity ofMAX_OPACITYmeans that all objects are fully opaque (i.e. visible).Values outside the allowed range are clipped.
- Parameters:
opacity- the desired opacity
-
beginFrame
void beginFrame()
Prepares for the next frame to be drawn, e.g. clears the screen or internal buffer. This method will be called by theEngineat the beginning of each iteration over the objects that are to be drawn.Note that a concrete
GfxBindingmight not need to do anything in this method, depending on the technology it uses for drawing onto the screen.
-
finishFrame
void finishFrame()
Finalizes the frame that is currently being drawn, e.g. copies buffer contents onto the screen. This method will be called by theEngineat the end of each iteration over the objects that are to be drawn.Note that a concrete
GfxBindingmight not need to do anything in this method, depending on the technology it uses for drawing onto the screen.
-
retrieveImageDimensions
Dimensions retrieveImageDimensions(java.lang.String filepath)
Retrieves the dimensions, i.e. width and height, of the image denoted by the given filepath.- Parameters:
filepath- the path to the image file (use prefix "file:" for file system paths; otherwise, file is expected to be on the classpath)- Returns:
- the dimensions of the image, encapsulated in a
Dimensionsobject
-
drawImage
void drawImage(long id, java.lang.String filepath, int x, int y, int z, int opacity)Draws the pixels of the given image file onto the screen (at the specified position within the active window). The width and height of the data in the image file are retained, i.e. no scaling is performed.- Parameters:
id- the unique ID of the underlying object; can be used by theGfxBindingfor internal caching (useful especially when the same object is drawn again and again, and/or when the same image is being used by several objects)filepath- the path to the image file (use prefix "file:" for file system paths; otherwise, file is expected to be on the classpath)x- the desired horizontal position (zero means left border of window)y- the desired vertical position (zero means top border of window)z- the desired z coordinate (higher means in the front, lower means in the back)opacity- the desired opacity (zero means fully transparent, 100 means fully opaque)
-
drawFilledArea
void drawFilledArea(long id, java.lang.String filepath, int x, int y, int z, int width, int height, int opacity)Draws the pixels of the given image file repeatedly onto the screen (starting at the specified position within the active window) until the rectangular area denoted bywidthandheightis covered.- Parameters:
id- the unique ID of the underlying object; can be used by theGfxBindingfor internal caching (useful especially when the same object is drawn again and again, and/or when the same image is being used by several objects)filepath- the path to the image file (use prefix "file:" for file system paths; otherwise, file is expected to be on the classpath)x- the desired horizontal position of the area (zero means left border of window)y- the desired vertical position of the area (zero means top border of window)z- the desired z coordinate (higher means in the front, lower means in the back)width- the desired width of the areaheight- the desired height of the areaopacity- the desired opacity (zero means fully transparent, 100 means fully opaque)
-
drawImageSection
void drawImageSection(long id, java.lang.String filepath, Rectangle imageSection, int x, int y, int z, int opacity, boolean flipX, boolean flipY)Draws the pixels of the given rectangular section of the given image file onto the screen (at the specified position within the active window).- Parameters:
id- the unique ID of the underlying object; can be used by theGfxBindingfor internal caching (useful especially when the same object is drawn again and again, and/or when the same image is being used by several objects)filepath- the path to the image file (use prefix "file:" for file system paths; otherwise, file is expected to be on the classpath)imageSection- the rectangular section of the image that should be drawn onto the screenx- the desired horizontal position (zero means left border of window)y- the desired vertical position (zero means top border of window)z- the desired z coordinate (higher means in the front, lower means in the back)opacity- the desired opacity (zero means fully transparent, 100 means fully opaque)flipX-truemeans that the image section should be flipped horizontallyflipY-truemeans that the image section should be flipped vertically
-
removeObject
void removeObject(long id)
Removes the object with the given ID from the screen and ensures that it will not be displayed until a new call todrawImage(long, String, int, int, int, int),drawImageSection(long, String, Rectangle, int, int, int, int, boolean, boolean)ordrawFilledArea(long, String, int, int, int, int, int, int)is made for the same object ID.- Parameters:
id- the unique ID of the underlying object; seedraw*methods- Throws:
java.lang.IllegalArgumentException- if the given ID is not found in theGfxBindings internal storage
-
supportsZOrdering
boolean supportsZOrdering()
Indicates if thisGfxBindingcan take care of drawing some objects on top of others depending on their z coordinate. If it does not support it, theEnginewill sort its objects according to their z coordinate so that theGfxBindingreceives them in the right order.- Returns:
trueif thisGfxBindingsupports z-ordering by itself
-
clear
void clear()
Clears the screen and ensures that no previously cached objects (i.e. images) are subsequently displayed (i.e. clears any caches).
-
isKeyPressed
boolean isKeyPressed(Key key)
Indicates if the givenKeyis currently being pressed on the keyboard.- Parameters:
key- the key to check- Returns:
trueif the given key is currently being pressed down,falseotherwise
-
isAnyKeyPressed
boolean isAnyKeyPressed()
Indicates if any key is currently being pressed on the keyboard.- Returns:
trueif at least one key is currently being pressed down,falseotherwise
-
-