| 1 | /** |
| 2 | * Copyright (c) 2006-2023 LOVE Development Team |
| 3 | * |
| 4 | * This software is provided 'as-is', without any express or implied |
| 5 | * warranty. In no event will the authors be held liable for any damages |
| 6 | * arising from the use of this software. |
| 7 | * |
| 8 | * Permission is granted to anyone to use this software for any purpose, |
| 9 | * including commercial applications, and to alter it and redistribute it |
| 10 | * freely, subject to the following restrictions: |
| 11 | * |
| 12 | * 1. The origin of this software must not be misrepresented; you must not |
| 13 | * claim that you wrote the original software. If you use this software |
| 14 | * in a product, an acknowledgment in the product documentation would be |
| 15 | * appreciated but is not required. |
| 16 | * 2. Altered source versions must be plainly marked as such, and must not be |
| 17 | * misrepresented as being the original software. |
| 18 | * 3. This notice may not be removed or altered from any source distribution. |
| 19 | **/ |
| 20 | |
| 21 | // LOVE |
| 22 | #include "Quad.h" |
| 23 | |
| 24 | // C |
| 25 | #include <cstring> // For memcpy |
| 26 | |
| 27 | namespace love |
| 28 | { |
| 29 | namespace graphics |
| 30 | { |
| 31 | |
| 32 | love::Type Quad::type("Quad" , &Object::type); |
| 33 | |
| 34 | Quad::Quad(const Quad::Viewport &v, double sw, double sh) |
| 35 | : sw(sw) |
| 36 | , sh(sh) |
| 37 | { |
| 38 | arrayLayer = 0; |
| 39 | refresh(v, sw, sh); |
| 40 | } |
| 41 | |
| 42 | Quad::~Quad() |
| 43 | { |
| 44 | } |
| 45 | |
| 46 | void Quad::refresh(const Quad::Viewport &v, double sw, double sh) |
| 47 | { |
| 48 | this->viewport = v; |
| 49 | this->sw = sw; |
| 50 | this->sh = sh; |
| 51 | |
| 52 | // Vertices are ordered for use with triangle strips: |
| 53 | // 0---2 |
| 54 | // | / | |
| 55 | // 1---3 |
| 56 | vertexPositions[0] = Vector2(0.0f, 0.0f); |
| 57 | vertexPositions[1] = Vector2(0.0f, (float) v.h); |
| 58 | vertexPositions[2] = Vector2((float) v.w, 0.0f); |
| 59 | vertexPositions[3] = Vector2((float) v.w, (float) v.h); |
| 60 | |
| 61 | vertexTexCoords[0] = Vector2((float) (v.x / sw), (float) (v.y / sh)); |
| 62 | vertexTexCoords[1] = Vector2((float) (v.x / sw), (float) ((v.y + v.h) / sh)); |
| 63 | vertexTexCoords[2] = Vector2((float) ((v.x + v.w) / sw), (float) (v.y / sh)); |
| 64 | vertexTexCoords[3] = Vector2((float) ((v.x + v.w) / sw), (float) ((v.y + v.h) / sh)); |
| 65 | } |
| 66 | |
| 67 | void Quad::setViewport(const Quad::Viewport &v) |
| 68 | { |
| 69 | refresh(v, sw, sh); |
| 70 | } |
| 71 | |
| 72 | Quad::Viewport Quad::getViewport() const |
| 73 | { |
| 74 | return viewport; |
| 75 | } |
| 76 | |
| 77 | double Quad::getTextureWidth() const |
| 78 | { |
| 79 | return sw; |
| 80 | } |
| 81 | |
| 82 | double Quad::getTextureHeight() const |
| 83 | { |
| 84 | return sh; |
| 85 | } |
| 86 | |
| 87 | void Quad::setLayer(int layer) |
| 88 | { |
| 89 | arrayLayer = layer; |
| 90 | } |
| 91 | |
| 92 | int Quad::getLayer() const |
| 93 | { |
| 94 | return arrayLayer; |
| 95 | } |
| 96 | |
| 97 | } // graphics |
| 98 | } // love |
| 99 | |