BookGump.cpp

Go to the documentation of this file.
00001 /*
00002  *  Copyright (C) 2004-2006  The Pentagram Team
00003  *
00004  *  This program is free software; you can redistribute it and/or modify
00005  *  it under the terms of the GNU General Public License as published by
00006  *  the Free Software Foundation; either version 2 of the License, or
00007  *  (at your option) any later version.
00008  *
00009  *  This program is distributed in the hope that it will be useful,
00010  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012  *  GNU General Public License for more details.
00013  *
00014  *  You should have received a copy of the GNU General Public License
00015  *  along with this program; if not, write to the Free Software
00016  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
00017  */
00018 
00019 #include "pent_include.h"
00020 #include "BookGump.h"
00021 #include "TextWidget.h"
00022 #include "GameData.h"
00023 #include "Shape.h"
00024 #include "GumpShapeArchive.h"
00025 #include "ShapeFrame.h"
00026 #include "UCMachine.h"
00027 #include "GumpNotifyProcess.h"
00028 #include "Item.h"
00029 #include "getObject.h"
00030 
00031 
00032 #include "IDataSource.h"
00033 #include "ODataSource.h"
00034 
00035 DEFINE_RUNTIME_CLASSTYPE_CODE(BookGump,ModalGump);
00036 
00037 // TODO: Remove all the hacks
00038 
00039 BookGump::BookGump()
00040         : ModalGump()
00041 {
00042 
00043 }
00044 
00045 BookGump::BookGump(ObjId owner, std::string msg) :
00046         ModalGump(0, 0, 100, 100, owner), text(msg)
00047 {
00048 }
00049 
00050 BookGump::~BookGump(void)
00051 {
00052 }
00053 
00054 void BookGump::InitGump(Gump* newparent, bool take_focus)
00055 {
00056         ModalGump::InitGump(newparent, take_focus);
00057 
00058         // Create the TextWidgets (NOTE: they _must_ have exactly the same dims)
00059         TextWidget *widget = new TextWidget(9,5,text,true,9,123,129); 
00060         widget->InitGump(this);
00061         textwidgetL = widget->getObjId();
00062         
00063         widget = new TextWidget(150,5,text,true,9,123,129); 
00064         widget->InitGump(this);
00065         textwidgetR = widget->getObjId();
00066         widget->setupNextText();
00067 
00068         text.clear(); // no longer need this
00069 
00071         Shape* shape = GameData::get_instance()->getGumps()->getShape(6);
00072 
00073         SetShape(shape, 0);
00074 
00075         ShapeFrame* sf = shape->getFrame(0);
00076         assert(sf);
00077 
00078         dims.w = sf->width;
00079         dims.h = sf->height;
00080 }
00081 
00082 void BookGump::NextText()
00083 {
00084         TextWidget *widgetL = p_dynamic_cast<TextWidget*>(getGump(textwidgetL));
00085         TextWidget *widgetR = p_dynamic_cast<TextWidget*>(getGump(textwidgetR));
00086         assert(widgetL);
00087         assert(widgetR);
00088         if (!widgetR->setupNextText()) {
00089                 Close();
00090         }
00091         widgetL->setupNextText();
00092         widgetL->setupNextText();
00093         widgetR->setupNextText();
00094 }
00095 
00096 bool BookGump::Run(const uint32 framenum)
00097 {
00098         ModalGump::Run(framenum);
00099 
00100         return true;
00101 }
00102 
00103 void BookGump::OnMouseClick(int button, int mx, int my)
00104 {
00105         // Scroll to next text, if possible
00106         NextText();
00107 }
00108 
00109 void BookGump::OnMouseDouble(int button, int mx, int my)
00110 {
00111         Close();
00112 }
00113 
00114 uint32 BookGump::I_readBook(const uint8* args, unsigned int /*argsize*/)
00115 {
00116         ARG_ITEM_FROM_PTR(item);
00117         ARG_STRING(str);
00118         assert(item);
00119 
00120         Gump *gump = new BookGump(item->getObjId(), str);
00121         gump->InitGump(0);
00122         gump->setRelativePosition(CENTER);
00123         
00124         return gump->GetNotifyProcess()->getPid();
00125 }
00126 
00127 void BookGump::saveData(ODataSource* ods)
00128 {
00129         CANT_HAPPEN_MSG("Trying to save ModalGump");
00130 }
00131 
00132 bool BookGump::loadData(IDataSource* ids, uint32 version)
00133 {
00134         CANT_HAPPEN_MSG("Trying to load ModalGump");
00135 
00136         return false;
00137 }

Generated on Fri Jul 27 22:27:10 2007 for pentagram by  doxygen 1.4.7