void script_addField(struct Shader_Script* me, struct ScriptFieldDecl* field) { #ifdef CPARSERVERBOSE printf ("script_addField: adding field %u to script %d (pointer %u)\n",field,me->num,me); #endif vector_pushBack(struct ScriptFieldDecl*, me->fields, field); #ifdef CPARSERVERBOSE { size_t i; for(i=0; i!=vectorSize(me->fields); ++i) { struct ScriptFieldDecl* curField= vector_get(struct ScriptFieldDecl*, me->fields, i); printf ("script_addField, now have field %d of %d, ASCIIname %s:",i,vectorSize(me->fields),fieldDecl_getShaderScriptName(curField->fieldDecl)); printf ("\n"); } } #endif #ifdef HAVE_JAVASCRIPT /* only do this for scripts */ if (me->ShaderScriptNode != NULL) { if (me->ShaderScriptNode->_nodeType==NODE_Script) scriptFieldDecl_jsFieldInit(field, me->num); } #endif /* HAVE_JAVASCRIPT */ }
/** * Returns the (spanning) column with the greatest difference between * childSize.x and the sum of the columns it spans (divided by the number of * columns it spans). * * @param self The table to determine the most undersized column of. * @param rowHeight An array containing the current column heights of the column * in the table. * @param childSize The desired (min/max) size of the children in the table. * @return The offset of the most undersized column in the table in the * WIDGET(self)->children array, or -1 if there are no such rows. * @see tableGetMostOversizedRow */ static int tableGetMostOversizedColumn(const table *self, const int *columnWidth, const size *childSize) { int i; float maxDelta = 0.0f; int maxDeltaIndex = -1; const int numChildren = vectorSize(WIDGET(self)->children); for (i = 0; i < numChildren; i++) { const childPositionInfo *pos = vectorAt(self->childPositions, i); // See if the column is a spanning column if (pos->colspan != 1) { float sum = tablePartialSum(columnWidth, pos->column - 1, pos->colspan); // If the column is wider than the sum of its spanned columns if (childSize[i].x > sum) { float delta = (childSize[i].x - sum) / (float) pos->colspan; if (delta > maxDelta) { maxDelta = delta; maxDeltaIndex = i; } } } } return maxDeltaIndex; }
void widgetDisableImpl(widget *self) { int i; eventMisc evt; // If we are currently disabled, return if (!self->isEnabled) { return; } // Disable ourself self->isEnabled = false; // Fire any on-disable callbacks evt.event = widgetCreateEvent(EVT_DISABLE); widgetFireCallbacks(self, (event *) &evt); // Disable our children for (i = 0; i < vectorSize(self->children); i++) { widgetDisable(vectorAt(self->children, i)); } }
widget *widgetFindById(widget *self, const char *id) { // See if we have that ID if (strcmp(self->id, id) == 0) { return self; } // Try our children else { int i; for (i = 0; i < vectorSize(self->children); i++) { // Get the child widget widget *child = vectorAt(self->children, i); // Call its findById method widget *match = widgetFindById(child, id); // If it matched, return if (match) { return match; } } } // If we found nothing return NULL return NULL; }
bool tableAddChildWithSpanAlign(table *self, widget *child, int row, int rowspan, vAlign v, int column, int colspan, hAlign h) { int i, j; const int rowCount = tableGetRowCount(self); const int columnCount = tableGetColumnCount(self); childPositionInfo *pos; // First, check the row and column is valid assert(row > 0 && row <= tableGetRowCount(self) + 1); assert(column > 0 && column <= tableGetColumnCount(self) + 1); // Second, check all of the cells spanned are empty for (i = row; i < row + rowspan && i <= rowCount; i++) { for (j = column; j < column + colspan && j <= columnCount; j++) { assert(tableGetCell(self, i, j) == NULL); } } // Update the row and column counts self->numRows = MAX(rowCount, row + rowspan - 1); self->numColumns = MAX(columnCount, column + colspan - 1); // Add positional information regarding the child to our list pos = malloc(sizeof(childPositionInfo)); pos->row = row; pos->rowspan = rowspan; pos->column = column; pos->colspan = colspan; pos->vAlignment = v; pos->hAlignment = h; vectorAdd(self->childPositions, pos); // Call widgetAddChildImpl, which will add the child and re-do the layout if (widgetAddChildImpl(WIDGET(self), child)) { return true; } // Problem adding the child; positional information needs to be restored else { vectorRemoveAt(self->childPositions, vectorSize(self->childPositions) - 1); // Release the memory we malloc'ed earlier free(pos); // Restore the row and column counts self->numRows = rowCount; self->numColumns = columnCount; return false; } }
bool widgetFireCallbacksImpl(widget *self, const event *evt) { int i; bool ret; for (i = 0; i < vectorSize(self->eventVtbl); i++) { eventTableEntry *handler = vectorAt(self->eventVtbl, i); // If handler is registered to handle evt if (handler->type == evt->type) { // Fire the callback ret = handler->callback(self, evt, handler->id, handler->userData); // Update the last called time handler->lastCalled = evt->time; // Break if the handler returned false if (!ret) { break; } } } // FIXME return true; }
void widgetRemoveChildImpl(widget *self, widget *child) { int i; for (i = 0; i < vectorSize(self->children); i++) { // If the child is the to-be-removed widget, remove it if (vectorAt(self->children, i) == child) { // Call the destructor for the widget widgetDestroy(vectorAt(self->children, i)); // Remove it from the list of children vectorRemoveAt(self->children, i); // Re-layout the window (so long as we are part of one) if (self->size.x != -1.0f && self->size.y != -1.0f) { widgetDoLayout(widgetGetRoot(self)); } } // See if it is one of its children else if (child->parent != self) { widgetRemoveChild(vectorAt(self->children, i), child); } } }
void widgetRemoveEventHandlerImpl(widget *self, int id) { int i; // Search for the handler with the id for (i = 0; i < vectorSize(self->eventVtbl); i++) { eventTableEntry *handler = vectorAt(self->eventVtbl, i); // If the handler matches, remove it if (handler->id == id) { // If there is a destructor; call it if (handler->destructor) { // Generate an EVT_DESTRUCT event eventMisc evtDestruct; evtDestruct.event = widgetCreateEvent(EVT_DESTRUCT); handler->destructor(self, (event *) &evtDestruct, handler->id, handler->userData); } // Release the handler free(handler); // Finally, remove the event handler from the table vectorRemoveAt(self->eventVtbl, i); break; } } }
bool widgetAddChildImpl(widget *self, widget *child) { // Make sure the id of the child is unquie assert(widgetFindById(widgetGetRoot(self), child->id) == NULL); // Make sure the child does not currently have a parent assert(child->parent == NULL); // Add the widget vectorAdd(self->children, child); // So long as our size is not (-1,-1) (NULL-size), re-layout the window if ((self->size.x == -1.0f && self->size.y == -1.0f) || widgetDoLayout(widgetGetRoot(self))) { // Set ourself as its parent child->parent = self; return true; } // Not enough space to fit the widget (widgetDoLayout returned false) else { // Remove child *without* calling its destructor vectorRemoveAt(self->children, vectorSize(self->children) - 1); // Restore the layout widgetDoLayout(widgetGetRoot(self)); return false; } }
void update_node(struct X3D_Node *node) { int i; #ifdef VERBOSE printf ("update_node for %d %s nparents %d renderflags %x\n",node, stringNodeType(node->_nodeType),node->_nparents, node->_renderFlags); if (node->_nparents == 0) { if (node == rootNode) printf ("...no parents, this IS the rootNode\n"); else printf ("...no parents, this IS NOT the rootNode\n"); } for (i = 0; i < node->_nparents; i++) { struct X3D_Node *n = X3D_NODE(node->_parents[i]); if( n != 0 ) { printf (" parent %u is %s\n",n,stringNodeType(n->_nodeType)); } else { printf (" parent %d is NULL\n",i); } } #endif node->_change ++; /* parentVector here yet?? */ if (node->_parentVector == NULL) { return; } for (i = 0; i < vectorSize(node->_parentVector); i++) { struct X3D_Node *n = vector_get(struct X3D_Node *, node->_parentVector,i); if(n == node) { fprintf(stderr, "Error: self-referential node structure! (node:'%s')\n", stringNodeType(node->_nodeType)); vector_set(struct X3D_Node*, node->_parentVector, i,NULL); } else if( n != 0 ) {
void ReportDialog::on_vectorButton_clicked() { bool ok; QString vectorSize("(" + QString::number(SimulationEngine::getInstance().places->count()) + "):"); QString vectorString = QInputDialog::getText(this, "Conservation respect to the vector", "Vector"+vectorSize, QLineEdit::Normal, "eg. 3,5,6,8", &ok); QStringList vectorElementsString = vectorString.split(","); QVector<int> weights; for (QString string : vectorElementsString){ int value = string.toInt(&ok); if (ok) { weights.append(value); } } SimulationEngine &simulationEngine = SimulationEngine::getInstance(); if (weights.count() != simulationEngine.places->count()){ ui->reportTextEdit->append("<b>Invalid vector size</b>"); } else { QString conservation = simulationEngine.generateConservationReportRespectToVector(weights); QString conservationReport = "<b>Net conservation for a given vector: " + vectorElementsString.join('\n') + "</b>"; ui->reportTextEdit->append(conservationReport); ui->reportTextEdit->append(conservation); } }
/** * Returns the (spanning) row with the greatest difference between childSize.y * and the sum of the rows it spans (divided by the number of rows it spans). * * This function is integral to solving the problem about how to decide which * rows to increase the height of when handing spanning rows. This is because * the order in which we increase the size of rows affects the final layout. * * @param self The table to determine the most undersized row of. * @param rowHeight An array containing the current row heights of the rows in * the table. * @param childSize The desired (min/max) size of the children in the table. * @return The offset of the most undersized row in the table in the * WIDGET(self)->children array, or -1 if there are no such rows. */ static int tableGetMostOversizedRow(const table *self, const int *rowHeight, const size *childSize) { int i; float maxDelta = 0.0f; int maxDeltaIndex = -1; const int numChildren = vectorSize(WIDGET(self)->children); for (i = 0; i < numChildren; i++) { const childPositionInfo *pos = vectorAt(self->childPositions, i); // See if the row is a spanning row if (pos->rowspan != 1) { float sum = tablePartialSum(rowHeight, pos->row - 1, pos->rowspan); // If the row is higher than the sum of its spanned rows if (childSize[i].y > sum) { float delta = (childSize[i].y - sum) / (float) pos->rowspan; if (delta > maxDelta) { maxDelta = delta; maxDeltaIndex = i; } } } } return maxDeltaIndex; }
widget *tableGetCell(const table *self, int row, int column) { int i; const int numChildren = vectorSize(WIDGET(self)->children); // Ensure that row and column are valid assert(row > 0 && row <= tableGetRowCount(self)); assert(column > 0 && column <= tableGetColumnCount(self)); // Search through the list of children until we find one matching for (i = 0; i < numChildren; i++) { // Legal as widget->children and table->childPositions are siblings const childPositionInfo *pos = vectorAt(self->childPositions, i); // See if it is a match if (row >= pos->row && row < pos->row + pos->rowspan && column >= pos->column && column < pos->column + pos->colspan) { // We've found the widget return vectorAt(WIDGET(self)->children, i); } } // If the cell is empty, return NULL return NULL; }
void widgetCompositeImpl(widget *self) { float blendColour[4]; int i; // Do not composite unless we are visible if (!self->isVisible) { return; } // Save the current model-view matrix glPushMatrix(); // Translate such that (0,0) is the top-left of ourself glTranslatef(self->offset.x, self->offset.y, 0.0f); // Scale if necessary glScalef(self->scale.x, self->scale.y, 1.0f); // Rotate ourself glRotatef(self->rotate, 0.0f, 0.0f, 1.0f); // Set our alpha (blend colour) glGetFloatv(GL_BLEND_COLOR, blendColour); glBlendColor(1.0f, 1.0f, 1.0f, blendColour[3] * self->alpha); // Composite ourself glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self->textureId); glBegin(GL_TRIANGLE_STRIP); glTexCoord2f(0.0f, self->size.y); glVertex2f(0.0f, self->size.y); glTexCoord2f(0.0f, 0.0f); glVertex2f(0.0f, 0.0f); glTexCoord2f(self->size.x, self->size.y); glVertex2f(self->size.x, self->size.y); glTexCoord2f(self->size.x, 0.0f); glVertex2f(self->size.x, 0.0f); glEnd(); // Now our children for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); // Composite widgetComposite(child); } // Restore the model-view matrix glPopMatrix(); // Restore the blend colour glBlendColor(1.0f, 1.0f, 1.0f, blendColour[3]); }
void widgetDraw(widget *self) { int i; // See if we need to be redrawn if (self->needsRedraw) { void *bits = cairo_image_surface_get_data(cairo_get_target(self->cr)); self->needsRedraw = false; // Mark the texture as needing uploading self->textureNeedsUploading = true; // Clear the current context cairo_set_operator(self->cr, CAIRO_OPERATOR_SOURCE); cairo_set_source_rgba(self->cr, 0.0, 0.0, 0.0, 0.0); cairo_paint(self->cr); // Restore the compositing operator back to the default cairo_set_operator(self->cr, CAIRO_OPERATOR_OVER); // Save (push) the current context cairo_save(self->cr); // Redaw ourself widgetDoDraw(self); // Restore the context cairo_restore(self->cr); // Update the texture if widgetEndGL has not done it for us if (self->textureNeedsUploading) { // Flush the cairo surface to ensure that all drawing is completed cairo_surface_flush(cairo_get_target(self->cr)); glBindTexture(GL_TEXTURE_RECTANGLE_ARB, self->textureId); glTexImage2D(GL_TEXTURE_RECTANGLE_ARB, 0, GL_RGBA, self->size.x, self->size.y, 0, GL_BGRA, GL_UNSIGNED_BYTE, bits); self->textureNeedsUploading = false; } } // Draw our children (even if we did not need redrawing our children might) for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); // Ask the child to re-draw itself widgetDraw(child); } }
void deleteScript(struct Shader_Script* me) { size_t i; for(i=0; i!=vectorSize(me->fields); ++i) deleteScriptFieldDecl(vector_get(struct ScriptFieldDecl*, me->fields, i)); deleteVector(struct ScriptFieldDecl*, me->fields); FREE_IF_NZ (me); /* FIXME: JS-handle is not freed! */ }
struct ScriptFieldDecl* script_getField(struct Shader_Script* me, indexT n, indexT mod) { size_t i; for(i=0; i!=vectorSize(me->fields); ++i) { struct ScriptFieldDecl* curField= vector_get(struct ScriptFieldDecl*, me->fields, i); if(scriptFieldDecl_isField(curField, n, mod)) return curField; } return NULL; }
void widgetResizeImpl(widget *self, int w, int h) { const size minSize = widgetGetMinSize(self); const size maxSize = widgetGetMaxSize(self); // Create an event eventResize evtResize; evtResize.event = widgetCreateEvent(EVT_RESIZE); // Save the current size in the event evtResize.oldSize = self->size; assert(minSize.x <= w); assert(minSize.y <= h); assert(w <= maxSize.x); assert(h <= maxSize.y); self->size.x = w; self->size.y = h; // Re-create the cairo context at this new size widgetCairoCreate(&self->cr, CAIRO_FORMAT_ARGB32, w, h); // If a mask is enabled; re-create it also if (self->maskEnabled) { widgetCairoCreate(&self->maskCr, CAIRO_FORMAT_A1, w, h); // Re-draw the mask (only done on resize) widgetDrawMask(self); } // If OpenGL is enabled disable and re-enable it if (self->openGLEnabled) { widgetDisableGL(self); widgetEnableGL(self); } // Set the needs redraw flag self->needsRedraw = true; // If we have any children, we need to redo their layout if (vectorSize(self->children)) { widgetDoLayout(self); } // Fire any EVT_RESIZE callbacks widgetFireCallbacks(self, (event *) &evtResize); }
/* look for the field, via the ASCII name. Slower than script_getField, though... */ struct ScriptFieldDecl* script_getField_viaCharName (struct Shader_Script* me, const char *name) { size_t i; struct CRjsnameStruct *JSparamnames = getJSparamnames(); for(i=0; i!=vectorSize(me->fields); ++i) { struct ScriptFieldDecl* curField= vector_get(struct ScriptFieldDecl*, me->fields, i); if(strcmp(name,fieldDecl_getShaderScriptName(curField->fieldDecl)) == 0) return curField; } return NULL; }
/** * Passes the event, evt, onto each child of self. * * @param self The widget to dispatch the event for. * @param evt The event to dispatch. * @return True if any child widgets of self handled the event, false if self * either has no children or if none of them handled the event. */ static bool widgetDispatchEventToChildren(widget *self, const event *evt) { int i; const int numChildren = vectorSize(self->children); bool handled = false; for (i = 0; i < numChildren; i++) { // 'We' handled the event if any of our children handled it if (widgetHandleEvent(vectorAt(self->children, i), evt)) { handled = true; } } return handled; }
void printInnerMatrix(const Vector *v) { int i; Item item; for (i = 0; i < vectorSize(v); i++) { item = vectorLoad(v, i); if (item.ind == COMP) printf("(%.2lf, %.2lf) ", item.c.a, item.c.b); else printf("%d ", item.ind); } printf("\n"); }
bool widgetFireTimerCallbacksImpl(widget *self, const event *evt) { int i; bool ret; eventTimer evtTimer = *((eventTimer *) evt); // We should only be passed EVT_TIMER events assert(evt->type == EVT_TIMER); for (i = 0; i < vectorSize(self->eventVtbl); i++) { eventTableEntry *handler = vectorAt(self->eventVtbl, i); // See if the handler is registered to handle timer events if (handler->type == EVT_TIMER_SINGLE_SHOT || handler->type == EVT_TIMER_PERSISTENT) { // See if the event needs to be fired if (evt->time >= (handler->lastCalled + handler->interval)) { // Ensure the type of our custom event matches evtTimer.event.type = handler->type; // Fire the associated callback ret = handler->callback(self, (event *) &evtTimer, handler->id, handler->userData); // Update the last called time handler->lastCalled = evt->time; // If the event is single shot then remove it if (handler->type == EVT_TIMER_SINGLE_SHOT) { widgetRemoveEventHandler(self, handler->id); } } } } // FIXME return true; }
/** * Returns a pointer to the event handler with an id of id. Should id be invalid * then NULL is returned. * * @param self The widget whose event handler table to search. * @param id The id of the desired event handler. * @return A pointer to the event handler, or NULL if id is invalid. */ static eventTableEntry *widgetGetEventHandlerById(const widget *self, int id) { int i; eventTableEntry *entry = NULL; // Search the event handler table for (i = 0; i < vectorSize(self->eventVtbl); i++) { eventTableEntry *currEntry = vectorAt(self->eventVtbl, id); // See if the id matches if (currEntry->id == id) { entry = currEntry; break; } } return entry; }
void tableRemoveChildImpl(widget *self, widget *child) { // If we are not the childs parent, delegate to widgetRemoveChildImpl if (self != child->parent) { widgetRemoveChildImpl(self, child); } // We are the childs parent, so there is some bookkeeping to tend to else { int i; // Find the index of the child for (i = 0; i < vectorSize(self->children); i++) { if (child == vectorAt(self->children, i)) { break; } } // Call the child's destructor and remove it widgetDestroy(vectorAt(self->children, i)); vectorRemoveAt(self->children, i); // Remove the childs positional information free(vectorAt(TABLE(self)->childPositions, i)); vectorRemoveAt(TABLE(self)->childPositions, i); // Remove any empty rows/columns tableRemoveEmptyRows(TABLE(self)); tableRemoveEmptyColumns(TABLE(self)); // Redo the layout of the window if (self->size.x != -1 && self->size.y != -1) { widgetDoLayout(widgetGetRoot(self)); } } }
/** * Removes any rows from the table which no cells occupy. * * @param self The table to remove empty rows from. */ static void tableRemoveEmptyRows(table *self) { int i, j, k; const int columnCount = tableGetColumnCount(self); const int numChildren = vectorSize(WIDGET(self)->children); // Iterate over each row of the table for (i = 1; i <= tableGetRowCount(self); i++) { // See if any of the columns in the row are occupied for (j = 1; j <= columnCount; j++) { if (tableGetCell(self, i, j)) { break; } } // If the cells are all empty, we can remove the row if (j > columnCount) { // Find all cells in rows after the one to be removed for (k = 0; k < numChildren; k++) { childPositionInfo *pos = vectorAt(self->childPositions, k); // Decrease the row number of all rows > i by 1 if (pos->row > i) { pos->row--; } } // The table now has one fewer rows in it self->numRows--; i--; } } }
widget *widgetGetCurrentlyFocused(widget *self) { int i; if (!self->hasFocus) { return NULL; } for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); if (child->hasFocus) { return widgetGetCurrentlyFocused(child); } } // None of our children are focused, return ourself return self; }
void widgetEnableImpl(widget *self) { int i; eventMisc evt; // First make sure our parent is enabled if (self->parent && !self->parent->isEnabled) { return; } // Enable ourself self->isEnabled = true; // Fire any on-enable callbacks evt.event = widgetCreateEvent(EVT_ENABLE); widgetFireCallbacks(self, (event *) &evt); // Enable all of our children for (i = 0; i < vectorSize(self->children); i++) { widgetEnable(vectorAt(self->children, i)); } }
void widgetFocusImpl(widget *self) { eventMisc evt; // Check that we are not currently focused if (self->hasFocus) { int i; // Blur any of our currently focused child widgets for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); if (child->hasFocus) { widgetBlur(child); } } return; } // If we have a parent, focus it if (self->parent) { widgetFocus(self->parent); } // Focus ourself self->hasFocus = true; // Fire our on-focus callbacks evt.event = widgetCreateEvent(EVT_FOCUS); widgetFireCallbacks(self, (event *) &evt); }
widget *widgetGetCurrentlyMousedOver(widget *self) { int i; // Make sure we have the mouse if (!self->hasMouse) { return NULL; } // See if any of our children are moused over for (i = 0; i < vectorSize(self->children); i++) { widget *child = vectorAt(self->children, i); if (child->hasMouse) { return widgetGetCurrentlyMousedOver(child); } } // None of our children have the mouse; return ourself return self; }
object vectorAppend(Thread* t, object vector, object value) { if (vectorLength(t, vector) == vectorSize(t, vector)) { PROTECT(t, vector); PROTECT(t, value); object newVector = makeVector (t, vectorSize(t, vector), max(16, vectorSize(t, vector) * 2)); if (vectorSize(t, vector)) { memcpy(&vectorBody(t, newVector, 0), &vectorBody(t, vector, 0), vectorSize(t, vector) * BytesPerWord); } vector = newVector; } set(t, vector, VectorBody + (vectorSize(t, vector) * BytesPerWord), value); ++ vectorSize(t, vector); return vector; }