int main (int argc, char *argv[]) { ClutterActor *stage, *box, *scrollview; if (clutter_init (&argc, &argv) != CLUTTER_INIT_SUCCESS) return 1; mx_style_load_from_file (mx_style_get_default(), "style/default.css", NULL); stage = clutter_stage_get_default (); clutter_actor_set_size (stage, 640, 480); clutter_stage_set_user_resizable ((ClutterStage *) stage, TRUE); scrollview = mx_scroll_view_new (); clutter_container_add_actor (CLUTTER_CONTAINER (stage), scrollview); clutter_actor_set_position (scrollview, 50, 50); clutter_actor_set_size (scrollview, 500, 300); box = mx_box_layout_new (); clutter_container_add_actor (CLUTTER_CONTAINER (scrollview), box); add_actor ((ClutterContainer*) box); add_actor ((ClutterContainer*) box); add_actor ((ClutterContainer*) box); g_signal_connect (stage, "key-release-event", G_CALLBACK (key_release_cb), box); g_signal_connect (stage, "notify::allocation", G_CALLBACK (stage_size_changed_cb), scrollview); clutter_actor_show (stage); clutter_main (); return EXIT_SUCCESS; }
void bc_hierarchy_component::initialize(bc_actor& p_actor, const core::bc_data_driven_parameter& p_parameters) { auto& l_child_entity_names = p_parameters.get_value_throw< core::bc_string >(core::g_param_child_actor); auto* l_entity_manager = core::bc_get_service< bc_entity_manager >(); core::bc_string::size_type l_last_pos = 0; core::bc_string::size_type l_pos = 0; core::bc_string l_child_entity_name; while ((l_pos = l_child_entity_names.find(':')) != std::string::npos) { l_child_entity_name = l_child_entity_names.substr(l_last_pos, l_pos); l_last_pos = l_pos; bc_actor l_child_actor = l_entity_manager->create_entity(l_child_entity_name.c_str()); add_actor(l_child_actor); } }
static gboolean key_release_cb (ClutterActor *actor, ClutterKeyEvent *event, MxBoxLayout *box) { if (event->keyval == 'v') { mx_box_layout_set_orientation (box, !mx_box_layout_get_orientation (box)); } if (event->keyval == '=') { add_actor ((ClutterContainer*) box); } if (event->keyval == '-') { ClutterActor *child = NULL; clutter_container_foreach (CLUTTER_CONTAINER (box), (ClutterCallback) find_last_child, &child); if (child) clutter_container_remove_actor (CLUTTER_CONTAINER (box), child); } if (event->keyval == 'c') { gboolean clip; g_object_get (actor, "clip-to-allocation", &clip, NULL); g_object_set (actor, "clip-to-allocation", !clip, NULL); } if (event->keyval == 's') { guint spacing; spacing = mx_box_layout_get_spacing (box); if (spacing > 6) spacing = 0; else spacing++; mx_box_layout_set_spacing (box, spacing); } if (event->keyval == 'e') { if (hover_actor) { gboolean expand; clutter_container_child_get ((ClutterContainer*) box, hover_actor, "expand", &expand, NULL); clutter_container_child_set ((ClutterContainer*) box, hover_actor, "expand", !expand, NULL); } } if (event->keyval == 'a') { mx_box_layout_set_enable_animations (box, !mx_box_layout_get_enable_animations (box)); } return FALSE; }
int main (int argc, char *argv[]) { ClutterActor *stage, *box, *instructions; ClutterLayoutManager *stage_layout, *grid_layout; GError *error = NULL; if (clutter_init_with_args (&argc, &argv, NULL, entries, NULL, &error) != CLUTTER_INIT_SUCCESS) { g_print ("Unable to run grid-layout: %s", error->message); g_error_free (error); return EXIT_FAILURE; } stage = clutter_stage_new (); clutter_stage_set_user_resizable (CLUTTER_STAGE (stage), TRUE); stage_layout = clutter_box_layout_new (); clutter_box_layout_set_orientation (CLUTTER_BOX_LAYOUT (stage_layout), CLUTTER_ORIENTATION_VERTICAL); clutter_actor_set_layout_manager (stage, stage_layout); grid_layout = clutter_grid_layout_new (); if (is_vertical) clutter_grid_layout_set_orientation (CLUTTER_GRID_LAYOUT (grid_layout), CLUTTER_ORIENTATION_VERTICAL); box = clutter_actor_new (); clutter_actor_set_background_color (box, CLUTTER_COLOR_LightGray); clutter_actor_set_x_expand (box, TRUE); clutter_actor_set_y_expand (box, TRUE); clutter_actor_set_layout_manager (box, grid_layout); clutter_actor_add_child (stage, box); clutter_actor_set_x_align (box, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (box, CLUTTER_ACTOR_ALIGN_FILL); add_actor (box, 0, 0, 1, 1); add_actor (box, 1, 0, 1, 1); add_actor (box, 2, 0, 1, 1); add_actor (box, 0, 1, 1, 1); add_actor (box, 1, 1, 2, 1); add_actor (box, 0, 2, 3, 1); add_actor (box, 0, 3, 2, 2); add_actor (box, 2, 3, 1, 1); add_actor (box, 2, 4, 1, 1); instructions = clutter_text_new_with_text ("Sans 12px", INSTRUCTIONS); clutter_actor_set_margin_top (instructions, 4); clutter_actor_set_margin_left (instructions, 4); clutter_actor_set_margin_bottom (instructions, 4); clutter_actor_add_child (stage, instructions); clutter_actor_set_x_align (instructions, CLUTTER_ACTOR_ALIGN_FILL); clutter_actor_set_y_align (instructions, CLUTTER_ACTOR_ALIGN_CENTER); g_signal_connect (stage, "destroy", G_CALLBACK (clutter_main_quit), NULL); g_signal_connect (stage, "key-release-event", G_CALLBACK (key_release_cb), box); clutter_actor_show (stage); clutter_main (); return 0; }
int process_message (unsigned char* data, int length) { unsigned char* temp; Uint8 command = data[0]; data += 3; // Handlers skip command switch (command) { case RAW_TEXT: printf("%s\n", data+1); handle_raw_text_from_server(data+1); break; case YOU_ARE: me = *((short *)(data)); break; case ADD_NEW_ACTOR: add_actor(*((short *)(data)), data+23, *((short*)(data+2)), *((short*)(data+4))); break; case ADD_NEW_ENHANCED_ACTOR: add_actor(*((short *)(data)), data+28, *((short*)(data+2)), *((short*)(data+4))); break; case REMOVE_ACTOR: destroy_actor(*((short *)(data))); break; case KILL_ALL_ACTORS: destroy_all_actors(); break; case ADD_ACTOR_COMMAND: handle_actor_command(*((short *)(data)), data[2]); break; case HERE_YOUR_INVENTORY: get_inventory_from_server(data); break; case GET_NEW_INVENTORY_ITEM: get_new_inventory_item_from_server(data); break; case REMOVE_ITEM_FROM_INVENTORY: remove_inventory_item(data[0]); break; case GET_TRADE_ACCEPT: printf ("Someone pressed accept!\n"); printf ("%d", data[0]); if (data[0]) { trade.he_accepted++; update_trade(); } else { trade.we_accepted++; } break; case GET_TRADE_REJECT: if (data[0]) { trade.he_accepted = 0; } else { trade.we_accepted = 0; } break; case GET_TRADE_EXIT: end_trade(); check_inventory(); break; case GET_TRADE_OBJECT: if /* (data[7]) */ (data[8]) { /* data[6] is type attribute data[7] is pos atribbute */ get_trade_object(/* data[6] */ data[7], *((Uint16 *)(data)), *((Uint32 *)(data+2))); } break; case REMOVE_TRADE_OBJECT: if /* (data[3]) */ (data[5]) { /* remove_trade_object(data[2], *((Uint16 *)(data))); */ remove_trade_object (data[4], *((Uint32*)(data))); } break; case GET_YOUR_TRADEOBJECTS: get_inventory_from_server(data); break; case GET_TRADE_PARTNER_NAME: temp = data +1; /* Skip storage_available */ temp[length] = 0; /* ?! Isn't this outside of data range? */ activate_trade(temp); /* Should pass the address of begining of partner name */ break; case LOG_IN_OK: logged_in = 1; break; case LOG_IN_NOT_OK: fprintf(stderr, "ERROR: Invalid password\n"); die(); case YOU_DONT_EXIST: fprintf(stderr, "ERROR: Invalid username\n"); die(); default: // ignore it break; } return 1; }
// used for hw07 // The helper2 function is used to determine how much information is needed, and which function to send that information to. // It uses pointers that are returned from these functions to produce the correct ouput. // There is no implementation needed here, but you should study this function and know how it works. // It is always helpful to understand how the code works before implementing new features. // Do not change anything in this function or the test cases will fail. void helper2(char c) { int index = 0; // used to print an index int genre = -1; char* movie_name; char* actor_name; movie_name = (char*)malloc(5000 * sizeof(char*)); actor_name = (char*)malloc(5000 * sizeof(char*)); if (c == 'b') // add an actor/actress to a movie { printf("Enter the actor/actress name:\n"); flush(); fgets(actor_name, line_size, stdin); printf("Enter the movie they were they in:\n"); fgets(movie_name, line_size, stdin); int result = add_actor(movie_name, actor_name); if (result == 0) { printf("That movie is not in your list, please add that movie first.\n\n"); } else if (result == 1) { printf("Actor added.\n\n"); } else if (result == -1) { printf("That actor is already listed for that movie.\n\n"); } } if (c == 'c') // display a list of movies for an actor/actress { printf("Enter the actor/actress name:\n"); flush(); fgets(actor_name, line_size, stdin); struct movie* temp = find_actor(actor_name); if (temp != NULL) { printf("That actor/actress is in:\n"); print_helper(temp); // ADDED TO PREVENT MEMORY LEAKS struct movie* temp2; while (temp != NULL) { temp2 = temp; temp = temp->next; free(temp2); } } else printf("That actor is not in any movies in your list.\n\n", index); } if (c == 'd') // delete all movies { delete_all(list); printf("All movies deleted.\n"); } if (c == 'e') // display all movies print_helper(print_all(list)); if (c == 'f') // display a movie by index { printf("Enter an index to print:\n"); while (index < 1) { scanf("%d", &index); if (index < 1) printf("Enter an index greater than 0:\n"); } struct movie* temp = print_by_index(index); if (temp != NULL) { struct actor* ptr = temp->actors; printf("Movie at index %d:\n", index); printf("Movie: %s", temp->name); printf("Rating: %d\n", temp->rating); printf("Genre: %s\n", gen[temp->type]); printf("Actor/Actress: "); if (ptr == NULL) { printf("no actor/actress listed.\n\n"); } else { printf("\n"); while (ptr != NULL) { printf("%s", ptr->name); ptr = ptr->next; } printf("\n"); } } else printf("There is no movie at index %d.\n\n", index); } if (c == 'g') // display a list of movies by genre { printf("Select a genre to display\n0. action\n1. comedy\n2. thriller\n"); while (genre < 0 || genre > 2) { scanf("%d", &genre); // enter an integer onl if (genre < 0 || genre > 2) printf("Select a valid option:\n"); } struct movie* temp = print_by_genre(genre); if (temp != NULL) { printf("%s movies:\n", gen[genre]); print_helper(temp); // ADDED TO PREVENT MEMORY LEAKS struct movie* temp2; while (temp != NULL) { temp2 = temp; temp = temp->next; free(temp2); } } else printf("There are no %s movies in the list.\n\n", gen[genre]); } free(actor_name); // ADDED TO PREVENT MEMORY LEAKS free(movie_name); // ADDED TO PREVENT MEMORY LEAKS }