Changed some of the menu code to use new graphics functions

svn-id: r45493
This commit is contained in:
Filippos Karapetis 2009-10-28 23:04:56 +00:00
parent 21323a8d12
commit 2d9d9bca13
4 changed files with 20 additions and 26 deletions

View File

@ -39,14 +39,17 @@ reg_t kAddMenu(EngineState *s, int argc, reg_t *argv) {
Common::String name = s->_segMan->getString(argv[0]);
Common::String contents = s->_segMan->getString(argv[1]);
int titlebarFont = 0;
#ifdef INCLUDE_OLDGFX
s->_menubar->addMenu(s->gfx_state, name,
contents, s->titlebar_port->_font, argv[1]);
titlebarFont = s->titlebar_port->_font;
#else
// TODO
warning("TODO: kAddMenu()");
// TODO: titlebar port font
#endif
s->_menubar->addMenu(s->gfx_state, name,
contents, titlebarFont, argv[1]);
return s->r_acc;
}

View File

@ -31,6 +31,7 @@
#include "sci/sci.h"
#include "sci/engine/state.h"
#include "sci/gfx/menubar.h"
#include "sci/gui/gui.h"
#include "sci/engine/kernel.h"
namespace Sci {
@ -77,15 +78,14 @@ MenuItem::MenuItem() {
_tag = 0;
}
#ifdef INCLUDE_OLDGFX
int Menu::addMenuItem(GfxState *state, MenuType type, const char *left, const char *right,
int font, int key, int modifiers, int tag, reg_t text_pos) {
// Returns the total text size, plus MENU_BOX_CENTER_PADDING if (right != NULL)
MenuItem newItem;
MenuItem *item;
int total_left_size = 0;
int width, height;
int16 width = 10, height = 10;
EngineState *s = ((SciEngine *)g_engine)->getEngineState(); // HACK
item = &newItem;
item->_type = type;
@ -108,18 +108,14 @@ int Menu::addMenuItem(GfxState *state, MenuType type, const char *left, const ch
}
if (right) {
#ifdef INCLUDE_OLDGFX
gfxop_get_text_params(state, font, item->_keytext.c_str(), SIZE_INF, &width, &height, 0, NULL, NULL, NULL);
#endif
s->_gui->textSize(item->_keytext.c_str(), font, -1, &width, &height);
total_left_size = MENU_BOX_CENTER_PADDING + width;
}
item->_enabled = 1;
item->_tag = tag;
item->_textPos = text_pos;
#ifdef INCLUDE_OLDGFX
gfxop_get_text_params(state, font, left, SIZE_INF, &width, &height, 0, NULL, NULL, NULL);
#endif
s->_gui->textSize(left, font, -1, &width, &height);
_items.push_back(newItem);
@ -132,15 +128,15 @@ void Menubar::addMenu(GfxState *state, const Common::String &title, const Common
reg_t left_origin = entries_base;
int string_len = 0;
int tag = 0, c_width, max_width = 0;
int height;
int16 height = 10;
EngineState *s = ((SciEngine *)g_engine)->getEngineState(); // HACK
Menu menu;
menu._title = title;
menu._titleWidth = 10;
#ifdef INCLUDE_OLDGFX
gfxop_get_text_params(state, font, title.c_str(), SIZE_INF, &(menu._titleWidth), &height, 0, NULL, NULL, NULL);
#endif
s->_gui->textSize(title.c_str(), font, -1, &(menu._titleWidth), &height);
const char *entries_p = entries.c_str();
@ -278,8 +274,6 @@ void Menubar::addMenu(GfxState *state, const Common::String &title, const Common
_menus.push_back(menu);
}
#endif
bool MenuItem::matchKey(int message, int modifiers) {
if ((_key == message) && ((modifiers & (SCI_EVM_CTRL | SCI_EVM_ALT)) == _modifiers))
return true;

View File

@ -121,10 +121,10 @@ public:
Common::String _title;
/** Width of the title in pixels */
int _titleWidth;
int16 _titleWidth;
/** Pixel width of the menu window */
int _width;
int16 _width;
/**
* Actual entries into the menu.
@ -139,10 +139,8 @@ public:
//protected:
// FIXME: This should be (partially) turned into a MenuItem constructor
#ifdef INCLUDE_OLDGFX
int addMenuItem(GfxState *state, MenuType type, const char *left, const char *right,
int font, int key, int modifiers, int tag, reg_t text_pos);
#endif
};
@ -174,9 +172,7 @@ public:
* @param[in] font The font which is to be used for drawing
* @param[in] entries_base Segmented VM address of the entries string
*/
#ifdef INCLUDE_OLDGFX
void addMenu(GfxState *state, const Common::String &title, const Common::String &entries, int font, reg_t entries_base);
#endif
/**
* Sets the attributes for a menu item.

View File

@ -270,7 +270,8 @@ void SciGui::display(const char *text, int argc, reg_t *argv) {
void SciGui::textSize(const char *text, int16 font, int16 maxWidth, int16 *textWidth, int16 *textHeight) {
Common::Rect rect(0, 0, *textWidth, *textHeight);
_text->Size(rect, text, font, maxWidth);
*textWidth = rect.width(); *textHeight = rect.height();
*textWidth = rect.width();
*textHeight = rect.height();
}
// Used SCI1+ for text codes