| 1 | /* |
| 2 | * This file is part of lanterna (http://code.google.com/p/lanterna/). |
| 3 | * |
| 4 | * lanterna is free software: you can redistribute it and/or modify |
| 5 | * it under the terms of the GNU Lesser General Public License as published by |
| 6 | * the Free Software Foundation, either version 3 of the License, or |
| 7 | * (at your option) any later version. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, |
| 10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | * GNU Lesser General Public License for more details. |
| 13 | * |
| 14 | * You should have received a copy of the GNU Lesser General Public License |
| 15 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 16 | * |
| 17 | * Copyright (C) 2010-2015 Martin |
| 18 | */ |
| 19 | package com.googlecode.lanterna.gui2; |
| 20 | |
| 21 | import com.googlecode.lanterna.SGR; |
| 22 | import com.googlecode.lanterna.TerminalPosition; |
| 23 | import com.googlecode.lanterna.TerminalSize; |
| 24 | import com.googlecode.lanterna.TextColor; |
| 25 | import com.googlecode.lanterna.graphics.TextGraphics; |
| 26 | |
| 27 | /** |
| 28 | * This WindowPostRenderer implementation draws a shadow under the window |
| 29 | * |
| 30 | * @author Martin |
| 31 | */ |
| 32 | public class WindowShadowRenderer implements WindowPostRenderer { |
| 33 | @Override |
| 34 | public void postRender( |
| 35 | TextGraphics textGraphics, |
| 36 | TextGUI textGUI, |
| 37 | Window window) { |
| 38 | |
| 39 | TerminalPosition windowPosition = window.getPosition(); |
| 40 | TerminalSize decoratedWindowSize = window.getDecoratedSize(); |
| 41 | textGraphics.setForegroundColor(TextColor.ANSI.BLACK); |
| 42 | textGraphics.setBackgroundColor(TextColor.ANSI.BLACK); |
| 43 | textGraphics.enableModifiers(SGR.BOLD); |
| 44 | TerminalPosition lowerLeft = windowPosition.withRelativeColumn(2).withRelativeRow(decoratedWindowSize.getRows()); |
| 45 | TerminalPosition lowerRight = lowerLeft.withRelativeColumn(decoratedWindowSize.getColumns() - 1); |
| 46 | textGraphics.drawLine(lowerLeft, lowerRight, ' '); |
| 47 | TerminalPosition upperRight = lowerRight.withRelativeRow(-decoratedWindowSize.getRows() + 1); |
| 48 | textGraphics.drawLine(lowerRight, upperRight, ' '); |
| 49 | |
| 50 | //Fill the remaining hole |
| 51 | upperRight = upperRight.withRelativeColumn(-1); |
| 52 | lowerRight = lowerRight.withRelativeColumn(-1); |
| 53 | textGraphics.drawLine(upperRight, lowerRight, ' '); |
| 54 | |
| 55 | } |
| 56 | } |