Skip to content

Commit

Permalink
Ticket #4120: draw shadows for dialog boxes and menus.
Browse files Browse the repository at this point in the history
Thanks Aleš Janda <ales.janda@kyblsoft.cz> for the original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
  • Loading branch information
aborodin committed Aug 2, 2020
1 parent da9966f commit 8b4386d
Show file tree
Hide file tree
Showing 44 changed files with 265 additions and 89 deletions.
3 changes: 3 additions & 0 deletions AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ Alexander Serkov <serkov@ukrpost.net>
Alessandro Rubini <rubini@ipvvis.unipv.it>
Mouse support.

Aleš Janda <ales.janda@kyblsoft.cz>
Shadows of dialog windows and menus.

Alexander Dong <ado@software-ag.de>
OS/2 port.

Expand Down
6 changes: 5 additions & 1 deletion doc/man/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -2113,13 +2113,17 @@ overwriting files, execution by pressing enter, quitting the program,
directory hotlist entries deletion and history cleanup.
.\"NODE " Appearance"
.SH " Appearance"
In this dialog you can select the skin to be used.
In this dialog you can select the skin to be used and enable shadow
for dialogs and drop down menus.
.PP
See the
.\"LINK2"
Skins
.\"Skins"
section for technical details about the skin definition files.
.PP
.I Shadows.
If this option is enabled, all dialogs and drop down menus will have a shadow.
.\"NODE " Display bits"
.SH " Display bits"
This is used to configure the range of visible characters on the
Expand Down
7 changes: 6 additions & 1 deletion doc/man/ru/mc.1.in
Original file line number Diff line number Diff line change
Expand Up @@ -2411,12 +2411,17 @@ Commander, выделены цветом, определённым ключев
на подтверждение.
.\"NODE " Appearance"
.SH " Оформление"
Используя это диалоговое окно, вы можете выбрать скин.
Используя это диалоговое окно, вы можете выбрать скин и разрещить отрисовку
теней у диалоговых окон и выпадающих меню.
.PP
Для получения более подробной информации о скинах обратитесь к разделу
.\"LINK2"
Внешний вид\&.
.\"Skins"
.PP
.I Тени.
Если эта опция включена, все диалоговые окна и выпадающие меню будут иметь
тени.
.\"NODE " Display bits"
.SH " Биты символов..."
Этот пункт меню используется для задания диапазона отображаемых на
Expand Down
1 change: 1 addition & 0 deletions lib/global.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ mc_global_t mc_global = {
.tty =
{
.skin = NULL,
.shadows = TRUE,
.setup_color_string = NULL,
.term_color_string = NULL,
.color_terminal_string = NULL,
Expand Down
2 changes: 2 additions & 0 deletions lib/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,8 @@ typedef struct
{
/* Use the specified skin */
char *skin;
/* Dialog window and frop down menu have a shadow */
gboolean shadows;

char *setup_color_string;
char *term_color_string;
Expand Down
125 changes: 63 additions & 62 deletions lib/skin.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,92 +22,93 @@
#define REVERSE_COLOR mc_skin_color__cache[6]
#define COMMAND_MARK_COLOR mc_skin_color__cache[7]
#define HEADER_COLOR mc_skin_color__cache[8]
#define SHADOW_COLOR mc_skin_color__cache[9]

/* Dialog colors */
#define COLOR_NORMAL mc_skin_color__cache[9]
#define COLOR_FOCUS mc_skin_color__cache[10]
#define COLOR_HOT_NORMAL mc_skin_color__cache[11]
#define COLOR_HOT_FOCUS mc_skin_color__cache[12]
#define COLOR_TITLE mc_skin_color__cache[13]
#define COLOR_NORMAL mc_skin_color__cache[10]
#define COLOR_FOCUS mc_skin_color__cache[11]
#define COLOR_HOT_NORMAL mc_skin_color__cache[12]
#define COLOR_HOT_FOCUS mc_skin_color__cache[13]
#define COLOR_TITLE mc_skin_color__cache[14]

/* Error dialog colors */
#define ERROR_COLOR mc_skin_color__cache[14]
#define ERROR_FOCUS mc_skin_color__cache[15]
#define ERROR_HOT_NORMAL mc_skin_color__cache[16]
#define ERROR_HOT_FOCUS mc_skin_color__cache[17]
#define ERROR_TITLE mc_skin_color__cache[18]
#define ERROR_COLOR mc_skin_color__cache[15]
#define ERROR_FOCUS mc_skin_color__cache[16]
#define ERROR_HOT_NORMAL mc_skin_color__cache[17]
#define ERROR_HOT_FOCUS mc_skin_color__cache[18]
#define ERROR_TITLE mc_skin_color__cache[19]

/* Menu colors */
#define MENU_ENTRY_COLOR mc_skin_color__cache[19]
#define MENU_SELECTED_COLOR mc_skin_color__cache[20]
#define MENU_HOT_COLOR mc_skin_color__cache[21]
#define MENU_HOTSEL_COLOR mc_skin_color__cache[22]
#define MENU_INACTIVE_COLOR mc_skin_color__cache[23]
#define MENU_ENTRY_COLOR mc_skin_color__cache[20]
#define MENU_SELECTED_COLOR mc_skin_color__cache[21]
#define MENU_HOT_COLOR mc_skin_color__cache[22]
#define MENU_HOTSEL_COLOR mc_skin_color__cache[23]
#define MENU_INACTIVE_COLOR mc_skin_color__cache[24]

/* Popup menu colors */
#define PMENU_ENTRY_COLOR mc_skin_color__cache[24]
#define PMENU_SELECTED_COLOR mc_skin_color__cache[25]
#define PMENU_HOT_COLOR mc_skin_color__cache[26] /* unused: not implemented yet */
#define PMENU_HOTSEL_COLOR mc_skin_color__cache[27] /* unused: not implemented yet */
#define PMENU_TITLE_COLOR mc_skin_color__cache[28]
#define PMENU_ENTRY_COLOR mc_skin_color__cache[25]
#define PMENU_SELECTED_COLOR mc_skin_color__cache[26]
#define PMENU_HOT_COLOR mc_skin_color__cache[27] /* unused: not implemented yet */
#define PMENU_HOTSEL_COLOR mc_skin_color__cache[28] /* unused: not implemented yet */
#define PMENU_TITLE_COLOR mc_skin_color__cache[29]

#define BUTTONBAR_HOTKEY_COLOR mc_skin_color__cache[29]
#define BUTTONBAR_BUTTON_COLOR mc_skin_color__cache[30]
#define BUTTONBAR_HOTKEY_COLOR mc_skin_color__cache[30]
#define BUTTONBAR_BUTTON_COLOR mc_skin_color__cache[31]

#define STATUSBAR_COLOR mc_skin_color__cache[31]
#define STATUSBAR_COLOR mc_skin_color__cache[32]

/*
* This should be selectable independently. Default has to be black background
* foreground does not matter at all.
*/
#define GAUGE_COLOR mc_skin_color__cache[32]
#define INPUT_COLOR mc_skin_color__cache[33]
#define INPUT_UNCHANGED_COLOR mc_skin_color__cache[34]
#define INPUT_MARK_COLOR mc_skin_color__cache[35]
#define INPUT_HISTORY_COLOR mc_skin_color__cache[36]
#define COMMAND_HISTORY_COLOR mc_skin_color__cache[37]

#define HELP_NORMAL_COLOR mc_skin_color__cache[38]
#define HELP_ITALIC_COLOR mc_skin_color__cache[39]
#define HELP_BOLD_COLOR mc_skin_color__cache[40]
#define HELP_LINK_COLOR mc_skin_color__cache[41]
#define HELP_SLINK_COLOR mc_skin_color__cache[42]
#define HELP_TITLE_COLOR mc_skin_color__cache[43]


#define VIEW_NORMAL_COLOR mc_skin_color__cache[44]
#define VIEW_BOLD_COLOR mc_skin_color__cache[45]
#define VIEW_UNDERLINED_COLOR mc_skin_color__cache[46]
#define VIEW_SELECTED_COLOR mc_skin_color__cache[47]
#define GAUGE_COLOR mc_skin_color__cache[33]
#define INPUT_COLOR mc_skin_color__cache[34]
#define INPUT_UNCHANGED_COLOR mc_skin_color__cache[35]
#define INPUT_MARK_COLOR mc_skin_color__cache[36]
#define INPUT_HISTORY_COLOR mc_skin_color__cache[37]
#define COMMAND_HISTORY_COLOR mc_skin_color__cache[38]

#define HELP_NORMAL_COLOR mc_skin_color__cache[39]
#define HELP_ITALIC_COLOR mc_skin_color__cache[40]
#define HELP_BOLD_COLOR mc_skin_color__cache[41]
#define HELP_LINK_COLOR mc_skin_color__cache[42]
#define HELP_SLINK_COLOR mc_skin_color__cache[43]
#define HELP_TITLE_COLOR mc_skin_color__cache[44]


#define VIEW_NORMAL_COLOR mc_skin_color__cache[45]
#define VIEW_BOLD_COLOR mc_skin_color__cache[46]
#define VIEW_UNDERLINED_COLOR mc_skin_color__cache[47]
#define VIEW_SELECTED_COLOR mc_skin_color__cache[48]

/*
* editor colors - only 4 for normal, search->found, select, and whitespace
* respectively
* Last is defined to view color.
*/
#define EDITOR_NORMAL_COLOR mc_skin_color__cache[48]
#define EDITOR_BOLD_COLOR mc_skin_color__cache[49]
#define EDITOR_MARKED_COLOR mc_skin_color__cache[50]
#define EDITOR_WHITESPACE_COLOR mc_skin_color__cache[51]
#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[52]
#define EDITOR_BACKGROUND mc_skin_color__cache[53]
#define EDITOR_FRAME mc_skin_color__cache[54]
#define EDITOR_FRAME_ACTIVE mc_skin_color__cache[55]
#define EDITOR_FRAME_DRAG mc_skin_color__cache[56]
#define EDITOR_NORMAL_COLOR mc_skin_color__cache[49]
#define EDITOR_BOLD_COLOR mc_skin_color__cache[50]
#define EDITOR_MARKED_COLOR mc_skin_color__cache[51]
#define EDITOR_WHITESPACE_COLOR mc_skin_color__cache[52]
#define EDITOR_RIGHT_MARGIN_COLOR mc_skin_color__cache[53]
#define EDITOR_BACKGROUND mc_skin_color__cache[54]
#define EDITOR_FRAME mc_skin_color__cache[55]
#define EDITOR_FRAME_ACTIVE mc_skin_color__cache[56]
#define EDITOR_FRAME_DRAG mc_skin_color__cache[57]
/* color of left 8 char status per line */
#define LINE_STATE_COLOR mc_skin_color__cache[57]
#define BOOK_MARK_COLOR mc_skin_color__cache[58]
#define BOOK_MARK_FOUND_COLOR mc_skin_color__cache[59]
#define LINE_STATE_COLOR mc_skin_color__cache[58]
#define BOOK_MARK_COLOR mc_skin_color__cache[59]
#define BOOK_MARK_FOUND_COLOR mc_skin_color__cache[60]

/* Diff colors */
#define DFF_ADD_COLOR mc_skin_color__cache[60]
#define DFF_CHG_COLOR mc_skin_color__cache[61]
#define DFF_CHH_COLOR mc_skin_color__cache[62]
#define DFF_CHD_COLOR mc_skin_color__cache[63]
#define DFF_DEL_COLOR mc_skin_color__cache[64]
#define DFF_ERROR_COLOR mc_skin_color__cache[65]

#define MC_SKIN_COLOR_CACHE_COUNT 66
#define DFF_ADD_COLOR mc_skin_color__cache[61]
#define DFF_CHG_COLOR mc_skin_color__cache[62]
#define DFF_CHH_COLOR mc_skin_color__cache[63]
#define DFF_CHD_COLOR mc_skin_color__cache[64]
#define DFF_DEL_COLOR mc_skin_color__cache[65]
#define DFF_ERROR_COLOR mc_skin_color__cache[66]

#define MC_SKIN_COLOR_CACHE_COUNT 67

/*** enums ***************************************************************************************/

Expand Down
1 change: 1 addition & 0 deletions lib/skin/colors.c
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ mc_skin_color_cache_init (void)
REVERSE_COLOR = mc_skin_color_get ("core", "reverse");
HEADER_COLOR = mc_skin_color_get ("core", "header");
COMMAND_MARK_COLOR = mc_skin_color_get ("core", "commandlinemark");
SHADOW_COLOR = mc_skin_color_get ("core", "shadow");

COLOR_NORMAL = mc_skin_color_get ("dialog", "_default_");
COLOR_FOCUS = mc_skin_color_get ("dialog", "dfocus");
Expand Down
2 changes: 2 additions & 0 deletions lib/tty/tty-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ char *mc_tty_normalize_from_utf8 (const char *);
void tty_init_xterm_support (gboolean is_xterm);
int tty_lowlevel_getch (void);

void tty_colorize_area (int y, int x, int rows, int cols, int color);

/*** inline functions ****************************************************************************/

#endif /* MC_TTY_INTERNAL_H */
97 changes: 73 additions & 24 deletions lib/tty/tty-ncurses.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

#include "tty-internal.h" /* mc_tty_normalize_from_utf8() */
#include "tty.h"
#include "color.h" /* tty_setcolor */
#include "color-internal.h"
#include "key.h"
#include "mouse.h"
Expand Down Expand Up @@ -119,6 +120,44 @@ sigwinch_handler (int dummy)
(void) n;
}

/* --------------------------------------------------------------------------------------------- */

/**
* Get visible part of area.
*
* @returns TRUE if any part of area is in screen bounds, FALSE otherwise.
*/
static gboolean
tty_clip (int *y, int *x, int *rows, int *cols)
{
if (*y < 0)
{
*rows += *y;

if (*rows <= 0)
return FALSE;

*y = 0;
}

if (*x < 0)
{
*cols += *x;

if (*cols <= 0)
return FALSE;

*x = 0;
}

if (*y + *rows > LINES)
*rows = LINES - *y;
if (*x + *cols > COLS)
*cols = COLS - *x;

return TRUE;
}

/* --------------------------------------------------------------------------------------------- */
/*** public functions ****************************************************************************/
/* --------------------------------------------------------------------------------------------- */
Expand Down Expand Up @@ -494,30 +533,8 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)
{
int i;

if (y < 0)
{
rows += y;

if (rows <= 0)
return;

y = 0;
}

if (x < 0)
{
cols += x;

if (cols <= 0)
return;

x = 0;
}

if (y + rows > LINES)
rows = LINES - y;
if (x + cols > COLS)
cols = COLS - x;
if (!tty_clip (&y, &x, &rows, &cols))
return;

for (i = 0; i < rows; i++)
{
Expand All @@ -533,6 +550,38 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)

/* --------------------------------------------------------------------------------------------- */

void
tty_colorize_area (int y, int x, int rows, int cols, int color)
{
cchar_t *ctext;
wchar_t wch[10]; /* TODO not sure if the length is correct */
attr_t attrs;
short color_pair;

if (!use_colors || !tty_clip (&y, &x, &rows, &cols))
return;

tty_setcolor (color);
ctext = g_malloc (sizeof (cchar_t) * (cols + 1));

for (int row = 0; row < rows; row++)
{
mvin_wchnstr (y + row, x, ctext, cols);

for (int col = 0; col < cols; col++)
{
getcchar (&ctext[col], wch, &attrs, &color_pair, NULL);
setcchar (&ctext[col], wch, attrs, color, NULL);
}

mvadd_wchnstr (y + row, x, ctext, cols);
}

g_free (ctext);
}

/* --------------------------------------------------------------------------------------------- */

void
tty_set_alt_charset (gboolean alt_charset)
{
Expand Down
9 changes: 9 additions & 0 deletions lib/tty/tty-slang.c
Original file line number Diff line number Diff line change
Expand Up @@ -622,6 +622,15 @@ tty_fill_region (int y, int x, int rows, int cols, unsigned char ch)

/* --------------------------------------------------------------------------------------------- */

void
tty_colorize_area (int y, int x, int rows, int cols, int color)
{
if (use_colors)
SLsmg_set_color_in_region (color, y, x, rows, cols);
}

/* --------------------------------------------------------------------------------------------- */

void
tty_set_alt_charset (gboolean alt_charset)
{
Expand Down
11 changes: 11 additions & 0 deletions lib/tty/tty.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,17 @@ tty_draw_box (int y, int x, int ys, int xs, gboolean single)

/* --------------------------------------------------------------------------------------------- */

void
tty_draw_box_shadow (int y, int x, int rows, int cols, int shadow_color)
{
/* draw right shadow */
tty_colorize_area (y + 1, x + cols, rows - 1, 2, shadow_color);
/* draw bottom shadow */
tty_colorize_area (y + rows, x + 2, 1, cols, shadow_color);
}

/* --------------------------------------------------------------------------------------------- */

char *
mc_tty_normalize_from_utf8 (const char *str)
{
Expand Down
Loading

0 comments on commit 8b4386d

Please sign in to comment.