11// This file is part of SmallBASIC
22//
3- // Copyright(C) 2001-2014 Chris Warren-Smith.
3+ // Copyright(C) 2001-2015 Chris Warren-Smith.
44//
55// This program is distributed under the terms of the GPL v2.0 or later
66// Download the GNU Public License (GPL) from www.gnu.org
2626#include < queue>
2727#include < cmath>
2828
29- #define WAIT_INTERVAL 25
29+ #define WAIT_INTERVAL 5
3030#define MAIN_BAS " __main_bas__"
3131#define AMPLITUDE 22000
3232#define FREQUENCY 44100
33+ #define OPTIONS_BOX_WIDTH_EXTRA 4
34+ #define OPTIONS_BOX_BG 0xd2d1d0
35+ #define OPTIONS_BOX_FG 0x3e3f3e
3336
3437Runtime *runtime;
3538
@@ -310,11 +313,8 @@ void Runtime::pause(int timeout) {
310313
311314void Runtime::pollEvents (bool blocking) {
312315 if (isActive () && !isRestart ()) {
313- if (blocking) {
314- SDL_WaitEvent (NULL );
315- }
316316 SDL_Event ev;
317- if (SDL_PollEvent (&ev)) {
317+ if (blocking ? SDL_WaitEvent (&ev) : SDL_PollEvent (&ev)) {
318318 MAEvent *maEvent = NULL ;
319319 switch (ev.type ) {
320320 case SDL_QUIT:
@@ -479,27 +479,27 @@ void Runtime::onResize(int width, int height) {
479479}
480480
481481void Runtime::optionsBox (StringList *items) {
482- int width = 0 ;
483- int textHeight = 0 ;
484-
485482 if (!_menuX) {
486483 _menuX = 2 ;
487484 }
488485 if (!_menuY) {
489486 _menuY = 2 ;
490487 }
491488
489+ int width = 0 ;
490+ int charWidth = _output->getCharWidth ();
492491 _output->registerScreen (MENU_SCREEN);
493492 List_each (String *, it, *items) {
494493 char *str = (char *)(* it)->c_str ();
495- MAExtent extent = maGetTextSize (str);
496- int w = EXTENT_X (extent);
497- int h = EXTENT_Y (extent);
494+ int w = (strlen (str) * charWidth);
498495 if (w > width) {
499- width = w + 48 ;
496+ width = w;
500497 }
501- textHeight = h + 8 ;
502498 }
499+ width += (charWidth * OPTIONS_BOX_WIDTH_EXTRA);
500+
501+ int charHeight = _output->getCharHeight ();
502+ int textHeight = charHeight + (charHeight / 3 );
503503 int height = textHeight * items->size ();
504504 if (_menuX + width >= _output->getWidth ()) {
505505 _menuX = _output->getWidth () - width;
@@ -518,7 +518,7 @@ void Runtime::optionsBox(StringList *items) {
518518 char *str = (char *)(* it)->c_str ();
519519 FormInput *item = new MenuButton (index, selectedIndex, str, 0 , y, width, textHeight);
520520 _output->addInput (item);
521- item->setColor (0xd2d1d0 , 0x3e3f3e );
521+ item->setColor (OPTIONS_BOX_BG, OPTIONS_BOX_FG );
522522 index++;
523523 y += textHeight;
524524 }
0 commit comments