Annotation of hatari/src/statusbar.c, revision 1.1.1.6

1.1       root        1: /*
                      2:   Hatari - statusbar.c
                      3: 
                      4:   This file is distributed under the GNU Public License, version 2 or at
                      5:   your option any later version. Read the file gpl.txt for details.
                      6: 
                      7:   Code to draw statusbar area, floppy leds etc.
1.1.1.3   root        8: 
1.1       root        9:   Use like this:
                     10:   - Before screen surface is (re-)created Statusbar_SetHeight()
                     11:     has to be called with the new screen height. Add the returned
                     12:     value to screen height (zero means no statusbar).  After this,
                     13:     Statusbar_GetHeight() can be used to retrieve the statusbar size
                     14:   - After screen surface is (re-)created, call Statusbar_Init()
                     15:     to re-initialize / re-draw the statusbar
                     16:   - Call Statusbar_SetFloppyLed() to set floppy drive led ON/OFF,
                     17:     or call Statusbar_EnableHDLed() to enabled HD led for a while
                     18:   - Whenever screen is redrawn, call Statusbar_Update() to draw the
                     19:     updated information to the statusbar (outside of screen locking)
                     20:   - If screen redraws may be partial, Statusbar_OverlayRestore()
                     21:     needs to be called before locking the screen for drawing and
                     22:     Statusbar_OverlayBackup() needs to be called after screen unlocking,
                     23:     but before calling Statusbar_Update().  These are needed for
                     24:     hiding the overlay drive led when drive leds are turned OFF.
                     25:   - If other information shown by Statusbar (TOS version etc) changes,
                     26:     call Statusbar_UpdateInfo()
                     27: 
                     28:   TODO:
                     29:   - re-calculate colors on each update to make sure they're
                     30:     correct in Falcon & TT 8-bit palette modes?
                     31:   - call Statusbar_AddMessage() from log.c?
                     32: */
1.1.1.3   root       33: const char Statusbar_fileid[] = "Hatari statusbar.c : " __DATE__ " " __TIME__;
1.1       root       34: 
                     35: #include <assert.h>
                     36: #include "main.h"
                     37: #include "configuration.h"
                     38: #include "screenSnapShot.h"
                     39: #include "sdlgui.h"
                     40: #include "statusbar.h"
                     41: #include "tos.h"
1.1.1.5   root       42: #include "screen.h"
1.1       root       43: #include "video.h"
                     44: #include "wavFormat.h"
                     45: #include "ymFormat.h"
1.1.1.4   root       46: #include "avi_record.h"
1.1       root       47: 
                     48: #define DEBUG 0
                     49: #if DEBUG
                     50: #define DEBUGPRINT(x) printf x
                     51: #else
                     52: #define DEBUGPRINT(x)
                     53: #endif
                     54: 
                     55: #define MAX_DRIVE_LEDS (DRIVE_LED_HD + 1)
                     56: 
                     57: /* whether drive leds should be ON and their previous shown state */
                     58: static struct {
                     59:        bool state;
                     60:        bool oldstate;
                     61:        Uint32 expire;  /* when to disable led, valid only if >0 && state=TRUE */
                     62:        int offset;     /* led x-pos on screen */
                     63: } Led[MAX_DRIVE_LEDS];
                     64: 
                     65: /* drive leds size & y-pos */
                     66: static SDL_Rect LedRect;
                     67: 
                     68: /* overlay led size & pos */
                     69: static SDL_Rect OverlayLedRect;
                     70: 
                     71: /* screen contents left under overlay led */
                     72: static SDL_Surface *OverlayUnderside;
                     73: 
                     74: static enum {
                     75:        OVERLAY_NONE,
                     76:        OVERLAY_DRAWN,
                     77:        OVERLAY_RESTORED
                     78: } bOverlayState;
                     79: 
                     80: static SDL_Rect RecLedRect;
                     81: static bool bOldRecording;
                     82: 
                     83: /* led colors */
                     84: static Uint32 LedColorOn, LedColorOff, RecColorOn, RecColorOff;
                     85: static Uint32 GrayBg, LedColorBg;
                     86: 
                     87: 
1.1.1.4   root       88: #define MAX_MESSAGE_LEN 33
1.1       root       89: typedef struct msg_item {
                     90:        struct msg_item *next;
                     91:        char msg[MAX_MESSAGE_LEN+1];
                     92:        Uint32 timeout; /* msecs, zero=no timeout */
                     93:        Uint32 expire;  /* when to expire message */
                     94:        bool shown;
                     95: } msg_item_t;
                     96: 
                     97: static msg_item_t DefaultMessage;
                     98: static msg_item_t *MessageList = &DefaultMessage;
                     99: static SDL_Rect MessageRect;
                    100: 
1.1.1.4   root      101: /* rect for both frame skip value and fast forward indicator */
1.1       root      102: static SDL_Rect FrameSkipsRect;
                    103: static int nOldFrameSkips;
1.1.1.4   root      104: static int bOldFastForward;
1.1       root      105: 
                    106: 
                    107: /* screen height above statusbar and height of statusbar below screen */
                    108: static int ScreenHeight;
                    109: static int StatusbarHeight;
                    110: 
                    111: 
                    112: /*-----------------------------------------------------------------------*/
                    113: /**
1.1.1.4   root      114:  * Return statusbar height for given width and height
1.1       root      115:  */
1.1.1.4   root      116: int Statusbar_GetHeightForSize(int width, int height)
1.1       root      117: {
                    118:        if (ConfigureParams.Screen.bShowStatusbar) {
                    119:                /* Should check the same thing as SDLGui_SetScreen()
                    120:                 * does to decide the font size.
                    121:                 */
1.1.1.3   root      122:                if (width >= 640 && height >= (400-24)) {
1.1.1.4   root      123:                        return 24;
1.1       root      124:                } else {
1.1.1.4   root      125:                        return 12;
1.1       root      126:                }
                    127:        }
1.1.1.4   root      128:        return 0;
                    129: }
                    130: 
                    131: /*-----------------------------------------------------------------------*/
                    132: /**
                    133:  * Set screen height used for statusbar height calculation.
                    134:  *
                    135:  * Return height of statusbar that should be added to the screen
                    136:  * height when screen is (re-)created, or zero if statusbar will
                    137:  * not be shown
                    138:  */
                    139: int Statusbar_SetHeight(int width, int height)
                    140: {
                    141:        ScreenHeight = height;
                    142:        StatusbarHeight = Statusbar_GetHeightForSize(width, height);
1.1.1.6 ! root      143:        DEBUGPRINT(("Statusbar_SetHeight(%d, %d) -> %d\n", width, height, StatusbarHeight));
1.1       root      144:        return StatusbarHeight;
                    145: }
                    146: 
                    147: /*-----------------------------------------------------------------------*/
                    148: /**
                    149:  * Return height of statusbar set with Statusbar_SetHeight()
                    150:  */
                    151: int Statusbar_GetHeight(void)
                    152: {
                    153:        return StatusbarHeight;
                    154: }
                    155: 
                    156: 
                    157: /*-----------------------------------------------------------------------*/
                    158: /**
                    159:  * Enable HD drive led, it will be automatically disabled after a while.
                    160:  */
                    161: void Statusbar_EnableHDLed(void)
                    162: {
                    163:        /* leds are shown for 1/2 sec after enabling */
                    164:        Led[DRIVE_LED_HD].expire = SDL_GetTicks() + 1000/2;
1.1.1.3   root      165:        Led[DRIVE_LED_HD].state = true;
1.1       root      166: }
                    167: 
                    168: /*-----------------------------------------------------------------------*/
                    169: /**
                    170:  * Set given floppy drive led state, anything enabling led with this
                    171:  * needs also to take care of disabling it.
                    172:  */
                    173: void Statusbar_SetFloppyLed(drive_index_t drive, bool state)
                    174: {
                    175:        assert(drive == DRIVE_LED_A || drive == DRIVE_LED_B);
                    176:        Led[drive].state = state;
                    177: }
                    178: 
                    179: 
                    180: /*-----------------------------------------------------------------------*/
                    181: /**
                    182:  * Set overlay led size/pos on given screen to internal Rect
                    183:  * and free previous resources.
                    184:  */
                    185: static void Statusbar_OverlayInit(const SDL_Surface *surf)
                    186: {
                    187:        int h;
                    188:        /* led size/pos needs to be re-calculated in case screen changed */
                    189:        h = surf->h / 50;
                    190:        OverlayLedRect.w = 2*h;
                    191:        OverlayLedRect.h = h;
                    192:        OverlayLedRect.x = surf->w - 5*h/2;
                    193:        OverlayLedRect.y = h/2;
                    194:        /* free previous restore surface if it's incompatible */
                    195:        if (OverlayUnderside &&
                    196:            OverlayUnderside->w == OverlayLedRect.w &&
                    197:            OverlayUnderside->h == OverlayLedRect.h &&
                    198:            OverlayUnderside->format->BitsPerPixel == surf->format->BitsPerPixel) {
                    199:                SDL_FreeSurface(OverlayUnderside);
                    200:                OverlayUnderside = NULL;
                    201:        }
                    202:        bOverlayState = OVERLAY_NONE;
                    203: }
                    204: 
                    205: /*-----------------------------------------------------------------------*/
                    206: /**
                    207:  * (re-)initialize statusbar internal variables for given screen surface
                    208:  * (sizes&colors may need to be re-calculated for the new SDL surface)
                    209:  * and draw the statusbar background.
                    210:  */
                    211: void Statusbar_Init(SDL_Surface *surf)
                    212: {
                    213:        msg_item_t *item;
                    214:        SDL_Rect ledbox, sbarbox;
                    215:        int i, fontw, fonth, offset;
                    216:        const char *text[MAX_DRIVE_LEDS] = { "A:", "B:", "HD:" };
                    217: 
1.1.1.6 ! root      218:        DEBUGPRINT(("Statusbar_Init()\n"));
1.1       root      219:        assert(surf);
                    220: 
                    221:        /* dark green and light green for leds themselves */
                    222:        LedColorOff = SDL_MapRGB(surf->format, 0x00, 0x40, 0x00);
                    223:        LedColorOn  = SDL_MapRGB(surf->format, 0x00, 0xe0, 0x00);
                    224:        LedColorBg  = SDL_MapRGB(surf->format, 0x00, 0x00, 0x00);
                    225:        RecColorOff = SDL_MapRGB(surf->format, 0x40, 0x00, 0x00);
                    226:        RecColorOn  = SDL_MapRGB(surf->format, 0xe0, 0x00, 0x00);
                    227:        GrayBg      = SDL_MapRGB(surf->format, 0xc0, 0xc0, 0xc0);
                    228: 
                    229:        /* disable leds */
                    230:        for (i = 0; i < MAX_DRIVE_LEDS; i++) {
1.1.1.3   root      231:                Led[i].state = Led[i].oldstate = false;
1.1       root      232:                Led[i].expire = 0;
                    233:        }
                    234:        Statusbar_OverlayInit(surf);
                    235:        
                    236:        /* disable statusbar if it doesn't fit to video mode */
                    237:        if (surf->h < ScreenHeight + StatusbarHeight) {
                    238:                StatusbarHeight = 0;
                    239:        }
                    240:        if (!StatusbarHeight) {
1.1.1.6 ! root      241:                DEBUGPRINT(("Doesn't fit <- Statusbar_Init()\n"));
1.1       root      242:                return;
                    243:        }
                    244: 
                    245:        /* prepare fonts */
                    246:        SDLGui_Init();
                    247:        SDLGui_SetScreen(surf);
                    248:        SDLGui_GetFontSize(&fontw, &fonth);
                    249: 
                    250:        /* video mode didn't match, need to recalculate sizes */
                    251:        if (surf->h > ScreenHeight + StatusbarHeight) {
                    252:                StatusbarHeight = fonth + 2;
                    253:                /* actually statusbar vertical offset */
                    254:                ScreenHeight = surf->h - StatusbarHeight;
                    255:        } else {
                    256:                assert(fonth+2 < StatusbarHeight);
                    257:        }
                    258: 
                    259:        /* draw statusbar background gray so that text shows */
                    260:        sbarbox.x = 0;
                    261:        sbarbox.y = surf->h - StatusbarHeight;
                    262:        sbarbox.w = surf->w;
                    263:        sbarbox.h = StatusbarHeight;
                    264:        SDL_FillRect(surf, &sbarbox, GrayBg);
                    265: 
                    266:        /* led size */
1.1.1.4   root      267:        LedRect.w = fonth/2;
1.1       root      268:        LedRect.h = fonth - 4;
                    269:        LedRect.y = ScreenHeight + StatusbarHeight/2 - LedRect.h/2;
1.1.1.4   root      270: 
1.1       root      271:        /* black box for the leds */
                    272:        ledbox = LedRect;
                    273:        ledbox.y -= 1;
                    274:        ledbox.w += 2;
                    275:        ledbox.h += 2;
                    276: 
                    277:        offset = fontw;
                    278:        MessageRect.y = LedRect.y - 2;
                    279:        /* draw led texts and boxes + calculate box offsets */
                    280:        for (i = 0; i < MAX_DRIVE_LEDS; i++) {
                    281:                SDLGui_Text(offset, MessageRect.y, text[i]);
                    282:                offset += strlen(text[i]) * fontw;
                    283:                offset += fontw/2;
                    284: 
                    285:                ledbox.x = offset - 1;
                    286:                SDL_FillRect(surf, &ledbox, LedColorBg);
                    287: 
                    288:                LedRect.x = offset;
                    289:                SDL_FillRect(surf, &LedRect, LedColorOff);
                    290: 
                    291:                Led[i].offset = offset;
1.1.1.4   root      292:                offset += LedRect.w + fontw;
1.1       root      293:        }
                    294: 
                    295:        /* draw frameskip */
                    296:        FrameSkipsRect.x = offset;
                    297:        FrameSkipsRect.y = MessageRect.y;
                    298:        SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "FS:");
                    299:        FrameSkipsRect.x += 3 * fontw + fontw/2;
1.1.1.4   root      300:        FrameSkipsRect.w = 4 * fontw;
1.1       root      301:        FrameSkipsRect.h = fonth;
1.1.1.4   root      302: 
                    303:        if(ConfigureParams.System.bFastForward) {
                    304:                SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0 >>");
                    305:        } else {
                    306:                SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, "0");
                    307:        }
                    308: 
1.1       root      309:        nOldFrameSkips = 0;
1.1.1.4   root      310: 
1.1       root      311:        /* intialize messages */
1.1.1.4   root      312:        MessageRect.x = FrameSkipsRect.x + FrameSkipsRect.w + fontw;
1.1       root      313:        MessageRect.w = MAX_MESSAGE_LEN * fontw;
                    314:        MessageRect.h = fonth;
                    315:        for (item = MessageList; item; item = item->next) {
1.1.1.3   root      316:                item->shown = false;
1.1       root      317:        }
                    318: 
                    319:        /* draw recording led box */
                    320:        RecLedRect = LedRect;
                    321:        RecLedRect.x = surf->w - fontw - RecLedRect.w;
                    322:        ledbox.x = RecLedRect.x - 1;
                    323:        SDLGui_Text(ledbox.x - 4*fontw - fontw/2, MessageRect.y, "REC:");
                    324:        SDL_FillRect(surf, &ledbox, LedColorBg);
                    325:        SDL_FillRect(surf, &RecLedRect, RecColorOff);
1.1.1.3   root      326:        bOldRecording = false;
1.1       root      327: 
                    328:        /* and blit statusbar on screen */
                    329:        SDL_UpdateRects(surf, 1, &sbarbox);
1.1.1.6 ! root      330:        DEBUGPRINT(("Drawn <- Statusbar_Init()\n"));
1.1       root      331: }
                    332: 
                    333: 
                    334: /*-----------------------------------------------------------------------*/
                    335: /**
                    336:  * Qeueue new statusbar message 'msg' to be shown for 'msecs' milliseconds
                    337:  */
                    338: void Statusbar_AddMessage(const char *msg, Uint32 msecs)
                    339: {
                    340:        msg_item_t *item;
                    341: 
                    342:        if (!ConfigureParams.Screen.bShowStatusbar) {
                    343:                /* no sense in queuing messages that aren't shown */
                    344:                return;
                    345:        }
                    346:        item = calloc(1, sizeof(msg_item_t));
                    347:        assert(item);
                    348: 
                    349:        item->next = MessageList;
                    350:        MessageList = item;
                    351: 
                    352:        strncpy(item->msg, msg, MAX_MESSAGE_LEN);
                    353:        item->msg[MAX_MESSAGE_LEN] = '\0';
                    354:        DEBUGPRINT(("Add message: '%s'\n", item->msg));
                    355: 
                    356:        if (msecs) {
                    357:                item->timeout = msecs;
                    358:        } else {
                    359:                /* show items by default for 2.5 secs */
                    360:                item->timeout = 2500;
                    361:        }
1.1.1.3   root      362:        item->shown = false;
1.1       root      363: }
                    364: 
                    365: /*-----------------------------------------------------------------------*/
                    366: /**
                    367:  * Write given 'more' string to 'buffer' and return new end of 'buffer'
                    368:  */
                    369: static char *Statusbar_AddString(char *buffer, const char *more)
                    370: {
                    371:        while(*more) {
                    372:                *buffer++ = *more++;
                    373:        }
                    374:        return buffer;
                    375: }
                    376: 
                    377: /*-----------------------------------------------------------------------*/
                    378: /**
                    379:  * Retrieve/update default statusbar information
                    380:  */
                    381: void Statusbar_UpdateInfo(void)
                    382: {
                    383:        char *end = DefaultMessage.msg;
                    384: 
1.1.1.4   root      385:        /* CPU MHz */
                    386:        if (ConfigureParams.System.nCpuFreq > 9) {
                    387:                *end++ = '0' + ConfigureParams.System.nCpuFreq / 10;
                    388:        }
                    389:        *end++ = '0' + ConfigureParams.System.nCpuFreq % 10;
                    390:        end = Statusbar_AddString(end, "MHz/");
                    391: 
                    392:        /* CPU type */
                    393:        if(ConfigureParams.System.nCpuLevel > 0) {
                    394:                *end++ = '0';
                    395:                *end++ = '0' + ConfigureParams.System.nCpuLevel % 10;
                    396:                *end++ = '0';
                    397:                *end++ = '/';
                    398:        }
                    399: 
1.1       root      400:        /* amount of memory */
                    401:        if (ConfigureParams.Memory.nMemorySize > 9) {
                    402:                *end++ = '1';
                    403:                *end++ = '0' + ConfigureParams.Memory.nMemorySize % 10;
                    404:        } else {
                    405:                if (ConfigureParams.Memory.nMemorySize) {
                    406:                        *end++ = '0' + ConfigureParams.Memory.nMemorySize;
                    407:                } else {
                    408:                        end = Statusbar_AddString(end, "1/2");
                    409:                }
                    410:        }
                    411:        end = Statusbar_AddString(end, "MB ");
1.1.1.4   root      412: 
1.1       root      413:        /* machine type */
                    414:        switch (ConfigureParams.System.nMachineType) {
                    415:        case MACHINE_ST:
                    416:                end = Statusbar_AddString(end, "ST");
                    417:                break;
                    418:        case MACHINE_STE:
                    419:                end = Statusbar_AddString(end, "STE");
                    420:                break;
1.1.1.5   root      421:        case MACHINE_MEGA_STE:
                    422:                end = Statusbar_AddString(end, "Mega STE");
                    423:                break;
1.1       root      424:        case MACHINE_TT:
                    425:                end = Statusbar_AddString(end, "TT");
                    426:                break;
                    427:        case MACHINE_FALCON:
                    428:                end = Statusbar_AddString(end, "Falcon");
                    429:                break;
                    430:        default:
                    431:                end = Statusbar_AddString(end, "???");
                    432:                break;
                    433:        }
                    434: 
                    435:        /* TOS type/version */
                    436:        if (bIsEmuTOS) {
                    437:                end = Statusbar_AddString(end, ", EmuTOS");
                    438:        } else {
                    439:                end = Statusbar_AddString(end, ", TOS v");
                    440:                *end++ = '0' + ((TosVersion & 0xf00) >> 8);
                    441:                *end++ = '.';
                    442:                *end++ = '0' + ((TosVersion & 0xf0) >> 4);
                    443:                *end++ = '0' + (TosVersion & 0xf);
                    444:        }
                    445:        *end = '\0';
1.1.1.4   root      446: 
1.1       root      447:        assert(end - DefaultMessage.msg < MAX_MESSAGE_LEN);
                    448:        DEBUGPRINT(("Set default message: '%s'\n", DefaultMessage.msg));
1.1.1.5   root      449:        /* make sure default message gets (re-)drawn when next checked */
1.1.1.3   root      450:        DefaultMessage.shown = false;
1.1       root      451: }
                    452: 
                    453: /*-----------------------------------------------------------------------*/
                    454: /**
                    455:  * Draw 'msg' centered to the message area
                    456:  */
                    457: static void Statusbar_DrawMessage(SDL_Surface *surf, const char *msg)
                    458: {
                    459:        int fontw, fonth, offset;
                    460:        SDL_FillRect(surf, &MessageRect, GrayBg);
                    461:        if (*msg) {
                    462:                SDLGui_GetFontSize(&fontw, &fonth);
                    463:                offset = (MessageRect.w - strlen(msg) * fontw) / 2;
                    464:                SDLGui_Text(MessageRect.x + offset, MessageRect.y, msg);
                    465:        }
                    466:        SDL_UpdateRects(surf, 1, &MessageRect);
                    467:        DEBUGPRINT(("Draw message: '%s'\n", msg));
                    468: }
                    469: 
                    470: /*-----------------------------------------------------------------------*/
                    471: /**
                    472:  * If message's not shown, show it.  If message's timed out,
                    473:  * remove it and show next one.
                    474:  */
                    475: static void Statusbar_ShowMessage(SDL_Surface *surf, Uint32 ticks)
                    476: {
                    477:        msg_item_t *next;
                    478: 
                    479:        if (MessageList->shown) {
                    480:                if (!MessageList->expire) {
1.1.1.5   root      481:                        /* last/default message newer expires */
1.1       root      482:                        return;
                    483:                }
                    484:                if (MessageList->expire > ticks) {
                    485:                        /* not timed out yet */
                    486:                        return;
                    487:                }
                    488:                assert(MessageList->next); /* last message shouldn't end here */
                    489:                next = MessageList->next;
                    490:                free(MessageList);
                    491:                MessageList = next;
                    492:                /* make sure next message gets shown */
1.1.1.3   root      493:                MessageList->shown = false;
1.1       root      494:        }
                    495:        if (!MessageList->shown) {
                    496:                /* not shown yet, show */
                    497:                Statusbar_DrawMessage(surf,  MessageList->msg);
                    498:                if (MessageList->timeout && !MessageList->expire) {
                    499:                        MessageList->expire = ticks + MessageList->timeout;
                    500:                }
1.1.1.3   root      501:                MessageList->shown = true;
1.1       root      502:        }
                    503: }
                    504: 
                    505: 
                    506: /*-----------------------------------------------------------------------*/
                    507: /**
                    508:  * Save the area that will be left under overlay led
                    509:  */
                    510: void Statusbar_OverlayBackup(SDL_Surface *surf)
                    511: {
1.1.1.3   root      512:        if ((StatusbarHeight && ConfigureParams.Screen.bShowStatusbar)
                    513:            || !ConfigureParams.Screen.bShowDriveLed) {
1.1       root      514:                /* overlay not used with statusbar */
                    515:                return;
                    516:        }
                    517:        assert(surf);
                    518:        if (!OverlayUnderside) {
                    519:                SDL_Surface *bak;
                    520:                SDL_PixelFormat *fmt = surf->format;
                    521:                bak = SDL_CreateRGBSurface(surf->flags,
                    522:                                           OverlayLedRect.w, OverlayLedRect.h,
                    523:                                           fmt->BitsPerPixel,
                    524:                                           fmt->Rmask, fmt->Gmask, fmt->Bmask,
                    525:                                           fmt->Amask);
                    526:                assert(bak);
                    527:                OverlayUnderside = bak;
                    528:        }
                    529:        SDL_BlitSurface(surf, &OverlayLedRect, OverlayUnderside, NULL);
                    530: }
                    531: 
                    532: /*-----------------------------------------------------------------------*/
                    533: /**
                    534:  * Restore the area left under overlay led
                    535:  */
                    536: void Statusbar_OverlayRestore(SDL_Surface *surf)
                    537: {
1.1.1.3   root      538:        if ((StatusbarHeight && ConfigureParams.Screen.bShowStatusbar)
                    539:            || !ConfigureParams.Screen.bShowDriveLed) {
1.1       root      540:                /* overlay not used with statusbar */
                    541:                return;
                    542:        }
                    543:        if (bOverlayState == OVERLAY_DRAWN && OverlayUnderside) {
                    544:                assert(surf);
                    545:                SDL_BlitSurface(OverlayUnderside, NULL, surf, &OverlayLedRect);
                    546:                /* this will make the draw function to update this the screen */
                    547:                bOverlayState = OVERLAY_RESTORED;
                    548:        }
                    549: }
                    550: 
                    551: /*-----------------------------------------------------------------------*/
                    552: /**
                    553:  * Draw overlay led
                    554:  */
                    555: static void Statusbar_OverlayDrawLed(SDL_Surface *surf, Uint32 color)
                    556: {
                    557:        SDL_Rect rect;
                    558:        if (bOverlayState == OVERLAY_DRAWN) {
                    559:                /* some led already drawn */
                    560:                return;
                    561:        }
                    562:        bOverlayState = OVERLAY_DRAWN;
                    563: 
                    564:        /* enabled led with border */
                    565:        rect = OverlayLedRect;
                    566:        rect.x += 1;
                    567:        rect.y += 1;
                    568:        rect.w -= 2;
                    569:        rect.h -= 2;
                    570:        SDL_FillRect(surf, &OverlayLedRect, LedColorBg);
                    571:        SDL_FillRect(surf, &rect, color);
                    572: }
                    573: 
                    574: /*-----------------------------------------------------------------------*/
                    575: /**
                    576:  * Draw overlay led onto screen surface if any drives are enabled.
                    577:  */
                    578: static void Statusbar_OverlayDraw(SDL_Surface *surf)
                    579: {
                    580:        Uint32 currentticks = SDL_GetTicks();
                    581:        int i;
                    582: 
                    583:        assert(surf);
1.1.1.4   root      584:        if (bRecordingYM || bRecordingWav || bRecordingAvi) {
1.1       root      585:                Statusbar_OverlayDrawLed(surf, RecColorOn);
                    586:        }
                    587:        for (i = 0; i < MAX_DRIVE_LEDS; i++) {
                    588:                if (Led[i].state) {
                    589:                        if (Led[i].expire && Led[i].expire < currentticks) {
1.1.1.3   root      590:                                Led[i].state = false;
1.1       root      591:                                continue;
                    592:                        }
                    593:                        Statusbar_OverlayDrawLed(surf, LedColorOn);
                    594:                        break;
                    595:                }
                    596:        }
                    597:        /* possible state transitions:
                    598:         *   NONE -> DRAWN -> RESTORED -> DRAWN -> RESTORED -> NONE
                    599:         * Other than NONE state needs to be updated on screen
                    600:         */
                    601:        switch (bOverlayState) {
                    602:        case OVERLAY_RESTORED:
                    603:                bOverlayState = OVERLAY_NONE;
                    604:        case OVERLAY_DRAWN:
                    605:                SDL_UpdateRects(surf, 1, &OverlayLedRect);
                    606:                DEBUGPRINT(("Overlay LED = %s\n", bOverlayState==OVERLAY_DRAWN?"ON":"OFF"));
                    607:                break;
                    608:        case OVERLAY_NONE:
                    609:                break;
                    610:        }
                    611: }
                    612: 
                    613: 
                    614: /*-----------------------------------------------------------------------*/
                    615: /**
                    616:  * Update statusbar information (leds etc) if/when needed.
                    617:  * 
                    618:  * May not be called when screen is locked (SDL limitation).
                    619:  */
                    620: void Statusbar_Update(SDL_Surface *surf)
                    621: {
                    622:        Uint32 color, currentticks;
                    623:        SDL_Rect rect;
                    624:        int i;
                    625: 
                    626:        if (!(StatusbarHeight && ConfigureParams.Screen.bShowStatusbar)) {
                    627:                /* not enabled (anymore), show overlay led instead? */
                    628:                if (ConfigureParams.Screen.bShowDriveLed) {
                    629:                        Statusbar_OverlayDraw(surf);
                    630:                }
                    631:                return;
                    632:        }
                    633:        assert(surf);
                    634:        /* Statusbar_Init() not called before this? */
1.1.1.6 ! root      635: #if DEBUG
        !           636:        if (surf->h != ScreenHeight + StatusbarHeight) {
        !           637:                printf("%d != %d + %d\n", surf->h, ScreenHeight, StatusbarHeight);
        !           638:        }
        !           639: #endif
1.1       root      640:        assert(surf->h == ScreenHeight + StatusbarHeight);
                    641: 
                    642:        rect = LedRect;
                    643:        currentticks = SDL_GetTicks();
                    644:        for (i = 0; i < MAX_DRIVE_LEDS; i++) {
                    645:                if (Led[i].expire && Led[i].expire < currentticks) {
1.1.1.3   root      646:                        Led[i].state = false;
1.1       root      647:                }
                    648:                if (Led[i].state == Led[i].oldstate) {
                    649:                        continue;
                    650:                }
                    651:                Led[i].oldstate = Led[i].state;
                    652:                if (Led[i].state) {
                    653:                        color = LedColorOn;
                    654:                } else {
                    655:                        color = LedColorOff;
                    656:                }
                    657:                rect.x = Led[i].offset;
                    658:                SDL_FillRect(surf, &rect, color);
                    659:                SDL_UpdateRects(surf, 1, &rect);
                    660:                DEBUGPRINT(("LED[%d] = %s\n", i, Led[i].state?"ON":"OFF"));
                    661:        }
1.1.1.4   root      662: 
1.1       root      663:        Statusbar_ShowMessage(surf, currentticks);
                    664: 
1.1.1.4   root      665:        if (nOldFrameSkips != nFrameSkips ||
                    666:            bOldFastForward != ConfigureParams.System.bFastForward) {
                    667:                char fscount[5];
                    668:                int end = 2;
                    669: 
1.1.1.3   root      670:                if (nFrameSkips < 10)
                    671:                        fscount[0] = '0' + nFrameSkips;
                    672:                else
                    673:                        fscount[0] = 'X';
1.1.1.4   root      674:                fscount[1] = ' ';
                    675:                if(ConfigureParams.System.bFastForward) {
                    676:                        fscount[2] = '>';
                    677:                        fscount[3] = '>';
                    678:                        end = 4;
                    679:                }
                    680:                fscount[end] = '\0';
                    681: 
1.1       root      682:                SDL_FillRect(surf, &FrameSkipsRect, GrayBg);
                    683:                SDLGui_Text(FrameSkipsRect.x, FrameSkipsRect.y, fscount);
                    684:                SDL_UpdateRects(surf, 1, &FrameSkipsRect);
                    685:                DEBUGPRINT(("FS = %s\n", fscount));
                    686:                nOldFrameSkips = nFrameSkips;
1.1.1.4   root      687:                bOldFastForward = ConfigureParams.System.bFastForward;
1.1       root      688:        }
                    689: 
1.1.1.4   root      690:        if ((bRecordingYM || bRecordingWav || bRecordingAvi)
1.1       root      691:            != bOldRecording) {
                    692:                bOldRecording = !bOldRecording;
                    693:                if (bOldRecording) {
                    694:                        color = RecColorOn;
                    695:                } else {
                    696:                        color = RecColorOff;
                    697:                }
                    698:                SDL_FillRect(surf, &RecLedRect, color);
                    699:                SDL_UpdateRects(surf, 1, &RecLedRect);
                    700:                DEBUGPRINT(("REC = ON\n"));
                    701:        }
                    702: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.