miniview: have only one buffer

devs/discomfitor/cc
Boris Faure 9 years ago
parent 7fbc02b7c6
commit 73930a6712
  1. 301
      src/bin/miniview.c
  2. 4
      src/bin/miniview.h
  3. 11
      src/bin/termio.c
  4. 1
      src/bin/termio.h
  5. 3
      src/bin/termptyops.c

@ -52,13 +52,11 @@ struct _Miniview
Evas_Object *termio;
Termpty *pty;
int img_h;
int img_hist; /* history rendered is between img_hpos(<0) and
img_pos - image_height */
int img_off; /* >0; offset for the visible part */
int viewport_h;
int rows;
int columns;
int img_hist; /* history rendered is between img_hist (<0) and
img_hist + img_h */
unsigned img_h;
unsigned rows;
unsigned cols;
int is_shown;
};
@ -82,7 +80,7 @@ _draw_line(unsigned int *pixels, Termcell *cells, int length)
{
switch (cells[x].att.fg)
{
// TODO: get pixel colors from current themee...
// TODO: get pixel colors from current theme...
case 0:
r = 180; g = 180; b = 180;
break;
@ -112,120 +110,6 @@ _draw_line(unsigned int *pixels, Termcell *cells, int length)
}
}
static void
_scroll(Miniview *mv, int z)
{
int history_len = mv->pty->backscroll_num,
new_offset,
d;
Evas_Coord ox, oy;
/* whether to move img or modify it */
DBG("history_len:%d z:%d img:h:%d hist:%d off:%d viewport:%d rows:%d",
history_len, z, mv->img_h, mv->img_hist, mv->img_off, mv->viewport_h,
mv->rows);
/* top? */
if ((mv->img_hist == -history_len && mv->img_off == 0 && z < 0))
{
DBG("TOP");
return;
}
/* bottom? */
if (mv->img_hist + mv->viewport_h + mv->img_off >= mv->rows && z > 0) /* bottom */
{
DBG("BOTTOM");
return;
}
evas_object_geometry_get(mv->img, &ox, &oy, NULL, NULL);
new_offset = mv->img_off + z;
if (new_offset >= 0 &&
new_offset + mv->viewport_h <= mv->img_h)
{
/* move */
/*
if (z > 0)
// TODO: boundaries
d = MIN(mv->viewport_h + z, history_len + mv->img_hist);
else
d = MIN(mv->viewport_h + z, history_len + mv->img_hist);
*/
mv->img_off = new_offset;
evas_object_move(mv->img, ox, oy - z);
}
else
{
Termcell *cells;
unsigned int *pixels;
int y, wret;
pixels = evas_object_image_data_get(mv->img, EINA_TRUE);
/*TODO: memmove, be more efficient: ftm, redraw it all */
if (z > 0)
{
/* draw bottom */
if (mv->img_hist + z + mv->viewport_h > mv->rows)
{
mv->img_hist = mv->rows - mv->viewport_h;
mv->img_off = 0;
}
else
{
mv->img_hist += mv->viewport_h + z;
mv->img_off = mv->viewport_h;
}
/* TODO: boris not working: offset issue */
memset(pixels, 0, sizeof(*pixels) * mv->columns * mv->img_h);
for (y = 0; y < mv->img_h; y++)
{
cells = termpty_cellrow_get(mv->pty, mv->img_hist + y, &wret);
if (cells == NULL)
break;
_draw_line(&pixels[y * mv->columns], cells, wret);
}
mv->img_off = mv->viewport_h;
evas_object_move(mv->img,
ox,
-mv->img_off);
}
else
{
if (mv->viewport_h + z < history_len + mv->img_hist)
{
d = mv->viewport_h + z;
mv->img_off = d;
}
else
{
d = history_len + mv->img_hist;
mv->img_off = 0;
}
mv->img_hist -= d;
if (!d) return;
/* draw top */
memset(pixels, 0, sizeof(*pixels) * mv->columns * mv->img_h);
for (y = 0; y < mv->img_h; y++)
{
cells = termpty_cellrow_get(mv->pty, mv->img_hist + y, &wret);
if (cells == NULL)
break;
_draw_line(&pixels[y * mv->columns], cells, wret);
}
evas_object_move(mv->img,
ox,
- mv->img_off);
}
}
}
static void
_smart_cb_mouse_wheel(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event)
@ -240,54 +124,9 @@ _smart_cb_mouse_wheel(void *data, Evas *e EINA_UNUSED,
DBG("ev->z:%d", ev->z);
_scroll(mv, ev->z * 10);
}
static void
_smart_cb_key_down(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event)
{
Evas_Event_Key_Down *ev = event;
Miniview *mv = evas_object_smart_data_get(data);
EINA_SAFETY_ON_NULL_RETURN(mv);
if (!strcmp(ev->key, "Prior"))
_scroll(mv, -10);
else if (!strcmp(ev->key, "Next"))
_scroll(mv, 10);
if (!strcmp(ev->keyname, "h") &&
!evas_key_modifier_is_set(ev->modifiers, "Alt") &&
evas_key_modifier_is_set(ev->modifiers, "Shift") &&
evas_key_modifier_is_set(ev->modifiers, "Control"))
{
evas_object_smart_callback_call(mv->termio, "miniview,toggle", NULL);
}
}
static void
_smart_cb_mouse_in(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
Miniview *mv = evas_object_smart_data_get(data);
EINA_SAFETY_ON_NULL_RETURN(mv);
elm_object_focus_set(mv->img, EINA_TRUE);
}
static void
_smart_cb_mouse_out(void *data, Evas *e EINA_UNUSED,
Evas_Object *obj EINA_UNUSED, void *event EINA_UNUSED)
{
Miniview *mv = evas_object_smart_data_get(data);
EINA_SAFETY_ON_NULL_RETURN(mv);
elm_object_focus_set(mv->img, EINA_FALSE);
mv->img_hist += ev->z * 10;
}
static void
_smart_add(Evas_Object *obj)
{
@ -312,12 +151,6 @@ _smart_add(Evas_Object *obj)
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_WHEEL,
_smart_cb_mouse_wheel, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_KEY_DOWN,
_smart_cb_key_down, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_IN,
_smart_cb_mouse_in, obj);
evas_object_event_callback_add(o, EVAS_CALLBACK_MOUSE_OUT,
_smart_cb_mouse_out, obj);
}
static void
@ -347,27 +180,36 @@ _smart_show(Evas_Object *obj)
{
Miniview *mv = evas_object_smart_data_get(obj);
DBG("smart show obj:%p mv:%p", obj, mv);
if (!mv) return;
if (!mv->is_shown)
{
Evas_Coord ox, oy, ow, oh, font_w, font_h;
mv->is_shown = 1;
miniview_redraw(obj, mv->columns, mv->rows);
mv->img_hist = 0;
evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh);
if (ow == 0 || oh == 0) return;
evas_object_size_hint_min_get(mv->termio, &font_w, &font_h);
if (font_w <= 0 || font_h <= 0) return;
mv->img_h = oh;
mv->rows = oh / font_h;
mv->cols = ow / font_w;
if (mv->rows == 0 || mv->cols == 0) return;
evas_object_resize(mv->img, mv->cols, mv->img_h);
evas_object_image_size_set(mv->img, mv->cols, mv->img_h);
evas_object_image_fill_set(mv->img, 0, 0, mv->cols, mv->img_h);
evas_object_move(mv->img, ox + ow - mv->cols, oy);
miniview_redraw(obj);
evas_object_show(mv->img);
}
/*
Evas_Coord ox, oy, ow, oh;
evas_object_geometry_get(mv->img, &ox, &oy, &ow, &oh);
DBG("ox:%d oy:%d ow:%d oh:%d visible:%d|%d %d %d %d",
ox, oy, ow, oh,
evas_object_visible_get(obj),
evas_object_visible_get(mv->img),
evas_object_layer_get(mv->img),
evas_object_layer_get(obj),
evas_object_layer_get(mv->termio));
*/
}
static void
@ -375,7 +217,6 @@ _smart_hide(Evas_Object *obj)
{
Miniview *mv = evas_object_smart_data_get(obj);
DBG("smart hide obj:%p mv:%p", obj, mv);
if (!mv) return;
if (mv->is_shown)
@ -386,57 +227,33 @@ _smart_hide(Evas_Object *obj)
}
void
miniview_redraw(Evas_Object *obj, int columns, int rows)
miniview_redraw(Evas_Object *obj)
{
Miniview *mv;
Evas_Coord ox, oy, ow, oh;
int history_len, h, y, wret;
unsigned int *pixels;
int history_len, wret;
unsigned int *pixels, y;
Termcell *cells;
if (!obj) return;
mv = evas_object_smart_data_get(obj);
if (!mv) return;
mv->columns = columns;
mv->rows = rows;
if (!mv->is_shown) return;
DBG("smart size %p", obj);
if (!mv || !mv->is_shown) return;
evas_object_geometry_get(mv->termio, &ox, &oy, &ow, &oh);
if (ow == 0 || oh == 0) return;
mv->img_h = 3 * oh;
DBG("ox:%d oy:%d ow:%d oh:%d columns:%d rows:%d",
ox, oy, ow, oh, mv->columns, mv->rows);
evas_object_resize(mv->img, mv->columns, mv->img_h);
evas_object_image_size_set(mv->img, mv->columns, mv->img_h);
evas_object_image_fill_set(mv->img, 0, 0, mv->columns, mv->img_h);
history_len = mv->pty->backscroll_num;
DBG("backscroll_num:%d backmax:%d backpos:%d",
mv->pty->backscroll_num, mv->pty->backmax, mv->pty->backpos);
pixels = evas_object_image_data_get(mv->img, EINA_TRUE);
memset(pixels, 0, sizeof(*pixels) * mv->columns * mv->img_h);
mv->viewport_h = oh;
h = mv->img_h - mv->rows;
if (h < history_len)
{
mv->img_hist = mv->rows - mv->img_h;
}
else
{
mv->img_hist = -history_len;
}
memset(pixels, 0, sizeof(*pixels) * mv->cols * mv->img_h);
DBG("img_h:%d history_len:%d h:%d img_hist:%d vph:%d",
mv->img_h, history_len, h, mv->img_hist, mv->viewport_h);
DBG("history_len:%d hist:%d img_h:%d rows:%d cols:%d",
history_len, mv->img_hist, mv->img_h, mv->rows, mv->cols);
/* "current"? */
if (mv->img_hist >= - ((int)mv->img_h - (int)mv->rows))
mv->img_hist = -((int)mv->img_h - (int)mv->rows);
if (mv->img_hist < -history_len)
mv->img_hist = -history_len;
for (y = 0; y < mv->img_h; y++)
{
@ -447,27 +264,12 @@ miniview_redraw(Evas_Object *obj, int columns, int rows)
break;
}
_draw_line(&pixels[y * mv->columns], cells, wret);
}
if (y > mv->viewport_h)
{
mv->img_off = y - mv->viewport_h;
evas_object_move(mv->img,
ox + ow - mv->columns,
- mv->img_off);
_draw_line(&pixels[y * mv->cols], cells, wret);
}
else
{
mv->img_off = 0;
evas_object_move(mv->img,
ox + ow - mv->columns,
0);
}
DBG("history_len:%d img:h:%d hist:%d off:%d viewport:%d",
history_len, mv->img_h, mv->img_hist, mv->img_off,mv->viewport_h);
DBG("history_len:%d hist:%d img_h:%d rows:%d cols:%d",
history_len, mv->img_hist, mv->img_h, mv->rows, mv->cols);
evas_object_image_data_set(mv->img, pixels);
evas_object_image_data_update_add(mv->img, 0, 0, mv->cols, mv->img_h);
}
@ -506,7 +308,6 @@ miniview_add(Evas_Object *parent, Evas_Object *termio)
Evas *e;
Evas_Object *obj;
Miniview *mv;
Evas_Coord ow, oh, font_w, font_h;
EINA_SAFETY_ON_NULL_RETURN_VAL(parent, NULL);
e = evas_object_evas_get(parent);
@ -523,14 +324,6 @@ miniview_add(Evas_Object *parent, Evas_Object *termio)
mv->termio = termio;
mv->pty = termio_pty_get(termio);
evas_object_geometry_get(mv->termio, NULL, NULL, &ow, &oh);
if (ow == 0 || oh == 0) return obj;
evas_object_size_hint_min_get(mv->termio, &font_w, &font_h);
if (font_w <= 0 || font_h <= 0) return obj;
miniview_redraw(obj, ow / font_w, oh / font_h);
return obj;
}

@ -1,10 +1,12 @@
#ifndef _MINIVIEW_H__
#define _MINIVIEW_H__ 1
#include "termpty.h"
Evas_Object * miniview_add(Evas_Object *parent, Evas_Object *termio);
void miniview_redraw(Evas_Object *obj, int columns, int rows);
void miniview_redraw(Evas_Object *obj);
void miniview_push_history(Evas_Object *obj, Termcell *cells, int cells_len);
void miniview_init(void);
void miniview_shutdown(void);

@ -1626,6 +1626,7 @@ _smart_apply(Evas_Object *obj)
if (sd->mouseover_delay) ecore_timer_del(sd->mouseover_delay);
sd->mouseover_delay = ecore_timer_add(0.05, _smart_mouseover_delay, obj);
//printf("How are you today?\n?");
miniview_redraw(term_miniview_get(sd->term));
}
static void
@ -1652,7 +1653,6 @@ _smart_size(Evas_Object *obj, int w, int h, Eina_Bool force)
sd->font.chh * sd->grid.h);
_sel_set(obj, EINA_FALSE);
termpty_resize(sd->pty, w, h);
miniview_redraw(term_miniview_get(sd->term), w, h);
_smart_calculate(obj);
_smart_apply(obj);
@ -5000,3 +5000,12 @@ termio_pty_get(Evas_Object *obj)
return sd->pty;
}
Evas_Object *
termio_miniview_get(Evas_Object *obj)
{
Termio *sd = evas_object_smart_data_get(obj);
EINA_SAFETY_ON_NULL_RETURN_VAL(sd, NULL);
return term_miniview_get(sd->term);
}

@ -43,5 +43,6 @@ Config *termio_config_get(const Evas_Object *obj);
void termio_debugwhite_set(Evas_Object *obj, Eina_Bool dbg);
Termpty *termio_pty_get(Evas_Object *obj);
Evas_Object * termio_miniview_get(Evas_Object *obj);
#endif

@ -6,6 +6,7 @@
#include "termptyops.h"
#include "termptygfx.h"
#include "termptysave.h"
#include "miniview.h"
#undef CRITICAL
#undef ERR
@ -46,7 +47,7 @@ termpty_text_save_top(Termpty *ty, Termcell *cells, ssize_t w_max)
if (ty->back[ty->backpos])
{
Termsave *ts2;
ts2 = termpty_save_extract(ty->back[ty->backpos]);
termpty_save_free(ts2);
ty->back[ty->backpos] = NULL;

Loading…
Cancel
Save