// Deletes every function in a list void clear_function_list(struct list *args) { struct cursor *c = NULL; for(c = cursor_new_front(args); cursor_valid(c); cursor_next(c)) if(cursor_get(c)) function_delete(cursor_get(c)); list_delete(args); cursor_delete(c); }
// Deletes a symtable void symtable_delete(struct symtable *table) { int i; struct list *list = NULL; struct cursor *c = NULL; struct symtable_entry *entry = NULL; if(!table) return; for(i = 0; i < SYMTABLE_SIZE; i++) { list = table->entries[i]; for(c = cursor_new_front(list); cursor_valid(c); cursor_next(c)) { entry = cursor_get(c); free(entry->name); function_delete(entry->data); free(entry); } list_delete(list); cursor_delete(c); } free(table); }
/*** map * Mapping functional form. Accepts a single function argument. Input to the * form should always be in the form of a list, and the return value will be * the result of applying the argument function to each element in the list. * * map{ f } : < x, y, z > = < f : x, f : y, f : z > */ struct value *map(struct list *args, struct value *in) { struct value *out = NULL; struct function *f = list_get(args, 0); struct list *l = NULL; struct cursor *c; // First ensure valid input if(args->count != 1 || in->type != SEQ_VAL) { value_delete(in); return value_new(); } // Otherwise create an output list by applying f to each element of in out = value_new(); out->type = SEQ_VAL; out->data.seq_val = list_new(); l = in->data.seq_val; for(c = cursor_new_front(l); cursor_valid(c); cursor_next(c)) list_push_back(out->data.seq_val, function_exec(f, value_copy(cursor_get(c)))); value_delete(in); cursor_delete(c); return out; }
bool render_editor() { cursor c = cursor_get(); map_view v = view_get(); glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); update_view(v.x, v.y, v.zoom); /*update_cursor_data(&selected_map, &selected_tile_x, &selected_tile_y);*/ bool can_place = cursor_in_bounds(c.selected_tile_x, c.selected_tile_y); mat4 t = ident; mat4 cursor_pos = ident; uint16_t tile_w = (TILE_WIDTH * v.zoom); uint16_t tile_h = (TILE_HEIGHT * v.zoom); if(tile_w == 0) tile_w = 1; if(tile_h == 0) tile_h = 1; mat4_translate(&cursor_pos, c.selected_tile_x * TILE_WIDTH + (c.selected_map % 3 * TILEMAP_DIMS * TILE_WIDTH), c.selected_tile_y * TILE_HEIGHT + (c.selected_map / 3 * TILEMAP_DIMS * TILE_HEIGHT), 0); draw_maps(t); if(can_place) { draw_single_tile(get_tileset_texture(), c.set_id, c.current_id, cursor_pos); } for(int i = 0; i < 3; ++i) for(int j = 0; j < 3; ++j) { mat4_translate(&t, TILEMAP_DIMS * TILE_WIDTH * i, TILEMAP_DIMS * TILE_HEIGHT * j, 0); draw_grid(t); } glFlush(); return true; }
static int _iter_next(iter_t iter, const int data){ // set/advance key iter->r = cursor_get((cursor_t)iter, &(iter->key), &(iter->data), iter->op); if(MDB_NEXT != iter->op) iter->op = MDB_NEXT; if(MDB_SUCCESS != iter->r) return iter->r; // possibly check pfx on updated key if(iter->pfx && memcmp(iter->key.mv_data, iter->pfx, iter->pfxlen)) return (iter->r = MDB_NOTFOUND); // maybe grab data too if(data) iter->r = cursor_get((cursor_t)iter, &(iter->key), &(iter->data), MDB_GET_CURRENT); return iter->r; }
/* Button press event handler for the image view */ static gboolean image_view_button_press_event (GtkWidget *widget, GdkEventButton *event) { ImageView *view; ImageViewPrivate *priv; GdkCursor *cursor; view = IMAGE_VIEW (widget); priv = view->priv; if (!GTK_WIDGET_HAS_FOCUS (widget)) gtk_widget_grab_focus (widget); if (priv->dragging) return FALSE; switch (event->button) { case 1: cursor = cursor_get (widget, CURSOR_HAND_CLOSED); gdk_window_set_cursor (widget->window, cursor); gdk_cursor_unref (cursor); priv->dragging = TRUE; priv->drag_anchor_x = event->x; priv->drag_anchor_y = event->y; priv->drag_ofs_x = priv->xofs; priv->drag_ofs_y = priv->yofs; return TRUE; case 4: image_view_set_zoom (view, priv->zoomx * IMAGE_VIEW_ZOOM_MULTIPLIER, priv->zoomy * IMAGE_VIEW_ZOOM_MULTIPLIER, TRUE, event->x, event->y); return TRUE; case 5: image_view_set_zoom (view, priv->zoomx / IMAGE_VIEW_ZOOM_MULTIPLIER, priv->zoomy / IMAGE_VIEW_ZOOM_MULTIPLIER, TRUE, event->x, event->y); return TRUE; default: break; } return FALSE; }
static void hotspot_list_init (Hotspot *hotspots) { hotspots[0].cursor = cursor_get (CURSOR_HAND_OPEN); hotspots[1].cursor = gdk_cursor_new (GDK_TOP_LEFT_CORNER); hotspots[2].cursor = gdk_cursor_new (GDK_TOP_RIGHT_CORNER); hotspots[3].cursor = gdk_cursor_new (GDK_BOTTOM_LEFT_CORNER); hotspots[4].cursor = gdk_cursor_new (GDK_BOTTOM_RIGHT_CORNER); hotspots[5].cursor = gdk_cursor_new (GDK_TOP_SIDE); hotspots[6].cursor = gdk_cursor_new (GDK_RIGHT_SIDE); hotspots[7].cursor = gdk_cursor_new (GDK_BOTTOM_SIDE); hotspots[8].cursor = gdk_cursor_new (GDK_LEFT_SIDE); hotspots[9].cursor = gdk_cursor_new (GDK_CROSSHAIR); }
static void gtk_image_tool_selector_init (GtkImageToolSelector *tool) { tool->background = NULL; tool->view = NULL; tool->sel_rect = (GdkRectangle){0, 0, 0, 0}; tool->bg_cache = gdk_pixbuf_draw_cache_new (); tool->fg_cache = gdk_pixbuf_draw_cache_new (); tool->drag_cursor = cursor_get (CURSOR_HAND_CLOSED); tool->mouse_handler = mouse_handler_new (tool->drag_cursor); tool->timer_id = 0; // Init hotspots cursors. hotspot_list_init (tool->hotspots); }
/*** construct * Sequence construction. Feeds its input to each of its argument functions, * and generate a sequence where each element is the output of one of the * argument functions. * * construct{ f, g } : x = < f : x, g : x > */ struct value *construct(struct list *args, struct value *in) { struct value *out = value_new(); struct cursor *c = NULL; out->type = SEQ_VAL; out->data.seq_val = list_new(); for(c = cursor_new_front(args); cursor_valid(c); cursor_next(c)) { list_push_back(out->data.seq_val, function_exec(cursor_get(c), value_copy(in))); } value_delete(in); cursor_delete(c); return out; }
/*** compose * Function composition. Feeds its input to the last function in its argument * list, then feeds that function's output to the second-to-last, and so on, * eventually returning the output of the last function in the list as the * combined function's output. * * compose{ f, g } : x = f : (g : x) */ struct value *compose(struct list *args, struct value *in) { struct value *current = in; struct value *last = in; struct function *f = NULL; struct cursor *c = NULL; // Stepping backwards through the list of arguments and feeding // input to successive functions, deleting intermediate values for(c = cursor_new_back(args); cursor_valid(c); cursor_prev(c)) { f = cursor_get(c); last = current; current = function_exec(f, current); } cursor_delete(c); return current; }
static int cursor_next(Value *vret, Value *v, RefNode *node) { RefCursor *rc = Value_vp(*v); int result = sqlite3_step(rc->stmt); if (result == SQLITE_DONE) { fs->throw_stopiter(); return FALSE; } else if (result == SQLITE_ROW) { if (!cursor_get(vret, rc)) { return FALSE; } } else { fs->throw_errorf(mod_sqlite, "SQLiteError", "sqlite3_step error (%d)", result); return FALSE; } return TRUE; }
/* Realize handler for the image view */ static void image_view_realize (GtkWidget *widget) { GdkWindowAttr attr; int attr_mask; GdkCursor *cursor; g_return_if_fail (widget != NULL); g_return_if_fail (IS_IMAGE_VIEW (widget)); GTK_WIDGET_SET_FLAGS (widget, GTK_REALIZED); attr.window_type = GDK_WINDOW_CHILD; attr.x = widget->allocation.x; attr.y = widget->allocation.y; attr.width = widget->allocation.width; attr.height = widget->allocation.height; attr.wclass = GDK_INPUT_OUTPUT; attr.visual = gdk_rgb_get_visual (); attr.colormap = gdk_rgb_get_colormap (); attr.event_mask = (gtk_widget_get_events (widget) | GDK_EXPOSURE_MASK | GDK_BUTTON_PRESS_MASK | GDK_BUTTON_RELEASE_MASK | GDK_POINTER_MOTION_MASK | GDK_POINTER_MOTION_HINT_MASK | GDK_SCROLL_MASK | GDK_KEY_PRESS_MASK); attr_mask = GDK_WA_X | GDK_WA_Y | GDK_WA_VISUAL | GDK_WA_COLORMAP; widget->window = gdk_window_new (gtk_widget_get_parent_window (widget), &attr, attr_mask); gdk_window_set_user_data (widget->window, widget); cursor = cursor_get (widget, CURSOR_HAND_OPEN); gdk_window_set_cursor (widget->window, cursor); gdk_cursor_unref (cursor); widget->style = gtk_style_attach (widget->style, widget->window); gdk_window_set_back_pixmap (widget->window, NULL, FALSE); }
// Retrieves an entry from the table struct function *symtable_find(struct symtable *table, char *name) { struct list *list = table->entries[hash(name) % table->size]; struct symtable_entry *entry = NULL; struct cursor *c = NULL; for(c = cursor_new_front(list); cursor_valid(c); cursor_next(c)) { entry = cursor_get(c); if(!entry) break; if(!strcmp(entry->name, name)) { cursor_delete(c); return entry->data; } } return NULL; }
/* Button release event handler for the image view */ static gboolean image_view_button_release_event (GtkWidget *widget, GdkEventButton *event) { ImageView *view; ImageViewPrivate *priv; GdkCursor *cursor; view = IMAGE_VIEW (widget); priv = view->priv; if (!priv->dragging || event->button != 1) return FALSE; drag_to (view, event->x, event->y); priv->dragging = FALSE; cursor = cursor_get (widget, CURSOR_HAND_OPEN); gdk_window_set_cursor (widget->window, cursor); gdk_cursor_unref (cursor); return TRUE; }
int trap_GetCursor(lua_State *s) { lua_pushlightuserdata(s, cursor_get()); return 1; }