fork/m-overlay
git clone https://git.julia.blue/fork/m-overlay
a193294
main
1local graphics =love . graphics 2 3local clear =graphics . clear 4local setColor =graphics . setColor 5local getColor =graphics . getColor 6local setBackgroundColor =graphics . setBackgroundColor 7local getBackgroundColor =graphics . getBackgroundColor 8 9-- Love2D changed color values to be 0-1 10-- Allow 0-255 values again.. 11function graphics . clear ( r , g , b , a , ... ) 12if type ( r ) == "table" then 13r , g , b , a =r . r , r . g , r . b , r . a 14else 15r , g , b , a =r or 255 , g or 255 , b or 255 , a or 255 16end 17clear ( r / 255 , g / 255 , b / 255 , a / 255 , ... ) 18end 19 20-- Love2D changed color values to be 0-1 21-- Allow 0-255 values again.. 22function graphics . setColor ( r , g , b , a ) 23if type ( r ) == "table" then 24r , g , b , a =r . r , r . g , r . b , r . a 25else 26r , g , b , a =r or 255 , g or 255 , b or 255 , a or 255 27end 28setColor ( r / 255 , g / 255 , b / 255 , a / 255 ) 29end 30 31function graphics . getColor () 32local r , g , b , a =getColor () 33return r * 255 , g * 255 , b * 255 , a * 255 34end 35 36-- Love2D changed color values to be 0-1 37-- Allow 0-255 values again.. 38function graphics . setBackgroundColor ( r , g , b , a ) 39if type ( r ) == "table" then 40r , g , b , a =r . r , r . g , r . b , r . a 41else 42r , g , b , a =r or 255 , g or 255 , b or 255 , a or 255 43end 44setBackgroundColor ( r / 255 , g / 255 , b / 255 , a / 255 ) 45end 46 47function graphics . getBackgroundColor () 48local r , g , b , a =getBackgroundColor () 49return r * 255 , g * 255 , b * 255 , a * 255 50end 51 52-- Draw an image using width and height in pixels 53-- OriginX and OriginY should be between 0 and 1 54-- An origin of 0.5, 0.5 would be the center 55function graphics . easyDraw ( obj , x , y , rotation , width , height , originX , originY , ... ) 56if not obj then return end 57 58local objW , objH =obj : getWidth (), obj : getHeight () 59 60rotation =rotation or 0 61width =width or objW 62height =height or objH 63originX =originX or 0 64originY =originY or 0 65 66local scaledW =width / objW 67local scaledH =height / objH 68graphics . draw ( obj , x , y , rotation , scaledW , scaledH , objW * originX , objH * originY , ... ) 69end 70 71--applies a transformation that maps 72-- 0,0 => ox, oy 73-- 1,0 => xx, xy 74-- 0,1 => yx, yy 75-- via love.graphics.translate, .rotate and .scale 76 77local sqrt =math . sqrt 78local atan2 =math . atan2 79local acos =math . acos 80local tan =math . tan 81local cos =math . cos 82local sin =math . sin 83 84function graphics . transform ( ox , oy , xx , xy , yx , yy ) 85 86local ex , ey , fx , fy =xx - ox , xy - oy , yx - ox , yy - oy 87if ex * fy < ey * fx then ex , ey , fx , fy =fx , fy , ex , ey end 88local e , f =math . sqrt ( ex * ex + ey * ey ), math . sqrt ( fx * fx + fy * fy ) 89 90ex , ey =ex / e , ey / e 91fx , fy =fx / f , fy / f 92 93local desiredOrientation =math . atan2 ( ey + fy , ex + fx ) 94local desiredAngle =math . acos ( ex * fx + ey * fy ) / 2 95local z =math . tan ( desiredAngle ) 96local distortion =math . sqrt (( 1 + z * z ) / 2 ) 97 98graphics . translate ( ox , oy ) 99graphics . rotate ( desiredOrientation ) 100graphics . scale ( 1 , z ) 101graphics . rotate ( - math . pi / 4 ) 102graphics . scale ( e / distortion , f / distortion ) 103 104end 105 106function graphics . innerRectangle ( x , y , w , h , ... ) 107local lw =graphics . getLineWidth () 108 109x =x + lw / 2 110y =y + lw / 2 111w =w - lw 112h =h - lw 113 114graphics . rectangle ( "line" , x , y , w , h , ... ) 115end 116 117-- Draw a rectangle to fit AROUND the width and height 118function graphics . outlineRectangle ( x , y , w , h , ... ) 119local lw =graphics . getLineWidth () 120 121x =x - lw / 2 122y =y - lw / 2 123w =w + lw 124h =h + lw 125 126graphics . rectangle ( "line" , x , y , w , h , ... ) 127end 128 129function graphics . textOutlinef ( text , width , x , y , ... ) 130local steps =width * 2 / 3 131if steps < 1 then steps =1 end 132 133for _x =- width , width , steps do 134for _y =- width , width , steps do 135graphics . printf ( text , x + _x , y + _y , ... ) 136end 137end 138end 139 140function graphics . textOutline ( text , width , x , y , ... ) 141local steps =width * 2 / 3 142if steps < 1 then steps =1 end 143 144for _x =- width , width , steps do 145for _y =- width , width , steps do 146graphics . ( text , x + _x , y + _y , ... ) 147end 148end 149end 150 151function graphics . roundRect ( x , y , width , height , radius ) 152--RECTANGLES 153graphics . rectangle ( "fill" , x + radius , y , width - 2 * radius , height ) 154graphics . rectangle ( "fill" , x , y + radius , radius , height - ( radius * 2 )) 155graphics . rectangle ( "fill" , x + ( width - radius ), y + radius , radius , height - ( radius * 2 )) 156 157--ARCS 158graphics . arc ( "fill" , x + radius , y + radius , radius , math . rad ( - 180 ), math . rad ( - 90 )) 159graphics . arc ( "fill" , x + width - radius , y + radius , radius , math . rad ( - 90 ), math . rad ( 0 )) 160graphics . arc ( "fill" , x + radius , y + height - radius , radius , math . rad ( - 180 ), math . rad ( - 270 )) 161graphics . arc ( "fill" , x + width - radius , y + height - radius , radius , math . rad ( 0 ), math . rad ( 90 )) 162end