annotate ui.h @ 642:c8e5949a8961

Use th-libs functions.
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 07 Jan 2015 16:56:54 +0200
parents 5b059a85cab8
children fc19ab0334b1
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * NNChat - Custom chat client for NewbieNudes.com chatrooms
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Written by Matti 'ccr' Hämäläinen
581
97a49a6cc959 Bump copyright year.
Matti Hamalainen <ccr@tnsp.org>
parents: 571
diff changeset
4 * (C) Copyright 2008-2013 Tecnic Software productions (TNSP)
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 */
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 #ifndef LIBNNUI_H
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #define LIBNNUI_H
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8
468
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
9 #ifdef __WIN32
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
10 #define SET_DELAY (0)
468
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
11 // Undefine because both windows.h and curses.h #define it
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
12 #undef MOUSE_MOVED
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
13 #else
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
14 #define SET_DELAY (5)
468
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
15 #endif
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
16
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #ifdef HAVE_NCURSES_H
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 #include <ncurses.h>
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #else
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 #include <curses.h>
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 #endif
554
13901e9be15b Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents: 541
diff changeset
22 #include <time.h>
468
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
23 #include "th_types.h"
607bd4491e79 Fix win32 build.
Matti Hamalainen <ccr@tnsp.org>
parents: 466
diff changeset
24 #include "th_string.h"
623
118276b60667 More work towards using th-libs th_network module.
Matti Hamalainen <ccr@tnsp.org>
parents: 622
diff changeset
25 #include "th_network.h"
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26
631
2c6945599b16 Rename a define.
Matti Hamalainen <ccr@tnsp.org>
parents: 630
diff changeset
27
2c6945599b16 Rename a define.
Matti Hamalainen <ccr@tnsp.org>
parents: 630
diff changeset
28 #define SET_MAX_WINDOWS (32) // Max chat buffer windows
2c6945599b16 Rename a define.
Matti Hamalainen <ccr@tnsp.org>
parents: 630
diff changeset
29 #define SET_BACKBUF_LEN (512) // Backbuffer size (in lines)
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
31
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
32 typedef struct
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
33 {
504
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
34 int *buf;
60e04709ce0f Refactor window backbuffer to use integer as internal storage to simplify
Matti Hamalainen <ccr@tnsp.org>
parents: 501
diff changeset
35 size_t len, bufsize;
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
36 } nn_line_t;
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
37
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
38
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 typedef struct
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 {
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 qringbuf_t *data; // "Backbuffer" data for this window
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 int pos; // Current position in the window, 0 = real time
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 BOOL dirty;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
45 int num;
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 char *id; // Chatter ID, NULL = main window
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
48 nn_line_t *line;
541
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
49
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
50 // Logging
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
51 char *logFilename;
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
52 FILE *logFile;
554
13901e9be15b Implement daily logs for room logs.
Matti Hamalainen <ccr@tnsp.org>
parents: 541
diff changeset
53 time_t logPrevMsgTime;
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 } nn_window_t;
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
57 typedef struct
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
58 {
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
59 time_t prevKeepAlive;
571
3ae357fd34bb Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
60 BOOL insertMode, isError, update, mask, done;
622
bb6b07b44800 Network code is being generalized into a th-libs module.
Matti Hamalainen <ccr@tnsp.org>
parents: 581
diff changeset
61 th_conn_t *conn;
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
62 void (*debugMsg)(const char *fmt, ...);
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
63 } nn_editstate_t;
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
64
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
65
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 extern nn_window_t *currWin;
571
3ae357fd34bb Rename quit-related internal variables.
Matti Hamalainen <ccr@tnsp.org>
parents: 554
diff changeset
67 extern BOOL appCursesInit, appQuitFlag;
509
942eea564b15 Fix backbuffer offset manipulation, prevents a segfault.
Matti Hamalainen <ccr@tnsp.org>
parents: 504
diff changeset
68 extern int scrHeight, scrWidth;
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
70 BOOL nnwin_init(int delay);
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
71 void nnwin_shutdown();
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
72 void nnwin_reset(void);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
74 void nnwin_update(BOOL force, BOOL mask, nn_editbuf_t *ebuf, char *optUserName, int optUserColor);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
76 nn_window_t * nnwin_main_window();
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
77 nn_window_t * nnwin_get(const int index);
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
78 nn_window_t * nnwin_find(const char *id);
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
79 void nnwin_set_current(nn_window_t *);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
81 BOOL nnwin_open(const char *name, BOOL curwin);
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
82 void nnwin_close(nn_window_t *win);
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83
501
ca88945d8eda Begin work on integrating the removal of ncurses "windowing" and transition
Matti Hamalainen <ccr@tnsp.org>
parents: 493
diff changeset
84 int nnwin_print(nn_window_t *win, const char *fmt);
513
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
85
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
86 void nnwin_input_process(nn_editbuf_t *editBuf, nn_editstate_t *editState,
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
87 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *));
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
88
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
89 char * nnwin_prompt_requester(BOOL allowEmpty, nn_editstate_t *,
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
90 BOOL (*callback)(int, nn_editbuf_t *, nn_editstate_t *),
ef5a2aa8382b Refactor input handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 509
diff changeset
91 void (*update)(nn_editbuf_t *, nn_editstate_t *));
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92
541
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
93
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
94 BOOL nn_log_open(nn_window_t *win);
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
95 void nn_log_close(nn_window_t *win);
44f67ec5e945 Improve logging facilities. Private chats in query windows are now logged
Matti Hamalainen <ccr@tnsp.org>
parents: 513
diff changeset
96
466
796508f828f6 Refactor much of the "windowing" UI code into a new module, ui.[ch]
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 #endif