summaryrefslogtreecommitdiff
path: root/slide.c
blob: aeb82a5f8ca2340538ba42bc28a0310f7b4e7995 (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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
/*
 * vim:ts=8:sw=3:sts=8:noexpandtab:cino=>5n-3f0^-2{2
 */
#include "main.h"

#define SMART_NAME "slide"
#define API_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd)
#define INTERNAL_ENTRY Smart_Data *sd; sd = evas_object_smart_data_get(obj); if (!sd) return;
#define WALK_ITEMS_BEGIN \
{ Evas_List *l; Smart_Item *si; \
for (l = sd->items; l; l = l->next) { \
   si = l->data;
#define WALK_ITEMS_END \
} }

typedef struct _Smart_Data Smart_Data;
typedef struct _Smart_Item Smart_Item;

struct _Smart_Data
{ 
   Evas        *evas;
   Evas_Object *smart_object;
   Evas_Object *marker_object;
   Evas_Coord   x, y, w, h;
   Evas_List   *items;
}; 

#define TITLE 0
#define TEXT  1
#define IMAGE 2
#define EDJE  3
#define ITEM  4
#define VIDEO 5

struct _Smart_Item
{
   int          type;
   Evas_Coord   x, y, w, h;
   double       align_x, align_y;
   double       size_w, size_h;
   int          dim_w, dim_h;
   int          pos_x, pos_y;
   int          alpha;
   Evas_Object *obj;
   char        *text;
};

/* local subsystem functions */
static Smart_Item *_smart_item_text_next(Smart_Data *sd);
static Smart_Item *_smart_item_image_next(Smart_Data *sd);
static Smart_Item *_smart_item_edje_next(Smart_Data *sd);
static Smart_Item *_smart_item_video_next(Smart_Data *sd);
static void _smart_reconfigure(Smart_Data *sd);
static void _smart_add(Evas_Object *obj);
static void _smart_del(Evas_Object *obj);
static void _smart_layer_set(Evas_Object *obj, int layer);
static void _smart_raise(Evas_Object *obj);
static void _smart_lower(Evas_Object *obj);
static void _smart_stack_above(Evas_Object *obj, Evas_Object *above);
static void _smart_stack_below(Evas_Object *obj, Evas_Object *below);
static void _smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y);
static void _smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h);
static void _smart_show(Evas_Object *obj);
static void _smart_hide(Evas_Object *obj);
static void _smart_color_set(Evas_Object *obj, int r, int g, int b, int a);
static void _smart_clip_set(Evas_Object *obj, Evas_Object * clip);
static void _smart_clip_unset(Evas_Object *obj);
static void _smart_init(void);

/* local subsystem globals */
static Evas_Smart *_smart = NULL;

/* externally accessible functions */
Evas_Object *
slide_add(Evas *evas)
{
   _smart_init();
   return evas_object_smart_add(evas, _smart);
}

void
slide_title_add(Evas_Object *obj, const char *str)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_text_next(sd);
   si->type = TITLE;
   si->text = strdup(str);
   printf ("slide_title_add\n\n");
   _smart_reconfigure(sd);
}

void
slide_text_add(Evas_Object *obj, const char *str)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_text_next(sd);
   si->type = TEXT;
   si->text = strdup(str);
   printf ("slide_text_add\n\n");
   _smart_reconfigure(sd);
}

void
slide_image_add(Evas_Object *obj, const char *str, const char *size)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_image_next(sd);
   si->type = IMAGE;
   si->size_w = -1;
   if (size) si->size_h = (double)atoi(size) / 100.0;
   else si->size_h = 0.25;
   si->text = strdup(str);
   printf ("slide_image_add\n\n");
   _smart_reconfigure(sd);
}

void
slide_edje_add(Evas_Object *obj, const char *str, const char *size, const char *dimensions)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_edje_next(sd);
   si->type = EDJE;
   si->size_w = -1;
   if (size) si->size_h = (double)atoi(size) / 100.0;
   else si->size_h = 0.25;
   if (dimensions)
     sscanf(dimensions, "%ix%i", &si->dim_w, &si->dim_h);
   si->text = strdup(str);
   printf ("slide_edje_add\n\n");
   _smart_reconfigure(sd);
}

void
slide_item_add(Evas_Object *obj, const char *str)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_text_next(sd);
   si->type = ITEM;
   si->text = strdup(str);
   printf ("slide_item_add\n\n");
   _smart_reconfigure(sd);
}

void
slide_video_add(Evas_Object *obj, const char *str, const char *size, const char *pos, const char *alpha)
{
   Smart_Item *si;

   API_ENTRY return;
   si = _smart_item_video_next(sd);
   si->type = VIDEO;
   si->text = strdup(str);
   si->size_w = -1;
   if (size) si->size_h = (double)atoi(size) / 100.0;
   else si->size_h = 0.25;
   if (pos) sscanf(pos, "%i+%i", &si->pos_x, &si->pos_y);
   if (alpha) si->alpha = atoi(alpha);
   si->text = strdup(str);
   printf ("slide_video_add\n\n");
   _smart_reconfigure(sd);
}

/* local subsystem functions */
static Smart_Item *
_smart_item_text_next(Smart_Data *sd)
{
   Smart_Item *si;
   
   si = calloc(1, sizeof(Smart_Item));
   si->obj = evas_object_textblock_add(sd->evas);
   evas_object_smart_member_add(si->obj, sd->smart_object);
   sd->items = evas_list_append(sd->items, si);
   return si;
}

static Smart_Item *
_smart_item_image_next(Smart_Data *sd)
{
   Smart_Item *si;
   
   si = calloc(1, sizeof(Smart_Item));
   si->obj = evas_object_image_add(sd->evas);
   si->align_x = 0.5;
   si->align_y = 0.0;
   si->size_w = -1.0;
   si->size_h = 0.25;
   evas_object_smart_member_add(si->obj, sd->smart_object);
   sd->items = evas_list_append(sd->items, si);
   return si;
}

static Smart_Item *
_smart_item_edje_next(Smart_Data *sd)
{
   Smart_Item *si;
   
   si = calloc(1, sizeof(Smart_Item));
   si->obj = edje_object_add(sd->evas);
   si->align_x = 0.5;
   si->align_y = 0.0;
   si->size_w = -1.0;
   si->size_h = 0.25;
   si->dim_w = 320;
   si->dim_h = 240;
   evas_object_smart_member_add(si->obj, sd->smart_object);
   sd->items = evas_list_append(sd->items, si);
   return si;
}

static Smart_Item *
_smart_item_video_next(Smart_Data *sd)
{
   Smart_Item *si;
   
   si = calloc(1, sizeof(Smart_Item));
   si->obj = emotion_object_add(sd->evas);
   si->align_x = 0.5;
   si->align_y = 0.0;
   si->size_w = -1.0;
   si->size_h = 0.25;
   si->pos_x = -1;
   si->pos_y = -1;
   si->alpha = 100;
   evas_object_smart_member_add(si->obj, sd->smart_object);
   sd->items = evas_list_append(sd->items, si);
   return si;
}

static void
_smart_reconfigure(Smart_Data *sd)
{
   Evas_Coord x, y, w, h;
   char buf[512];
   int padjust = 0;
   int special_pos = 0;
   int sx, sy;
   
   x = 0;
   y = 0;
   WALK_ITEMS_BEGIN;
   special_pos = 0;
   y += padjust;
   if (si->type == TITLE)
     {
	printf("_smart_reconfigure: si->type == TITLE\n\n");
	snprintf(buf, sizeof(buf), 
		 "font=%s size=%i wrap=word align=center color=#ffffffff "
		 "outer_glow_color=#00000010 glow_color=#00000020 style=glow"
		 ,
		 "Vera-Bold",
		 (int)sd->h / 16);
	evas_object_textblock_clear(si->obj);
//	evas_object_textblock_format_insert(si->obj, buf);
	si->obj = realloc(si->obj, strlen (si->obj) + strlen(buf) + 1);
	strcat (si->obj, buf);
//	evas_object_textblock_text_insert(si->obj, si->text);
	si->obj = realloc(si->obj, strlen (si->obj) + strlen(si->text) + 1);
	strcat (si->obj, si->text);
	evas_object_resize(si->obj, sd->w, 1);
//	evas_object_textblock_format_size_get(si->obj, &w, &h);
//	edje_extern_object_min_size_set(si->obj, w, h);
	w = sd->w;
	padjust = 0;
     }
   else if (si->type == TEXT)
     {
	printf("_smart_reconfigure: si->type == TEXT\n");
	snprintf(buf, sizeof(buf), 
		 "font=%s size=%i wrap=word align=left color=#ffffffff "
		 "outer_glow_color=#00000010 glow_color=#00000020 style=glow"
		 ,
		 "Vera",
		 (int)sd->h / 24);
	printf ("passed snprintf\n");
	evas_object_textblock_clear(si->obj);
	printf ("passed evas_object_textblock_clear\n");
//	evas_object_textblock_format_insert(si->obj, buf);
	si->obj = malloc(strlen(buf) + strlen(si->text) + 1);
	strcpy (si->obj, buf);
	printf ("passed strcpy\n");
	strcat (si->obj, si->text);
	printf ("passed stracat\n");
	printf ("si->obj : %s\n", si->obj);
//	evas_object_textblock_text_insert(si->obj, si->text);
	evas_object_resize(si->obj, sd->w, 1);
	printf ("passed evas_object_resize\n\n");
//	evas_object_textblock_format_size_get(si->obj, &w, &h);
//	edje_extern_object_min_size_set(si->obj, w, h);
	w = sd->w;
	padjust = 0;
     }
   else if (si->type == IMAGE)
     {
	printf("_smart_reconfigure: si->type == IMAGE\n\n");
	int iw, ih;

	evas_object_image_file_set(si->obj, si->text, NULL);
	evas_object_image_size_get(si->obj, &iw, &ih);
	if ((si->size_w < 0) && (si->size_h < 0))
	  {
	     w = iw;
	     h = ih;
	  }
	else if (si->size_h < 0)
	  {
	     w = sd->w * si->size_w;
	     if (iw > 0) h = (w * ih) / iw;
	     else h = 0;
	  }
	else if (si->size_w < 0)
	  {
	     h = sd->h * si->size_h;
	     if (ih > 0) w = (h * iw) / ih;
	     else w = 0;
	  }
	else
	  {
	     w = sd->w * si->size_w;
	     h = sd->h * si->size_h;
	  }
	evas_object_image_fill_set(si->obj, 0, 0, w, h);
	padjust = 0;
     }
   else if (si->type == EDJE)
     {
	printf("_smart_reconfigure: si->type == EDGE\n\n");
	int iw, ih;

	edje_object_file_set(si->obj, si->text, "desktop/background");
	iw = si->dim_w;
	ih = si->dim_h;
	if ((si->size_w < 0) && (si->size_h < 0))
	  {
	     w = iw;
	     h = ih;
	  }
	else if (si->size_h < 0)
	  {
	     w = sd->w * si->size_w;
	     if (iw > 0) h = (w * ih) / iw;
	     else h = 0;
	  }
	else if (si->size_w < 0)
	  {
	     h = sd->h * si->size_h;
	     if (ih > 0) w = (h * iw) / ih;
	     else w = 0;
	  }
	else
	  {
	     w = sd->w * si->size_w;
	     h = sd->h * si->size_h;
	  }
	padjust = 0;
     }
   else if (si->type == ITEM)
     {
	printf("_smart_reconfigure: si->type == ITEM\n\n");
	snprintf(buf, sizeof(buf), 
		 "font=%s size=%i wrap=word align=left color=#ffffffff "
		 "outer_glow_color=#00000010 glow_color=#00000020 style=glow left_tab_stop=20%"
		 ,
		 "Vera",
		 (int)sd->h / 24);
	evas_object_textblock_clear(si->obj);
//	evas_object_textblock_format_insert(si->obj, buf);
//	evas_object_textblock_format_insert(si->obj, "\t");
	si->obj = realloc(si->obj, strlen (si->obj) + strlen(buf) + 2);
	strcat (si->obj, buf);
	strcat (si->obj, "\t");
//	evas_object_textblock_text_insert(si->obj, "* ");
//	evas_object_textblock_text_insert(si->obj, si->text);
	si->obj = realloc(si->obj, strlen (si->obj) + strlen(si->text) + 3);
	strcat (si->obj, "* ");
	strcat (si->obj, si->text);
	evas_object_resize(si->obj, sd->w, 1);
//	evas_object_textblock_format_size_get(si->obj, &w, &h);
//	edje_extern_object_min_size_set(si->obj, w, h);
	w = sd->w;
	padjust = -(sd->h / 40);
     }
   else if (si->type == VIDEO)
     {
	printf("_smart_reconfigure: si->type == VIDEO\n\n");
	int iw, ih;

	emotion_object_file_set(si->obj, si->text);
	emotion_object_play_set(si->obj, 1);
	emotion_object_smooth_scale_set(si->obj, 1);
	emotion_object_size_get(si->obj, &iw, &ih);
	evas_object_color_set(si->obj, 255, 255, 255, (si->alpha * 255) / 100);
	if ((si->size_w < 0) && (si->size_h < 0))
	  {
	     w = iw;
	     h = ih;
	  }
	else if (si->size_h < 0)
	  {
	     w = sd->w * si->size_w;
	     if (iw > 0) h = (w * ih) / iw;
	     else h = 0;
	  }
	else if (si->size_w < 0)
	  {
	     h = sd->h * si->size_h;
	     if (ih > 0) w = (h * iw) / ih;
	     else w = 0;
	  }
	else
	  {
	     w = sd->w * si->size_w;
	     h = sd->h * si->size_h;
	  }
	special_pos = 1;
	sx = (si->pos_x * (sd->w - w)) / 100;
	sy = (si->pos_y * (sd->h - h)) / 100;
	padjust = (-h) - (sd->h / 40);
     }
   if (special_pos)
     {
	si->x = sx;
	si->y = sy;
     }
   else
     {
	si->x = x + ((double)(sd->w - w) * si->align_x); 
	si->y = y;
     }
   printf ("End tests\n");
   si->w = w;
   si->h = h;
   y += h + (sd->h / 40);
   evas_object_move(si->obj, sd->x + si->x, sd->y + si->y);
   evas_object_resize(si->obj, si->w, si->h);

   WALK_ITEMS_END;
   printf ("passed WALK_ITEMS_END\n\n");
}

static void
_smart_add(Evas_Object *obj)
{
   Smart_Data *sd;
   
   sd = calloc(1, sizeof(Smart_Data));
   if (!sd) return;
   sd->x = 0;
   sd->y = 0;
   sd->w = 0;
   sd->h = 0;
   sd->smart_object = obj;
   sd->evas = evas_object_evas_get(obj);
   sd->marker_object = evas_object_rectangle_add(sd->evas);
   evas_object_smart_member_add(sd->marker_object, sd->smart_object);
   evas_object_smart_data_set(obj, sd);
}

static void
_smart_del(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_del(si->obj);
   if (si->text) free(si->text);
   free(si);
   WALK_ITEMS_END;
   evas_object_del(sd->marker_object);
   evas_list_free(sd->items);
   free(sd);
}
   
static void
_smart_layer_set(Evas_Object *obj, int layer)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_layer_set(si->obj, layer);
   WALK_ITEMS_END;
   evas_object_layer_set(sd->marker_object, layer);
}

static void
_smart_raise(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_raise(si->obj);
   WALK_ITEMS_END;
   evas_object_raise(sd->marker_object);
}

static void
_smart_lower(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   evas_object_lower(sd->marker_object);
   WALK_ITEMS_BEGIN;
   evas_object_lower(si->obj);
   WALK_ITEMS_END;
}
                                                             
static void
_smart_stack_above(Evas_Object *obj, Evas_Object *above)
{
   INTERNAL_ENTRY;
   evas_object_stack_above(sd->marker_object, above);
   WALK_ITEMS_BEGIN;
   evas_object_stack_below(si->obj, sd->marker_object);
   WALK_ITEMS_END;
}
   
static void
_smart_stack_below(Evas_Object *obj, Evas_Object *below)
{
   INTERNAL_ENTRY;
   evas_object_stack_below(sd->marker_object, below);
   WALK_ITEMS_BEGIN;
   evas_object_stack_below(si->obj, sd->marker_object);
   WALK_ITEMS_END;
}

static void
_smart_move(Evas_Object *obj, Evas_Coord x, Evas_Coord y)
{
   INTERNAL_ENTRY;
   sd->x = x;
   sd->y = y;
   printf ("_smart_move\n\n");
   _smart_reconfigure(sd);
}

static void
_smart_resize(Evas_Object *obj, Evas_Coord w, Evas_Coord h)
{
   INTERNAL_ENTRY;
   sd->w = w;
   sd->h = h;
   printf ("_smart_resize\n\n");
   _smart_reconfigure(sd);
}

static void
_smart_show(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_show(si->obj);
   WALK_ITEMS_END;
}

static void
_smart_hide(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_hide(si->obj);
   WALK_ITEMS_END;
}

static void
_smart_color_set(Evas_Object *obj, int r, int g, int b, int a)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_color_set(si->obj, r, g, b, a);
   WALK_ITEMS_END;
}

static void
_smart_clip_set(Evas_Object *obj, Evas_Object *clip)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_clip_set(si->obj, clip);
   WALK_ITEMS_END;
}

static void
_smart_clip_unset(Evas_Object *obj)
{
   INTERNAL_ENTRY;
   WALK_ITEMS_BEGIN;
   evas_object_clip_unset(si->obj);
   WALK_ITEMS_END;
}  

/* never need to touch this */

static void
_smart_init(void)
{
   if (_smart) return;
   _smart = evas_smart_new
     (SMART_NAME, _smart_add, _smart_del, _smart_layer_set,
      _smart_raise, _smart_lower, _smart_stack_above,
      _smart_stack_below, _smart_move, _smart_resize,
      _smart_show, _smart_hide, _smart_color_set,
      _smart_clip_set, _smart_clip_unset, NULL);
}