Repository navigation
Expand file tree
/
Copy pathlabelclass.c
More file actions
962 lines (878 loc) · 24 KB
/
Copy pathlabelclass.c
File metadata and controls
962 lines (878 loc) · 24 KB
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
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
/*
* @(#) $Header$
*
* BGUI library
* labelclass.c
*
* (C) Copyright 1998 Manuel Lemos.
* (C) Copyright 1996-1997 Ian J. Einman.
* (C) Copyright 1993-1996 Jaba Development.
* (C) Copyright 1993-1996 Jan van den Baard.
* All Rights Reserved.
*
* $Log$
* Revision 42.8 2004/06/16 20:16:48 verhaegs
* Use METHODPROTO, METHOD_END and REGFUNCPROTOn where needed.
*
* Revision 42.7 2003/01/18 19:09:57 chodorowski
* Instead of using the _AROS or __AROS preprocessor symbols, use __AROS__.
*
* Revision 42.6 2000/08/17 15:09:18 chodorowski
* Fixed compiler warnings.
*
* Revision 42.5 2000/07/03 21:21:00 bergers
* Replaced stch_l & stcu_d and had to make a few changes in other places because of that.
*
* Revision 42.4 2000/07/02 06:08:33 bergers
* Compiles library alright (except that I took stch_l & stcu_d out) and seems to create the right type of object. Test1 also compiles alright but crashes somewhere...
*
* Revision 42.3 2000/05/29 15:42:49 stegerg
* fixed some "comparison is always 1 due to limited range of data type"
* errors
*
* Revision 42.2 2000/05/29 00:40:24 bergers
* Update to compile with AROS now. Should also still compile with SASC etc since I only made changes that test the define __AROS__. The compilation is still very noisy but it does the trick for the main directory. Maybe members of the BGUI team should also have a look at the compiler warnings because some could also cause problems on other systems... (Comparison always TRUE due to datatype (or something like that)). And please compile it on an Amiga to see whether it still works... Thanks.
*
* Revision 42.1 2000/05/15 19:27:01 stegerg
* another hundreds of REG() macro replacements in func headers/protos.
*
* Revision 42.0 2000/05/09 22:09:16 mlemos
* Bumped to revision 42.0 before handing BGUI to AROS team
*
* Revision 41.11 2000/05/09 19:54:29 mlemos
* Merged with the branch Manuel_Lemos_fixes.
*
* Revision 41.10.2.7 1999/08/03 05:11:53 mlemos
* Ensured that the creation of the label rotation bitmaps are allocated as
* friends of the rastport's bitmap.
*
* Revision 41.10.2.6 1998/12/07 03:07:01 mlemos
* Replaced OpenFont and CloseFont calls by the respective BGUI debug macros.
*
* Revision 41.10.2.5 1998/10/16 02:58:47 mlemos
* Fixed a bug in the computation of label dimensions that was ignoring that
* labels may have padding space to left or above them.
*
* Revision 41.10.2.4 1998/10/15 04:59:44 mlemos
* Fixed a bug in the computation of label dimensions that was ignoring that
* labels have padding space arround them depending on their positions.
* Fixed a bug that was making label class maximum size to not update
* depending on nominal size.
*
* Revision 41.10.2.3 1998/05/22 03:50:04 mlemos
* Ensured that the extent fields are initialized even when the label text is
* set to NULL.
*
* Revision 41.10.2.2 1998/03/02 23:48:46 mlemos
* Switched vector allocation functions calls to BGUI allocation functions.
*
* Revision 41.10.2.1 1998/02/28 02:24:43 mlemos
* Made Dimensions method return size (0,0) when the label text is set to NULL
*
* Revision 41.10 1998/02/25 21:12:21 mlemos
* Bumping to 41.10
*
* Revision 1.1 1998/02/25 17:08:42 mlemos
* Ian sources
*
*
*/
/// Class definitions.
#include "include/classdefs.h"
/*
* Object instance data.
*/
typedef struct ld_ {
ULONG ld_Flags; /* Flags. */
UBYTE *ld_Text; /* The label itself. */
ULONG ld_TextID; /* Text ID. */
struct IBox ld_Extent; /* Label extent. */
UWORD ld_Width, ld_Height; /* Nominal label size. */
struct TextAttr *ld_TextAttr; /* Font to use. */
struct TextFont *ld_Font; /* The opened font. */
UWORD ld_Style, ld_SelStyle; /* Style in which to render. */
UBYTE ld_Pen, ld_SelPen; /* Pens to render normal/selected. */
UBYTE ld_Place; /* Where to render. */
UBYTE ld_UnderscoreChar; /* Underscore indicator. */
UBYTE ld_ErasePen; /* Pen to erase with. */
} LD;
#define LABF_SELFOPEN (1<<31)
#define LABF_EXT_VALID (1<<30)
#define LABF_DRIPEN (1<<29)
#define LABF_SELDRIPEN (1<<28)
#define LABF_DEFPEN (1<<27)
#define LABF_DEFSELPEN (1<<26)
#define LABF_NOPLACEIN (1<<25)
#define LD_ENTRY(tag, offset, flags) PACK_ENTRY(LAB_TAGSTART, tag, ld_, offset, flags)
#define LD_FLAG(tag, flag) PACK_LONGBIT(LAB_TAGSTART, tag, ld_, ld_Flags, PKCTRL_BIT, flag)
#define LD_PENTRY(tag, offset, flags) PACK_ENTRY(BGUI_PB, tag, ld_, offset, flags)
#define LD_PFLAG(tag, flag) PACK_LONGBIT(BGUI_PB, tag, ld_, ld_Flags, PKCTRL_BIT, flag)
static ULONG LabelPackTable[] =
{
PACK_STARTTABLE(LAB_TAGSTART),
LD_ENTRY(LAB_LabelID, ld_TextID, PKCTRL_ULONG),
LD_ENTRY(LAB_Style, ld_Style, PKCTRL_UWORD),
LD_ENTRY(LAB_SelectedStyle, ld_SelStyle, PKCTRL_UWORD),
LD_ENTRY(LAB_Place, ld_Place, PKCTRL_UBYTE),
LD_ENTRY(LAB_Underscore, ld_UnderscoreChar, PKCTRL_UBYTE),
LD_FLAG(LAB_Highlight, LABF_HIGHLIGHT),
LD_FLAG(LAB_HighUScore, LABF_HIGH_USCORE),
LD_FLAG(LAB_FlipX, LABF_FLIP_X),
LD_FLAG(LAB_FlipY, LABF_FLIP_Y),
LD_FLAG(LAB_FlipXY, LABF_FLIP_XY),
LD_FLAG(LAB_NoPlaceIn, LABF_NOPLACEIN),
PACK_NEWOFFSET(BGUI_PB),
LD_PENTRY(IMAGE_ErasePen, ld_ErasePen, PKCTRL_UBYTE),
PACK_ENDTABLE
};
///
/// OM_NEW
/*
* Create a shiny new object.
*/
METHOD(LabelClassNew, struct opSet *, ops)
{
LD *ld;
IPTR rc;
/*
* First we let the superclass
* create an object.
*/
if ((rc = AsmDoSuperMethodA(cl, obj, (Msg)ops)))
{
/*
* Get to the instance data.
*/
ld = INST_DATA(cl, rc);
/*
* Clear instance data and
* setup the defaults.
*/
ld->ld_Flags = LABF_DEFPEN|LABF_DEFSELPEN;
ld->ld_Style = (UWORD)~0;
ld->ld_SelStyle = (UWORD)~0;
ld->ld_Place = PLACE_IN;
ld->ld_UnderscoreChar = '_';
/*
* Set attributes.
*/
AsmCoerceMethod(cl, (Object *)rc, RM_SETM, ops->ops_AttrList, RAF_INITIAL);
#if 0
if (fail)
{
/*
* Failure!
*/
AsmCoerceMethod(cl, (Object *)rc, OM_DISPOSE);
rc = 0;
}
#endif
// ld->ld_Flags |= LABF_FLIP_XY;
}
return rc;
}
METHOD_END
///
/// RM_GETATTRFLAGS
/*
* Get the flags of an attribute.
*/
METHOD(LabelClassGetAttrFlags, struct rmAttr *, ra)
{
static struct TagItem chart[] =
{
{ LAB_Label, CHART_ATTR(ld_, ld_Text ) | RAF_RESIZE, },
{ LAB_LabelID, CHART_ATTR(ld_, ld_TextID ), },
{ LAB_TextAttr, CHART_ATTR(ld_, ld_TextAttr ) | RAF_CUSTOM | RAF_RESIZE, },
{ LAB_Style, CHART_ATTR(ld_, ld_Style ) | RAF_REDRAW, },
{ LAB_SelectedStyle, CHART_ATTR(ld_, ld_SelStyle ) | RAF_REDRAW, },
{ LAB_Place, CHART_ATTR(ld_, ld_Place ) | RAF_REDRAW, },
{ LAB_Underscore, CHART_ATTR(ld_, ld_UnderscoreChar ) | RAF_CUSTOM, },
{ LAB_Template, CHART_ATTR(ld_, ld_Flags ) | RAF_CUSTOM | RAF_ADDRESS, },
{ IMAGE_ErasePen, CHART_ATTR(ld_, ld_ErasePen ), },
{ IMAGE_TextFont, CHART_ATTR(ld_, ld_Font ) | RAF_CUSTOM | RAF_NOP, },
{ LAB_Pen, CHART_ATTR(ld_, ld_Pen ) | RAF_CUSTOM | RAF_NOP, },
{ LAB_DriPen, CHART_ATTR(ld_, ld_Pen ) | RAF_CUSTOM | RAF_NOP, },
{ LAB_SelectedPen, CHART_ATTR(ld_, ld_SelPen ) | RAF_CUSTOM | RAF_NOP, },
{ LAB_SelectedDriPen, CHART_ATTR(ld_, ld_SelPen ) | RAF_CUSTOM | RAF_NOP, },
{ LAB_Highlight, CHART_FLAG(ld_, ld_Flags, LABF_HIGHLIGHT ) | RAF_REDRAW, },
{ LAB_HighUScore, CHART_FLAG(ld_, ld_Flags, LABF_HIGH_USCORE) | RAF_REDRAW, },
{ LAB_FlipX, CHART_FLAG(ld_, ld_Flags, LABF_FLIP_X ) | RAF_REDRAW, },
{ LAB_FlipY, CHART_FLAG(ld_, ld_Flags, LABF_FLIP_Y ) | RAF_REDRAW, },
{ LAB_FlipXY, CHART_FLAG(ld_, ld_Flags, LABF_FLIP_XY ) | RAF_RESIZE, },
{ LAB_NoPlaceIn, CHART_FLAG(ld_, ld_Flags, LABF_NOPLACEIN ) | RAF_CUSTOM, },
{ TAG_DONE },
};
ULONG rc = GetTagData(ra->ra_Attr->ti_Tag, 0, chart);
return rc;
}
METHOD_END
///
/// RM_SET
/*
* Set standard attributes.
*/
METHOD(LabelClassSet, struct rmAttr *, ra)
{
return BGUI_SetAttrChart(cl, obj, ra);
}
METHOD_END
///
/// RM_SETCUSTOM
/*
* Set custom attributes.
*/
METHOD(LabelClassSetCustom, struct rmAttr *, ra)
{
LD *ld = (LD *)INST_DATA(cl, obj);
struct TextFont *tf;
IPTR attr = ra->ra_Attr->ti_Tag;
IPTR data = ra->ra_Attr->ti_Data;
switch (attr)
{
case LAB_Template:
if (data)
{
attr = 0;
Get_Attr((Object *)data, LAB_Template, &attr);
if (attr)
{
CopyMem((LD *)attr, ld, sizeof(LD));
ld->ld_Flags &= ~LABF_SELFOPEN;
};
};
break;
case IMAGE_TextFont:
if (ld->ld_Font && (ld->ld_Flags & LABF_SELFOPEN))
BGUI_CloseFont(ld->ld_Font);
ld->ld_Font = (struct TextFont *)data;
ld->ld_Flags &= ~LABF_SELFOPEN;
break;
case LAB_Place:
case LAB_NoPlaceIn:
if ((ld->ld_Flags & LABF_NOPLACEIN) && (ld->ld_Place == PLACE_IN))
ld->ld_Place = PLACE_LEFT;
break;
case LAB_Flags:
ld->ld_Flags = (ld->ld_Flags & 0xFFFF0000) | data;
break;
case LAB_TextAttr:
if (data && (tf = BGUI_OpenFont((struct TextAttr *)data)))
{
if (ld->ld_Font && (ld->ld_Flags & LABF_SELFOPEN))
BGUI_CloseFont(ld->ld_Font);
ld->ld_Font = tf;
ld->ld_TextAttr = (struct TextAttr *)data;
ld->ld_Flags |= LABF_SELFOPEN;
};
break;
case LAB_Pen:
case LAB_DriPen:
if ((UWORD)data == (UWORD)~0)
{
ld->ld_Flags |= LABF_DEFPEN;
}
else
{
ld->ld_Flags &= ~LABF_DEFPEN;
ld->ld_Pen = data;
};
if (attr == LAB_Pen) ld->ld_Flags &= ~LABF_DRIPEN;
else ld->ld_Flags |= LABF_DRIPEN;
break;
case LAB_SelectedPen:
case LAB_SelectedDriPen:
if ((UWORD)data == (UWORD)~0)
{
ld->ld_Flags |= LABF_DEFSELPEN;
}
else
{
ld->ld_Flags &= ~LABF_DEFSELPEN;
ld->ld_SelPen = data;
};
if (attr == LAB_SelectedPen) ld->ld_Flags &= ~LABF_SELDRIPEN;
else ld->ld_Flags |= LABF_SELDRIPEN;
break;
};
return 1;
}
METHOD_END
///
/// OM_GET
/*
* Give an attribute.
*/
METHOD(LabelClassGet, struct opGet *, opg)
{
LD *ld = INST_DATA(cl, obj);
ULONG rc = 1;
Tag tag = opg->opg_AttrID;
IPTR *store = opg->opg_Storage;
UBYTE *u;
/*
* First we try if the attribute is known to us. If not we pass
* it on to the superclass.
*/
switch (tag)
{
case LAB_Template:
STORE ld;
break;
case LAB_Label:
STORE ld->ld_Text;
break;
case LAB_TextAttr:
STORE ld->ld_TextAttr;
break;
case LAB_Pen:
STORE (!(ld->ld_Flags & LABF_DEFPEN) && !(ld->ld_Flags & LABF_DRIPEN)) ? ld->ld_Pen : (ULONG)~0;
break;
case LAB_DriPen:
STORE (!(ld->ld_Flags & LABF_DEFPEN) && (ld->ld_Flags & LABF_DRIPEN)) ? ld->ld_Pen : (ULONG)~0;
break;
case LAB_SelectedPen:
STORE (!(ld->ld_Flags & LABF_DEFSELPEN) && !(ld->ld_Flags & LABF_SELDRIPEN)) ? ld->ld_SelPen : (ULONG)~0;
break;
case LAB_SelectedDriPen:
STORE (!(ld->ld_Flags & LABF_DEFSELPEN) && (ld->ld_Flags & LABF_SELDRIPEN)) ? ld->ld_SelPen : (ULONG)~0;
break;
case LAB_KeyChar:
if (ld->ld_Text && ld->ld_UnderscoreChar)
{
if ((u = strchr(ld->ld_Text, ld->ld_UnderscoreChar)))
STORE (u + 1);
};
break;
case LAB_Flags:
STORE ld->ld_Flags;
break;
default:
rc = BGUI_UnpackStructureTag((UBYTE *)ld, LabelPackTable, tag, store);
if (!rc) rc = AsmDoSuperMethodA(cl, obj, (Msg)opg);
break;
};
return rc;
}
METHOD_END
///
/// OM_DISPOSE
/*
* Dispose of the object.
*/
METHOD(LabelClassDispose, Msg, msg)
{
LD *ld = INST_DATA(cl, obj);
/*
* Close the font.
*/
if (ld->ld_Font && (ld->ld_Flags & LABF_SELFOPEN))
BGUI_CloseFont(ld->ld_Font);
/*
* The rest goes to the superclass.
*/
return AsmDoSuperMethodA(cl, obj, msg);
}
METHOD_END
///
/// IM_DRAW, IM_ERASE, IM_EXTENT
/*
* Render, erase or find out it's extensions.
*/
METHOD(LabelClassDrawErase, struct impDraw *, dr)
{
LD *ld = INST_DATA(cl, obj);
struct RastPort rrp = *(dr->imp_RPort), trp;
struct impExtent *ie = (struct impExtent *)dr;
struct IBox *bounds, box;
UBYTE *chunky1, *chunky2;
UBYTE *text = NULL, *s, *d, c;
UWORD *pens = NULL, pen, style;
WORD xpos, ypos, tw, th;
ULONG rc = 0;
int i1, j1, j2, rw, rh;
BOOL sel = (dr->imp_State == IDS_SELECTED) || (dr->imp_State == IDS_INACTIVESELECTED);
/*
* Obtain image box bounds.
*/
WORD l = IMAGE(obj)->LeftEdge;
WORD t = IMAGE(obj)->TopEdge;
WORD w = IMAGE(obj)->Width;
WORD h = IMAGE(obj)->Height;
/*
* Get pens.
*/
if (dr->MethodID == IM_DRAW) pens = PENS(dr->imp_DrInfo);
/*
* Add offsets when necessary.
*/
if (dr->MethodID != IM_EXTENT)
{
l += dr->imp_Offset.X;
t += dr->imp_Offset.Y;
}
else
{
bounds = ie->impe_Extent;
bounds->Left = bounds->Top = bounds->Width = bounds->Height = 0;
}
/*
* Only do the label when it actually exists.
*/
if ((s = ld->ld_Text))
{
text = BGUI_AllocPoolMem(strlen(s) + 30);
};
if ((d = text))
{
rc = 1;
*d++ = '\33'; /* 2 */
switch (ld->ld_Place)
{
case PLACE_LEFT:
*d++ = 'r';
break;
case PLACE_RIGHT:
*d++ = 'l';
break;
default:
*d++ = 'c';
break;
};
/*
* Set font style.
*/
style = sel ? ld->ld_SelStyle : ld->ld_Style;
if (sel && (style == (UWORD)~0)) style = ld->ld_Style;
if (style != (UWORD)~0)
{
if (style & FSF_ITALIC) /* 2 */
{
*d++ = '\33';
*d++ = 'i';
};
if (style & FSF_BOLD) /* 2 */
{
*d++ = '\33';
*d++ = 'b';
};
if (style & FSF_UNDERLINED) /* 2 */
{
*d++ = '\33';
*d++ = 'u';
};
};
c = 0;
if (dr->MethodID == IM_DRAW) /* 5 */
{
if (ld->ld_Flags & LABF_HIGHLIGHT)
{
c = 'd';
pen = HIGHLIGHTTEXTPEN;
}
else
{
/*
* What state are we in?
*/
if (sel)
{
/*
* First see if a selected (dri)pen is
* given. If not use the default colors.
*/
if (ld->ld_Flags & LABF_DEFSELPEN)
{
c = 'd';
pen = (dr->imp_State == IDS_SELECTED) ? FILLTEXTPEN : TEXTPEN;
}
else
{
c = (ld->ld_Flags & LABF_SELDRIPEN) ? 'd' : 'p';
pen = ld->ld_SelPen;
};
}
else
{
/*
* First see if a normal (dri)pen is
* given. If not use the default colors.
*/
if (ld->ld_Flags & LABF_DEFPEN)
{
c = 'd';
pen = TEXTPEN;
}
else
{
c = (ld->ld_Flags & LABF_DRIPEN) ? 'd' : 'p';
pen = ld->ld_Pen;
};
};
};
}
else if (dr->MethodID == IM_ERASE)
{
c = 'p';
pen = ld->ld_ErasePen;
};
if (c) /* 6 */
{
*d++ = '\33';
*d++ = c;
#ifdef __AROS__
d += sprintf(d, "%u", pen);
#else
d += stcu_d(d, pen);
#endif
};
*d++ = '\33'; /* 2 */
*d++ = '\33';
while ((c = *s++))
{
if (c == ld->ld_UnderscoreChar) /* 5 */
{
if (*s)
{
if ((*s < 32) || (*s == 127))
{
s++;
}
else
{
c = (ld->ld_Flags & LABF_HIGH_USCORE) ? 'Z' : 'z';
*d++ = '\33';
*d++ = c;
*d++ = *s++;
if (*s)
{
*d++ = '\33';
*d++ = '-';
*d++ = c;
};
};
strcpy(d, s);
};
break;
};
*d++ = c;
};
/*
* If a font is available, set it in the rastport.
*/
if (ld->ld_Font) FSetFont(&rrp, ld->ld_Font);
/*
* Setup drawmode.
*/
FSetDrMd(&rrp, JAM1);
/*
* Get label pixel size.
*/
th = TotalHeight(&rrp, text);
tw = TotalWidth (&rrp, text);
if (ld->ld_Flags & LABF_FLIP_XY)
{
i1 = th; th = tw; tw = i1;
};
ld->ld_Width = tw;
ld->ld_Height = th;
/*
* Preset x & y position.
*/
xpos = l;
ypos = t;
/*
* No need to place the text when we
* want the maximum extentiions.
*/
if (dr->MethodID == IM_EXTENT && (ie->impe_Flags & EXTF_MAXIMUM))
goto maximumExtent;
reCalculate:
/*
* Determine Y position.
*/
switch (ld->ld_Place)
{
case PLACE_LEFT:
case PLACE_IN:
case PLACE_RIGHT:
ypos += (h - th) >> 1;
break;
case PLACE_ABOVE:
ypos -= (th + 4);
break;
case PLACE_BELOW:
ypos += (h + 3);
break;
}
/*
* Determine X position.
*/
switch (ld->ld_Place)
{
case PLACE_ABOVE:
case PLACE_IN:
case PLACE_BELOW:
xpos += (w - tw) >> 1;
break;
case PLACE_LEFT:
xpos -= (tw + 8);
break;
case PLACE_RIGHT:
xpos += (w + 7);
break;
}
/*
* IM_EXTENT method?
*/
if (dr->MethodID == IM_EXTENT)
{
maximumExtent:
/*
* Pick up extent storage, preset to 0.
*/
bounds = ie->impe_Extent;
bounds->Left = bounds->Top = bounds->Width = bounds->Height = 0;
/*
* No negative offsets.
*/
if ((l <= 0) || (t <= 0))
{
if (l <= 0) l = tw + 8;
if (t <= 0) t = th + 4;
goto reCalculate;
}
/*
* Maximum?
*/
if (ie->impe_Flags & EXTF_MAXIMUM)
{
switch (ld->ld_Place)
{
case PLACE_LEFT:
bounds->Left = -(tw + 8);
break;
case PLACE_RIGHT:
bounds->Width = (tw + 7);
break;
case PLACE_ABOVE:
bounds->Top = -(th + 4);
break;
case PLACE_BELOW:
bounds->Height = (th + 3);
break;
}
}
else
{
if (xpos < l) bounds->Left = -(l - xpos);
if ((xpos + tw) > (l + w - 1)) bounds->Width = (xpos + tw) - (l + w - 1);
if (ypos < t) bounds->Top = -(t - ypos);
if ((ypos + th) > (t + h - 1)) bounds->Height = (ypos + th) - (t + h - 1);
}
/*
* Store label width and height.
*/
if (ie->impe_LabelSize.Width) *(ie->impe_LabelSize.Width) = tw;
if (ie->impe_LabelSize.Height) *(ie->impe_LabelSize.Height) = th;
}
else
{
if (ld->ld_Flags & (LABF_FLIP_XY|LABF_FLIP_X|LABF_FLIP_Y))
{
rrp.BitMap = BGUI_AllocBitMap(tw, th, FGetDepth(&rrp), BMF_STANDARD, dr->imp_RPort->BitMap);
if (rrp.BitMap)
{
rrp.Layer = NULL;
ClipBlit(dr->imp_RPort, xpos, ypos, &rrp, 0, 0, tw, th, 0xC0);
};
box.Left = box.Top = 0;
}
else
{
box.Left = xpos;
box.Top = ypos;
};
/*
* Move to the correct location.
*/
box.Width = tw;
box.Height = th;
if (rrp.BitMap) RenderInfoText(&rrp, text, pens, &box, (UWORD)~0);
if (ld->ld_Flags & (LABF_FLIP_XY|LABF_FLIP_X|LABF_FLIP_Y))
{
if (rrp.BitMap)
{
rw = ((tw + 15) >> 4) << 4;
if ((chunky1 = BGUI_AllocPoolMem(rw * th)))
{
trp = rrp;
if ((trp.BitMap = BGUI_AllocBitMap(rw, 1, FGetDepth(&rrp), BMF_STANDARD, dr->imp_RPort->BitMap)))
{
ReadPixelArray8(&rrp, 0, 0, tw - 1, th - 1, chunky1, &trp);
BGUI_FreeBitMap(rrp.BitMap);
rrp.BitMap = NULL;
if (ld->ld_Flags & LABF_FLIP_X)
{
s = chunky1;
for (i1 = th; i1; i1--)
{
for (j1 = 0, j2 = tw - 1; j1 < j2; j1++, j2--)
{
c = s[j1];
s[j1] = s[j2];
s[j2] = c;
};
s += rw;
};
};
if (ld->ld_Flags & LABF_FLIP_Y)
{
s = chunky1;
d = chunky1 + rw * (th - 1);
while (s < d)
{
for (j1 = tw - 1; j1; j1--)
{
c = s[j1];
s[j1] = d[j1];
d[j1] = c;
};
s += rw;
d -= rw;
};
};
if (ld->ld_Flags & LABF_FLIP_XY)
{
chunky2 = chunky1;
rh = ((th + 15) >> 4) << 4;
if ((chunky1 = BGUI_AllocPoolMem(tw * rh)))
{
for (i1 = 0; i1 < th; i1++)
{
for (j1 = 0; j1 < tw; j1++)
{
chunky1[(j1 * rh) + i1] = chunky2[(i1 * rw) + j1];
};
};
BGUI_FreePoolMem(chunky2);
}
else chunky1 = chunky2;
i1 = tw; tw = th; th = i1;
BGUI_FreeBitMap(trp.BitMap);
trp.BitMap = BGUI_AllocBitMap(rw, 1, FGetDepth(&rrp), BMF_STANDARD, dr->imp_RPort->BitMap);
};
if (trp.BitMap)
{
WritePixelArray8(dr->imp_RPort, xpos, ypos,
xpos + tw - 1, ypos + th - 1, chunky1, &trp);
BGUI_FreeBitMap(trp.BitMap);
};
};
BGUI_FreePoolMem(chunky1);
};
BGUI_FreeBitMap(rrp.BitMap);
};
};
};
BGUI_FreePoolMem(text);
}
return rc;
}
METHOD_END
///
/// BASE_LOCALIZE
METHOD(LabelClassLocalize, struct bmLocalize *, bml)
{
LD *ld = INST_DATA(cl, obj);
ULONG rc = 0;
if (ld->ld_TextID)
{
ld->ld_Text = BGUI_GetCatalogStr(bml->bml_Locale, ld->ld_TextID, ld->ld_Text);
rc = 1;
}
return rc;
}
METHOD_END
///
/// BASE_DIMENSIONS
METHOD(LabelClassDimensions, struct bmDimensions *, bmd)
{
LD *ld = INST_DATA(cl, obj);
struct BaseInfo *bi = bmd->bmd_BInfo;
struct bguiExtent *be = bmd->bmd_Extent;
UWORD lh;
UWORD lw;
{
struct IBox extentions;
if(DoExtentMethod(obj, bi->bi_RPort, &extentions, &lw, &lh, EXTF_MAXIMUM))
{
lw=max(lw,max(-extentions.Left,extentions.Width));
lh=max(lh,max(-extentions.Top,extentions.Height));
}
else
lw=lh=0;
}
switch (ld->ld_Place)
{
case PLACE_ABOVE:
case PLACE_BELOW:
if (be->be_Min.Width < lw) be->be_Min.Width = lw;
if (be->be_Nom.Width < lw) be->be_Nom.Width = lw;
break;
case PLACE_IN:
lw += 4;
default:
be->be_Min.Width += lw;
be->be_Nom.Width += lw;
break;
};
switch (ld->ld_Place)
{
case PLACE_LEFT:
case PLACE_RIGHT:
if (be->be_Min.Height < lh) be->be_Min.Height = lh;
if (be->be_Nom.Height < lh) be->be_Nom.Height = lh;
break;
case PLACE_IN:
lh += 2;
default:
be->be_Min.Height += lh;
be->be_Nom.Height += lh;
break;
};
be->be_Max.Width=max(be->be_Max.Width,be->be_Nom.Width);
be->be_Max.Height=max(be->be_Max.Height,be->be_Nom.Height);
return 1;
}
METHOD_END
///
/// Class initialization.
/*
* Class function table.
*/
STATIC DPFUNC ClassFunc[] = {
{ RM_SET, LabelClassSet, },
{ RM_SETCUSTOM, LabelClassSetCustom, },
{ RM_GETATTRFLAGS, LabelClassGetAttrFlags, },
{ IM_DRAW, LabelClassDrawErase, },
{ OM_GET, LabelClassGet, },
{ OM_NEW, LabelClassNew, },
{ OM_DISPOSE, LabelClassDispose, },
{ IM_EXTENT, LabelClassDrawErase, },
{ IM_ERASE, LabelClassDrawErase, },
{ BASE_LOCALIZE, LabelClassLocalize, },
{ BASE_DIMENSIONS, LabelClassDimensions, },
{ DF_END },
};
/*
* Simple class initialization.
*/
makeproto Class *InitLabelClass(void)
{
return BGUI_MakeClass(CLASS_SuperClassBGUI, BGUI_IMAGE_OBJECT,
CLASS_ObjectSize, sizeof(LD),
CLASS_DFTable, ClassFunc,
TAG_DONE);
}
///