Skip to content

Commit

Permalink
Added horizontal and vertical text drawing
Browse files Browse the repository at this point in the history
  • Loading branch information
DeveloperGY committed Dec 22, 2022
1 parent 013e28c commit 78181a8
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 9 deletions.
Binary file modified bin/libtermDisplay.a
Binary file not shown.
Binary file modified bin/out
Binary file not shown.
Binary file modified obj/draw.o
Binary file not shown.
10 changes: 2 additions & 8 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,8 @@ int main(void)

while (ch != 'q')
{
td_drawStrokeRect(2, 2, 5, 5, '#', TD_COLOR_WHITE, TD_COLOR_WHITE);
td_drawFillRect(3,3, 3, 3, '.', TD_COLOR_WHITE, TD_COLOR_DEFAULT);
td_drawRect(10, 7, 22, 12, 's', 'f', TD_COLOR_YELLOW, TD_COLOR_MAGENTA, TD_COLOR_WHITE, TD_COLOR_RED);
td_drawLine(0, 0, 10, 4, '*', TD_COLOR_RED, TD_COLOR_CYAN);
td_drawLine(0, 4, 10, 0, '*', TD_COLOR_BLACK, TD_COLOR_BLUE);
td_drawLine(0, 0, 4, 10, '*', TD_COLOR_CYAN, TD_COLOR_RED);
td_drawLine(0, 10, 4, 0, '*', TD_COLOR_BLUE, TD_COLOR_BLACK);
td_drawPoint(x, y, '@', TD_COLOR_YELLOW, TD_COLOR_DEFAULT);
td_drawTextHorizontal(0, 0, "Name: korpine", TD_COLOR_YELLOW, TD_COLOR_DEFAULT);
td_drawPoint(x, y, '@', TD_COLOR_CYAN, TD_COLOR_DEFAULT);
td_display();

ch = getch();
Expand Down
24 changes: 24 additions & 0 deletions src/termDisplay/draw.c
Original file line number Diff line number Diff line change
Expand Up @@ -219,5 +219,29 @@ void td_drawLine(int x1, int y1, int x2, int y2, char c, int fgColor, int bgColo
}
}

return;
}

void td_drawTextHorizontal(int x, int y, const char *str, int fgColor, int bgColor)
{
size_t len = strlen(str);

for (int i=0; i<len; i++)
{
td_drawPoint(x+i, y, str[i], fgColor, bgColor);
}

return;
}

void td_drawTextVertical(int x, int y, const char *str, int fgColor, int bgColor)
{
size_t len = strlen(str);

for (int i=0; i<len; i++)
{
td_drawPoint(x, y+i, str[i], fgColor, bgColor);
}

return;
}
33 changes: 32 additions & 1 deletion src/termDisplay/termDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>
#include <stddef.h>
#include <math.h>
#include <string.h>

#include <termios.h>

Expand Down Expand Up @@ -180,6 +181,34 @@ void td_drawRect(int x, int y, unsigned int width, unsigned int height, char str
*/
void td_drawLine(int x1, int y1, int x2, int y2, char c, int fgColor, int bgColor);

/**
* @brief Draws text horizontally at the specified coordinates with the specified colors
*
* @param x The X Coordinate
* @param y The Y Coordinate
*
* @param str The text to print (must be null terminated)
*
* @param fgColor The foreground color
* @param bgColor The background color
*
*/
void td_drawTextHorizontal(int x, int y, const char *str, int fgColor, int bgColor);

/**
* @brief Draws text verically at the specified coordinates with the specified colors
*
* @param x The X Coordinate
* @param y The Y Coordinate
*
* @param str The text to print (must be null terminated)
*
* @param fgColor The foreground color
* @param bgColor The background color
*
*/
void td_drawTextVertical(int x, int y, const char *str, int fgColor, int bgColor);

#ifdef __cplusplus
}
#endif
Expand All @@ -196,7 +225,9 @@ extern "C" {
/**
* @brief An unbuffered character input function to remove the need
* to press enter to input a character
*
*
* @warning Linux only!!!
*
*/
char getch();

Expand Down

0 comments on commit 78181a8

Please sign in to comment.