// Returns on the layer's textures. const Texture* FontFaceLayer::GetTexture(int index) { ROCKET_ASSERT(index >= 0); ROCKET_ASSERT(index < GetNumTextures()); return textures[index]; }
// Returns one of the layout's textures. TextureLayoutTexture& TextureLayout::GetTexture(int index) { ROCKET_ASSERT(index >= 0); ROCKET_ASSERT(index < GetNumTextures()); return textures[index]; }
// Returns one of the layout's rectangles. TextureLayoutRectangle& TextureLayout::GetRectangle(int index) { ROCKET_ASSERT(index >= 0); ROCKET_ASSERT(index < GetNumRectangles()); return rectangles[index]; }
// Called by a closing line box child. LayoutInlineBox* LayoutBlockBox::CloseLineBox(LayoutLineBox* child, LayoutInlineBox* overflow, LayoutInlineBox* overflow_chain) { ROCKET_ASSERT(context == INLINE); if (child->GetDimensions().x > 0) box_cursor = (child->GetPosition().y - (box.GetPosition().y + position.y)) + child->GetDimensions().y; // If we have any pending floating elements for our parent, then this would be an ideal time to position them. if (!float_elements.empty()) { for (size_t i = 0; i < float_elements.size(); ++i) parent->PositionFloat(float_elements[i], box_cursor); float_elements.clear(); } // Add a new line box. line_boxes.push_back(new LayoutLineBox(this)); if (overflow_chain != NULL) line_boxes.back()->AddChainedBox(overflow_chain); if (overflow != NULL) return line_boxes.back()->AddBox(overflow); return NULL; }
UnicodeRange::UnicodeRange(int _min_codepoint, int _max_codepoint) { min_codepoint = _min_codepoint; max_codepoint = _max_codepoint; ROCKET_ASSERT(min_codepoint <= max_codepoint); }
bool EventListener::Compile() { Rocket::Core::String function_name(64, "Event_%x", this); Rocket::Core::String function_code(64, "def %s():", function_name.CString()); Rocket::Core::StringList lines; Rocket::Core::StringUtilities::ExpandString(lines, source_code, ';'); for (size_t i = 0; i < lines.size(); i++) { // Python doesn't handle \r's, strip em and indent the code correctly function_code += Rocket::Core::String(1024, "\n\t%s", lines[i].CString()).Replace("\r", ""); } ROCKET_ASSERT(element != NULL); PyObject* py_namespace = GetGlobalNamespace(); // Add our function to the namespace PyObject* result = PyRun_String(function_code.CString(), Py_file_input, py_namespace, py_namespace); if (!result) { Rocket::Core::Python::Utilities::PrintError(); return false; } Py_DECREF(result); // Get a handle to our function callable = PyDict_GetItemString(py_namespace, function_name.CString()); Py_INCREF(callable); return true; }
// Adds a new option to the select control. int ElementFormControlSelect::Add(const Rocket::Core::String& rml, const Rocket::Core::String& value, int before, bool selectable) { OnUpdate(); ROCKET_ASSERT(widget != NULL); return widget->AddOption(rml, value, before, false, selectable); }
// Sets the index of the selection. If the new index lies outside of the bounds, it will be clamped. void ElementFormControlSelect::SetSelection(int selection) { OnUpdate(); ROCKET_ASSERT(widget != NULL); widget->SetSelection(selection); }
// Returns one of the select control's option elements. SelectOption* ElementFormControlSelect::GetOption(int index) { OnUpdate(); ROCKET_ASSERT(widget != NULL); return widget->GetOption(index); }
// Removes all options from the select control. void ElementFormControlSelect::RemoveAll() { OnUpdate(); ROCKET_ASSERT(widget != NULL); widget->ClearOptions(); }
// Sets the current value of the form control. void ElementFormControlSelect::SetValue(const Rocket::Core::String& value) { OnUpdate(); ROCKET_ASSERT(widget != NULL); widget->SetValue(value); }
// Removes an option from the select control. void ElementFormControlSelect::Remove(int index) { OnUpdate(); ROCKET_ASSERT(widget != NULL); widget->RemoveOption(index); }
// Adds an element to this block box to be handled as an absolutely-positioned element. void LayoutBlockBox::AddAbsoluteElement(Element* element) { ROCKET_ASSERT(context == BLOCK); AbsoluteElement absolute_element; absolute_element.element = element; PositionBox(absolute_element.position, 0); // If we have an open inline-context block box as our last child, then the absolute element must appear after it, // but not actually close the box. if (!block_boxes.empty() && block_boxes.back()->context == INLINE) { LayoutBlockBox* inline_context_box = block_boxes.back(); float last_line_height = inline_context_box->line_boxes.back()->GetDimensions().y; absolute_element.position.y += (inline_context_box->box_cursor + Math::Max(0.0f, last_line_height)); } // Find the positioned parent for this element. LayoutBlockBox* absolute_parent = this; while (absolute_parent != absolute_parent->offset_parent) absolute_parent = absolute_parent->parent; absolute_parent->absolute_elements.push_back(absolute_element); }
// Adds a new block element to this block box. LayoutBlockBox* LayoutBlockBox::AddBlockElement(Element* element) { ROCKET_ASSERT(context == BLOCK); // Check if our most previous block box is rendering in an inline context. if (!block_boxes.empty() && block_boxes.back()->context == INLINE) { LayoutBlockBox* inline_block_box = block_boxes.back(); LayoutInlineBox* open_inline_box = inline_block_box->line_boxes.back()->GetOpenInlineBox(); if (open_inline_box != NULL) { // There's an open inline box chain, which means this block element is parented to it. The chain needs to // be positioned (if it hasn't already), closed and duplicated after this block box closes. Also, this // block needs to be aware of its parentage, so it can correctly compute its relative position. First of // all, we need to close the inline box; this will position the last line if necessary, but it will also // create a new line in the inline block box; we want this line to be in an inline box after our block // element. if (inline_block_box->Close() != OK) return NULL; interrupted_chain = open_inline_box; } else { // There are no open inline boxes, so this inline box just needs to be closed. if (CloseInlineBlockBox() != OK) return NULL; } } block_boxes.push_back(new LayoutBlockBox(layout_engine, this, element)); return block_boxes.back(); }
// Closes one of the line box's inline boxes. void LayoutLineBox::CloseInlineBox(LayoutInlineBox* inline_box) { ROCKET_ASSERT(open_inline_box == inline_box); open_inline_box = inline_box->GetParent(); box_cursor += GetSpacing(inline_box->GetBox(), Box::RIGHT); }
// Returns the number of options in the select control. int ElementFormControlSelect::GetNumOptions() { OnUpdate(); ROCKET_ASSERT(widget != NULL); return widget->GetNumOptions(); }
// Called by a closing block box child. bool LayoutBlockBox::CloseBlockBox(LayoutBlockBox* child) { ROCKET_ASSERT(context == BLOCK); box_cursor = (child->GetPosition().y - child->box.GetEdge(Box::MARGIN, Box::TOP) - (box.GetPosition().y + position.y)) + child->GetBox().GetSize(Box::MARGIN).y; return CatchVerticalOverflow(); }
HighScores::~HighScores() { ROCKET_ASSERT(instance == this); SaveScores(); instance = NULL; }
void ElementDocument::LockLayout(bool lock) { if (lock) lock_layout++; else lock_layout--; ROCKET_ASSERT(lock_layout >= 0); }
// Returns a reference to one of the rows of the filter kernel. float* ConvolutionFilter::operator[](int index) { ROCKET_ASSERT(kernel != NULL); index = Math::Max(index, 0); index = Math::Min(index, kernel_size - 1); return kernel + kernel_size * index; }
void DataQuery::LoadRow() { ROCKET_ASSERT(current_row <= (int)rows.size()); if (current_row >= (int)rows.size()) { rows.push_back(Rocket::Core::StringList()); data_source->GetRow(rows[current_row], table, offset + current_row, fields); } }
// Removes a reference from the object. void ReferenceCountable::RemoveReference() { ROCKET_ASSERT(reference_count > 0); reference_count--; if (reference_count == 0) { OnReferenceDeactivate(); } }
Core::Element* XMLNodeHandlerDataGrid::ElementStart(Core::XMLParser* parser, const Rocket::Core::String& name, const Rocket::Core::XMLAttributes& attributes) { Core::Element* element = NULL; Core::Element* parent = parser->GetParseFrame()->element; ROCKET_ASSERT(name == "datagrid" || name == "col"); if (name == "datagrid") { // Attempt to instance the grid. element = Core::Factory::InstanceElement(parent, name, name, attributes); ElementDataGrid* grid = dynamic_cast< ElementDataGrid* >(element); if (grid == NULL) { if (element != NULL) element->RemoveReference(); Core::Log::Message(Rocket::Core::Log::LT_ERROR, "Instancer failed to create data grid for tag %s.", name.CString()); return NULL; } // Set the data source and table on the data grid. Rocket::Core::String data_source = attributes.Get< Rocket::Core::String >("source", ""); grid->SetDataSource(data_source); parent->AppendChild(grid); grid->RemoveReference(); // Switch to this handler for all columns. parser->PushHandler("datagrid"); } else if (name == "col") { // Make a new node handler to handle the header elements. element = Core::Factory::InstanceElement(parent, "datagridcolumn", "datagridcolumn", attributes); if (element == NULL) return NULL; ElementDataGrid* grid = dynamic_cast< ElementDataGrid* >(parent); if (grid != NULL) { grid->AddColumn(attributes.Get< Rocket::Core::String >("fields", ""), attributes.Get< Rocket::Core::String >("formatter", ""), attributes.Get< float >("width", 0), element); element->RemoveReference(); } // Switch to element handler for all children. parser->PushDefaultHandler(); } else { ROCKET_ERROR; } return element; }
// Called by Rocket when it wants to release application-compiled geometry. void RocketSFMLRenderer::ReleaseCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry) { #ifdef ENABLE_GLEW MyWindow->SetActive(); delete (RocketSFMLRendererGeometryHandler *)geometry; #else ROCKET_ASSERT(false /*& "Not Implemented"*/); #endif }
// Closes the box. void LayoutInlineBox::Close() { if (chain) chain->Close(); else { ROCKET_ASSERT(line != NULL); line->CloseInlineBox(this); } }
HighScores::HighScores() : Rocket::Controls::DataSource("high_scores") { ROCKET_ASSERT(instance == NULL); instance = this; for (int i = 0; i < NUM_SCORES; i++) { scores[i].score = -1; } LoadScores(); }
// Called by Rocket when it wants to render application-compiled geometry. void RocketSFMLRenderer::RenderCompiledGeometry(Rocket::Core::CompiledGeometryHandle geometry, const Rocket::Core::Vector2f& translation) { #ifdef ENABLE_GLEW MyWindow->setActive(); RocketSFMLRendererGeometryHandler *RealGeometry = (RocketSFMLRendererGeometryHandler *)geometry; glPushMatrix(); glTranslatef(translation.x, translation.y, 0); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); sf::Texture *sfTexture = (sf::Texture *)RealGeometry->Texture; if(sfTexture) { sf::Texture::bind(sfTexture); } else { glBindTexture(GL_TEXTURE_2D, 0); }; glEnable(GL_VERTEX_ARRAY); glEnable(GL_TEXTURE_COORD_ARRAY); glEnable(GL_COLOR_ARRAY); #define BUFFER_OFFSET(x) ((char*)0 + x) glBindBuffer(GL_ARRAY_BUFFER, RealGeometry->VertexID); glVertexPointer(2, GL_FLOAT, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(0)); glTexCoordPointer(2, GL_FLOAT, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(sizeof(sf::Vector2f))); glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(RocketSFMLRendererVertex), BUFFER_OFFSET(sizeof(sf::Vector2f[2]))); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, RealGeometry->IndexID); glDrawElements(GL_TRIANGLES, RealGeometry->NumVertices, GL_UNSIGNED_INT, BUFFER_OFFSET(0)); glBindBuffer(GL_ARRAY_BUFFER, 0); glDisable(GL_COLOR_ARRAY); glDisable(GL_TEXTURE_COORD_ARRAY); glDisable(GL_VERTEX_ARRAY); glColor4f(1, 1, 1, 1); glPopMatrix(); #else ROCKET_ASSERT(false /*& "Not Implemented"*/); #endif }
ConsoleBuffer::ConsoleBuffer() : Rocket::Controls::DataSource("console_buffer") { ROCKET_ASSERT(instance == NULL); instance = this; systemMsgColor = Rocket::Core::Colourb(255, 255, 255); Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(systemMsgColor,systemMsgColorString); moveMsgColor = Rocket::Core::Colourb(0, 0, 255); Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(moveMsgColor,moveMsgColorString); attackMsgColor = Rocket::Core::Colourb(255, 0, 0); Rocket::Core::TypeConverter< Rocket::Core::Colourb, Rocket::Core::String >::Convert(attackMsgColor,attackMsgColorString); this->messages.resize(BUFFER_SIZE); }
Plugin::Plugin() { ROCKET_ASSERT(instance == NULL); instance = this; host_context = NULL; debug_context = NULL; log_hook = NULL; menu_element = NULL; info_element = NULL; log_element = NULL; render_outlines = false; }
// Builds and sets the box for an element. static void SetBox(Element* element) { Element* parent = element->GetParentNode(); ROCKET_ASSERT(parent != NULL); Vector2f containing_block = parent->GetBox().GetSize(); containing_block.x -= parent->GetElementScroll()->GetScrollbarSize(ElementScroll::VERTICAL); containing_block.y -= parent->GetElementScroll()->GetScrollbarSize(ElementScroll::HORIZONTAL); Box box; LayoutEngine::BuildBox(box, containing_block, element); if (element->GetLocalProperty(HEIGHT) == NULL) box.SetContent(Vector2f(box.GetSize().x, containing_block.y)); element->SetBox(box); }