[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[paragui-cvs] CVS: paragui/src/layout Makefile.am,NONE,1.2.2.1 layoutpar
From: |
Teunis Peters <address@hidden> |
Subject: |
[paragui-cvs] CVS: paragui/src/layout Makefile.am,NONE,1.2.2.1 layoutparsers.cpp,NONE,1.5.2.1 pgxmllayoutloader.cpp,NONE,1.6.2.1 |
Date: |
Wed, 30 Oct 2002 14:56:30 -0500 |
Update of /cvsroot/paragui/paragui/src/layout
In directory subversions:/tmp/cvs-serv18782/src/layout
Added Files:
Tag: devel-opengl
Makefile.am layoutparsers.cpp pgxmllayoutloader.cpp
Log Message:
huh?
I thought these were in already...
--- NEW FILE ---
noinst_LTLIBRARIES = libpglayout.la
libpglayout_la_SOURCES = \
layoutparsers.cpp \
pgxmllayoutloader.cpp
INCLUDES = \
$(SDL_CFLAGS) \
$(SIGC_CFLAGS) \
$(SIGCX_CFLAGS) \
-I$(top_srcdir)/include
style_cvs:
astyle --style=kr --indent=tab=4 --indent-switches *.cpp
style_personal:
astyle *.cpp
--- NEW FILE ---
#include "pgxmltag.h"
#include "pgwidget.h"
#include "pgbutton.h"
#include "pglabel.h"
#include "pglistboxitem.h"
#include "pglog.h"
void PG_Widget::ParseXMLAttributes(PG_XMLTag& xmltag) {
PG_LogMSG("PG_XMLLayoutObject<PG_Widget>::ParseXMLAttributes()");
int w, h;
SetText(xmltag.GetString("text").c_str());
PG_Rect pos = xmltag.GetRect("pos", GetParent());
w = xmltag.GetInt("width");
h = xmltag.GetInt("height");
if(w > 0) {
pos.w = w;
}
if(h > 0) {
pos.h = h;
}
MoveWidget(pos);
int x = xmltag.GetInt("id");
if(x > 0) {
SetID(x);
}
x = xmltag.GetInt("fsize");
if(x > 0) {
SetFontSize(x);
}
}
void PG_Label::ParseXMLAttributes(PG_XMLTag& xmltag) {
PG_LogMSG("PG_XMLLayoutObject<PG_Label>::ParseXMLAttributes()");
PG_Widget::ParseXMLAttributes(xmltag);
SetAlignment(xmltag.GetAlignment("align"));
}
void PG_Button::ParseXMLAttributes(PG_XMLTag& xmltag) {
PG_LogMSG("PG_XMLLayoutObject<PG_Button>::ParseXMLAttributes()");
PG_Widget::ParseXMLAttributes(xmltag);
}
void PG_ListBoxItem::ParseXMLAttributes(PG_XMLTag& xmltag) {
PG_LogMSG("PG_XMLLayoutObject<PG_ListBoxItem>::ParseXMLAttributes()");
PG_ListBoxBaseItem::ParseXMLAttributes(xmltag);
}
--- NEW FILE ---
#include "pgxmllayoutloader.h"
#include "pgwidget.h"
#include "pgapplication.h"
#include "pglog.h"
#include "pgdraw.h"
#include "expat.h"
#include "pgfactory.h"
#include <stack>
#define XML_BUFF_SIZE 512
class PG_XMLParseUserData {
public:
XML_Parser parser;
PG_XML_SECTION section;
PG_Widget* parent;
PG_Widget* currentwidget;
PG_XMLLayoutLoader* caller;
PG_XMLParseUserData() {
parser = XML_ParserCreate(NULL);
section = DOC;
parent = NULL;
currentwidget = NULL;
}
void push() {
stack_parent.push(parent);
stack_widget.push(currentwidget);
stack_section.push(section);
}
void pop() {
parent = stack_parent.top();
currentwidget = stack_widget.top();
section = stack_section.top();
stack_parent.pop();
stack_widget.pop();
stack_section.pop();
}
private:
std::stack<PG_Widget*> stack_parent;
std::stack<PG_Widget*> stack_widget;
std::stack<PG_XML_SECTION> stack_section;
};
PG_XMLTagList::PG_XMLTagList(const char** atts) {
if(atts == NULL) {
return;
}
std::string xmltag;
std::string value;
while(*atts != NULL) {
xmltag = *atts;
atts++;
value = *atts;
atts++;
(*this)[xmltag] = value;
}
}
PG_XMLTag::PG_XMLTag(const char* n, const char** a, PG_XML_SECTION sec) :
taglist(a), section(sec) {
if(n != NULL) {
name = n;
}
}
void PG_XMLTag::Log() {
PG_LogMSG("Tagname: %s", name.c_str());
PG_LogMSG("Section: %i", section);
PG_LogMSG("Attributes: %i", taglist.size());
for(PG_XMLTagList::iterator i = taglist.begin(); i != taglist.end();
i++) {
PG_LogMSG("%s: %s", (*i).first.c_str(), (*i).second.c_str());
}
}
PG_Rect PG_XMLTag::GetRect(const char* name, PG_Widget* parent) {
PG_Rect result;
std::string value = taglist[name];
if(value.empty()) {
return result;
}
PG_Draw::PG_DrawableSurface* screen = PG_Application::GetScreen();
char* parm;
char *d;
char tmp[16];
int i=0;
int mx;
int r[4];
r[0] = r[1] = r[2] = r[3] = 0;
parm = strdup(value.c_str());
// PG_LogDBG("ParaGUI[%s]: %s:%i", __FILE__, __FUNCTION__, __LINE__);
for(d = strtok(parm,","); d != NULL; d = strtok(NULL,",")) {
if(parent == NULL) {
mx = ((i%2)==0) ? screen->GetWidth() :
screen->GetHeight();
} else {
mx = ((i%2)==0) ? parent->w : parent->h;
}
if( sscanf(d, "%d%[%]", & r[i], tmp) == 2 )
r[i] = (int) ((float)r[i]*mx/100);
if(r[i]<0)
r[i] = mx+r[i];
i++;
}
result.SetRect(r[0], r[1], r[2], r[3]);
fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
free(parm);
return result;
}
int PG_XMLTag::GetInt(const char* name) {
return atoi(taglist[name].c_str());
}
int PG_XMLTag::GetAlignment(const char* name) {
int result = PG_TA_LEFT;
std::string value = taglist[name];
if(value.empty()) {
return result;
}
if (value == "left")
result = PG_TA_LEFT;
if (value == "right")
result = PG_TA_RIGHT;
if (value == "center")
result = PG_TA_CENTER;
if (result == -1) {
PG_LogWRN("Unknown align type %s !", value.c_str());
}
return result;
}
int PG_XMLTag::GetBackmode(const char* name) {
int result = BKMODE_TILE;
std::string value = taglist[name];
if (value == "tile")
result = BKMODE_TILE;
if (value == "stretch")
result = BKMODE_STRETCH;
if (value == "h3tile")
result = BKMODE_3TILEH;
if (value == "v3tile")
result = BKMODE_3TILEV;
return result;
}
PG_Gradient* PG_XMLTag::GetGradient(const char* name) {
std::string value = taglist[name];
int r1,g1,b1,r2,g2,b2,r3,g3,b3,r4,g4,b4;
if(value.empty()) {
return NULL;
}
sscanf(value.c_str(),"%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d,%d",&r1,&g1,&b1,&r2,&g2,&b2,&r3,&g3,&b3,&r4,&g4,&b4);
PG_Gradient* result = new PG_Gradient;
result->colors[0].r = r1;
result->colors[0].g = g1;
result->colors[0].b = b1;
result->colors[1].r = r2;
result->colors[1].g = g2;
result->colors[1].b = b2;
result->colors[2].r = r3;
result->colors[2].g = g3;
result->colors[2].b = b3;
result->colors[3].r = r4;
result->colors[3].g = g4;
result->colors[3].b = b4;
return result;
}
bool PG_XMLLayoutLoader::Load(PG_Widget* parent, const char* filename) {
bool status = true;
int bytes_pos = 0;
PG_XMLParseUserData XMLParser;
fprintf(stderr, "%s:%s:%i\n", __FILE__, __FUNCTION__, __LINE__);
XMLParser.parent = parent;
XMLParser.caller = this;
XML_SetUserData(XMLParser.parser, &XMLParser);
XML_SetElementHandler(XMLParser.parser,
PG_XMLLayoutLoader::XMLStartDoc, PG_XMLLayoutLoader::XMLEndDoc);
PG_File* f = PG_FileArchive::OpenFile(filename);
if (f == NULL) {
PG_LogWRN("Layout file %s not found !", filename);
return false;
}
for (;;) {
int bytes_read;
void* buff;
if ((buff = XML_GetBuffer(XMLParser.parser, XML_BUFF_SIZE)) ==
NULL) {
PG_LogWRN("Can`t get parse buffer");
status = false;
break;
}
bytes_read = f->read(buff, XML_BUFF_SIZE);
bytes_pos += bytes_read;
/*if (WorkCallback != NULL) {
WorkCallback(bytes_pos , f->fileLength());
}*/
if (XML_ParseBuffer(XMLParser.parser, bytes_read, bytes_read ==
0) == 0) {
PG_LogWRN("%s on the line %d pos
%d",XML_ErrorString(XML_GetErrorCode(XMLParser.parser)),XML_GetCurrentLineNumber(XMLParser.parser),
XML_GetCurrentColumnNumber(XMLParser.parser));
status = false;
break;
}
if (bytes_read == 0) {
status = true;
break;
}
}
if (XMLParser.parser != NULL) {
XML_ParserFree(XMLParser.parser);
}
delete f;
return status;
}
void PG_XMLLayoutLoader::XMLStartDoc(void *userData, const char *name, const
char **atts) {
// get pointer to our private parser data
PG_XMLParseUserData* parser =
static_cast<PG_XMLParseUserData*>(userData);
// put our status on the stack
parser->push();
std::string n = name;
if(n == "layout") {
parser->section = LAYOUT;
}
else if(n == "head") {
parser->section = HEAD;
}
else if(n == "body") {
parser->section = BODY;
return;
}
else if(parser->section == BODY) {
parser->section = WIDGET;
}
// create new tag object
PG_XMLTag xmltag(name, atts, parser->section);
// fac-to-ry
if(xmltag.section == BODY || xmltag.section == WIDGET) {
PG_LogDBG("createobject (parent = 0x%08x)", parser->parent);
parser->currentwidget = PG_Factory::CreateObject(xmltag.name,
parser->parent);
if(parser->currentwidget != NULL) {
parser->currentwidget->ParseXMLAttributes(xmltag);
parser->parent = parser->currentwidget;
}
else {
PG_LogWRN("Unknown factory object '%s' !!!",
xmltag.name.c_str());
}
}
// execute it
parser->caller->sigStartTag(xmltag);
}
void PG_XMLLayoutLoader::XMLEndDoc(void *userData, const char *name) {
PG_XMLParseUserData* parser =
static_cast<PG_XMLParseUserData*>(userData);
// create new tag object
PG_XMLTag xmltag(name, NULL, parser->section);
// execute it
parser->caller->sigEndTag(xmltag);
if(parser->section == WIDGET) {
if(parser->currentwidget != NULL) {
parser->currentwidget->Show();
}
}
// get our status from the stack
parser->pop();
}
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [paragui-cvs] CVS: paragui/src/layout Makefile.am,NONE,1.2.2.1 layoutparsers.cpp,NONE,1.5.2.1 pgxmllayoutloader.cpp,NONE,1.6.2.1,
Teunis Peters <address@hidden> <=
- Prev by Date:
[paragui-cvs] CVS: paragui/src/draw/opengl glpriv.hh,NONE,1.1.2.1 pgglcore.cpp,NONE,1.1.2.1 pgglmem.cpp,NONE,1.1.2.1 pggloper.cpp,NONE,1.1.2.1
- Next by Date:
[paragui-cvs] CVS: paragui/src/factory Makefile.am,NONE,1.2.2.1 pgfactory.cpp,NONE,1.5.2.1
- Previous by thread:
[paragui-cvs] CVS: paragui/src/draw/opengl glpriv.hh,NONE,1.1.2.1 pgglcore.cpp,NONE,1.1.2.1 pgglmem.cpp,NONE,1.1.2.1 pggloper.cpp,NONE,1.1.2.1
- Next by thread:
[paragui-cvs] CVS: paragui/src/factory Makefile.am,NONE,1.2.2.1 pgfactory.cpp,NONE,1.5.2.1
- Index(es):