Author: tom
Date: Mon Dec 22 07:51:49 2008
New Revision: 3603
URL: http://svn.slimdevices.com?rev=3603&root=Jive&view=rev
Log:
pango:
- textarea scrolling - arrows move pixel by pixel(for now), mouse drag does
smooth scrolling.
- Initial pango context work. not used yet
Modified:
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h
7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c
7.4/branches/pango/squeezeplay/src/squeezeplay_contrib/share/applets/Test/test.txt
Modified:
7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
URL:
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua?rev=3603&root=Jive&r1=3602&r2=3603&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/share/jive/ui/Textarea.lua
Mon Dec 22 07:51:49 2008
@@ -58,6 +58,9 @@
local EVENT_SCROLL = jive.ui.EVENT_SCROLL
local EVENT_KEY_PRESS = jive.ui.EVENT_KEY_PRESS
local EVENT_MOUSE_DRAG = jive.ui.EVENT_MOUSE_DRAG
+local EVENT_MOUSE_DOWN = jive.ui.EVENT_MOUSE_DOWN
+local EVENT_MOUSE_UP = jive.ui.EVENT_MOUSE_UP
+local EVENT_MOUSE_HOLD = jive.ui.EVENT_MOUSE_HOLD
local EVENT_CONSUME = jive.ui.EVENT_CONSUME
local EVENT_UNUSED = jive.ui.EVENT_UNUSED
@@ -101,8 +104,10 @@
obj.topLine = 0
obj.visibleLines = 0
obj.text = text
-
- obj:addListener(EVENT_SCROLL | EVENT_KEY_PRESS | EVENT_MOUSE_DRAG,
+ obj.dragOrigin = {}
+
+
+ obj:addListener(EVENT_SCROLL | EVENT_KEY_PRESS | EVENT_MOUSE_DRAG |
EVENT_MOUSE_DOWN| EVENT_MOUSE_UP ,
function (event)
return obj:_eventHandler(event)
end)
@@ -161,8 +166,9 @@
--]]
function scrollBy(self, scroll)
_assert(type(scroll) == "number")
-
- self:_scrollTo(self.topLine + scroll)
+
+ self:scroll(scroll);
+ --self:_scrollTo(self.topLine + scroll)
end
function _scrollTo(self, topLine)
@@ -178,18 +184,45 @@
self:reDraw()
end
-
function _eventHandler(self, event)
local type = event:getType()
if type == EVENT_SCROLL then
self:scrollBy(event:getScroll())
+ return EVENT_CONSUME
+
+ elseif type == EVENT_MOUSE_DOWN then
+ if (not self.scrollbar:mouseInside(event)) then
+ self.dragOrigin.x, self.dragOrigin.y = event:getMouse();
+
+ --else - todo: handle scrollbar case, but what are we doing with
textarea scrollbars in new model
+ end
+
+ return EVENT_CONSUME
+
+ elseif type == EVENT_MOUSE_UP then
+ self.dragOrigin.x, self.dragOrigin.y = nil, nil;
+
+ return EVENT_CONSUME
+
+ elseif type == EVENT_MOUSE_DRAG then
+ if ( self.dragOrigin.y == nil) then
+ --might have started drag outside of this textarea's bounds, so
reset origin
+ self.dragOrigin.x, self.dragOrigin.y = event:getMouse();
+ end
+
+ local mouseX, mouseY = event:getMouse()
+
+ local dragAmountY = self.dragOrigin.y - mouseY
+ self:scroll(dragAmountY);
+
+ --reset origin
+ self.dragOrigin.x, self.dragOrigin.y = mouseX, mouseY
+
+ self:reDraw();
+
return EVENT_CONSUME
-
- elseif type == EVENT_MOUSE_DRAG then
-
- return self.scrollbar:_event(event)
elseif type == EVENT_KEY_PRESS then
local keycode = event:getKeycode()
Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h
URL:
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h?rev=3603&root=Jive&r1=3602&r2=3603&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h (original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive.h Mon Dec 22
07:51:49 2008
@@ -167,6 +167,7 @@
typedef struct jive_font JiveFont;
+typedef struct jive_pango_context JivePangoContext;
struct jive_peer_meta {
size_t size;
@@ -253,6 +254,11 @@
const char *magic;
};
+struct jive_pango_context {
+ PangoContext *context;
+ PangoFontMap *font_map;
+};
+
struct jive_perfwarn {
Uint32 screen;
Uint32 layout;
@@ -267,6 +273,7 @@
extern int (*jive_sdlevent_pump)(lua_State *L);
extern int (*jive_sdlfilter_pump)(const SDL_Event *event);
+SDLPango_Context * jive_create_sdl_pango_context();
void jive_send_key_event(JiveEventType keyType, JiveKey keyCode);
@@ -284,6 +291,7 @@
/*hack - global sdl_pango context*/
extern SDLPango_Context *pangocontext;
+extern JivePangoContext *jive_pango_context;
/* Util functions */
void jive_print_stack(lua_State *L, char *str);
@@ -466,6 +474,7 @@
int jiveL_textarea_skin(lua_State *L);
int jiveL_textarea_layout(lua_State *L);
int jiveL_textarea_draw(lua_State *L);
+int jiveL_textarea_scroll(lua_State *L);
int jiveL_textarea_gc(lua_State *L);
int jiveL_window_skin(lua_State *L);
Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
URL:
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c?rev=3603&root=Jive&r1=3602&r2=3603&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_framework.c Mon
Dec 22 07:51:49 2008
@@ -26,6 +26,7 @@
struct jive_perfwarn perfwarn = { 0, 0, 0, 0, 0, 0 };
SDLPango_Context *pangocontext;
+JivePangoContext *jive_pango_context;
/* Frame rate calculations */
//static Uint32 framedue = 0;
@@ -151,13 +152,20 @@
exit(-1);
}
- pangocontext = SDLPango_CreateContext_GivenFontDesc("FreeSans Bold 15");
+//future
+// jive_pango_context = malloc(sizeof(JivePangoContext));
+// jive_pango_context->font_map = pango_ft2_font_map_new ();
+// pango_ft2_font_map_set_resolution (PANGO_FT2_FONT_MAP
(context->font_map), 75.0, 75.0);
+//
+// context->context = pango_ft2_font_map_create_context (PANGO_FT2_FONT_MAP
(context->font_map));
- SDLPango_SetDpi(pangocontext, 75.0, 75.0);
-
- SDLPango_SetDefaultColor(pangocontext,
MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
- SDLPango_SetMinimumSize(pangocontext, 0, 0);
-
+
+ //will likely be replaced
+ pangocontext = jive_create_sdl_pango_context();
+
+
+
+
/* Register callback for additional events (used for multimedia keys)*/
SDL_EventState(SDL_SYSWMEVENT,SDL_ENABLE);
SDL_SetEventFilter(filter_events);
@@ -204,6 +212,17 @@
lua_pop(L, 2);
return 0;
+}
+
+SDLPango_Context * jive_create_sdl_pango_context() {
+ SDLPango_Context *context = SDLPango_CreateContext_GivenFontDesc("FreeSans
Bold 15");
+
+ SDLPango_SetDpi(context, 75.0, 75.0);
+
+ SDLPango_SetDefaultColor(context, MATRIX_TRANSPARENT_BACK_WHITE_LETTER);
+ SDLPango_SetMinimumSize(context, 0, 0);
+
+ return context;
}
static int filter_events(const SDL_Event *event)
@@ -1273,6 +1292,7 @@
{ "_skin", jiveL_textarea_skin },
{ "_layout", jiveL_textarea_layout },
{ "draw", jiveL_textarea_draw },
+ { "scroll", jiveL_textarea_scroll },
{ NULL, NULL }
};
Modified: 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c
URL:
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c?rev=3603&root=Jive&r1=3602&r2=3603&view=diff
==============================================================================
--- 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c
(original)
+++ 7.4/branches/pango/squeezeplay/src/squeezeplay/src/ui/jive_textarea.c Mon
Dec 22 07:51:49 2008
@@ -25,6 +25,11 @@
Uint32 sh;
Uint32 fg;
JiveTile *bg_tile;
+ bool is_prepared;
+
+ JiveSurface *text_surface; //todo:free me
+ int text_surface_y;
+
} TextareaWidget;
@@ -68,7 +73,9 @@
peer->bg_tile = jive_tile_ref(bg_tile);
}
- peer->line_height = jive_style_int(L, 1, "lineHeight",
jive_font_height(peer->font));
+ //todo: line height no longer constant - refactor this
+ peer->line_height = jive_style_int(L, 1, "lineHeight",
jive_font_height(peer->font));
+
peer->text_offset = jive_font_offset(peer->font);
peer->align = jive_style_align(L, 1, "textAlign", JIVE_ALIGN_LEFT);
@@ -104,8 +111,14 @@
}
w = peer->w.bounds.w + peer->w.padding.left + peer->w.padding.right;
+ fprintf(stderr, "peer->w.bounds.h: %d\n", peer->w.bounds.h);
+ //how to get the h value - want full space but bounds not yet set
+// h = peer->w.bounds.h;
h = (peer->num_lines * peer->line_height) + peer->w.padding.top +
peer->w.padding.bottom;
-
+
+ //todo: fix - hack by exceeding screen size until we can get the full
space value
+ h = 600;
+
if (peer->w.preferred_bounds.x == JIVE_XY_NIL) {
lua_pushnil(L);
}
@@ -123,6 +136,65 @@
lua_pushinteger(L, (peer->w.preferred_bounds.h == JIVE_WH_NIL) ? h :
peer->w.preferred_bounds.h);
return 4;
}
+
+static void prepare(lua_State *L) {
+ TextareaWidget *peer;
+ Uint16 width;
+ const char *str;
+
+
+ peer = jive_getpeer(L, 1, &textareaPeerMeta);
+
+ //this will go away when prepare/layout are only called once per real
layout (currently is called 4 times)
+ if (peer->is_prepared) {
+ fprintf(stderr, "ALREADY PREPARED\n");
+ return;
+ }
+
+ peer->is_prepared = true;
+
+
+ /* free existing text surfaces - this seems odd, shoudl regular gc
associated with the window
+ be the place to deal with this rather than here in prepare*/
+ //jive_textarea_gc_lines(peer); - remember to free sdlpango context,
etc, but why here in prepare
+
+
+ lua_getglobal(L, "tostring");
+ lua_getfield(L, 1, "text");
+ lua_call(L, 1, 1);
+
+ str = (char *) lua_tostring(L, -1);
+
+ width = peer->w.bounds.w - peer->w.padding.left - peer->w.padding.right;
+ peer->text_surface = jive_font_draw_text_wrap(peer->font, peer->fg, str,
width);
+ peer->text_surface_y = 0;
+
+ //todo: apply shadow surface - blit to text_surface?
+
+ return;
+// if (!str || *str == '\0') {
+// return;
+// }
+//
+// peer->text_sh = peer->base.is_sh ? jive_font_draw_text(peer->base.font,
peer->base.sh, str) : NULL;
+// peer->text_fg = jive_font_draw_text(peer->base.font, peer->base.fg,
str);
+//
+//
+// /* label dimensions */
+// jive_surface_get_size(peer->text_fg, &width, &height);
+// //Note: surface height being returned is higher than
peer->base.lineHeight, why? for now commenting out next line because of this
+// // height = MAX(peer->base.lineHeight, height);
+// height = peer->base.lineHeight;
+//
+// /* text width and height */
+// peer->text_h = height;
+// peer->text_w = width;
+//
+// /* reset scroll position */
+// peer->scroll_offset = SCROLL_PAD_START;
+
+}
+
int jiveL_textarea_layout(lua_State *L) {
@@ -135,9 +207,13 @@
/* stack is:
* 1: widget
*/
-
peer = jive_getpeer(L, 1, &textareaPeerMeta);
+ if (peer->w.bounds.w != 0) {
+ //"if check" is a hack until I understand more - prepare needs
w.bounds.w to render the pango with w.bounds.w
+ // isn't set during first jiveL_textarea_layout call (not clear to me
why)
+ prepare(L);
+ }
/* scrollbar size */
sw = 0;
@@ -257,11 +333,42 @@
return 0;
}
+int jiveL_textarea_scroll(lua_State *L) {
+ /* stack is:
+ * 1: widget
+ * 2: scroll_amount
+ */
+ TextareaWidget *peer;
+ int scroll_amount;
+ Uint16 bottom;
+ Uint16 srf_w, srf_h;
+
+ peer = jive_getpeer(L, 1, &textareaPeerMeta);
+ scroll_amount = tolua_tointeger(L, 2, 0);
+
+ peer->text_surface_y += scroll_amount;
+
+ if (peer->text_surface_y < 0) {
+ peer->text_surface_y = 0;
+ }
+
+ //todo: factor in padding?
+ jive_surface_get_size(peer->text_surface, &srf_w, &srf_h);
+ bottom = srf_h - peer->w.bounds.h;
+ if (peer->text_surface_y > bottom) {
+ peer->text_surface_y = bottom;
+ }
+
+ return 0;
+}
+
int jiveL_textarea_draw(lua_State *L) {
- char *text;
- Uint16 y;
- int i, top_line, visible_lines, bottom_line;
+ Uint16 x, y;
+// int i;
+ int top_line, visible_lines;
+// int bottom_line;
+ Uint16 srf_w, srf_h;
/* stack is:
* 1: widget
@@ -281,16 +388,7 @@
jive_tile_blit(peer->bg_tile, srf, peer->w.bounds.x,
peer->w.bounds.y, peer->w.bounds.w, peer->w.bounds.h);
}
- lua_getglobal(L, "tostring");
- lua_getfield(L, 1, "text");
- if (lua_isnil(L, -1) && !peer->font) {
- lua_pop(L, 2);
- return 0;
- }
- lua_call(L, 1, 1);
-
- text = (char *) lua_tostring(L, -1);
-
+ x = peer->w.bounds.x + peer->w.padding.left;
y = peer->w.bounds.y + peer->w.padding.top - peer->text_offset;
lua_getfield(L, 1, "topLine");
@@ -302,49 +400,52 @@
lua_pop(L, 1);
- bottom_line = top_line + visible_lines;
-
- for (i = top_line; i < bottom_line; i++) {
- JiveSurface *tsrf;
- int x;
- int width;
-
- int line = peer->lines[i];
- int next = peer->lines[i+1];
-
- unsigned char b = text[(next - 1)];
- unsigned char c = text[next];
- text[next] = '\0';
- if (b == '\n') {
- text[(next - 1)] = '\0';
- }
-
- x = peer->w.bounds.x + peer->w.padding.left;
- if (peer->align != JIVE_ALIGN_LEFT) {
- Uint16 line_width = jive_font_width(peer->font,
&text[line]);
- x = jive_widget_halign((JiveWidget *)peer, peer->align,
line_width);
- }
-
- //todo: get actual width - think this is wrong
- width = peer->w.bounds.w - peer->w.padding.left -
peer->w.padding.right;
-
- /* shadow text */
- if (peer->is_sh) {
- tsrf = jive_font_draw_text_wrap(peer->font, peer->sh,
&text[line], width);
- jive_surface_blit(tsrf, srf, x + 1, y + 1);
- jive_surface_free(tsrf);
- }
-
- /* foreground text */
- tsrf = jive_font_draw_text_wrap(peer->font, peer->fg,
&text[line], width);
- jive_surface_blit(tsrf, srf, x, y);
- jive_surface_free(tsrf);
-
- text[next] = c;
- text[(next - 1)] = b;
-
- y += peer->line_height;
- }
+ jive_surface_get_size(srf, &srf_w, &srf_h);
+
+ jive_surface_blit_clip(peer->text_surface, 0, peer->text_surface_y, srf_w,
srf_h, srf, x, y);
+
+// bottom_line = top_line + visible_lines;
+// for (i = top_line; i < bottom_line; i++) {
+// JiveSurface *tsrf;
+// int x;
+// int width;
+//
+// int line = peer->lines[i];
+// int next = peer->lines[i+1];
+//
+// unsigned char b = text[(next - 1)];
+// unsigned char c = text[next];
+// text[next] = '\0';
+// if (b == '\n') {
+// text[(next - 1)] = '\0';
+// }
+//
+// x = peer->w.bounds.x + peer->w.padding.left;
+// if (peer->align != JIVE_ALIGN_LEFT) {
+// Uint16 line_width = jive_font_width(peer->font,
&text[line]);
+// x = jive_widget_halign((JiveWidget *)peer, peer->align,
line_width);
+// }
+//
+// //todo: get actual width - think this is wrong
+// width = peer->w.bounds.w - peer->w.padding.left -
peer->w.padding.right;
+//
+// /* shadow text */
+// if (peer->is_sh) {
+// tsrf = jive_font_draw_text_wrap(peer->font, peer->sh,
&text[line], width);
+// jive_surface_blit(tsrf, srf, x + 1, y + 1);
+// jive_surface_free(tsrf);
+// }
+//
+// /* foreground text */
+// tsrf = jive_font_draw_text_wrap(peer->font, peer->fg,
&text[line], width);
+// jive_surface_blit(tsrf, srf, x, y);
+// jive_surface_free(tsrf);
+//
+// text[next] = c;
+// text[(next - 1)] = b;
+//
+// y += peer->line_height;
+// }
/* draw scrollbar */
if (peer->has_scrollbar) {
Modified:
7.4/branches/pango/squeezeplay/src/squeezeplay_contrib/share/applets/Test/test.txt
URL:
http://svn.slimdevices.com/7.4/branches/pango/squeezeplay/src/squeezeplay_contrib/share/applets/Test/test.txt?rev=3603&root=Jive&r1=3602&r2=3603&view=diff
==============================================================================
---
7.4/branches/pango/squeezeplay/src/squeezeplay_contrib/share/applets/Test/test.txt
(original)
+++
7.4/branches/pango/squeezeplay/src/squeezeplay_contrib/share/applets/Test/test.txt
Mon Dec 22 07:51:49 2008
@@ -3,7 +3,8 @@
UTF-8 encoded sample plain-text file
â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾â¾
-Markus Kuhn [ËmaʳkÊs kuËn] <http://www.cl.cam.ac.uk/~mgk25/> â 2002-07-25
+-TODO: Italics getting clipped
+<i>Markus Kuhn [ËmaʳkÊs kuËn]</i> <http://www.cl.cam.ac.uk/~mgk25/>
â 2002-07-25
The ASCII compatible UTF-8 encoding used in this plain-text file
@@ -20,7 +21,7 @@
â â ââ â ⤠â â â â â â,
- ⥠< a â b â¡ c ⤠d ⪠⤠â (â¦Aâ§ â âªBâ«),
+ ⥠a â b â¡ c ⤠d ⪠⤠â (â¦Aâ§ â âªBâ«),
2Hâ + Oâ â 2HâO, R = 4.7 kΩ, â 200 mm
_______________________________________________
Jive-checkins mailing list
[email protected]
http://lists.slimdevices.com/cgi-bin/mailman/listinfo/jive-checkins