|
From: <sch...@us...> - 2008-11-21 22:59:57
|
Revision: 38
http://deraciel.svn.sourceforge.net/deraciel/?rev=38&view=rev
Author: schnippi001
Date: 2008-11-21 22:59:49 +0000 (Fri, 21 Nov 2008)
Log Message:
-----------
Multiline output, first
Modified Paths:
--------------
trunk/main.c
trunk/text_window.c
Modified: trunk/main.c
===================================================================
--- trunk/main.c 2008-11-21 20:44:23 UTC (rev 37)
+++ trunk/main.c 2008-11-21 22:59:49 UTC (rev 38)
@@ -28,8 +28,8 @@
curs_set(0); /* Hide the cursor */
start_color();
- init_pair(1, COLOR_BLUE, COLOR_BLACK);
- init_pair(2, COLOR_YELLOW, COLOR_RED);
+ init_pair(1, COLOR_WHITE, COLOR_BLUE);
+ init_pair(2, COLOR_BLACK, COLOR_YELLOW);
clear();
refresh();
@@ -38,8 +38,25 @@
text_window_create();
- text_window_out("Deraciel v0.1");
+ // 1 Line output
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+ sleep(1);
+
+ // 2 Line output
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+
+ sleep(1);
+
+ // 3 Line output
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmoLorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+
+ sleep(1);
+
+ // 1 Line output
+ text_window_out("Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy eirmo");
+
+
int ch;
while(ch != KEY_ESCAPE){
Modified: trunk/text_window.c
===================================================================
--- trunk/text_window.c 2008-11-21 20:44:23 UTC (rev 37)
+++ trunk/text_window.c 2008-11-21 22:59:49 UTC (rev 38)
@@ -3,81 +3,113 @@
#include <string.h>
#include <form.h>
-#define TEXTWND_MAXWIDTH (80)
-#define TEXTWND_MAXHEIGHT (2)
-#define TEXTWND_LINEBUFFER_SIZE 256
-#define TEXTWND_BORDER
+#define BORDER_WND_MAXWIDTH (80)
+#define BORDER_WND_MAXHEIGHT (2)
+#define TEXTWINDOW_LINEBUFFER_SIZE (3*78 + 1) // 3 lines * 78 characters + '\n'
+#define TEXTWINDOW_BORDER
-static WINDOW *TEXTWND; /* Window handle */
-static char linebuffer[TEXTWND_LINEBUFFER_SIZE];
+static WINDOW *border_wnd; /* Window handle */
+static WINDOW *text_wnd; /* Window handle */
+static char linebuffer[TEXTWINDOW_LINEBUFFER_SIZE];
-static void text_window_repaint(void);
+static void repaint(void);
+static void draw_border();
-
void text_window_create(void)
{
- TEXTWND = newwin(TEXTWND_MAXHEIGHT, TEXTWND_MAXWIDTH, 0, 0);
+ border_wnd = newwin(BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH, 0, 0);
+ text_wnd = newwin(BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2, 0, 1);
- if (!TEXTWND) {
+ if (!border_wnd || !text_wnd) {
fprintf(stderr, "text window creation failed!\n");
return;
}
- wborder(TEXTWND, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
+ wattron(border_wnd, COLOR_PAIR(1));
+ wbkgd(text_wnd, COLOR_PAIR(2));
- wrefresh(TEXTWND);
+
+ draw_border();
+
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
}
void text_window_destroy()
{
- if (TEXTWND) {
+ if (border_wnd) {
/* Clear window from screen */
- wclear(TEXTWND);
- wrefresh(TEXTWND);
+ wclear(border_wnd);
+ wrefresh(border_wnd);
/* Free resources consumed by the window */
- delwin(TEXTWND);
- TEXTWND = NULL;
+ delwin(text_wnd);
+ text_wnd = NULL;
+
+ delwin(border_wnd);
+ border_wnd = NULL;
}
}
-void text_window_repaint()
+
+
+void text_window_resize(void)
{
/* Clear window from screen */
- wclear(TEXTWND);
+ wclear(border_wnd);
+ wclear(text_wnd);
-#ifdef TEXTWND_BORDER
- /* Redraw border with new dimensions */
- wborder(TEXTWND, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
-#endif // TEXTWND_BORDER
+ /* Reallocate storage for resized text window */
+ wresize(border_wnd, BORDER_WND_MAXHEIGHT, BORDER_WND_MAXWIDTH);
+ wresize(text_wnd, BORDER_WND_MAXHEIGHT-1, BORDER_WND_MAXWIDTH-2);
- wmove(TEXTWND, 0, 1);
- wprintw(TEXTWND, linebuffer);
- wrefresh(TEXTWND);
+ repaint();
}
-void text_window_resize(void)
+
+
+void text_window_out(const char *string)
{
- /* Clear window from screen */
- wclear(TEXTWND);
+ strncpy(linebuffer, string, TEXTWINDOW_LINEBUFFER_SIZE);
+ linebuffer[TEXTWINDOW_LINEBUFFER_SIZE-1] = '\0';
- if (TEXTWND) {
- /* Reallocate storage for resized text window */
- wresize(TEXTWND, TEXTWND_MAXHEIGHT, TEXTWND_MAXWIDTH);
- }
+ // mod will be 0 if buffer fits *exactly* into line and 1 if we have to add a new line
+ int mod = strlen(linebuffer) % (BORDER_WND_MAXWIDTH-2);
- text_window_repaint();
+ int lines = (mod == 0 ? 0 : 1) + strlen(linebuffer)/(BORDER_WND_MAXWIDTH-2);
+
+ wresize(text_wnd, lines, BORDER_WND_MAXWIDTH-2);
+ wresize(border_wnd, lines+1, BORDER_WND_MAXWIDTH);
+
+ repaint();
}
-void text_window_out(const char *string)
+void draw_border()
{
- strncpy(linebuffer, string, TEXTWND_LINEBUFFER_SIZE);
- linebuffer[TEXTWND_LINEBUFFER_SIZE-1] = '\0';
- text_window_repaint();
+ wborder(border_wnd, 0, 0, ' ', 0, ACS_VLINE, ACS_VLINE, '\\', '/');
}
+
+
+void repaint()
+{
+ /* Clear window from screen */
+ wclear(border_wnd);
+ wclear(text_wnd);
+
+#ifdef TEXTWINDOW_BORDER
+ /* Redraw border with new dimensions */
+ draw_border();
+#endif // TEXTWINDOW_BORDER
+
+ wmove(text_wnd, 0, 0);
+ wprintw(text_wnd, linebuffer);
+
+ wrefresh(border_wnd);
+ wrefresh(text_wnd);
+}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|