w.i.p - correctly remap ColorModel_TrueColor images.
[AROS.git] / workbench / demos / test_text.c
blobf513ee61c38a09a133afd5731db16dc3bc0bd424
1 /*
2 Copyright © 1998, The AROS Development Team. All rights reserved.
3 $Id$
5 Desc: Demo showing x11gfx.hidd
6 Lang: English.
7 */
9 #include <stdio.h>
10 #include <string.h>
11 #include <exec/types.h>
12 #include <graphics/rastport.h>
13 #include <graphics/gfxmacros.h>
14 #include <intuition/intuition.h>
15 #include <proto/dos.h>
16 #include <proto/exec.h>
17 #include <proto/graphics.h>
18 #include <proto/intuition.h>
20 #define SDEBUG 1
21 #define DEBUG 1
23 #include <aros/debug.h>
25 #define WIN_WIDTH 400
26 #define WIN_HEIGHT 300
28 struct IntuitionBase *IntuitionBase;
29 struct GfxBase *GfxBase;
30 struct Library *LayersBase;
31 struct DosLibrary *DOSBase;
33 struct Window *openwindow(STRPTR title, LONG x, LONG y, LONG w, LONG h);
35 void test_text(struct Window *w);
37 int handleevents(struct Window *win);
39 enum { EV_KEY_PRESSED, EV_QUIT };
41 int main(int argc, char **argv)
43 /* Intialize debugging */
44 SDInit();
46 if ((IntuitionBase = (struct IntuitionBase *) OpenLibrary("intuition.library", 0)))
48 if ((GfxBase = (struct GfxBase *)OpenLibrary("graphics.library", 0)))
50 if ((DOSBase = (struct DosLibrary *) OpenLibrary("dos.library",0)))
52 struct Window *w1;
55 w1 = openwindow("Text speed test. Press key to show JAM1"
56 ,0, 0
57 , WIN_WIDTH, WIN_HEIGHT
60 if (w1)
62 struct TextAttr ta = { "topaz.font", 8, 0, 0 };
63 struct TextFont *tf;
65 /* Get the default font */
68 tf = OpenFont(&ta);
70 SetFont(w1->RPort, tf);
72 if (handleevents(w1) == EV_QUIT)
73 goto quit;
75 SetDrMd(w1->RPort, JAM1);
76 test_text(w1);
78 SetWindowTitles(w1, "Press any key to test JAM2", NULL);
81 if (handleevents(w1) == EV_QUIT)
82 goto quit;
84 SetDrMd(w1->RPort, JAM2);
85 SetAPen(w1->RPort, DETAILPEN);
86 SetBPen(w1->RPort, BLOCKPEN);
87 test_text(w1);
89 SetWindowTitles(w1, "Press a key to quit", NULL);
91 handleevents(w1);
94 quit:
96 CloseWindow(w1);
98 CloseLibrary((struct Library *)DOSBase);
100 CloseLibrary((struct Library *)GfxBase);
102 CloseLibrary((struct Library *) IntuitionBase);
104 return 0;
105 } /* main */
107 #define TEST_TEXT "Blah"
109 void test_text(struct Window *w)
111 int len, pixlen, pixleft, iw;
112 int x, y, bottom;
113 struct TextFont *tf;
115 tf = w->RPort->Font;
117 bottom = WIN_HEIGHT - w->BorderBottom - 1 - (tf->tf_YSize - tf->tf_Baseline);
118 printf("bottom: %d\n", bottom);
119 y = w->BorderTop + tf->tf_Baseline;
121 iw = w->Width - w->BorderLeft - w->BorderRight;
123 len = sizeof (TEST_TEXT) - 1;
125 pixlen = TextLength(w->RPort, TEST_TEXT, len);
127 for (; y < bottom; y += tf->tf_YSize)
129 pixleft = iw;
130 x = w->BorderLeft;
133 pixleft -= pixlen;
134 Move(w->RPort, x, y);
135 Text(w->RPort, TEST_TEXT, len);
136 x += pixlen;
138 while (pixleft > pixlen);
140 return;
144 struct Window *openwindow(STRPTR title, LONG x, LONG y, LONG w, LONG h)
147 struct Window *window;
149 window = OpenWindowTags(NULL,
150 WA_IDCMP, IDCMP_RAWKEY,
151 WA_Left, x,
152 WA_Top, y,
153 WA_Width, w,
154 WA_Height, h,
155 WA_Activate, TRUE,
156 WA_DepthGadget, TRUE,
157 WA_CloseGadget, TRUE,
158 WA_Title, (IPTR)title,
159 TAG_END
163 return window;
166 int handleevents(struct Window *win)
168 struct IntuiMessage *imsg;
169 struct MsgPort *port = win->UserPort;
170 BOOL done = FALSE;
171 int event = 0;
173 EnterFunc(bug("HandleEvents(win=%p)\n", win));
175 while (!done)
177 if ((imsg = (struct IntuiMessage *)GetMsg(port)) != NULL)
180 switch (imsg->Class)
184 case IDCMP_REFRESHWINDOW:
185 BeginRefresh(win);
186 EndRefresh(win, TRUE);
187 break;
189 case IDCMP_CLOSEWINDOW:
190 done = TRUE;
191 event = EV_QUIT;
192 break;
194 case IDCMP_RAWKEY:
195 if (imsg->Code & 0x80)
197 done = TRUE;
198 event = EV_KEY_PRESSED;
200 break;
204 } /* switch (imsg->Class) */
205 ReplyMsg((struct Message *)imsg);
208 } /* if ((imsg = GetMsg(port)) != NULL) */
209 else
211 Wait(1L << port->mp_SigBit);
213 } /* while (!terminated) */
215 ReturnInt("HandleEvents", int, event);
216 } /* HandleEvents() */