summaryrefslogtreecommitdiff
path: root/layerdlg.c
blob: ffddb5de0664f6291998105820658b89644d78f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
Copyright (c) 2003 Bruno T. C. de Oliveira

LICENSE INFORMATION:
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
Copyright (c) 2002 Bruno T. C. de Oliveira

INFORMA��ES DE LICEN�A:
Este programa � um software de livre distribui��o; voc� pode
redistribu�-lo e/ou modific�-lo sob os termos da GNU General
Public License, conforme publicado pela Free Software Foundation,
pela vers�o 2 da licen�a ou qualquer vers�o posterior.

Este programa � distribu�do na esperan�a de que ele ser� �til
aos seus usu�rios, por�m, SEM QUAISQUER GARANTIAS; sem sequer
a garantia impl�cita de COMERCIABILIDADE ou DE ADEQUA��O A
QUALQUER FINALIDADE ESPEC�FICA. Consulte a GNU General Public
License para obter mais detalhes (uma c�pia acompanha este
programa, armazenada no arquivo COPYING).
*/

#include "bores/bores.h"
#include <ncurses.h>

#include "document.h"
#include "colordlg.h"
#include "psd.h"
#include "absmenu.h"

/*                 DLG_W
-      ,---------------------------,
D      | -                         |
L      | : LIST_H                  |
G      | :                         |
|      | :                         |
H      | -                         |
:      +---------------------------+
:      | A                         |
:      |                           |
:      |                           |
:      |                           |
-      `---------------------------'
*/

#define DLG_W 42
#define DLG_H 19
#define LIST_H 11

static AbsMenu *menu = 0;

static void painter(int i, AbsMenu *m) {
   Layer *l = _doc->layers[i];
   printw("%2d: %c%c (%3d x %3d) %s", i, 
           l->visible ? 'v' : ' ',
           l->transp ? 't' : ' ',
           l->width, l->height, (l->name ? l->name : "(untitled)"));
}

static void paint_dlg(void) {
   int x0, y0; int x, y;
   
   kurses_color(7, 0);
   draw_centered_window(DLG_W, DLG_H, "Layer Manager", &x0, &y0);
   
   if (!menu) {
      menu = menu_create(&(_doc->layer_count), x0,
                         y0, DLG_W - 2, LIST_H,
                         0x71, 0x70, painter);
      menu_select_item(menu, _lyr);
   }
   
   draw_hline(x0 - 1, y0 + LIST_H, DLG_W, ACS_LTEE, ACS_HLINE, ACS_RTEE);

   /* print instructions */
   kurses_move(x = x0 + 1, y = y0 + LIST_H + 1);

   kurses_color(2, 0); addch('<'); addch(ACS_LRCORNER); addch(' ');
   kurses_color(7, 0);
   printw(": go to layer");

   kurses_move(x, ++y);
   kurses_color(2, 0); addstr("d  "); kurses_color(7, 0);
   printw(": delete layer");

   kurses_move(x, ++y);
   kurses_color(2, 0); addstr("+/-"); kurses_color(7, 0);
   printw(": move layer up/down");

   kurses_move(x, ++y);
   kurses_color(2, 0); addstr("v  "); kurses_color(7, 0);
   printw(": toggle visibility");
   
   kurses_move(x, ++y);
   kurses_color(2, 0); addstr("t  "); kurses_color(7, 0);
   printw(": toggle transparency");

   menu_paint(menu);
}

void show_layer_dlg(void) {
   int ch; int quit = 0;
   Layer *lyr;

   menu = 0;
   
   while (!quit) {
      paint_dlg();
      refresh();
      ch = getch();
      switch (ch) {
         case 10: switch_to_layer(menu->sel_item);
                  /* fall through */
         case 27: case 3: case 7: quit = 1; break;
         case 'd': /* delete layer */
                  document_del_layer(_doc, menu->sel_item);
                  if (_doc->layer_count == 0) /* no layers, so close dialog */
                     quit = 1;
                  else if (menu->sel_item >= _doc->layer_count)
                     menu->sel_item = _doc->layer_count - 1;
                  break;
         case '+': case '=': /* move layer up */
                  if (menu->sel_item > 0) {
                     int i = menu->sel_item; Layer **ls = _doc->layers;
                     Layer* l = ls[i-1];
                     ls[i-1] = ls[i];
                     ls[i] = l;

                     menu->sel_item--;
                  }
                  break;
         case '-': case '_':
                  if (menu->sel_item < _doc->layer_count - 1) {
                     int i = menu->sel_item; Layer **ls = _doc->layers;
                     Layer* l = ls[i+1];
                     ls[i+1] = ls[i];
                     ls[i] = l;

                     menu->sel_item++;
                  }
                  break;
         case 'v': /* toggle layer visibility */
                  lyr = _doc->layers[menu->sel_item];
                  lyr->visible = !lyr->visible;
                  break;
         case 't': /* toggle layer transparency */
                  lyr = _doc->layers[menu->sel_item];
                  lyr->transp = !lyr->transp;
                  break;
         
         default: if (menu) menu_handle_key(menu, ch);
      }
   }

   if (menu) menu_destroy(menu);
}