From 685e77c88499aafba6aaccbf7aa92cd48a3ca7d9 Mon Sep 17 00:00:00 2001 From: Cyp Date: Tue, 12 Mar 2013 09:12:55 +0100 Subject: [PATCH] widget: Convert the intelmap stuff from W_TABFORMs to ListTabWidgets. --- lib/widget/listwidget.cpp | 20 +++- lib/widget/listwidget.h | 5 + src/hci.cpp | 11 --- src/hci.h | 7 -- src/intdisplay.cpp | 18 ---- src/intdisplay.h | 1 - src/intelmap.cpp | 195 ++++++++------------------------------ src/intimage.cpp | 8 -- src/intimage.h | 3 - 9 files changed, 64 insertions(+), 204 deletions(-) diff --git a/lib/widget/listwidget.cpp b/lib/widget/listwidget.cpp index 5fa58786b..52c3ce12a 100644 --- a/lib/widget/listwidget.cpp +++ b/lib/widget/listwidget.cpp @@ -245,6 +245,7 @@ ListTabWidget::ListTabWidget(WIDGET *parent) : WIDGET(parent) , tabs(new TabSelectionWidget(this)) , widgets(new ListWidget(this)) + , tabPos(Top) { connect(tabs, SIGNAL(tabChanged(int)), widgets, SLOT(setCurrentPage(int))); connect(widgets, SIGNAL(currentPageChanged(int)), tabs, SLOT(setTab(int))); @@ -254,8 +255,17 @@ ListTabWidget::ListTabWidget(WIDGET *parent) void ListTabWidget::geometryChanged() { - tabs->setGeometry(0, 0, width(), tabs->height()); - widgets->setGeometry(0, tabs->height(), width(), height() - tabs->height()); + switch (tabPos) + { + case Top: + tabs->setGeometry(0, 0, width(), tabs->height()); + widgets->setGeometry(0, tabs->height(), width(), height() - tabs->height()); + break; + case Bottom: + tabs->setGeometry(0, height() - tabs->height(), width(), tabs->height()); + widgets->setGeometry(0, 0, width(), height() - tabs->height()); + break; + } } void ListTabWidget::addWidgetToLayout(WIDGET *widget) @@ -267,3 +277,9 @@ void ListTabWidget::addWidgetToLayout(WIDGET *widget) } widgets->addWidgetToLayout(widget); } + +void ListTabWidget::setTabPosition(TabPosition pos) +{ + tabPos = pos; + geometryChanged(); +} diff --git a/lib/widget/listwidget.h b/lib/widget/listwidget.h index 311fe81e6..ac2de692b 100644 --- a/lib/widget/listwidget.h +++ b/lib/widget/listwidget.h @@ -122,6 +122,8 @@ class ListTabWidget : public WIDGET Q_OBJECT public: + enum TabPosition {Top, Bottom}; + ListTabWidget(WIDGET *parent); virtual void geometryChanged(); @@ -134,12 +136,15 @@ public: int currentPage() const { return widgets->currentPage(); } int pages() const { return widgets->pages(); } + void setTabPosition(TabPosition pos); + TabSelectionWidget *tabWidget() { return tabs; } ListWidget *listWidget() { return widgets; } private: TabSelectionWidget *tabs; ListWidget *widgets; + TabPosition tabPos; }; #endif //THISISALISTWIDGET_H diff --git a/src/hci.cpp b/src/hci.cpp index 89eb2c4b7..df261c3b9 100644 --- a/src/hci.cpp +++ b/src/hci.cpp @@ -2679,17 +2679,6 @@ void intAlliedResearchChanged() } } -/* Do the annoying calculation for how many forms are needed - * given the total number of buttons and the number of - * buttons per page. - * A simple div just doesn't quite do it.... - */ -UWORD numForms(UDWORD total, UDWORD perForm) -{ - return std::max((total + perForm - 1) / perForm, 1u); -} - - /* Add the reticule widgets to the widget screen */ bool intAddReticule() { diff --git a/src/hci.h b/src/hci.h index 764b30f41..a9f78e33e 100644 --- a/src/hci.h +++ b/src/hci.h @@ -138,11 +138,6 @@ #define POW_Y (OBJ_BACKY + OBJ_BACKHEIGHT + 6) #define POW_BARWIDTH 308 -//tab details -#define OBJ_TABWIDTH 26 -#define OBJ_TABHEIGHT 11 -#define OBJ_TABOFFSET 2 - /* close button data */ #define CLOSE_WIDTH 15 #define CLOSE_HEIGHT 15 @@ -311,8 +306,6 @@ extern bool intBuildMode(void); // add the construction interface if a constructor droid is selected void intCommanderSelected(DROID *psDroid); -extern UWORD numForms(UDWORD total, UDWORD perForm); - //sets up the Intelligence Screen as far as the interface is concerned extern void addIntelScreen(void); diff --git a/src/intdisplay.cpp b/src/intdisplay.cpp index 2c639b11a..4dfc2b4a6 100644 --- a/src/intdisplay.cpp +++ b/src/intdisplay.cpp @@ -1437,24 +1437,6 @@ void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset) psWidget->UserData = PACKDWORD_QUAD(flashTime, flashing, DownTime, Index); } - -void intDisplayTab(WIDGET *psWidget, UDWORD Position, - UDWORD Number, bool Selected, bool Hilight, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height) -{ - TABDEF *Tab = (TABDEF *)psWidget->pUserData; - - iV_DrawImage(IntImages, (UWORD)Tab->MajorUp, x, y); - - if (Hilight) - { - iV_DrawImage(IntImages, (UWORD)Tab->MajorHilight, x, y); - } - else if (Selected) - { - iV_DrawImage(IntImages, (UWORD)Tab->MajorSelected, x, y); - } -} - // Display one of three images depending on if the widget is currently depressed (ah!). // void intDisplayButtonPressed(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset) diff --git a/src/intdisplay.h b/src/intdisplay.h index 99783c2d5..4d88ecc0d 100644 --- a/src/intdisplay.h +++ b/src/intdisplay.h @@ -181,7 +181,6 @@ void intDisplayButtonPressed(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset); void intDisplayReticuleButton(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset); -void intDisplayTab(WIDGET *psWidget, UDWORD Position, UDWORD Number, bool Selected, bool Hilight, UDWORD x, UDWORD y, UDWORD Width, UDWORD Height); void intDisplaySlider(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset); void intDisplayNumber(WIDGET *psWidget, UDWORD xOffset, UDWORD yOffset); diff --git a/src/intelmap.cpp b/src/intelmap.cpp index a8e1efb33..b4e44846e 100644 --- a/src/intelmap.cpp +++ b/src/intelmap.cpp @@ -76,7 +76,6 @@ #define IDINTMAP_FLICVIEW 6008 //The Flic View part of MSGVIEW #define IDINTMAP_TEXTVIEW 6009 //The Text area of MSGVIEW #define IDINTMAP_TITLELABEL 6010 //The title text -#define IDINTMAP_SEQTEXT 6011 //Sequence subtitle text #define IDINTMAP_MSGSTART 6100 //The first button on the intelligence form #define IDINTMAP_MSGEND 6139 //The last button on the intelligence form (40 MAX) @@ -95,9 +94,7 @@ #define INTMAP_LABELHEIGHT 20 /*tabbed message form screen positions */ -#define INTMAP_MSGX OBJ_TABX #define INTMAP_MSGY OBJ_TABY -#define INTMAP_MSGWIDTH OBJ_WIDTH #define INTMAP_MSGHEIGHT OBJ_HEIGHT //define the 3D View sizes and positions that are required - relative to INTMAP_FORM @@ -265,81 +262,24 @@ bool intAddIntelMap(void) /* Add the Message sub form */ static bool intAddMessageForm(bool playCurrent) { - UDWORD numButtons; - MESSAGE *psMessage; - RESEARCH *psResearch; - SDWORD BufferID; + WIDGET *msgForm = widgGetFromID(psWScreen, IDINTMAP_FORM); /* Add the Message form */ - W_FORMINIT sFormInit; - sFormInit.formID = IDINTMAP_FORM; - sFormInit.id = IDINTMAP_MSGFORM; - sFormInit.style = WFORM_TABBED; - sFormInit.width = INTMAP_MSGWIDTH; - sFormInit.height = INTMAP_MSGHEIGHT; - sFormInit.x = INTMAP_MSGX; - sFormInit.y = INTMAP_MSGY; - - sFormInit.majorPos = WFORM_TABTOP; - sFormInit.majorSize = OBJ_TABWIDTH; - sFormInit.majorOffset = OBJ_TABOFFSET; - sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2); - sFormInit.tabMajorThickness = OBJ_TABHEIGHT; - - numButtons = 0; - /*work out the number of buttons */ - for(psMessage = apsMessages[selectedPlayer]; psMessage; psMessage = - psMessage->psNext) - { - //ignore proximity messages here - if (psMessage->type != MSG_PROXIMITY) - { - numButtons++; - } - - // stop adding the buttons once max has been reached - if (numButtons > (IDINTMAP_MSGEND - IDINTMAP_MSGSTART)) - { - break; - } - } - - //set the number of tabs required - sFormInit.numMajor = numForms((OBJ_BUTWIDTH + OBJ_GAP) * numButtons, - (OBJ_WIDTH - OBJ_GAP)*2); - - sFormInit.pUserData = &StandardTab; - sFormInit.pTabDisplay = intDisplayTab; - - if (sFormInit.numMajor > MAX_TAB_STD_SHOWN) - { // we do NOT use smallTab icons here, so be safe and only display max # of - // standard sized tab icons. - sFormInit.numMajor = MAX_TAB_STD_SHOWN; - } - - if (!widgAddForm(psWScreen, &sFormInit)) - { - return false; - } - + IntListTabWidget *msgList = new IntListTabWidget(msgForm); + msgList->id = IDINTMAP_MSGFORM; + msgList->setChildSize(OBJ_BUTWIDTH, OBJ_BUTHEIGHT); + msgList->setChildSpacing(OBJ_GAP, OBJ_GAP); + int msgListWidth = OBJ_BUTWIDTH*5 + OBJ_GAP*4; + msgList->setGeometry((msgForm->width() - msgListWidth)/2, INTMAP_MSGY, msgListWidth, msgForm->height() - INTMAP_MSGY); /* Add the message buttons */ - W_FORMINIT sBFormInit; - sBFormInit.formID = IDINTMAP_MSGFORM; - sBFormInit.id = IDINTMAP_MSGSTART; - sBFormInit.majorID = 0; - sBFormInit.style = WFORM_CLICKABLE; - sBFormInit.x = OBJ_STARTX; - sBFormInit.y = OBJ_STATSTARTY; - sBFormInit.width = OBJ_BUTWIDTH; - sBFormInit.height = OBJ_BUTHEIGHT; + int nextButtonId = IDINTMAP_MSGSTART; ClearObjectBuffers(); //add each button messageID = 0; - for(psMessage = apsMessages[selectedPlayer]; psMessage; psMessage = - psMessage->psNext) + for (MESSAGE *psMessage = apsMessages[selectedPlayer]; psMessage != nullptr; psMessage = psMessage->psNext) { /*if (psMessage->type == MSG_TUTORIAL) { @@ -353,73 +293,58 @@ static bool intAddMessageForm(bool playCurrent) continue; } + W_CLICKFORM *button = new W_CLICKFORM(msgList); + button->id = nextButtonId; + button->displayFunction = intDisplayMessageButton; + msgList->addWidgetToLayout(button); + /* Set the tip and add the button */ + RESEARCH *psResearch; switch (psMessage->type) { case MSG_RESEARCH: - psResearch = getResearchForMsg((VIEWDATA *)psMessage->pViewData); + psResearch = getResearchForMsg((VIEWDATA *)psMessage->pViewData); if (psResearch) { - sBFormInit.pTip = getStatName(psResearch);; + button->setTip(getStatName(psResearch)); } else { - sBFormInit.pTip = _("Research Update"); + button->setTip(_("Research Update")); } break; case MSG_CAMPAIGN: - sBFormInit.pTip = _("Project Goals"); + button->setTip(_("Project Goals")); break; case MSG_MISSION: - sBFormInit.pTip = _("Current Objective"); + button->setTip(_("Current Objective")); break; default: break; } - BufferID = GetObjectBuffer(); + int BufferID = GetObjectBuffer(); ASSERT( BufferID >= 0,"Unable to acquire object buffer." ); RENDERBUTTON_INUSE(&ObjectBuffers[BufferID]); ObjectBuffers[BufferID].Data = (void*)psMessage; - sBFormInit.pUserData = &ObjectBuffers[BufferID]; - sBFormInit.pDisplay = intDisplayMessageButton; - - if (!widgAddForm(psWScreen, &sBFormInit)) - { - return false; - } + button->pUserData = &ObjectBuffers[BufferID]; /* if the current message matches psSelected lock the button */ if (psMessage == psCurrentMsg) { - messageID = sBFormInit.id; - widgSetButtonState(psWScreen, messageID, WBUT_LOCK); - widgSetTabs(psWScreen, IDINTMAP_MSGFORM, sBFormInit.majorID); + messageID = nextButtonId; + button->setState(WBUT_LOCK); + msgList->setCurrentPage(msgList->pages() - 1); } /* Update the init struct for the next button */ - sBFormInit.id += 1; + ++nextButtonId; // stop adding the buttons when at max - if (sBFormInit.id > IDINTMAP_MSGEND) + if (nextButtonId > IDINTMAP_MSGEND) { break; } - - ASSERT( sBFormInit.id < (IDINTMAP_MSGEND+1),"Too many message buttons" ); - - sBFormInit.x += OBJ_BUTWIDTH + OBJ_GAP; - if (sBFormInit.x + OBJ_BUTWIDTH + OBJ_GAP > INTMAP_MSGWIDTH) - { - sBFormInit.x = OBJ_STARTX; - sBFormInit.y += OBJ_BUTHEIGHT + OBJ_GAP; - } - - if (sBFormInit.y + OBJ_BUTHEIGHT + OBJ_GAP > INTMAP_MSGHEIGHT) - { - sBFormInit.y = OBJ_STATSTARTY; - sBFormInit.majorID += 1; - } } //check to play current message instantly if (playCurrent) @@ -480,65 +405,27 @@ bool intAddMessageView(MESSAGE * psMessage) ((VIEWDATA*)psMessage->pViewData)->type == VIEW_RPL) { VIEW_REPLAY *psViewReplay; - size_t i, cur_seq, cur_seqpage; psViewReplay = (VIEW_REPLAY *)((VIEWDATA *)psMessage->pViewData)->pData; /* Add a big tabbed text box for the subtitle text */ - W_FORMINIT sFormInit; - sFormInit.id = IDINTMAP_SEQTEXT; - sFormInit.formID = IDINTMAP_MSGVIEW; - sFormInit.style = WFORM_TABBED; - sFormInit.x = INTMAP_SEQTEXTX; - sFormInit.y = INTMAP_SEQTEXTY; - sFormInit.width = INTMAP_SEQTEXTWIDTH; - sFormInit.height = INTMAP_SEQTEXTHEIGHT; + IntListTabWidget *seqList = new IntListTabWidget(intMapMsgView); + seqList->setChildSize(INTMAP_SEQTEXTTABWIDTH, INTMAP_SEQTEXTTABHEIGHT); + seqList->setChildSpacing(2, 2); + seqList->setGeometry(INTMAP_SEQTEXTX, INTMAP_SEQTEXTY, INTMAP_SEQTEXTWIDTH, INTMAP_SEQTEXTHEIGHT); + seqList->setTabPosition(ListTabWidget::Bottom); + // Don't think the tabs are actually ever used... - sFormInit.majorPos = WFORM_TABBOTTOM; - sFormInit.majorSize = OBJ_TABWIDTH; - sFormInit.majorOffset = OBJ_TABOFFSET; - sFormInit.tabVertOffset = (OBJ_TABHEIGHT/2); - sFormInit.tabMajorThickness = OBJ_TABHEIGHT; - - sFormInit.numMajor = 0; - - cur_seq = cur_seqpage = 0; + size_t cur_seq = 0, cur_seqpage = 0; + int nextPageId = IDINTMAP_SEQTEXTSTART; do { - sFormInit.numMajor++; - } - while (!intDisplaySeqTextViewPage(psViewReplay, 0, 0, - sFormInit.width, sFormInit.height, - false, &cur_seq, &cur_seqpage)); - - sFormInit.pUserData = &StandardTab; - sFormInit.pTabDisplay = intDisplayTab; - - if (!widgAddForm(psWScreen, &sFormInit)) - { - return false; - } - - W_FORMINIT sTabForm; - sTabForm.formID = IDINTMAP_SEQTEXT; - sTabForm.id = IDINTMAP_SEQTEXTSTART; - sTabForm.majorID = 0; - sTabForm.style = WFORM_PLAIN; - sTabForm.x = INTMAP_SEQTEXTTABX; - sTabForm.y = INTMAP_SEQTEXTTABY; - sTabForm.width = INTMAP_SEQTEXTTABWIDTH; - sTabForm.height = INTMAP_SEQTEXTTABHEIGHT; - sTabForm.pDisplay = intDisplaySeqTextView; - sTabForm.pUserData = psViewReplay; - - for (i = 0; i < sFormInit.numMajor; i++) - { - sTabForm.id = IDINTMAP_SEQTEXTSTART + i; - sTabForm.majorID = i; - if (!widgAddForm(psWScreen, &sTabForm)) - { - return false; - } + W_FORM *page = new W_FORM(seqList); + page->id = nextPageId++; + page->displayFunction = intDisplaySeqTextView; + page->pUserData = psViewReplay; + seqList->addWidgetToLayout(page); } + while (!intDisplaySeqTextViewPage(psViewReplay, 0, 0, INTMAP_SEQTEXTTABWIDTH, INTMAP_SEQTEXTHEIGHT, false, &cur_seq, &cur_seqpage)); return true; } diff --git a/src/intimage.cpp b/src/intimage.cpp index 67e47dcf8..a63ad0f3f 100644 --- a/src/intimage.cpp +++ b/src/intimage.cpp @@ -144,14 +144,6 @@ IMAGEFRAME FrameRadar = { {FR_IGNORE, 0,0, 0,0 ,0}}, }; -// Tab definitions, defines graphics to use for major and minor tabs. -TABDEF StandardTab = { - IMAGE_TAB1, // Major tab normal. - IMAGE_TAB1DOWN, // Major tab clicked. - IMAGE_TABHILIGHT, // Major tab hilighted by mouse. - IMAGE_TABSELECTED, // Major tab currently selected. -}; - // Read bitmaps used by the interface. // bool imageInitBitmaps(void) diff --git a/src/intimage.h b/src/intimage.h index 4bbe25ac0..b04f7edd2 100644 --- a/src/intimage.h +++ b/src/intimage.h @@ -50,9 +50,6 @@ public: extern IMAGEFILE *IntImages; //< All the 2d graphics for the user interface. -// A few useful defined tabs. -extern TABDEF StandardTab; - bool imageInitBitmaps(void); /** Draws a transparent window. */