[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Texmacs-dev] Displaying table grids
From: |
Norbert Nemec |
Subject: |
Re: [Texmacs-dev] Displaying table grids |
Date: |
Sun, 20 Dec 2009 22:33:31 +0000 |
User-agent: |
Thunderbird 2.0.0.23 (X11/20090817) |
OK, here is a new version of the patch. It does now display the table
grid just one px wide. To achive a smooth and symmetric look, I had to
change the 'outline' function, shifting some of the lines by one pixel.
The visual appearance seems fine to me.
Unfortunately, the whole logic for outline rectangles is integer based
and does not have access to the subpixel precision of individual
elements. Therefore, the elements are first rounded to integer positions
and then shifted by individual pixels. Theoretically, the display should
be somewhat more precise if the rectangle manipulations could be done
before rounding to exact pixels. In practice, I am not sure whether
anyone would notice the difference.
The slightly awkward details remain:
* the cyan rectangles and the red selection have two pixels space on the
top and the bottom and none at the sides. This makes sense. The gray
table grid does not have this spacing, because there is no room for it.
This also makes sense. The combination leads to tables having double
lines at the top and the bottom but single lines at the sides.
* the eqnarray* display still does not deal with the interparagraph
space in any special way.
In both cases, I do not what a proper and consistent solution should
look like. Furthermore, I found the current implementation tricky enough
and have no idea how to implement anything that involves obtaining more
information about the document than the box geometries that are used at
the moment.
Anyone who want to give it a try is free to improve upon this solution.
Greetings,
Norbert
Joris van der Hoeven wrote:
Dear Norbert,
On Mon, Dec 14, 2009 at 09:39:09PM +0000, Norbert Nemec wrote:
in fact, I had initially intended to make the lines 1px wide just as you
describe. After some fiddling I found that it always ended up looking
strangely asymmetric. The problem is that the cyan environment frames
are always 1px-wide lines outside the box, defining the box boundaries
to sit exactly between pixels. A 1px wide line can therefore only sit
either to the left or to the right of the box boundary. Any way you
choose this, it looks crooked. The only solution to allow good-looking
1px-wide grids would be to shift the cyan box guides as well as the red
selection markers.
Hmm, I still would like to see this.
Ultimately, though, I found that 2px lines actually have the advantage
that they can be displayed in fainter gray while still giving the same
visual impact. This should reduce the visual clutter with the black page
content.
As for the eqnarray* grids - indeed that look takes some getting used
to. After using it for some time, I actually began to like it. I am not
quite sure how to change this cleanly. Currently, the whole code is
really simple, drawing a rectangle around each cell individually. Trying
to find adjacent cells and then determining the line between is
certainly much more messy and may be quite tricky to get correct for
cell spans etc.
I think that one ultimately gets used to about any convention.
Nevertheless, the first impression is important, and it still seems
a bit messy to me. But I think that it should be possible to do
something about it. Also true that the implementation will be non trivial;
the current solution is definitely the easiest one.
Actually, do you have an idea what the mechanism is that causes the
space between the lines in eqnarray* ? I never managed to cause the same
effect in a table.
This is just the interparagraph space.
Currently, my own major grievance with the table grid code is that cell
borders are hidden *behind* the grid. I tried to put the visual hints
behind the text, but this did not work nicely with overlays (which I use
heavily in one special layout). As I said, alpha-channel rastering would
be the perfect solution for this...
Yes, we should try to implement alpha rendering sometime soon;
this should be possible with the Qt port.
Best wishes, --Joris
PS: happy christmas to everybody on the list;
I will be off for a long week.
_______________________________________________
Texmacs-dev mailing list
address@hidden
http://lists.gnu.org/mailman/listinfo/texmacs-dev
>From f29e27747d8908cb6d36d38416e1d01813c03b10 Mon Sep 17 00:00:00 2001
From: Norbert Nemec <address@hidden>
Date: Sun, 20 Dec 2009 22:16:06 +0000
Subject: [PATCH] Display table grid (very faint gray). Also change color of
environment boxes from intense cyan to faint gray cyan and put them behind the
displayed content.
---
src/src/Edit/Interface/edit_interface.cpp | 37 ++++++++++++++++++----------
src/src/Edit/Interface/edit_interface.hpp | 3 +-
src/src/Edit/Interface/edit_repaint.cpp | 10 ++++++-
src/src/Kernel/Types/rectangles.cpp | 21 +++++++++++++++-
src/src/Kernel/Types/rectangles.hpp | 1 +
5 files changed, 54 insertions(+), 18 deletions(-)
diff --git a/src/src/Edit/Interface/edit_interface.cpp
b/src/src/Edit/Interface/edit_interface.cpp
index a035b5a..aa9f72f 100644
--- a/src/src/Edit/Interface/edit_interface.cpp
+++ b/src/src/Edit/Interface/edit_interface.cpp
@@ -261,26 +261,36 @@ is_graphical (tree t) {
}
void
-edit_interface_rep::compute_env_rects (path p, rectangles& rs, bool recurse) {
+edit_interface_rep::compute_env_rects (path p,
+ rectangles& rs, rectangles& tcrs, bool recurse) {
p= path_up (p);
if (p == rp) return;
tree st= subtree (et, p);
- if (is_atomic (st) ||
+ if(is_func(st,TABLE)) {
+ rectangles r;
+ for(int i=0;i<N(st);i++)
+ if(is_func(st[i],ROW))
+ for(int j=0;j<N(st[i]);j++) {
+ selection sel= eb->find_check_selection (p*i*j*0,p*i*j*1);
+ r << outline_narrow(sel->rs,pixel);
+ }
+ tcrs << simplify(r);
+ compute_env_rects (p, rs, tcrs, recurse);
+ } else if (is_atomic (st) ||
drd->is_child_enforcing (st) ||
//is_document (st) || is_concat (st) ||
- is_func (st, TABLE) || is_func (st, SUBTABLE) ||
+ is_func (st, SUBTABLE) ||
is_func (st, ROW) || is_func (st, TFORMAT) ||
is_graphical (st) ||
(is_func (st, WITH) && is_graphical (st[N(st)-1])) ||
(is_func (st, WITH) && is_func (st[N(st)-1], TEXT_AT)) ||
(is_compound (st, "math", 1) &&
is_compound (subtree (et, path_up (p)), "input")))
- compute_env_rects (p, rs, recurse);
+ compute_env_rects (p, rs, tcrs, recurse);
else {
int new_mode= DRD_ACCESS_NORMAL;
if (get_init_string (MODE) == "src") new_mode= DRD_ACCESS_SOURCE;
int old_mode= set_access_mode (new_mode);
- tree st= subtree (et, p);
if (is_accessible_cursor (et, p * right_index (st)) || in_source ()) {
bool right;
path p1= p * 0, p2= p * 1, q1, q2;
@@ -294,7 +304,7 @@ edit_interface_rep::compute_env_rects (path p, rectangles&
rs, bool recurse) {
rs << outline (sel->rs, pixel);
}
set_access_mode (old_mode);
- if (recurse) compute_env_rects (p, rs, recurse);
+ if (recurse) compute_env_rects (p, rs, tcrs, recurse);
}
}
@@ -457,8 +467,14 @@ edit_interface_rep::apply_changes () {
oc= copy (cu);
rectangles old_rects= env_rects;
+ rectangles old_tc_rects= tblcell_rects;
env_rects= rectangles ();
- compute_env_rects (path_up (tp), env_rects, true);
+ tblcell_rects= rectangles ();
+ compute_env_rects (path_up (tp), env_rects, tblcell_rects, true);
+ if (tblcell_rects != old_tc_rects) {
+ invalidate (old_tc_rects);
+ invalidate (tblcell_rects);
+ }
if (env_rects != old_rects) {
invalidate (old_rects);
invalidate (env_rects);
@@ -473,12 +489,7 @@ edit_interface_rep::apply_changes () {
if (made_selection) {
table_selection= selection_active_table ();
selection sel; selection_get (sel);
- /*
- selection_rects=
- simplify (::correct (thicken (sel->rs, pixel, pixel) - sel->rs));
- */
- selection_rects= simplify (::correct (thicken (sel->rs, pixel, 3*pixel) -
- thicken (sel->rs, 0, 2*pixel)));
+ selection_rects= outline (sel->rs, pixel);
invalidate (selection_rects);
}
}
diff --git a/src/src/Edit/Interface/edit_interface.hpp
b/src/src/Edit/Interface/edit_interface.hpp
index 05cf7d8..dbf5c85 100644
--- a/src/src/Edit/Interface/edit_interface.hpp
+++ b/src/src/Edit/Interface/edit_interface.hpp
@@ -55,6 +55,7 @@ protected:
bool table_selection;
rectangles selection_rects;
rectangles env_rects;
+ rectangles tblcell_rects;
cursor oc;
bool temp_invalid_cursor;
array<string> completions;
@@ -110,7 +111,7 @@ public:
void animate ();
/* miscellaneous */
- void compute_env_rects (path p, rectangles& rs, bool recurse);
+ void compute_env_rects (path p, rectangles& rs, rectangles& trs, bool
recurse);
void cursor_visible ();
void selection_visible ();
void full_screen_mode (bool flag);
diff --git a/src/src/Edit/Interface/edit_repaint.cpp
b/src/src/Edit/Interface/edit_repaint.cpp
index 69a1efd..08a2a6b 100644
--- a/src/src/Edit/Interface/edit_repaint.cpp
+++ b/src/src/Edit/Interface/edit_repaint.cpp
@@ -35,9 +35,15 @@ edit_interface_rep::draw_text (renderer ren, rectangles& l) {
void
edit_interface_rep::draw_env (renderer ren) {
if (!full_screen) {
- rectangles rs= env_rects;
+ rectangles rs= tblcell_rects;
while (!is_nil (rs)) {
- ren->set_color (rgb_color (0, 255, 255));
+ ren->set_color (rgb_color (224, 224, 224));
+ ren->fill (rs->item->x1, rs->item->y1, rs->item->x2, rs->item->y2);
+ rs= rs->next;
+ }
+ rs= env_rects;
+ while (!is_nil (rs)) {
+ ren->set_color (rgb_color (162, 224, 224));
ren->fill (rs->item->x1, rs->item->y1, rs->item->x2, rs->item->y2);
rs= rs->next;
}
diff --git a/src/src/Kernel/Types/rectangles.cpp
b/src/src/Kernel/Types/rectangles.cpp
index 5c44903..a3fd794 100644
--- a/src/src/Kernel/Types/rectangles.cpp
+++ b/src/src/Kernel/Types/rectangles.cpp
@@ -193,9 +193,26 @@ thicken (rectangles l, SI width, SI height) {
}
rectangles
+halfshift (rectangles rs,SI pixel) {
+ if (is_nil (rs)) return rs;
+ rectangle& r= rs->item;
+ return rectangles (rectangle (r->x1, r->y1, r->x2+pixel, r->y2+pixel),
+ halfshift (rs->next,pixel));
+}
+
+rectangles
outline (rectangles rs, SI pixel) {
- return simplify (correct (thicken (rs, pixel, 3*pixel) -
- thicken (rs, 0, 2*pixel)));
+ return simplify (correct (
+ thicken (halfshift (rs,pixel), 0, 2*pixel)
+ - thicken (halfshift(rs,pixel), -pixel, pixel)
+ ));
+}
+
+rectangles
+outline_narrow (rectangles rs,SI pixel) {
+ return simplify (correct (
+ halfshift (rs,pixel) - thicken (halfshift(rs,pixel), -pixel, -pixel)
+ ));
}
rectangles
diff --git a/src/src/Kernel/Types/rectangles.hpp
b/src/src/Kernel/Types/rectangles.hpp
index 9021eef..c4f4758 100644
--- a/src/src/Kernel/Types/rectangles.hpp
+++ b/src/src/Kernel/Types/rectangles.hpp
@@ -51,6 +51,7 @@ rectangles operator / (rectangles l, int d);
rectangles translate (rectangles l, SI x, SI y);
rectangles thicken (rectangles l, SI width, SI height);
rectangles outline (rectangles l, SI pixel);
+rectangles outline_narrow (rectangles l, SI pixel);
rectangles correct (rectangles l);
rectangles simplify (rectangles l);
rectangle least_upper_bound (rectangles l);
--
1.6.3.3