aboutsummaryrefslogtreecommitdiff
path: root/engines/sci/gui32
diff options
context:
space:
mode:
authorMartin Kiewitz2009-10-11 12:15:17 +0000
committerMartin Kiewitz2009-10-11 12:15:17 +0000
commit0d98fa3fe4ff5100fa66f23d18c45aeea732d265 (patch)
treed3102d19066ecc232ad697719f20e0cc277a0673 /engines/sci/gui32
parent47988039ea009940f20e56b79749d6800cfc806c (diff)
downloadscummvm-rg350-0d98fa3fe4ff5100fa66f23d18c45aeea732d265.tar.gz
scummvm-rg350-0d98fa3fe4ff5100fa66f23d18c45aeea732d265.tar.bz2
scummvm-rg350-0d98fa3fe4ff5100fa66f23d18c45aeea732d265.zip
SCI: made kEditControl use SciGui class, not currently implemented in newgui
svn-id: r44913
Diffstat (limited to 'engines/sci/gui32')
-rw-r--r--engines/sci/gui32/gui32.cpp207
-rw-r--r--engines/sci/gui32/gui32.h1
2 files changed, 208 insertions, 0 deletions
diff --git a/engines/sci/gui32/gui32.cpp b/engines/sci/gui32/gui32.cpp
index 4a509b00b6..8669ae0810 100644
--- a/engines/sci/gui32/gui32.cpp
+++ b/engines/sci/gui32/gui32.cpp
@@ -621,6 +621,213 @@ void SciGui32::drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewI
if (!s->pic_not_valid) FULL_REDRAW();
}
+// Control types and flags
+enum {
+ K_CONTROL_BUTTON = 1,
+ K_CONTROL_TEXT = 2,
+ K_CONTROL_EDIT = 3,
+ K_CONTROL_ICON = 4,
+ K_CONTROL_CONTROL = 6,
+ K_CONTROL_CONTROL_ALIAS = 7,
+ K_CONTROL_BOX = 10
+};
+
+#define _K_EDIT_DELETE \
+ if (cursor < textlen) { \
+ text.deleteChar(cursor); \
+ }
+
+#define _K_EDIT_BACKSPACE \
+ if (cursor) { \
+ --cursor; \
+ text.deleteChar(cursor); \
+ --textlen; \
+ }
+
+void update_cursor_limits(int *display_offset, int *cursor, int max_displayed) {
+ if (*cursor < *display_offset + 4) {
+ if (*cursor < 8)
+ *display_offset = 0;
+ else
+ *display_offset = *cursor - 8;
+ } else if (*cursor - *display_offset > max_displayed - 8)
+ *display_offset = 12 + *cursor - max_displayed;
+}
+
+void _k_draw_control(EngineState *s, reg_t obj, bool hilite);
+
+void SciGui32::editControl(reg_t controlObject, reg_t eventObject) {
+ SegManager *segMan = s->_segMan;
+ uint16 ct_type = GET_SEL32V(controlObject, type);
+
+ switch (ct_type) {
+
+ case 0:
+ break; // NOP
+
+ case K_CONTROL_EDIT:
+ if (eventObject.segment && ((GET_SEL32V(eventObject, type)) == SCI_EVT_KEYBOARD)) {
+ int max_displayed = GET_SEL32V(controlObject, max);
+ int max = max_displayed;
+ int cursor = GET_SEL32V(controlObject, cursor);
+ int modifiers = GET_SEL32V(eventObject, modifiers);
+ int key = GET_SEL32V(eventObject, message);
+ reg_t text_pos = GET_SEL32(controlObject, text);
+ int display_offset = 0;
+
+ Common::String text = s->_segMan->getString(text_pos);
+ int textlen;
+
+#if 0
+ if (!text) {
+ warning("Could not draw control: %04x:%04x does not reference text", PRINT_REG(text_pos));
+ return s->r_acc;
+ }
+#endif
+
+ textlen = text.size();
+
+ cursor += display_offset;
+
+ if (cursor > textlen)
+ cursor = textlen;
+
+ if (modifiers & SCI_EVM_CTRL) {
+
+ switch (tolower((char)key)) {
+ case 'a':
+ cursor = 0;
+ break;
+ case 'e':
+ cursor = textlen;
+ break;
+ case 'f':
+ if (cursor < textlen) ++cursor;
+ break;
+ case 'b':
+ if (cursor > 0) --cursor;
+ break;
+ case 'k':
+ text = Common::String(text.c_str(), cursor);
+ break; // Terminate string
+ case 'h':
+ _K_EDIT_BACKSPACE;
+ break;
+ case 'd':
+ _K_EDIT_DELETE;
+ break;
+ }
+ PUT_SEL32V(eventObject, claimed, 1);
+
+ } else if (modifiers & SCI_EVM_ALT) { // Ctrl has precedence over Alt
+ switch (key) {
+ case 0x2100 /* A-f */:
+ while ((cursor < textlen) && (text[cursor++] != ' '))
+ ;
+ break;
+ case 0x3000 /* A-b */:
+ while ((cursor > 0) && (text[--cursor - 1] != ' '))
+ ;
+ break;
+ case 0x2000 /* A-d */: {
+ while ((cursor < textlen) && (text[cursor] == ' ')) {
+ _K_EDIT_DELETE;
+ textlen--;
+ }
+ while ((cursor < textlen) && (text[cursor] != ' ')) {
+ _K_EDIT_DELETE;
+ textlen--;
+ }
+ break;
+ }
+ }
+ PUT_SEL32V(eventObject, claimed, 1);
+ } else if (key < 31) {
+ PUT_SEL32V(eventObject, claimed, 1);
+ switch (key) {
+ case SCI_K_BACKSPACE:
+ _K_EDIT_BACKSPACE;
+ break;
+ default:
+ PUT_SEL32V(eventObject, claimed, 0);
+ }
+ } else if (key & 0xff00) {
+ switch (key) {
+ case SCI_K_HOME:
+ cursor = 0;
+ break;
+ case SCI_K_END:
+ cursor = textlen;
+ break;
+ case SCI_K_RIGHT:
+ if (cursor + 1 <= textlen)
+ ++cursor;
+ break;
+ case SCI_K_LEFT:
+ if (cursor > 0)
+ --cursor;
+ break;
+ case SCI_K_DELETE:
+ _K_EDIT_DELETE;
+ break;
+ }
+ PUT_SEL32V(eventObject, claimed, 1);
+ } else if ((key > 31) && (key < 128)) {
+ int inserting = (modifiers & SCI_EVM_INSERT);
+
+ modifiers &= ~(SCI_EVM_RSHIFT | SCI_EVM_LSHIFT | SCI_EVM_CAPSLOCK);
+
+ if (cursor == textlen) {
+ if (textlen < max) {
+ text += key;
+ cursor++;
+ }
+ } else if (inserting) {
+ if (textlen < max) {
+ int i;
+
+ for (i = textlen + 2; i >= cursor; i--)
+ text.setChar(text[i - 1], i);
+ text.setChar(key, cursor++);
+
+ }
+ } else { // Overwriting
+ text.setChar(key, cursor++);
+ }
+
+ if (max_displayed < max)
+ update_cursor_limits(&display_offset, &cursor, max_displayed);
+
+ cursor -= display_offset;
+
+ PUT_SEL32V(eventObject, claimed, 1);
+ }
+
+ PUT_SEL32V(controlObject, cursor, cursor); // Write back cursor position
+ s->_segMan->strcpy(text_pos, text.c_str()); // Write back string
+ }
+ if (eventObject.segment) PUT_SEL32V(eventObject, claimed, 1);
+ _k_draw_control(s, controlObject, false);
+ return;
+
+ case K_CONTROL_ICON:
+ case K_CONTROL_BOX:
+ case K_CONTROL_BUTTON:
+ return;
+
+ case K_CONTROL_TEXT: {
+ int state = GET_SEL32V(controlObject, state);
+ PUT_SEL32V(controlObject, state, state | kControlStateDitherFramed);
+ _k_draw_control(s, controlObject, false);
+ PUT_SEL32V(controlObject, state, state);
+ }
+ break;
+
+ default:
+ warning("Attempt to edit control type %d", ct_type);
+ }
+}
+
static gfx_color_t graph_map_color(EngineState *s, int color, int priority, int control) {
gfx_color_t retval;
diff --git a/engines/sci/gui32/gui32.h b/engines/sci/gui32/gui32.h
index 2408593448..d8cc985e3f 100644
--- a/engines/sci/gui32/gui32.h
+++ b/engines/sci/gui32/gui32.h
@@ -63,6 +63,7 @@ public:
void drawControlButton(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 style, bool hilite);
void drawControlText(Common::Rect rect, reg_t obj, const char *text, int16 fontId, int16 mode, int16 style, bool hilite);
void drawControlIcon(Common::Rect rect, reg_t obj, GuiResourceId viewId, GuiViewLoopNo loopNo, GuiViewCelNo, int16 style, bool hilite);
+ void editControl(reg_t controlObject, reg_t eventObject);
void graphFillBoxForeground(Common::Rect rect);
void graphFillBoxBackground(Common::Rect rect);