Re: [AD] Re: Alleg-developers digest, Vol 1 #948 - 9 msgs |
[ Thread Index |
Date Index
| More lists.liballeg.org/allegro-developers Archives
]
On Tue, 2005-03-22 at 13:20 +0100, Elias Pschernig wrote:
> Makes sense. Feel free to make the change. Or else, I'd actually like to
> try now to implement the less-crowded layout mentioned above, and also
> add non-unicode languages.. can then easily change the direction
> depending on the already present left_ro_right flag.
Attached is the patch. It already includes the Kannada patch, and also
adds German. And now there's enough room to add all languages we want :)
So who knows "Welcome to Allegro" in Portuguese or Polish or Greek or
whatever else? I also made the texts move 1 pixel up/down, and gave
everything random low-contrast colors, so the missing anti-aliasing
isn't that apparent. Left-to-right texts now scroll right-to-left, and
right-to-left texts left-to-right. And I gave it a proper animation
timer and double buffering.
--
Elias Pschernig
Index: examples/exunicod.c
===================================================================
RCS file: /cvsroot/alleg/allegro/examples/exunicod.c,v
retrieving revision 1.12
diff -r1.12 exunicod.c
21c21
< #define NLANGUAGES 10
---
> #define NLANGUAGES 12
23a24,30
> /* Animation timer. */
> volatile int ticks = 0;
> void ticker(void)
> {
> ticks++;
> }
>
42a50,51
> char message_ka[] = "\x20\x00\xa8\x0C\xbf\x0C\xae\x0C\x97\x0C\xc6\x0C\x20\x00\xb8\x0C\xc1\x0C\xb8\x0C\xcd\x0C\xb5\x0C\xbe\x0C\x97\x0C\xa4\x0C";
>
44c53
<
---
>
46a56,57
> char message_de[] = "\x57\x00\x69\x00\x6c\x00\x6c\x00\x6b\x00\x6f\x00\x6d\x00\x6d\x00\x65\x00\x6e\x00\x20\x00\x62\x00\x65\x00\x69\x00\x20\x00\x00\x00";
>
67a79,80
> char message_ka[] = "\x20\x00\x0C\xa8\x0C\xbf\x0C\xae\x0C\x97\x0C\xc6\x20\x00\x0C\xb8\x0C\xc1\x0C\xb8\x0C\xcd\x0C\xb5\x0C\xbe\x0C\x97\xa4\x0C";
>
71a85,86
> char message_de[] = "\x00\x57\x00\x69\x00\x6c\x00\x6c\x00\x6b\x00\x6f\x00\x6d\x00\x6d\x00\x65\x00\x6e\x00\x20\x00\x62\x00\x65\x00\x69\x00\x20\x00\x00";
>
80c95
< char *data;
---
> char *data, *str;
81a97,99
> int dx, dy;
> int x, y, w, h;
> int c;
85,94c103,115
< struct MESSAGE message[] = { {message_en, FALSE},
< {message_fr, FALSE},
< {message_es, FALSE},
< {message_it, FALSE},
< {message_el, FALSE},
< {message_ru, FALSE},
< {message_he, TRUE},
< {message_ja, TRUE},
< {message_ta, TRUE},
< {message_zh, FALSE} };
---
> struct MESSAGE message[] = { {message_en, NULL, FALSE, -1, 0, 0, 0, 0, 0, 0},
> {message_fr, NULL, FALSE, -2, 0, 0, 0, 0, 0, 0},
> {message_es, NULL, FALSE, -4, 0, 0, 0, 0, 0, 0},
> {message_it, NULL, FALSE, -3, 0, 0, 0, 0, 0, 0},
> {message_el, NULL, FALSE, -2, 0, 0, 0, 0, 0, 0},
> {message_ru, NULL, FALSE, -3, 0, 0, 0, 0, 0, 0},
> {message_he, NULL, TRUE, 2, 0, 0, 0, 0, 0, 0},
> {message_ja, NULL, TRUE, 4, 0, 0, 0, 0, 0, 0},
> {message_ka, NULL, TRUE, 4, 0, 0, 0, 0, 0, 0},
> {message_ta, NULL, TRUE, 5, 0, 0, 0, 0, 0, 0},
> {message_zh, NULL, FALSE, -3, 0, 0, 0, 0, 0, 0},
> {message_de, NULL, FALSE, -2, 0, 0, 0, 0, 0, 0}
> };
96c117,124
< int speed[] = {1, 2, 4, 3, 2, 3, 2, 4, 5, 3};
---
>
> static int overlap(int i, int j, int pad)
> {
> return message[i].x - pad < message[j].x + message[j].w + pad &&
> message[j].x - pad < message[i].x + message[i].w + pad &&
> message[i].y - pad < message[j].y + message[j].h + pad &&
> message[j].y - pad < message[i].y + message[i].h + pad;
> }
103,106c131,136
< BITMAP *mesg_bmp[NLANGUAGES];
< int length[NLANGUAGES], pos[NLANGUAGES];
< int i, nmesgs, height, hpad, delta;
< char *mesg, buf[256], tmp[256], tmp2[256];
---
> BITMAP *buffer;
> int i, j, k, height;
> char buf[256], tmp[256], tmp2[256];
> int counter = 0, drawn = 0;
> int scroll_w, scroll_h;
> int background_color;
114a145
> srand(time(NULL));
140c171,172
< clear_to_color(screen, makecol(255, 255, 255));
---
> /* create a buffer for drawing */
> buffer = create_bitmap(SCREEN_W, SCREEN_H);
144c176,182
< height = text_height(f) + 8;
---
> height = text_height(f);
>
> /* The are for the text messages. If it gets too crowded once we have more
> * languages, this can be increased.
> */
> scroll_w = SCREEN_W * 2;
> scroll_h = SCREEN_H + height;
146,148c184,185
< /* find the number of actually displayed messages */
< nmesgs = MIN(SCREEN_H/height, NLANGUAGES);
< hpad = (SCREEN_H - nmesgs*height)/(nmesgs+1);
---
> /* one of the bright colors in the default palette */
> background_color = 56 + AL_RAND() % 48;
150,151c187,188
< /* prepare the bitmaps */
< for (i=0; i<nmesgs; i++) {
---
> /* prepare the messages */
> for (i = 0; i < NLANGUAGES; i++) {
156c193
< mesg = malloc(ustrsize(message[i].data) + ustrsizez(allegro_str));
---
> message[i].str = malloc(ustrsize(message[i].data) + ustrsizez(allegro_str));
159,160c196,197
< ustrcpy(mesg, allegro_str);
< ustrcat(mesg, message[i].data);
---
> ustrcpy(message[i].str, allegro_str);
> ustrcat(message[i].str, message[i].data);
163,164c200,201
< ustrcpy(mesg, message[i].data);
< ustrcat(mesg, allegro_str);
---
> ustrcpy(message[i].str, message[i].data);
> ustrcat(message[i].str, allegro_str);
167,171c204,210
< length[i] = text_length(f, mesg) + 8;
< pos[i] = ((float)AL_RAND()/RAND_MAX) * SCREEN_W;
< mesg_bmp[i] = create_system_bitmap(length[i], height);
< clear_to_color(mesg_bmp[i], makecol(255, 255, 255));
< textout_ex(mesg_bmp[i], f, mesg, 8, 1, makecol(0, 0, 0), -1);
---
> message[i].w = text_length(f, message[i].str);
> message[i].h = text_height(f);
>
> /* one of the dark colors in the default palette */
> message[i].c = 104 + AL_RAND() % 144;
>
> message[i].dy = AL_RAND() % 3 - 1;
173c212,223
< free(mesg);
---
> /* find not-overlapped position, try 1000 times */
> for (k = 0; k < 1000; k++) {
> message[i].x = AL_RAND() % scroll_w;
> /* make sure the message is not sliced by a screen edge */
> message[i].y = 10 + AL_RAND() % (SCREEN_H - height - 20);
> for (j = 0; j < i; j++) {
> if (overlap(i, j, 10))
> break;
> }
> if (j == i)
> break;
> }
175a226
> install_int_ex(ticker, BPS_TO_TIMER(30));
178,186c229,243
< for (i=0; i<nmesgs; i++) {
< blit(mesg_bmp[i], screen, 0, 0, pos[i], hpad + i*(height+hpad), length[i], height);
< delta = pos[i] + length[i] - SCREEN_W;
< if (delta > 0)
< blit(mesg_bmp[i], screen, length[i] - delta, 0, 0, hpad + i*(height+hpad), delta, height);
<
< pos[i] += speed[i];
< if (pos[i] >= SCREEN_W)
< pos[i] -= SCREEN_W;
---
> /* Animation. */
> while (counter <= ticks) {
> for (i = 0; i < NLANGUAGES; i++) {
> message[i].x += message[i].dx;
> if (message[i].x >= scroll_w)
> message[i].x -= scroll_w;
> if (message[i].x < 0)
> message[i].x += scroll_w;
> message[i].y += message[i].dy;
> if (message[i].y >= scroll_h)
> message[i].y -= scroll_h;
> if (message[i].y < 0)
> message[i].y += scroll_h;
> }
> counter++;
189c246,265
< rest(33);
---
> /* Draw current frame. */
> if (drawn < counter) {
> clear_to_color(buffer, background_color);
> for (i = 0; i < NLANGUAGES; i++) {
> char *str = message[i].str;
> int x = message[i].x;
> int y = message[i].y;
> int c = message[i].c;
> /* draw it 4 times to get the wrap-around effect */
> textout_ex(buffer, f, str, x, y, c, -1);
> textout_ex(buffer, f, str, x - scroll_w, y, c, -1);
> textout_ex(buffer, f, str, x, y - scroll_h, c, -1);
> textout_ex(buffer, f, str, x - scroll_w, y - scroll_h, c, -1);
> }
> blit(buffer, screen, 0, 0, 0, 0, SCREEN_W, SCREEN_H);
> drawn = counter;
> }
> else {
> rest(10); /* We are too fast, give time to the OS. */
> }
192,195d267
< /* free allocated resources */
< for (i=0; i<nmesgs; i++)
< destroy_bitmap(mesg_bmp[i]);
<