changeset 432:331467b8e778

Make calcuator uses stext instead of text. It is a demo for sh_stext. To use stext, program should call functions of stext and invoke svg2code.py with '-s' option.
author Thinker K.F. Li <thinker@branda.to>
date Wed, 29 Jul 2009 15:03:37 +0800
parents bf1addb037b7
children 099941c3becf
files examples/calculator/Makefile.am examples/calculator/main.c
diffstat 2 files changed, 10 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/examples/calculator/Makefile.am	Wed Jul 29 15:03:26 2009 +0800
+++ b/examples/calculator/Makefile.am	Wed Jul 29 15:03:37 2009 +0800
@@ -12,7 +12,7 @@
 CLEANFILES = calculator_scr.c calculator_scr.h calculator_scr.mb
 
 calculator_scr.mb: $(srcdir)/calculator_scr.svg
-	$(top_srcdir)/tools/svg2code.py $? $@
+	$(top_srcdir)/tools/svg2code.py -s $? $@
 
 calculator_scr.h: calculator_scr.mb
 	m4 -I $(top_srcdir)/tools mb_c_header.m4 $< > $@
--- a/examples/calculator/main.c	Wed Jul 29 15:03:26 2009 +0800
+++ b/examples/calculator/main.c	Wed Jul 29 15:03:37 2009 +0800
@@ -1,4 +1,5 @@
 #include <stdio.h>
+#include <string.h>
 #include <mb.h>
 #include "calculator_scr.h"
 
@@ -66,14 +67,20 @@
     rdman = X_MB_rdman(calc_data->rt);
 
     sprintf(buf, "%d%s", num, suffix);
-    sh_text_set_text(calc_data->code->screen_text_u, buf);
+    sh_stext_set_text(calc_data->code->screen_text_u, buf);
+    calc_data->code->screen_text_u_style_blks[0].n_chars = strlen(buf);
+    sh_stext_set_style(calc_data->code->screen_text_u,
+		       calc_data->code->screen_text_u_style_blks, 1);
     rdman_shape_changed(rdman, calc_data->code->screen_text_u);
 
     if(op == 'n')
 	sprintf(buf, "None");
     else
 	sprintf(buf, "%d%c", saved, op);
-    sh_text_set_text(calc_data->code->saved_text, buf);
+    sh_stext_set_text(calc_data->code->saved_text, buf);
+    calc_data->code->saved_text_style_blks[0].n_chars = strlen(buf);
+    sh_stext_set_style(calc_data->code->saved_text,
+		       calc_data->code->saved_text_style_blks, 1);
     rdman_shape_changed(rdman, calc_data->code->saved_text);
 }