Copyright | (c) Daniel Winograd-Cort 2015 |
---|---|
License | see the LICENSE file in the distribution |
Maintainer | dwc@cs.yale.edu |
Stability | experimental |
Safe Haskell | None |
Language | Haskell98 |
- type Point = (Int, Int)
- type Angle = Double
- type Dimension = (Int, Int)
- type Rect = (Point, Dimension)
- data Color
- = Black
- | Blue
- | Green
- | Cyan
- | Red
- | Magenta
- | Yellow
- | White
- | Gray
- | VLightBeige
- | LightBeige
- | MediumBeige
- | DarkBeige
- data RGB
- colorToRGB :: Color -> RGB
- rgb :: (Integral r, Integral g, Integral b) => r -> g -> b -> Maybe RGB
- rgbE :: (Integral r, Integral g, Integral b, Show r, Show g, Show b) => r -> g -> b -> RGB
- extractRGB :: (Integral r, Integral g, Integral b) => RGB -> (r, g, b)
- data Graphic
- nullGraphic :: Graphic
- overGraphic :: Graphic -> Graphic -> Graphic
- withColor :: Color -> Graphic -> Graphic
- withColor' :: RGB -> Graphic -> Graphic
- text :: UITexty s => Point -> s -> Graphic
- textLines :: UITexty s => [(Point, s)] -> Graphic
- ellipse :: Rect -> Graphic
- shearEllipse :: Point -> Rect -> Graphic
- line :: Point -> Point -> Graphic
- polygon :: [Point] -> Graphic
- polyline :: [Point] -> Graphic
- polybezier :: [Point] -> Graphic
- arc :: Rect -> Angle -> Angle -> Graphic
- circleFilled :: Point -> Int -> Graphic
- circleOutline :: Point -> Int -> Graphic
- rectangleFilled :: Rect -> Graphic
- rectangleOutline :: Rect -> Graphic
- translateGraphic :: Point -> Graphic -> Graphic
- rotateGraphic :: Point -> Angle -> Graphic -> Graphic
- scaleGraphic :: Double -> Double -> Graphic -> Graphic
- boundGraphic :: Rect -> Graphic -> Graphic
- newtype UIText = UIText {
- unwrapUIT :: [(Maybe RGB, BitmapFont, String)]
- class UITexty a where
- uitextToString :: UIText -> String
- splitUIText :: Int -> UIText -> (UIText, UIText)
- takeUIText :: Int -> UIText -> UIText
- dropUIText :: Int -> UIText -> UIText
- uitextLen :: UIText -> Int
- pureUIText :: String -> UIText
- appendUIText :: (UITexty s1, UITexty s2) => s1 -> s2 -> UIText
- coloredUIText :: UITexty s => Color -> s -> UIText
- rgbUIText :: UITexty s => Maybe RGB -> s -> UIText
- fontUIText :: UITexty s => BitmapFont -> s -> UIText
- textWidth :: UITexty s => s -> Int
- textWithinPixels :: UITexty s => Int -> s -> (UIText, UIText)
- textHeight :: UITexty s => s -> Int
- data WrapSetting
- prepText :: UITexty s => WrapSetting -> Double -> Rect -> s -> ([Point], [UIText])
- textWidth' :: BitmapFont -> String -> Int
- textWithinPixels' :: BitmapFont -> Int -> String -> (String, String)
- textHeight' :: BitmapFont -> String -> Int
- data BitmapFont :: *
Documentation
Angles are used when making arcs, circles, etc. or when performing rotations. Angles are measured in Degrees
We provide a data type for colors to allow users to easily and clearly specify common colors. Primary and secondary RGB colors are represented along with a few beige colors for use in many GUI elements.
Black | |
Blue | |
Green | |
Cyan | |
Red | |
Magenta | |
Yellow | |
White | |
Gray | |
VLightBeige | |
LightBeige | This is the default background color for the UI window. |
MediumBeige | |
DarkBeige |
colorToRGB :: Color -> RGB Source
Generally used as an internal function for converting Color to RGB, but can be used by anyone.
rgb :: (Integral r, Integral g, Integral b) => r -> g -> b -> Maybe RGB Source
This function takes three integral values between 0 and 255 inclusive and create an RGB value with them. If any of the values fall outside the acceptable range, Nothing is returned.
rgbE :: (Integral r, Integral g, Integral b, Show r, Show g, Show b) => r -> g -> b -> RGB Source
This is a version of rgb
that throws an error when a given
value falls outside the acceptable 0-255 range. The error message
shows the bad input, so the extra Show constraint is necessary.
extractRGB :: (Integral r, Integral g, Integral b) => RGB -> (r, g, b) Source
Use this to extract the values from an RGB color.
The main Graphic data type stores graphic information. Constructors are not directly exposed to encourage the use of the smart constructors.
If you would like to add custom rendering functions for Graphic, you will clearly need access to the constructors to destruct the graphics. Please request this, and I can either export them or we can discuss adding more rendering functions to this library.
The absence of a graphic.
overGraphic :: Graphic -> Graphic -> Graphic Source
The overlay of two graphics, the first over the second.
withColor' :: RGB -> Graphic -> Graphic Source
Use the given RGB color to paint the given graphic.
textLines :: UITexty s => [(Point, s)] -> Graphic Source
A convenience function for painting a set of (Point,String) pairs.
shearEllipse :: Point -> Rect -> Graphic Source
Draw a shear ellipse bounded by the given rectangle. This code was written originally by Paul Liu.
polybezier :: [Point] -> Graphic Source
Draw a Bezier curve defined by the given points.
arc :: Rect -> Angle -> Angle -> Graphic Source
Draw an arc of the ellipse bounded by the given rectangle that starts at the first angle measure and ends at the second.
circleFilled :: Point -> Int -> Graphic Source
Draw a filled circle with given center and radius.
circleOutline :: Point -> Int -> Graphic Source
Draw the outline of a circle with given center and radius.
rectangleFilled :: Rect -> Graphic Source
Draw a filled rectangle.
rectangleOutline :: Rect -> Graphic Source
Draw the outline of a rectangle.
translateGraphic :: Point -> Graphic -> Graphic Source
Translate the given graphic so that its origin is at the given point.
rotateGraphic :: Point -> Angle -> Graphic -> Graphic Source
Rotate the given graphic around the given point by the given number of degrees.
scaleGraphic :: Double -> Double -> Graphic -> Graphic Source
Scale the given graphic in the X and Y dimension respectively.
boundGraphic :: Rect -> Graphic -> Graphic Source
Cut the given graphic so that nothing outside of the given rectangle is visible.
Text in UISF can be rendered in multiple fonts and colors, so we need a more powerful data type to encode it. The UIText data type does this.
To retain easy compatibility with Strings (or other text representations), we also provide the UITexty class, which is how all widgets that accept UIText should do so.
uitextToString :: UIText -> String Source
Removes all font and color formatting from a UIText, returning its underlying String representation.
takeUIText :: Int -> UIText -> UIText Source
Take a certain number of characters off of a UIText
dropUIText :: Int -> UIText -> UIText Source
Drop a certain number of characters from a UIText
pureUIText :: String -> UIText Source
Lifts a String to a UIText (with default color and font).
appendUIText :: (UITexty s1, UITexty s2) => s1 -> s2 -> UIText Source
Appends two UITexty objects together.
coloredUIText :: UITexty s => Color -> s -> UIText Source
Colors a UITexty object.
rgbUIText :: UITexty s => Maybe RGB -> s -> UIText Source
Colors a UITexty object with an exact RGB value.
fontUIText :: UITexty s => BitmapFont -> s -> UIText Source
Converts the UITexty object to the given font.
textWidth :: UITexty s => s -> Int Source
Returns the width of the String in pixels as it will be rendered
textWithinPixels :: UITexty s => Int -> s -> (UIText, UIText) Source
Given a String and a number of pixels, returns the leading substring that fits within the horizontal number of pixels along with the remaining text of the String.
textHeight :: UITexty s => s -> Int Source
Returns the height of the String in pixels as it will be rendered
data WrapSetting Source
The Wrap Setting is used to determine how to split up a long piece of text.
:: UITexty s | |
=> WrapSetting | Whether we prefer newer or older text |
-> Double | Line spacing |
-> Rect | Bounding Box |
-> s | The text to print (which is allowed to have new lines) |
-> ([Point], [UIText]) |
Turn the given String into a list of Strings. If the wrap setting is NoWrap, then this is basically just the lines function. If it is CharWrap or WordWrap, then no string in the list will be wider than the width of the bounding box. The returned list of points indicate each Point where a line should be drawn. Note that this list may not be the same length as the list of strings.
Typically, this will be used in conjunction with zip and textLines to produce text graphics.
textWidth' :: BitmapFont -> String -> Int Source
Returns the text width of a String rendered in the given bitmap font.
textWithinPixels' :: BitmapFont -> Int -> String -> (String, String) Source
Splits a String based on what can fit within the given number of pixels (the fst of the result) and what's left over (the snd).
textHeight' :: BitmapFont -> String -> Int Source
Returns the text height of a String rendered in the given bitmap font.
data BitmapFont :: *
The bitmap fonts available in GLUT. The exact bitmap to be used is defined by the standard X glyph bitmaps for the X font with the given name.
Fixed8By13 | A fixed width font with every character fitting in an 8
by 13 pixel rectangle.
( |
Fixed9By15 | A fixed width font with every character fitting in an 9
by 15 pixel rectangle.
( |
TimesRoman10 | A 10-point proportional spaced Times Roman font.
( |
TimesRoman24 | A 24-point proportional spaced Times Roman font.
( |
Helvetica10 | A 10-point proportional spaced Helvetica font.
( |
Helvetica12 | A 12-point proportional spaced Helvetica font.
( |
Helvetica18 | A 18-point proportional spaced Helvetica font.
( |