2010-05-29 00:04:04 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Robert Bieber
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2010-05-26 21:13:14 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
#include "symbols.h"
|
2010-06-01 16:44:52 +00:00
|
|
|
#include "tag_table.h"
|
2010-05-26 21:13:14 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
#include "parsetreenode.h"
|
2010-06-01 19:55:20 +00:00
|
|
|
#include "parsetreemodel.h"
|
2010-05-29 00:04:04 +00:00
|
|
|
|
2010-06-23 07:18:22 +00:00
|
|
|
#include "rbimage.h"
|
|
|
|
|
2010-06-21 20:11:58 +00:00
|
|
|
#include <iostream>
|
|
|
|
|
2010-06-02 07:48:48 +00:00
|
|
|
int ParseTreeNode::openConditionals = 0;
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
/* Root element constructor */
|
|
|
|
ParseTreeNode::ParseTreeNode(struct skin_element* data)
|
|
|
|
: parent(0), element(0), param(0), children()
|
|
|
|
{
|
|
|
|
while(data)
|
2010-05-27 19:57:15 +00:00
|
|
|
{
|
2010-05-29 00:04:04 +00:00
|
|
|
children.append(new ParseTreeNode(data, this));
|
|
|
|
data = data->next;
|
2010-05-27 19:57:15 +00:00
|
|
|
}
|
2010-05-26 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
/* Normal element constructor */
|
|
|
|
ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent)
|
|
|
|
: parent(parent), element(data), param(0), children()
|
2010-05-27 19:57:15 +00:00
|
|
|
{
|
2010-05-29 00:04:04 +00:00
|
|
|
switch(element->type)
|
|
|
|
{
|
2010-05-27 19:57:15 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
case TAG:
|
|
|
|
for(int i = 0; i < element->params_count; i++)
|
|
|
|
{
|
|
|
|
if(element->params[i].type == skin_tag_parameter::CODE)
|
|
|
|
children.append(new ParseTreeNode(element->params[i].data.code,
|
|
|
|
this));
|
|
|
|
else
|
|
|
|
children.append(new ParseTreeNode(&element->params[i], this));
|
|
|
|
}
|
|
|
|
break;
|
2010-05-27 19:57:15 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
case CONDITIONAL:
|
2010-06-10 21:02:44 +00:00
|
|
|
for(int i = 0; i < element->params_count; i++)
|
|
|
|
children.append(new ParseTreeNode(&data->params[i], this));
|
|
|
|
for(int i = 0; i < element->children_count; i++)
|
|
|
|
children.append(new ParseTreeNode(data->children[i], this));
|
|
|
|
break;
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
case SUBLINES:
|
|
|
|
for(int i = 0; i < element->children_count; i++)
|
|
|
|
{
|
|
|
|
children.append(new ParseTreeNode(data->children[i], this));
|
|
|
|
}
|
|
|
|
break;
|
2010-05-27 19:57:15 +00:00
|
|
|
|
2010-06-11 19:51:34 +00:00
|
|
|
case VIEWPORT:
|
|
|
|
for(int i = 0; i < element->params_count; i++)
|
|
|
|
children.append(new ParseTreeNode(&data->params[i], this));
|
|
|
|
/* Deliberate fall-through here */
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
case LINE:
|
2010-06-01 18:31:58 +00:00
|
|
|
for(int i = 0; i < data->children_count; i++)
|
2010-05-29 00:04:04 +00:00
|
|
|
{
|
2010-06-01 18:31:58 +00:00
|
|
|
for(struct skin_element* current = data->children[i]; current;
|
|
|
|
current = current->next)
|
|
|
|
{
|
|
|
|
children.append(new ParseTreeNode(current, this));
|
|
|
|
}
|
2010-05-29 00:04:04 +00:00
|
|
|
}
|
|
|
|
break;
|
2010-05-26 21:13:14 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2010-05-26 21:13:14 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
/* Parameter constructor */
|
|
|
|
ParseTreeNode::ParseTreeNode(skin_tag_parameter *data, ParseTreeNode *parent)
|
|
|
|
: parent(parent), element(0), param(data), children()
|
2010-05-26 21:13:14 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-06-18 21:10:01 +00:00
|
|
|
ParseTreeNode::~ParseTreeNode()
|
|
|
|
{
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
delete children[i];
|
|
|
|
}
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
QString ParseTreeNode::genCode() const
|
2010-05-26 21:13:14 +00:00
|
|
|
{
|
2010-05-29 00:04:04 +00:00
|
|
|
QString buffer = "";
|
2010-05-26 21:13:14 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
if(element)
|
|
|
|
{
|
|
|
|
switch(element->type)
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
case UNKNOWN:
|
|
|
|
break;
|
2010-06-01 07:11:23 +00:00
|
|
|
case VIEWPORT:
|
2010-06-11 08:03:32 +00:00
|
|
|
/* Generating the Viewport tag, if necessary */
|
|
|
|
if(element->tag)
|
|
|
|
{
|
|
|
|
buffer.append(TAGSYM);
|
|
|
|
buffer.append(element->tag->name);
|
|
|
|
buffer.append(ARGLISTOPENSYM);
|
|
|
|
for(int i = 0; i < element->params_count; i++)
|
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
if(i != element->params_count - 1)
|
|
|
|
buffer.append(ARGLISTSEPERATESYM);
|
|
|
|
}
|
|
|
|
buffer.append(ARGLISTCLOSESYM);
|
2010-06-02 06:41:41 +00:00
|
|
|
buffer.append('\n');
|
2010-06-11 08:03:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = element->params_count; i < children.count(); i++)
|
2010-06-02 06:41:41 +00:00
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
break;
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
case LINE:
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
}
|
2010-06-10 21:52:53 +00:00
|
|
|
if(openConditionals == 0
|
|
|
|
&& !(parent && parent->element->type == SUBLINES))
|
|
|
|
{
|
2010-06-02 07:48:48 +00:00
|
|
|
buffer.append('\n');
|
2010-06-10 21:52:53 +00:00
|
|
|
}
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case SUBLINES:
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
if(i != children.count() - 1)
|
|
|
|
buffer.append(MULTILINESYM);
|
|
|
|
}
|
2010-06-10 21:52:53 +00:00
|
|
|
if(openConditionals == 0)
|
|
|
|
buffer.append('\n');
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case CONDITIONAL:
|
2010-06-02 07:48:48 +00:00
|
|
|
openConditionals++;
|
2010-06-10 21:52:53 +00:00
|
|
|
|
|
|
|
/* Inserting the tag part */
|
2010-05-29 00:04:04 +00:00
|
|
|
buffer.append(TAGSYM);
|
|
|
|
buffer.append(CONDITIONSYM);
|
2010-06-10 21:52:53 +00:00
|
|
|
buffer.append(element->tag->name);
|
|
|
|
if(element->params_count > 0)
|
|
|
|
{
|
|
|
|
buffer.append(ARGLISTOPENSYM);
|
|
|
|
for(int i = 0; i < element->params_count; i++)
|
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
if( i != element->params_count - 1)
|
|
|
|
buffer.append(ARGLISTSEPERATESYM);
|
|
|
|
buffer.append(ARGLISTCLOSESYM);
|
|
|
|
}
|
|
|
|
}
|
2010-05-29 00:04:04 +00:00
|
|
|
|
|
|
|
/* Inserting the sublines */
|
|
|
|
buffer.append(ENUMLISTOPENSYM);
|
2010-06-10 21:52:53 +00:00
|
|
|
for(int i = element->params_count; i < children.count(); i++)
|
2010-05-29 00:04:04 +00:00
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
if(i != children.count() - 1)
|
|
|
|
buffer.append(ENUMLISTSEPERATESYM);
|
|
|
|
}
|
|
|
|
buffer.append(ENUMLISTCLOSESYM);
|
2010-06-02 07:48:48 +00:00
|
|
|
openConditionals--;
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG:
|
2010-06-10 21:52:53 +00:00
|
|
|
buffer.append(TAGSYM);
|
2010-06-01 16:44:52 +00:00
|
|
|
buffer.append(element->tag->name);
|
2010-05-29 00:04:04 +00:00
|
|
|
|
|
|
|
if(element->params_count > 0)
|
|
|
|
{
|
|
|
|
/* Rendering parameters if there are any */
|
|
|
|
buffer.append(ARGLISTOPENSYM);
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
{
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
if(i != children.count() - 1)
|
|
|
|
buffer.append(ARGLISTSEPERATESYM);
|
|
|
|
}
|
|
|
|
buffer.append(ARGLISTCLOSESYM);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TEXT:
|
2010-06-10 21:02:44 +00:00
|
|
|
for(char* cursor = (char*)element->data; *cursor; cursor++)
|
2010-06-02 05:55:41 +00:00
|
|
|
{
|
|
|
|
if(find_escape_character(*cursor))
|
|
|
|
buffer.append(TAGSYM);
|
|
|
|
buffer.append(*cursor);
|
|
|
|
}
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMENT:
|
|
|
|
buffer.append(COMMENTSYM);
|
2010-06-10 21:02:44 +00:00
|
|
|
buffer.append((char*)element->data);
|
2010-06-01 20:19:51 +00:00
|
|
|
buffer.append('\n');
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(param)
|
|
|
|
{
|
|
|
|
switch(param->type)
|
|
|
|
{
|
|
|
|
case skin_tag_parameter::STRING:
|
2010-06-02 05:55:41 +00:00
|
|
|
for(char* cursor = param->data.text; *cursor; cursor++)
|
|
|
|
{
|
|
|
|
if(find_escape_character(*cursor))
|
|
|
|
buffer.append(TAGSYM);
|
|
|
|
buffer.append(*cursor);
|
|
|
|
}
|
2010-05-29 00:04:04 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
case skin_tag_parameter::NUMERIC:
|
|
|
|
buffer.append(QString::number(param->data.numeric, 10));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case skin_tag_parameter::DEFAULT:
|
|
|
|
buffer.append(DEFAULTSYM);
|
|
|
|
break;
|
|
|
|
|
2010-05-30 01:20:05 +00:00
|
|
|
case skin_tag_parameter::CODE:
|
|
|
|
buffer.append(QObject::tr("This doesn't belong here"));
|
|
|
|
break;
|
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
}
|
|
|
|
}
|
2010-05-26 21:13:14 +00:00
|
|
|
else
|
2010-05-29 00:04:04 +00:00
|
|
|
{
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
buffer.append(children[i]->genCode());
|
|
|
|
}
|
2010-05-26 21:13:14 +00:00
|
|
|
|
2010-05-29 00:04:04 +00:00
|
|
|
return buffer;
|
2010-05-26 21:13:14 +00:00
|
|
|
}
|
2010-05-30 01:20:05 +00:00
|
|
|
|
2010-06-02 20:36:30 +00:00
|
|
|
/* A more or less random hashing algorithm */
|
|
|
|
int ParseTreeNode::genHash() const
|
|
|
|
{
|
|
|
|
int hash = 0;
|
2010-06-10 21:02:44 +00:00
|
|
|
char *text;
|
2010-06-02 20:36:30 +00:00
|
|
|
|
|
|
|
if(element)
|
|
|
|
{
|
|
|
|
hash += element->type;
|
|
|
|
switch(element->type)
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
case UNKNOWN:
|
|
|
|
break;
|
2010-06-02 20:36:30 +00:00
|
|
|
case VIEWPORT:
|
|
|
|
case LINE:
|
|
|
|
case SUBLINES:
|
|
|
|
case CONDITIONAL:
|
|
|
|
hash += element->children_count;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TAG:
|
|
|
|
for(unsigned int i = 0; i < strlen(element->tag->name); i++)
|
|
|
|
hash += element->tag->name[i];
|
|
|
|
break;
|
|
|
|
|
|
|
|
case COMMENT:
|
|
|
|
case TEXT:
|
2010-06-10 21:02:44 +00:00
|
|
|
text = (char*)element->data;
|
|
|
|
for(unsigned int i = 0; i < strlen(text); i++)
|
2010-06-02 20:36:30 +00:00
|
|
|
{
|
|
|
|
if(i % 2)
|
2010-06-10 21:02:44 +00:00
|
|
|
hash += text[i] % element->type;
|
2010-06-02 20:36:30 +00:00
|
|
|
else
|
2010-06-10 21:02:44 +00:00
|
|
|
hash += text[i] % element->type * 2;
|
2010-06-02 20:36:30 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(param)
|
|
|
|
{
|
|
|
|
hash += param->type;
|
|
|
|
switch(param->type)
|
|
|
|
{
|
|
|
|
case skin_tag_parameter::DEFAULT:
|
|
|
|
case skin_tag_parameter::CODE:
|
|
|
|
break;
|
|
|
|
|
|
|
|
case skin_tag_parameter::NUMERIC:
|
|
|
|
hash += param->data.numeric * (param->data.numeric / 4);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case skin_tag_parameter::STRING:
|
|
|
|
for(unsigned int i = 0; i < strlen(param->data.text); i++)
|
|
|
|
{
|
|
|
|
if(i % 2)
|
|
|
|
hash += param->data.text[i] * 2;
|
|
|
|
else
|
|
|
|
hash += param->data.text[i];
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
{
|
|
|
|
hash += children[i]->genHash();
|
|
|
|
}
|
|
|
|
|
|
|
|
return hash;
|
|
|
|
}
|
|
|
|
|
2010-05-30 01:20:05 +00:00
|
|
|
ParseTreeNode* ParseTreeNode::child(int row)
|
|
|
|
{
|
|
|
|
if(row < 0 || row >= children.count())
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
return children[row];
|
|
|
|
}
|
|
|
|
|
|
|
|
int ParseTreeNode::numChildren() const
|
|
|
|
{
|
2010-06-02 20:36:30 +00:00
|
|
|
return children.count();
|
2010-05-30 01:20:05 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
QVariant ParseTreeNode::data(int column) const
|
|
|
|
{
|
|
|
|
switch(column)
|
|
|
|
{
|
2010-06-01 19:55:20 +00:00
|
|
|
case ParseTreeModel::typeColumn:
|
2010-05-30 01:20:05 +00:00
|
|
|
if(element)
|
|
|
|
{
|
|
|
|
switch(element->type)
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
case UNKNOWN:
|
|
|
|
return QObject::tr("Unknown");
|
2010-06-01 07:11:23 +00:00
|
|
|
case VIEWPORT:
|
|
|
|
return QObject::tr("Viewport");
|
|
|
|
|
2010-05-30 01:20:05 +00:00
|
|
|
case LINE:
|
|
|
|
return QObject::tr("Logical Line");
|
|
|
|
|
|
|
|
case SUBLINES:
|
|
|
|
return QObject::tr("Alternator");
|
|
|
|
|
|
|
|
case COMMENT:
|
|
|
|
return QObject::tr("Comment");
|
|
|
|
|
|
|
|
case CONDITIONAL:
|
|
|
|
return QObject::tr("Conditional Tag");
|
|
|
|
|
|
|
|
case TAG:
|
|
|
|
return QObject::tr("Tag");
|
|
|
|
|
|
|
|
case TEXT:
|
|
|
|
return QObject::tr("Plaintext");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(param)
|
|
|
|
{
|
|
|
|
switch(param->type)
|
|
|
|
{
|
|
|
|
case skin_tag_parameter::STRING:
|
|
|
|
return QObject::tr("String");
|
|
|
|
|
|
|
|
case skin_tag_parameter::NUMERIC:
|
|
|
|
return QObject::tr("Number");
|
|
|
|
|
|
|
|
case skin_tag_parameter::DEFAULT:
|
|
|
|
return QObject::tr("Default Argument");
|
|
|
|
|
|
|
|
case skin_tag_parameter::CODE:
|
|
|
|
return QObject::tr("This doesn't belong here");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QObject::tr("Root");
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-01 19:55:20 +00:00
|
|
|
case ParseTreeModel::valueColumn:
|
2010-05-30 01:20:05 +00:00
|
|
|
if(element)
|
|
|
|
{
|
|
|
|
switch(element->type)
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
case UNKNOWN:
|
2010-06-01 07:11:23 +00:00
|
|
|
case VIEWPORT:
|
2010-05-30 01:20:05 +00:00
|
|
|
case LINE:
|
|
|
|
case SUBLINES:
|
|
|
|
return QString();
|
|
|
|
|
2010-06-10 21:02:44 +00:00
|
|
|
case CONDITIONAL:
|
|
|
|
return QString(element->tag->name);
|
|
|
|
|
2010-05-30 01:20:05 +00:00
|
|
|
case TEXT:
|
|
|
|
case COMMENT:
|
2010-06-10 21:02:44 +00:00
|
|
|
return QString((char*)element->data);
|
2010-05-30 01:20:05 +00:00
|
|
|
|
|
|
|
case TAG:
|
2010-06-01 16:44:52 +00:00
|
|
|
return QString(element->tag->name);
|
2010-05-30 01:20:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else if(param)
|
|
|
|
{
|
|
|
|
switch(param->type)
|
|
|
|
{
|
|
|
|
case skin_tag_parameter::DEFAULT:
|
|
|
|
return QObject::tr("-");
|
|
|
|
|
|
|
|
case skin_tag_parameter::STRING:
|
|
|
|
return QString(param->data.text);
|
|
|
|
|
|
|
|
case skin_tag_parameter::NUMERIC:
|
|
|
|
return QString::number(param->data.numeric, 10);
|
|
|
|
|
|
|
|
case skin_tag_parameter::CODE:
|
|
|
|
return QObject::tr("Seriously, something's wrong here");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return QString();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-01 19:55:20 +00:00
|
|
|
case ParseTreeModel::lineColumn:
|
2010-05-30 01:20:05 +00:00
|
|
|
if(element)
|
|
|
|
return QString::number(element->line, 10);
|
|
|
|
else
|
|
|
|
return QString();
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
int ParseTreeNode::getRow() const
|
|
|
|
{
|
|
|
|
if(!parent)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
return parent->children.indexOf(const_cast<ParseTreeNode*>(this));
|
|
|
|
}
|
|
|
|
|
|
|
|
ParseTreeNode* ParseTreeNode::getParent() const
|
|
|
|
{
|
|
|
|
return parent;
|
|
|
|
}
|
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
/* This version is called for the root node and for viewports */
|
2010-06-18 21:10:01 +00:00
|
|
|
void ParseTreeNode::render(const RBRenderInfo& info)
|
2010-05-30 01:20:05 +00:00
|
|
|
{
|
2010-06-18 21:10:01 +00:00
|
|
|
/* Parameters don't get rendered */
|
|
|
|
if(!element && param)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* If we're at the root, we need to render each viewport */
|
|
|
|
if(!element && !param)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
{
|
|
|
|
children[i]->render(info);
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-06-21 20:11:58 +00:00
|
|
|
if(element->type != VIEWPORT)
|
2010-06-18 21:10:01 +00:00
|
|
|
{
|
2010-06-21 20:11:58 +00:00
|
|
|
std::cerr << QObject::tr("Error in parse tree").toStdString()
|
|
|
|
<< std::endl;
|
|
|
|
return;
|
2010-06-18 21:10:01 +00:00
|
|
|
}
|
2010-06-21 20:11:58 +00:00
|
|
|
|
|
|
|
rendered = new RBViewport(element, info);
|
2010-06-22 07:55:50 +00:00
|
|
|
|
|
|
|
for(int i = element->params_count; i < children.count(); i++)
|
|
|
|
children[i]->render(info, dynamic_cast<RBViewport*>(rendered));
|
2010-06-23 07:18:22 +00:00
|
|
|
|
2010-05-30 01:20:05 +00:00
|
|
|
}
|
2010-06-18 21:10:01 +00:00
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
/* This version is called for logical lines and such */
|
|
|
|
void ParseTreeNode::render(const RBRenderInfo &info, RBViewport* viewport)
|
|
|
|
{
|
|
|
|
if(element->type == LINE)
|
|
|
|
{
|
|
|
|
for(int i = 0; i < children.count(); i++)
|
|
|
|
children[i]->render(info, viewport);
|
|
|
|
viewport->newline();
|
|
|
|
}
|
|
|
|
else if(element->type == TAG)
|
|
|
|
{
|
|
|
|
QString filename;
|
2010-06-23 07:18:22 +00:00
|
|
|
QString id;
|
2010-06-23 07:37:48 +00:00
|
|
|
int x, y, tiles, tile;
|
|
|
|
char c;
|
2010-06-23 07:18:22 +00:00
|
|
|
RBImage* image;
|
2010-06-22 07:55:50 +00:00
|
|
|
|
|
|
|
/* Two switch statements to narrow down the tag name */
|
|
|
|
switch(element->tag->name[0])
|
|
|
|
{
|
|
|
|
|
2010-06-23 07:18:22 +00:00
|
|
|
case 'x':
|
|
|
|
switch(element->tag->name[1])
|
|
|
|
{
|
2010-06-23 07:37:48 +00:00
|
|
|
case 'd':
|
|
|
|
/* %xd */
|
|
|
|
id = "";
|
|
|
|
id.append(element->params[0].data.text[0]);
|
|
|
|
c = element->params[0].data.text[1];
|
|
|
|
|
|
|
|
if(c == '\0')
|
|
|
|
{
|
|
|
|
tile = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if(isupper(c))
|
|
|
|
tile = c - 'A' + 25;
|
|
|
|
else
|
|
|
|
tile = c - 'a';
|
|
|
|
}
|
|
|
|
|
|
|
|
image = info.screen()->getImage(id);
|
|
|
|
if(image)
|
|
|
|
{
|
|
|
|
image->setTile(tile);
|
|
|
|
image->show();
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2010-06-23 07:18:22 +00:00
|
|
|
case 'l':
|
|
|
|
/* %xl */
|
|
|
|
id = element->params[0].data.text;
|
|
|
|
filename = info.settings()->value("imagepath", "") + "/" +
|
|
|
|
element->params[1].data.text;
|
|
|
|
x = element->params[2].data.numeric;
|
|
|
|
y = element->params[3].data.numeric;
|
|
|
|
if(element->params_count > 4)
|
|
|
|
tiles = element->params[4].data.numeric;
|
|
|
|
else
|
|
|
|
tiles = 1;
|
|
|
|
|
|
|
|
info.screen()->loadImage(id, new RBImage(filename, tiles, x, y,
|
|
|
|
viewport));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case '\0':
|
|
|
|
/* %x */
|
|
|
|
id = element->params[0].data.text;
|
|
|
|
filename = info.settings()->value("imagepath", "") + "/" +
|
|
|
|
element->params[1].data.text;
|
|
|
|
x = element->params[2].data.numeric;
|
|
|
|
y = element->params[3].data.numeric;
|
|
|
|
image = new RBImage(filename, 1, x, y, viewport);
|
|
|
|
info.screen()->loadImage(id, new RBImage(filename, 1, x, y,
|
|
|
|
viewport));
|
|
|
|
info.screen()->getImage(id)->show();
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-23 19:41:30 +00:00
|
|
|
case 'V':
|
|
|
|
|
|
|
|
switch(element->tag->name[1])
|
|
|
|
{
|
|
|
|
|
|
|
|
case 'b':
|
|
|
|
/* %Vb */
|
|
|
|
viewport->setBGColor(RBScreen::
|
|
|
|
stringToColor(QString(element->params[0].
|
|
|
|
data.text),
|
|
|
|
Qt::white));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'd':
|
|
|
|
/* %Vd */
|
|
|
|
id = element->params[0].data.text;
|
|
|
|
info.screen()->showViewport(id);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'f':
|
|
|
|
/* %Vf */
|
|
|
|
viewport->setFGColor(RBScreen::
|
|
|
|
stringToColor(QString(element->params[0].
|
|
|
|
data.text),
|
|
|
|
Qt::black));
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 'I':
|
|
|
|
/* %VI */
|
|
|
|
info.screen()->makeCustomUI(element->params[0].data.text);
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
2010-06-22 07:55:50 +00:00
|
|
|
case 'X':
|
|
|
|
|
|
|
|
switch(element->tag->name[1])
|
|
|
|
{
|
|
|
|
case '\0':
|
2010-06-23 07:18:22 +00:00
|
|
|
/* %X */
|
2010-06-22 07:55:50 +00:00
|
|
|
filename = QString(element->params[0].data.text);
|
|
|
|
info.screen()->setBackdrop(filename);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|