Update from trunk.
Subversion-branch: /branches/raven-branch Subversion-revision: 1467
This commit is contained in:
commit
6e2c404f64
20 changed files with 2138 additions and 58 deletions
99
src/i_main.c
99
src/i_main.c
|
|
@ -24,7 +24,6 @@
|
|||
//
|
||||
//-----------------------------------------------------------------------------
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "SDL.h"
|
||||
|
|
@ -53,9 +52,76 @@
|
|||
|
||||
void D_DoomMain (void);
|
||||
|
||||
#if !defined(_WIN32) && !defined(HAVE_SCHED_SETAFFINITY)
|
||||
#if defined(_WIN32)
|
||||
|
||||
typedef BOOL WINAPI (*SetAffinityFunc)(HANDLE hProcess, DWORD_PTR mask);
|
||||
|
||||
// This is a bit more complicated than it really needs to be. We really
|
||||
// just need to call the SetProcessAffinityMask function, but that
|
||||
// function doesn't exist on systems before Windows 2000. Instead,
|
||||
// dynamically look up the function and call the pointer to it. This
|
||||
// way, the program will run on older versions of Windows (Win9x, etc.)
|
||||
|
||||
static void LockCPUAffinity(void)
|
||||
{
|
||||
HMODULE kernel32_dll;
|
||||
SetAffinityFunc SetAffinity;
|
||||
|
||||
// Find the kernel interface DLL.
|
||||
|
||||
kernel32_dll = LoadLibrary("kernel32.dll");
|
||||
|
||||
if (kernel32_dll == NULL)
|
||||
{
|
||||
// This should never happen...
|
||||
|
||||
fprintf(stderr, "Failed to load kernel32.dll\n");
|
||||
return;
|
||||
}
|
||||
// Find the SetProcessAffinityMask function.
|
||||
|
||||
SetAffinity = GetProcAddress(kernel32_dll, "SetProcessAffinityMask");
|
||||
|
||||
// If the function was not found, we are on an old (Win9x) system
|
||||
// that doesn't have this function. That's no problem, because
|
||||
// those systems don't support SMP anyway.
|
||||
|
||||
if (SetAffinity != NULL)
|
||||
{
|
||||
if (!SetAffinity(GetCurrentProcess(), 1))
|
||||
{
|
||||
fprintf(stderr, "Failed to set process affinity (%d)\n",
|
||||
(int) GetLastError());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#elif defined(HAVE_SCHED_SETAFFINITY)
|
||||
|
||||
// Unix (Linux) version:
|
||||
|
||||
static void LockCPUAffinity(void)
|
||||
{
|
||||
cpu_set_t set;
|
||||
|
||||
CPU_ZERO(&set);
|
||||
CPU_SET(0, &set);
|
||||
|
||||
sched_setaffinity(getpid(), sizeof(set), &set);
|
||||
}
|
||||
|
||||
#else
|
||||
|
||||
#warning No known way to set processor affinity on this platform.
|
||||
#warning You may experience crashes due to SDL_mixer.
|
||||
|
||||
static void LockCPUAffinity(void)
|
||||
{
|
||||
fprintf(stderr,
|
||||
"WARNING: No known way to set processor affinity on this platform.\n"
|
||||
" You may experience crashes due to SDL_mixer.\n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
int main(int argc, char **argv)
|
||||
|
|
@ -65,33 +131,10 @@ int main(int argc, char **argv)
|
|||
myargc = argc;
|
||||
myargv = argv;
|
||||
|
||||
#ifdef _WIN32
|
||||
// Only schedule on a single core, if we have multiple
|
||||
// cores. This is to work around a bug in SDL_mixer.
|
||||
|
||||
// Set the process affinity mask so that all threads
|
||||
// run on the same processor. This is a workaround for a bug in
|
||||
// SDL_mixer that causes occasional crashes.
|
||||
|
||||
if (!SetProcessAffinityMask(GetCurrentProcess(), 1))
|
||||
{
|
||||
fprintf(stderr, "Failed to set process affinity mask (%d)\n",
|
||||
(int) GetLastError());
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SCHED_SETAFFINITY
|
||||
|
||||
// Linux version:
|
||||
|
||||
{
|
||||
cpu_set_t set;
|
||||
|
||||
CPU_ZERO(&set);
|
||||
CPU_SET(0, &set);
|
||||
|
||||
sched_setaffinity(getpid(), sizeof(set), &set);
|
||||
}
|
||||
|
||||
#endif
|
||||
LockCPUAffinity();
|
||||
|
||||
// start doom
|
||||
|
||||
|
|
|
|||
|
|
@ -35,6 +35,12 @@
|
|||
#include "w_file.h"
|
||||
#include "z_zone.h"
|
||||
|
||||
// This constant doesn't exist in VC6:
|
||||
|
||||
#ifndef INVALID_SET_FILE_POINTER
|
||||
#define INVALID_SET_FILE_POINTER 0xffffffff
|
||||
#endif
|
||||
|
||||
typedef struct
|
||||
{
|
||||
wad_file_t wad;
|
||||
|
|
|
|||
1366
textscreen/Doxyfile
Normal file
1366
textscreen/Doxyfile
Normal file
File diff suppressed because it is too large
Load diff
|
|
@ -30,3 +30,6 @@ libtextscreen_a_SOURCES = \
|
|||
txt_window_action.c txt_window_action.h \
|
||||
txt_font.h
|
||||
|
||||
doc:
|
||||
doxygen
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,19 @@
|
|||
#ifndef TXT_BUTTON_H
|
||||
#define TXT_BUTTON_H
|
||||
|
||||
/**
|
||||
* @file txt_button.h
|
||||
*
|
||||
* Button widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Button widget.
|
||||
*
|
||||
* A button is a widget that can be selected to perform some action.
|
||||
* When a button is pressed, it emits the "pressed" signal.
|
||||
*/
|
||||
|
||||
typedef struct txt_button_s txt_button_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -32,9 +45,35 @@ struct txt_button_s
|
|||
char *label;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new button widget.
|
||||
*
|
||||
* @param label The label to use on the new button.
|
||||
* @return Pointer to the new button widget.
|
||||
*/
|
||||
|
||||
txt_button_t *TXT_NewButton(char *label);
|
||||
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
|
||||
|
||||
/**
|
||||
* Create a new button widget, binding the "pressed" signal to a
|
||||
* specified callback function.
|
||||
*
|
||||
* @param label The label to use on the new button.
|
||||
* @param func The callback function to invoke.
|
||||
* @param user_data User-specified pointer to pass to the callback.
|
||||
* @return Pointer to the new button widget.
|
||||
*/
|
||||
|
||||
txt_button_t *TXT_NewButton2(char *label, TxtWidgetSignalFunc func,
|
||||
void *user_data);
|
||||
|
||||
/**
|
||||
* Change the label used on a button.
|
||||
*
|
||||
* @param button The button.
|
||||
* @param label The new label.
|
||||
*/
|
||||
|
||||
void TXT_SetButtonLabel(txt_button_t *button, char *label);
|
||||
|
||||
#endif /* #ifndef TXT_BUTTON_H */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,25 @@
|
|||
#ifndef TXT_CHECKBOX_H
|
||||
#define TXT_CHECKBOX_H
|
||||
|
||||
/**
|
||||
* @file txt_checkbox.h
|
||||
*
|
||||
* Checkbox widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Checkbox widget.
|
||||
*
|
||||
* A checkbox is used to control boolean values that may be either on
|
||||
* or off. The widget has a label that is displayed to the right of
|
||||
* the checkbox indicator. The widget tracks an integer variable;
|
||||
* if the variable is non-zero, the checkbox is checked, while if it
|
||||
* is zero, the checkbox is unchecked. It is also possible to
|
||||
* create "inverted" checkboxes where this logic is reversed.
|
||||
*
|
||||
* When a checkbox is changed, it emits the "changed" signal.
|
||||
*/
|
||||
|
||||
typedef struct txt_checkbox_s txt_checkbox_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -34,7 +53,29 @@ struct txt_checkbox_s
|
|||
int inverted;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new checkbox.
|
||||
*
|
||||
* @param label The label for the new checkbox.
|
||||
* @param variable Pointer to the variable containing this checkbox's
|
||||
* value.
|
||||
* @return Pointer to the new checkbox.
|
||||
*/
|
||||
|
||||
txt_checkbox_t *TXT_NewCheckBox(char *label, int *variable);
|
||||
|
||||
/**
|
||||
* Create a new inverted checkbox.
|
||||
*
|
||||
* An inverted checkbox displays the opposite of a normal checkbox;
|
||||
* where it would be checked, it appears unchecked, and vice-versa.
|
||||
*
|
||||
* @param label The label for the new checkbox.
|
||||
* @param variable Pointer to the variable containing this checkbox's
|
||||
* value.
|
||||
* @return Pointer to the new checkbox.
|
||||
*/
|
||||
|
||||
txt_checkbox_t *TXT_NewInvertedCheckBox(char *label, int *variable);
|
||||
|
||||
#endif /* #ifndef TXT_CHECKBOX_H */
|
||||
|
|
|
|||
|
|
@ -22,18 +22,47 @@
|
|||
#ifndef TXT_DESKTOP_H
|
||||
#define TXT_DESKTOP_H
|
||||
|
||||
/**
|
||||
* @file txt_desktop.h
|
||||
*
|
||||
* Textscreen desktop.
|
||||
*/
|
||||
|
||||
#include "txt_window.h"
|
||||
|
||||
void TXT_AddDesktopWindow(txt_window_t *win);
|
||||
void TXT_RemoveDesktopWindow(txt_window_t *win);
|
||||
void TXT_SetDesktopTitle(char *title);
|
||||
void TXT_DrawDesktop(void);
|
||||
void TXT_GUIMainLoop(void);
|
||||
void TXT_DispatchEvents(void);
|
||||
void TXT_ExitMainLoop(void);
|
||||
void TXT_DrawWindow(txt_window_t *window, int selected);
|
||||
void TXT_WindowKeyPress(txt_window_t *window, int c);
|
||||
|
||||
#endif /* #ifndef TXT_DESKTOP_T */
|
||||
/**
|
||||
* Set the title displayed at the top of the screen.
|
||||
*
|
||||
* @param title The title to display.
|
||||
*/
|
||||
|
||||
void TXT_SetDesktopTitle(char *title);
|
||||
|
||||
/**
|
||||
* Exit the currently-running main loop and return from the
|
||||
* @ref TXT_GUIMainLoop function.
|
||||
*/
|
||||
|
||||
void TXT_ExitMainLoop(void);
|
||||
|
||||
/**
|
||||
* Start the main event loop. At least one window must have been
|
||||
* opened prior to running this function. When no windows are left
|
||||
* open, the event loop exits.
|
||||
*
|
||||
* It is possible to trigger an exit from this function using the
|
||||
* @ref TXT_ExitMainLoop function.
|
||||
*/
|
||||
|
||||
void TXT_GUIMainLoop(void);
|
||||
|
||||
#endif /* #ifndef TXT_DESKTOP_H */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,22 @@
|
|||
#ifndef TXT_DROPDOWN_H
|
||||
#define TXT_DROPDOWN_H
|
||||
|
||||
/**
|
||||
* @file txt_dropdown.h
|
||||
*
|
||||
* Dropdown list widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Dropdown list widget.
|
||||
*
|
||||
* A dropdown list allows the user to select from a list of values,
|
||||
* which appears when the list is selected.
|
||||
*
|
||||
* When the value of a dropdown list is changed, the "changed" signal
|
||||
* is emitted.
|
||||
*/
|
||||
|
||||
typedef struct txt_dropdown_list_s txt_dropdown_list_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -38,6 +54,20 @@ struct txt_dropdown_list_s
|
|||
int num_values;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new dropdown list widget.
|
||||
*
|
||||
* The parameters specify a list of string labels, and a pointer to an
|
||||
* integer variable. The variable contains the current "value" of the
|
||||
* list, as an index within the list of labels.
|
||||
*
|
||||
* @param variable Pointer to the variable containing the
|
||||
* list's value.
|
||||
* @param values Pointer to an array of strings containing
|
||||
* the labels to use for the list.
|
||||
* @param num_values The number of variables in the list.
|
||||
*/
|
||||
|
||||
txt_dropdown_list_t *TXT_NewDropdownList(int *variable,
|
||||
char **values, int num_values);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,21 @@
|
|||
#ifndef TXT_INPUTBOX_H
|
||||
#define TXT_INPUTBOX_H
|
||||
|
||||
/**
|
||||
* @file txt_inputbox.h
|
||||
*
|
||||
* Input box widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Input box widget.
|
||||
*
|
||||
* An input box is a widget that displays a value, which can be
|
||||
* selected to enter a new value.
|
||||
*
|
||||
* Input box widgets can be of an integer or string type.
|
||||
*/
|
||||
|
||||
typedef struct txt_inputbox_s txt_inputbox_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -35,7 +50,30 @@ struct txt_inputbox_s
|
|||
void *value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new input box widget for controlling a string value.
|
||||
*
|
||||
* @param value Pointer to a string variable that contains
|
||||
* a pointer to the current value of the
|
||||
* input box. The value should be allocated
|
||||
* dynamically; when the string is changed it
|
||||
* will be freed and the variable set to point
|
||||
* to the new string value.
|
||||
* @param size Width of the input box, in characters.
|
||||
* @return Pointer to the new input box widget.
|
||||
*/
|
||||
|
||||
txt_inputbox_t *TXT_NewInputBox(char **value, int size);
|
||||
|
||||
/**
|
||||
* Create a new input box widget for controlling an integer value.
|
||||
*
|
||||
* @param value Pointer to an integer variable containing
|
||||
* the value of the input box.
|
||||
* @param size Width of the input box, in characters.
|
||||
* @return Pointer to the new input box widget.
|
||||
*/
|
||||
|
||||
txt_inputbox_t *TXT_NewIntInputBox(int *value, int size);
|
||||
|
||||
#endif /* #ifndef TXT_INPUTBOX_H */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,18 @@
|
|||
#ifndef TXT_LABEL_H
|
||||
#define TXT_LABEL_H
|
||||
|
||||
/**
|
||||
* @file txt_label.h
|
||||
*
|
||||
* Text label widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Label widget.
|
||||
*
|
||||
* A label widget does nothing except show a text label.
|
||||
*/
|
||||
|
||||
typedef struct txt_label_s txt_label_t;
|
||||
|
||||
#include "txt_main.h"
|
||||
|
|
@ -37,9 +49,40 @@ struct txt_label_s
|
|||
txt_color_t bgcolor;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new label widget.
|
||||
*
|
||||
* @param label String to display in the widget.
|
||||
* @return Pointer to the new label widget.
|
||||
*/
|
||||
|
||||
txt_label_t *TXT_NewLabel(char *label);
|
||||
|
||||
/**
|
||||
* Set the string displayed in a label widget.
|
||||
*
|
||||
* @param label The widget.
|
||||
* @param value The string to display.
|
||||
*/
|
||||
|
||||
void TXT_SetLabel(txt_label_t *label, char *value);
|
||||
|
||||
/**
|
||||
* Set the background color of a label widget.
|
||||
*
|
||||
* @param label The widget.
|
||||
* @param color The background color to use.
|
||||
*/
|
||||
|
||||
void TXT_SetBGColor(txt_label_t *label, txt_color_t color);
|
||||
|
||||
/**
|
||||
* Set the foreground color of a label widget.
|
||||
*
|
||||
* @param label The widget.
|
||||
* @param color The foreground color to use.
|
||||
*/
|
||||
|
||||
void TXT_SetFGColor(txt_label_t *label, txt_color_t color);
|
||||
|
||||
#endif /* #ifndef TXT_LABEL_H */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,30 @@
|
|||
#ifndef TXT_RADIOBUTTON_H
|
||||
#define TXT_RADIOBUTTON_H
|
||||
|
||||
/**
|
||||
* @file txt_radiobutton.h
|
||||
*
|
||||
* Radio button widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A radio button widget.
|
||||
*
|
||||
* Radio buttons are typically used in groups, to allow a value to be
|
||||
* selected from a range of options. Each radio button corresponds
|
||||
* to a particular option that may be selected. A radio button
|
||||
* has an indicator to indicate whether it is the currently-selected
|
||||
* value, and a text label.
|
||||
*
|
||||
* Internally, a radio button tracks an integer variable that may take
|
||||
* a range of different values. Each radio button has a particular
|
||||
* value associated with it; if the variable is equal to that value,
|
||||
* the radio button appears selected. If a radio button is pressed
|
||||
* by the user through the GUI, the variable is set to its value.
|
||||
*
|
||||
* When a radio button is selected, the "selected" signal is emitted.
|
||||
*/
|
||||
|
||||
typedef struct txt_radiobutton_s txt_radiobutton_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -34,7 +58,26 @@ struct txt_radiobutton_s
|
|||
int value;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new radio button widget.
|
||||
*
|
||||
* @param label The label to display next to the radio button.
|
||||
* @param variable Pointer to the variable tracking whether this
|
||||
* radio button is selected.
|
||||
* @param value If the variable is equal to this value, the
|
||||
* radio button appears selected.
|
||||
* @return Pointer to the new radio button widget.
|
||||
*/
|
||||
|
||||
txt_radiobutton_t *TXT_NewRadioButton(char *label, int *variable, int value);
|
||||
|
||||
/**
|
||||
* Set the label on a radio button.
|
||||
*
|
||||
* @param radiobutton The radio button.
|
||||
* @param value The new label.
|
||||
*/
|
||||
|
||||
void TXT_SetRadioButtonLabel(txt_radiobutton_t *radiobutton, char *value);
|
||||
|
||||
#endif /* #ifndef TXT_RADIOBUTTON_H */
|
||||
|
|
|
|||
|
|
@ -233,8 +233,8 @@ static void ShowSelectedWidget(txt_scrollpane_t *scrollpane)
|
|||
{
|
||||
scrollpane->y -= scrollpane->widget.y - selected->y;
|
||||
}
|
||||
else if (selected->y + selected->h >
|
||||
scrollpane->widget.y + scrollpane->h)
|
||||
else if ((signed) (selected->y + selected->h) >
|
||||
(signed) (scrollpane->widget.y + scrollpane->h))
|
||||
{
|
||||
scrollpane->y += (selected->y + selected->h)
|
||||
- (scrollpane->widget.y + scrollpane->h);
|
||||
|
|
@ -246,8 +246,8 @@ static void ShowSelectedWidget(txt_scrollpane_t *scrollpane)
|
|||
{
|
||||
scrollpane->x -= scrollpane->widget.x - selected->x;
|
||||
}
|
||||
else if (selected->x + selected->w >
|
||||
scrollpane->widget.x + scrollpane->w)
|
||||
else if ((signed) (selected->x + selected->w) >
|
||||
(signed) (scrollpane->widget.x + scrollpane->w))
|
||||
{
|
||||
scrollpane->x += (selected->x + selected->w)
|
||||
- (scrollpane->widget.x + scrollpane->w);
|
||||
|
|
|
|||
|
|
@ -22,6 +22,20 @@
|
|||
#ifndef TXT_SCROLLPANE_H
|
||||
#define TXT_SCROLLPANE_H
|
||||
|
||||
/**
|
||||
* @file txt_scrollpane.h
|
||||
*
|
||||
* Scrollable pane widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Scrollable pane widget.
|
||||
*
|
||||
* A scrollable pane widget is a widget that contains another widget
|
||||
* that is larger than it. Scroll bars appear on the side to allow
|
||||
* different areas of the contained widget to be seen.
|
||||
*/
|
||||
|
||||
typedef struct txt_scrollpane_s txt_scrollpane_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -35,6 +49,16 @@ struct txt_scrollpane_s
|
|||
txt_widget_t *child;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new scroll pane widget.
|
||||
*
|
||||
* @param w Width of the scroll pane, in characters.
|
||||
* @param h Height of the scroll pane, in lines.
|
||||
* @param target The target widget that the scroll pane will
|
||||
* contain.
|
||||
* @return Pointer to the new scroll pane widget.
|
||||
*/
|
||||
|
||||
txt_scrollpane_t *TXT_NewScrollPane(int w, int h, TXT_UNCAST_ARG(target));
|
||||
|
||||
#endif /* #ifndef TXT_SCROLLPANE_H */
|
||||
|
|
|
|||
|
|
@ -22,6 +22,21 @@
|
|||
#ifndef TXT_SEPARATOR_H
|
||||
#define TXT_SEPARATOR_H
|
||||
|
||||
/**
|
||||
* @file txt_separator.h
|
||||
*
|
||||
* Horizontal separator widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Horizontal separator.
|
||||
*
|
||||
* A horizontal separator appears as a horizontal line divider across
|
||||
* the length of the window in which it is added. An optional label
|
||||
* allows the separator to be used as a section divider for grouping
|
||||
* related controls.
|
||||
*/
|
||||
|
||||
typedef struct txt_separator_s txt_separator_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -34,6 +49,14 @@ struct txt_separator_s
|
|||
|
||||
extern txt_widget_class_t txt_separator_class;
|
||||
|
||||
/**
|
||||
* Create a new horizontal separator widget.
|
||||
*
|
||||
* @param label Label to display on the separator. If this is
|
||||
* set to NULL, no label is displayed.
|
||||
* @return The new separator widget.
|
||||
*/
|
||||
|
||||
txt_separator_t *TXT_NewSeparator(char *label);
|
||||
|
||||
#endif /* #ifndef TXT_SEPARATOR_H */
|
||||
|
|
|
|||
|
|
@ -22,7 +22,22 @@
|
|||
#ifndef TXT_SPINCONTROL_H
|
||||
#define TXT_SPINCONTROL_H
|
||||
|
||||
/**
|
||||
* @file txt_spinctrl.h
|
||||
*
|
||||
* Spin control widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Spin control widget.
|
||||
*
|
||||
* A spin control widget works as an input box that can be used to
|
||||
* set numeric values, but also has buttons that allow its value
|
||||
* to be increased or decreased.
|
||||
*/
|
||||
|
||||
typedef struct txt_spincontrol_s txt_spincontrol_t;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TXT_SPINCONTROL_INT,
|
||||
|
|
@ -40,7 +55,28 @@ struct txt_spincontrol_s
|
|||
char *buffer;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new spin control widget tracking an integer value.
|
||||
*
|
||||
* @param value Pointer to the variable containing the value
|
||||
* displayed in the widget.
|
||||
* @param min Minimum value that may be set.
|
||||
* @param max Maximum value that may be set.
|
||||
* @return Pointer to the new spin control widget.
|
||||
*/
|
||||
|
||||
txt_spincontrol_t *TXT_NewSpinControl(int *value, int min, int max);
|
||||
|
||||
/**
|
||||
* Create a new spin control widget tracking a float value.
|
||||
*
|
||||
* @param value Pointer to the variable containing the value
|
||||
* displayed in the widget.
|
||||
* @param min Minimum value that may be set.
|
||||
* @param max Maximum value that may be set.
|
||||
* @return Pointer to the new spin control widget.
|
||||
*/
|
||||
|
||||
txt_spincontrol_t *TXT_NewFloatSpinControl(float *value, float min, float max);
|
||||
|
||||
#endif /* #ifndef TXT_SPINCONTROL_H */
|
||||
|
|
|
|||
|
|
@ -22,15 +22,24 @@
|
|||
#ifndef TXT_STRUT_H
|
||||
#define TXT_STRUT_H
|
||||
|
||||
/**
|
||||
* @file txt_strut.h
|
||||
*
|
||||
* Strut widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Strut widget.
|
||||
*
|
||||
* A strut is a widget that takes up a fixed amount of space. It can
|
||||
* be visualised as a transparent box. Struts are used to provide
|
||||
* spacing between widgets.
|
||||
*/
|
||||
|
||||
typedef struct txt_strut_s txt_strut_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
||||
//
|
||||
// A strut is used to force a table to a minimum width/height. It is not
|
||||
// visible but it takes up space.
|
||||
//
|
||||
|
||||
struct txt_strut_s
|
||||
{
|
||||
txt_widget_t widget;
|
||||
|
|
@ -38,6 +47,13 @@ struct txt_strut_s
|
|||
int height;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new strut.
|
||||
*
|
||||
* @param width Width of the strut, in characters.
|
||||
* @param height Height of the strut, in characters.
|
||||
*/
|
||||
|
||||
txt_strut_t *TXT_NewStrut(int width, int height);
|
||||
|
||||
#endif /* #ifndef TXT_STRUT_H */
|
||||
|
|
|
|||
|
|
@ -22,9 +22,29 @@
|
|||
#ifndef TXT_TABLE_H
|
||||
#define TXT_TABLE_H
|
||||
|
||||
/**
|
||||
* @file txt_table.h
|
||||
*
|
||||
* Table widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Table widget.
|
||||
*
|
||||
* A table is a widget that contains other widgets. It may have
|
||||
* multiple columns, in which case the child widgets are laid out
|
||||
* in a grid. Columns automatically grow as necessary, although
|
||||
* minimum column widths can be set using @ref TXT_SetColumnWidths.
|
||||
*
|
||||
* To create a new table, use @ref TXT_NewTable. It is also
|
||||
* possible to use @ref TXT_NewHorizBox to create a table, specifying
|
||||
* widgets to place inside a horizontal list. A vertical list is
|
||||
* possible simply by creating a table containing a single column.
|
||||
*/
|
||||
|
||||
typedef struct txt_table_s txt_table_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
#include "txt_widget.h"
|
||||
|
||||
struct txt_table_s
|
||||
{
|
||||
|
|
@ -48,14 +68,114 @@ struct txt_table_s
|
|||
|
||||
extern txt_widget_class_t txt_table_class;
|
||||
|
||||
txt_table_t *TXT_NewTable(int columns);
|
||||
txt_table_t *TXT_NewHorizBox(TXT_UNCAST_ARG(first_widget), ...);
|
||||
void TXT_InitTable(txt_table_t *table, int columns);
|
||||
|
||||
/**
|
||||
* Create a new table.
|
||||
*
|
||||
* @param columns The number of columns in the new table.
|
||||
* @return Pointer to the new table structure.
|
||||
*/
|
||||
|
||||
txt_table_t *TXT_NewTable(int columns);
|
||||
|
||||
/**
|
||||
* Create a table containing the specified widgets packed horizontally,
|
||||
* from left to right.
|
||||
*
|
||||
* The arguments to this function are variable. Each argument must
|
||||
* be a pointer to a widget, and the list is terminated with a
|
||||
* NULL.
|
||||
*
|
||||
* @return Pointer to the new table structure.
|
||||
*/
|
||||
|
||||
txt_table_t *TXT_NewHorizBox(TXT_UNCAST_ARG(first_widget), ...);
|
||||
|
||||
/**
|
||||
* Get the currently selected widget within a table.
|
||||
*
|
||||
* This function will recurse through subtables if necessary.
|
||||
*
|
||||
* @param table The table.
|
||||
* @return Pointer to the widget that is currently selected.
|
||||
*/
|
||||
|
||||
txt_widget_t *TXT_GetSelectedWidget(TXT_UNCAST_ARG(table));
|
||||
|
||||
/**
|
||||
* Add a widget to a table.
|
||||
*
|
||||
* Widgets are added to tables horizontally, from left to right.
|
||||
* For example, for a table with three columns, the first call
|
||||
* to this function will add a widget to the first column, the second
|
||||
* call to the second column, the third call to the third column,
|
||||
* and the fourth will return to the first column, starting a new
|
||||
* row.
|
||||
*
|
||||
* For adding many widgets, it may be easier to use
|
||||
* @ref TXT_AddWidgets.
|
||||
*
|
||||
* @param table The table.
|
||||
* @param widget The widget to add.
|
||||
*/
|
||||
|
||||
void TXT_AddWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));
|
||||
|
||||
/**
|
||||
* Add multiple widgets to a table.
|
||||
*
|
||||
* Widgets are added as described in the documentation for the
|
||||
* @ref TXT_AddWidget function. This function adds multiple
|
||||
* widgets. The number of arguments is variable, and the argument
|
||||
* list must be terminated by a NULL pointer.
|
||||
*
|
||||
* @param table The table.
|
||||
*/
|
||||
|
||||
void TXT_AddWidgets(TXT_UNCAST_ARG(table), ...);
|
||||
|
||||
/**
|
||||
* Select the given widget that is contained within the specified
|
||||
* table.
|
||||
*
|
||||
* This function will recursively search through subtables if
|
||||
* necessary.
|
||||
*
|
||||
* @param table The table.
|
||||
* @param widget The widget to select.
|
||||
* @return Non-zero (true) if it has been selected,
|
||||
* or zero (false) if it was not found within
|
||||
* this table.
|
||||
*/
|
||||
|
||||
int TXT_SelectWidget(TXT_UNCAST_ARG(table), TXT_UNCAST_ARG(widget));
|
||||
|
||||
/**
|
||||
* Set the widths of the columns of the table.
|
||||
*
|
||||
* The arguments to this function are variable, and correspond
|
||||
* to the number of columns in the table. For example, if a table
|
||||
* has five columns, the width of each of the five columns must be
|
||||
* specified.
|
||||
*
|
||||
* The width values are in number of characters.
|
||||
*
|
||||
* Note that this function only sets the minimum widths for columns;
|
||||
* if the columns contain widgets that are wider than the widths
|
||||
* specified, they will be larger.
|
||||
*
|
||||
* @param table The table.
|
||||
*/
|
||||
|
||||
void TXT_SetColumnWidths(TXT_UNCAST_ARG(table), ...);
|
||||
|
||||
/**
|
||||
* Remove all widgets from a table.
|
||||
*
|
||||
* @param table The table.
|
||||
*/
|
||||
|
||||
void TXT_ClearTable(TXT_UNCAST_ARG(table));
|
||||
|
||||
#endif /* #ifndef TXT_TABLE_T */
|
||||
|
|
|
|||
|
|
@ -19,15 +19,27 @@
|
|||
// 02111-1307, USA.
|
||||
//
|
||||
|
||||
// Base GUI "widget" class that all widgets inherit from.
|
||||
|
||||
#ifndef TXT_WIDGET_H
|
||||
#define TXT_WIDGET_H
|
||||
|
||||
/**
|
||||
* @file txt_widget.h
|
||||
*
|
||||
* Base "widget" GUI component class.
|
||||
*/
|
||||
|
||||
#ifndef DOXYGEN
|
||||
|
||||
#define TXT_UNCAST_ARG_NAME(name) uncast_ ## name
|
||||
#define TXT_UNCAST_ARG(name) void * TXT_UNCAST_ARG_NAME(name)
|
||||
#define TXT_CAST_ARG(type, name) type *name = (type *) uncast_ ## name
|
||||
|
||||
#else
|
||||
|
||||
#define TXT_UNCAST_ARG(name) txt_widget_t *name
|
||||
|
||||
#endif
|
||||
|
||||
typedef enum
|
||||
{
|
||||
TXT_VERT_TOP,
|
||||
|
|
@ -42,8 +54,20 @@ typedef enum
|
|||
TXT_HORIZ_RIGHT,
|
||||
} txt_horiz_align_t;
|
||||
|
||||
typedef struct txt_widget_class_s txt_widget_class_t;
|
||||
/**
|
||||
* A GUI widget.
|
||||
*
|
||||
* A widget is an individual component of a GUI. Various different widget
|
||||
* types exist.
|
||||
*
|
||||
* Widgets may emit signals. The types of signal emitted by a widget
|
||||
* depend on the type of the widget. It is possible to be notified
|
||||
* when a signal occurs using the @ref TXT_SignalConnect function.
|
||||
*/
|
||||
|
||||
typedef struct txt_widget_s txt_widget_t;
|
||||
|
||||
typedef struct txt_widget_class_s txt_widget_class_t;
|
||||
typedef struct txt_callback_table_s txt_callback_table_t;
|
||||
|
||||
typedef void (*TxtWidgetSizeCalc)(TXT_UNCAST_ARG(widget));
|
||||
|
|
@ -82,15 +106,34 @@ struct txt_widget_s
|
|||
void TXT_InitWidget(TXT_UNCAST_ARG(widget), txt_widget_class_t *widget_class);
|
||||
void TXT_CalcWidgetSize(TXT_UNCAST_ARG(widget));
|
||||
void TXT_DrawWidget(TXT_UNCAST_ARG(widget), int selected);
|
||||
void TXT_SignalConnect(TXT_UNCAST_ARG(widget), char *signal_name,
|
||||
TxtWidgetSignalFunc func, void *user_data);
|
||||
void TXT_EmitSignal(TXT_UNCAST_ARG(widget), char *signal_name);
|
||||
int TXT_WidgetKeyPress(TXT_UNCAST_ARG(widget), int key);
|
||||
void TXT_WidgetMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b);
|
||||
void TXT_DestroyWidget(TXT_UNCAST_ARG(widget));
|
||||
void TXT_SetWidgetAlign(TXT_UNCAST_ARG(widget), txt_horiz_align_t horiz_align);
|
||||
void TXT_LayoutWidget(TXT_UNCAST_ARG(widget));
|
||||
|
||||
/**
|
||||
* Set a callback function to be invoked when a signal occurs.
|
||||
*
|
||||
* @param widget The widget to watch.
|
||||
* @param signal_name The signal to watch.
|
||||
* @param func The callback function to invoke.
|
||||
* @param user_data User-specified pointer to pass to the callback function.
|
||||
*/
|
||||
|
||||
void TXT_SignalConnect(TXT_UNCAST_ARG(widget), char *signal_name,
|
||||
TxtWidgetSignalFunc func, void *user_data);
|
||||
|
||||
/**
|
||||
* Set the policy for how a widget should be aligned within a table.
|
||||
* By default, widgets are aligned to the left of the column.
|
||||
*
|
||||
* @param widget The widget.
|
||||
* @param horiz_align The alignment to use.
|
||||
*/
|
||||
|
||||
void TXT_SetWidgetAlign(TXT_UNCAST_ARG(widget), txt_horiz_align_t horiz_align);
|
||||
|
||||
#endif /* #ifndef TXT_WIDGET_H */
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,31 @@
|
|||
#ifndef TXT_WINDOW_H
|
||||
#define TXT_WINDOW_H
|
||||
|
||||
/**
|
||||
* @file txt_window.h
|
||||
*
|
||||
* Windows.
|
||||
*/
|
||||
|
||||
/**
|
||||
* A window.
|
||||
*
|
||||
* A window contains widgets, and may also be treated as a table
|
||||
* (@ref txt_table_t) containing a single column.
|
||||
*
|
||||
* Windows can be created using @ref TXT_NewWindow and closed using
|
||||
* @ref TXT_CloseWindow. When a window is closed, it emits the
|
||||
* "closed" signal.
|
||||
*
|
||||
* In addition to the widgets within a window, windows also have
|
||||
* a "tray" area at their bottom containing window action widgets.
|
||||
* These widgets allow keyboard shortcuts to trigger common actions.
|
||||
* Each window has three slots for keyboard shortcuts. By default,
|
||||
* the left slot contains an action to close the window when the
|
||||
* escape button is pressed, while the right slot contains an
|
||||
* action to activate the currently-selected widget.
|
||||
*/
|
||||
|
||||
typedef struct txt_window_s txt_window_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -68,18 +93,86 @@ struct txt_window_s
|
|||
unsigned int window_w, window_h;
|
||||
};
|
||||
|
||||
/**
|
||||
* Open a new window.
|
||||
*
|
||||
* @param title Title to display in the titlebar of the new window.
|
||||
* @return Pointer to a new @ref txt_window_t structure
|
||||
* representing the new window.
|
||||
*/
|
||||
|
||||
txt_window_t *TXT_NewWindow(char *title);
|
||||
|
||||
/**
|
||||
* Close a window.
|
||||
*
|
||||
* @param window Tine window to close.
|
||||
*/
|
||||
|
||||
void TXT_CloseWindow(txt_window_t *window);
|
||||
void TXT_SetWindowPosition(txt_window_t *window,
|
||||
|
||||
/**
|
||||
* Set the position of a window on the screen.
|
||||
*
|
||||
* The window is specified as coordinates relative to a predefined
|
||||
* position on the screen (eg. center of the screen, top left of the
|
||||
* screen, etc).
|
||||
*
|
||||
* @param window The window.
|
||||
* @param horiz_align Horizontal position on the screen to which the
|
||||
* coordinates are relative (left side, right side
|
||||
* or center).
|
||||
* @param vert_align Vertical position on the screen to which the
|
||||
* coordinates are relative (top, bottom or center).
|
||||
* @param x X coordinate (horizonal axis) for window position.
|
||||
* @param y Y coordinate (vertical axis) for window position.
|
||||
*/
|
||||
|
||||
void TXT_SetWindowPosition(txt_window_t *window,
|
||||
txt_horiz_align_t horiz_align,
|
||||
txt_vert_align_t vert_align,
|
||||
int x, int y);
|
||||
|
||||
/**
|
||||
* Set a window action for a given window.
|
||||
*
|
||||
* Each window can have up to three window actions, which provide
|
||||
* keyboard shortcuts that can be used within a given window.
|
||||
*
|
||||
* @param window The window.
|
||||
* @param position The window action slot to set (left, center or right).
|
||||
* @param action The window action widget. If this is NULL, any
|
||||
* current window action in the given slot is removed.
|
||||
*/
|
||||
|
||||
void TXT_SetWindowAction(txt_window_t *window, txt_horiz_align_t position,
|
||||
txt_window_action_t *action);
|
||||
void TXT_SetKeyListener(txt_window_t *window,
|
||||
TxtWindowKeyPress key_listener,
|
||||
|
||||
/**
|
||||
* Set a callback function to be invoked whenever a key is pressed within
|
||||
* a window.
|
||||
*
|
||||
* @param window The window.
|
||||
* @param key_listener Callback function.
|
||||
* @param user_data User-specified pointer to pass to the callback
|
||||
* function.
|
||||
*/
|
||||
|
||||
void TXT_SetKeyListener(txt_window_t *window,
|
||||
TxtWindowKeyPress key_listener,
|
||||
void *user_data);
|
||||
void TXT_SetMouseListener(txt_window_t *window,
|
||||
|
||||
/**
|
||||
* Set a callback function to be invoked whenever a mouse button is pressed
|
||||
* within a window.
|
||||
*
|
||||
* @param window The window.
|
||||
* @param mouse_listener Callback function.
|
||||
* @param user_data User-specified pointer to pass to the callback
|
||||
* function.
|
||||
*/
|
||||
|
||||
void TXT_SetMouseListener(txt_window_t *window,
|
||||
TxtWindowMousePress mouse_listener,
|
||||
void *user_data);
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,22 @@
|
|||
#ifndef TXT_WINDOW_ACTION_H
|
||||
#define TXT_WINDOW_ACTION_H
|
||||
|
||||
/**
|
||||
* @file txt_window_action.h
|
||||
*
|
||||
* Window action widget.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Window action widget.
|
||||
*
|
||||
* A window action is attached to a window and corresponds to a
|
||||
* keyboard shortcut that is active within that window. When the
|
||||
* key is pressed, the action is triggered.
|
||||
*
|
||||
* When a window action is triggered, the "pressed" signal is emitted.
|
||||
*/
|
||||
|
||||
typedef struct txt_window_action_s txt_window_action_t;
|
||||
|
||||
#include "txt_widget.h"
|
||||
|
|
@ -34,17 +50,45 @@ struct txt_window_action_s
|
|||
int key;
|
||||
};
|
||||
|
||||
/**
|
||||
* Create a new window action.
|
||||
*
|
||||
* @param key The keyboard key that triggers this action.
|
||||
* @param label Label to display for this action in the tray
|
||||
* at the bottom of the window.
|
||||
* @return Pointer to the new window action widget.
|
||||
*/
|
||||
|
||||
txt_window_action_t *TXT_NewWindowAction(int key, char *label);
|
||||
|
||||
// Creates an "escape" button that closes the window
|
||||
/**
|
||||
* Create a new window action that closes the window when the
|
||||
* escape key is pressed. The label "Close" is used.
|
||||
*
|
||||
* @param window The window to close.
|
||||
* @return Pointer to the new window action widget.
|
||||
*/
|
||||
|
||||
txt_window_action_t *TXT_NewWindowEscapeAction(txt_window_t *window);
|
||||
|
||||
// Same as above, but the button is named "abort"
|
||||
/**
|
||||
* Create a new window action that closes the window when the
|
||||
* escape key is pressed. The label "Abort" is used.
|
||||
*
|
||||
* @param window The window to close.
|
||||
* @return Pointer to the new window action widget.
|
||||
*/
|
||||
|
||||
txt_window_action_t *TXT_NewWindowAbortAction(txt_window_t *window);
|
||||
|
||||
// Accept button that does nothing
|
||||
/**
|
||||
* Create a new "select" window action. This does not really do
|
||||
* anything, but reminds the user that "enter" can be pressed to
|
||||
* activate the currently-selected widget.
|
||||
*
|
||||
* @param window The window.
|
||||
* @return Pointer to the new window action widget.
|
||||
*/
|
||||
|
||||
txt_window_action_t *TXT_NewWindowSelectAction(txt_window_t *window);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue