static int ProcAppleWMFrameGetRect( register ClientPtr client ) { xAppleWMFrameGetRectReply rep; BoxRec ir, or, rr; REQUEST(xAppleWMFrameGetRectReq); REQUEST_SIZE_MATCH(xAppleWMFrameGetRectReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh); if (appleWMProcs->FrameGetRect(stuff->frame_rect, stuff->frame_class, &or, &ir, &rr) != Success) { return BadValue; } rep.x = rr.x1; rep.y = rr.y1; rep.w = rr.x2 - rr.x1; rep.h = rr.y2 - rr.y1; WriteToClient(client, sizeof(xAppleWMFrameGetRectReply), (char *)&rep); return (client->noClientException); }
static int ProcAppleWMFrameHitTest( register ClientPtr client ) { xAppleWMFrameHitTestReply rep; BoxRec ir, or; int ret; REQUEST(xAppleWMFrameHitTestReq); REQUEST_SIZE_MATCH(xAppleWMFrameHitTestReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; ir = make_box (stuff->ix, stuff->iy, stuff->iw, stuff->ih); or = make_box (stuff->ox, stuff->oy, stuff->ow, stuff->oh); if (appleWMProcs->FrameHitTest(stuff->frame_class, stuff->px, stuff->py, &or, &ir, &ret) != Success) { return BadValue; } rep.ret = ret; WriteToClient(client, sizeof(xAppleWMFrameHitTestReply), (char *)&rep); return (client->noClientException); }
static int ProcAppleWMFrameDraw(register ClientPtr client) { BoxRec ir, or; unsigned int title_length, title_max; unsigned char *title_bytes; REQUEST(xAppleWMFrameDrawReq); WindowPtr pWin; REQUEST_AT_LEAST_SIZE(xAppleWMFrameDrawReq); if (Success != dixLookupWindow(&pWin, stuff->window, client, DixReadAccess)) return BadValue; ir = make_box(stuff->ix, stuff->iy, stuff->iw, stuff->ih); or = make_box(stuff->ox, stuff->oy, stuff->ow, stuff->oh); title_length = stuff->title_length; title_max = (stuff->length << 2) - sizeof(xAppleWMFrameDrawReq); if (title_max < title_length) return BadValue; title_bytes = (unsigned char *)&stuff[1]; errno = appleWMProcs->FrameDraw(pWin, stuff->frame_class, stuff->frame_attr, &or, &ir, title_length, title_bytes); if (errno != Success) { return errno; } return Success; }
int main(int /*argc*/, char** /*argv*/) { std::cout << "--------------------------" << std::endl; std::cout << "EXPLODING BOMBS EXAMPLE!" << std::endl; std::cout << "--------------------------" << std::endl; std::cout << "This example displays the interaction between multiple entities via uncoupled components." << std::endl; std::cout << "--------------------------" << std::endl; std::cout << "CREATING ENTITIES" << std::endl; std::cout << "--------------------------" << std::endl; EntityManager mgr; auto boxA = make_box("BoxA", mgr); auto boxB = make_box("BoxB", mgr); auto bombA = make_bomb("BombA", mgr); auto bombB = make_bomb("BombB", mgr); std::cout << "--------------------------" << std::endl; std::cout << "SETTING PROPERTIES" << std::endl; std::cout << "--------------------------" << std::endl; std::cout << "Position of " << bombA->get_name() << " is " << bombA->get<Vec2i>(PROPERTY_POSITION).get().x << ", " << bombA->get<Vec2i>(PROPERTY_POSITION).get().y << std::endl; bombB->get<Vec2i>(PROPERTY_POSITION) = Vec2i(2,0); boxA->get<Vec2i>(PROPERTY_POSITION) = Vec2i(2,1); boxB->get<Vec2i>(PROPERTY_POSITION) = Vec2i(5,0); boxA->get<int>(PROPERTY_HEALTH) = 150; boxB->get<int>(PROPERTY_HEALTH) = 150; std::cout << "Health of " << bombA->get_name() << " is " << bombA->get<int>(PROPERTY_HEALTH) << std::endl; std::cout << "Health of " << bombB->get_name() << " is " << bombB->get<int>(PROPERTY_HEALTH) << std::endl; std::cout << "--------------------------" << std::endl; std::cout << "START EXPLOSION" << std::endl; std::cout << "--------------------------" << std::endl; bombA->get<int>(PROPERTY_HEALTH) = 0; std::cout << "--------------------------" << std::endl; std::cout << "UPDATE ENTITY MANAGER STATE" << std::endl; std::cout << "--------------------------" << std::endl; mgr.update(); std::cout << "--------------------------" << std::endl; std::cout << "ENTITIES IN ENTITY MANAGER" << std::endl; std::cout << "--------------------------" << std::endl; for(auto entity : mgr.get_entities()) { std::cout << entity->get_name() << std::endl; } std::cout << "--------------------------" << std::endl; system("pause"); return 0; }
void two_boxes() { Polyhedron a; make_box(0,0,0, 4, 5, 2, a); Polyhedron b; make_box(1, 1, -1, 2, 2, 1, b); if (a.is_pure_triangle()) std::cout << "a is pure triangle" << std::endl; if (b.is_pure_triangle()) std::cout << "b is pure triangle" << std::endl; Polyhedron &biggest = a.size_of_facets() > b.size_of_facets() ? a : b; Polyhedron &smallest = a.size_of_facets() > b.size_of_facets() ? b : a; std::list<std::list<boost::tuple<Facet_handle, Facet_handle, Segment> > > polylines; { std::list<boost::tuple<Facet_handle, Facet_handle, Segment> > intersections; compute_intersections(biggest, smallest, std::back_inserter(intersections)); for (std::list<boost::tuple<Facet_handle, Facet_handle, Segment> >::iterator it = intersections.begin(); it != intersections.end(); it++) { { Halfedge_handle h = it->get<0>()->halfedge(); Triangle t(h->vertex()->point(), h->next()->vertex()->point(), h->next()->next()->vertex()->point()); assert(t.has_on(it->get<2>().source())); assert(t.has_on(it->get<2>().target())); } { Halfedge_handle h = it->get<1>()->halfedge(); Triangle t(h->vertex()->point(), h->next()->vertex()->point(), h->next()->next()->vertex()->point()); assert(t.has_on(it->get<2>().source())); assert(t.has_on(it->get<2>().target())); } } sort_polylines<Polyhedron>(biggest, smallest, intersections, polylines); } std::list<std::vector<Halfedge_handle> > a_edges; split_facets<Polyhedron, 0>(biggest, polylines, a_edges); check_splitting<Polyhedron, 0>(biggest, polylines, a_edges); //split_facets<Polyhedron, 1>(smallest, /* smallest, */ polylines); }
static int ProcWindowsWMFrameGetRect(ClientPtr client) { xWindowsWMFrameGetRectReply rep; BoxRec ir; RECT rcNew; REQUEST(xWindowsWMFrameGetRectReq); #if CYGMULTIWINDOW_DEBUG ErrorF("ProcWindowsWMFrameGetRect %d %d\n", (sizeof(xWindowsWMFrameGetRectReq) >> 2), (int) client->req_len); #endif REQUEST_SIZE_MATCH(xWindowsWMFrameGetRectReq); rep.type = X_Reply; rep.length = 0; rep.sequenceNumber = client->sequence; ir = make_box(stuff->ix, stuff->iy, stuff->iw, stuff->ih); if (stuff->frame_rect != 0) { ErrorF("ProcWindowsWMFrameGetRect - stuff->frame_rect != 0\n"); return BadValue; } /* Store the origin, height, and width in a rectangle structure */ SetRect(&rcNew, stuff->ix, stuff->iy, stuff->ix + stuff->iw, stuff->iy + stuff->ih); #if CYGMULTIWINDOW_DEBUG ErrorF("ProcWindowsWMFrameGetRect - %d %d %d %d\n", stuff->ix, stuff->iy, stuff->ix + stuff->iw, stuff->iy + stuff->ih); #endif /* * Calculate the required size of the Windows window rectangle, * given the size of the Windows window client area. */ AdjustWindowRectEx(&rcNew, stuff->frame_style, FALSE, stuff->frame_style_ex); rep.x = rcNew.left; rep.y = rcNew.top; rep.w = rcNew.right - rcNew.left; rep.h = rcNew.bottom - rcNew.top; #if CYGMULTIWINDOW_DEBUG ErrorF("ProcWindowsWMFrameGetRect - %d %d %d %d\n", rep.x, rep.y, rep.w, rep.h); #endif WriteToClient(client, sizeof(xWindowsWMFrameGetRectReply), &rep); return Success; }
int main( int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; GtkWidget *box1; GtkWidget *box2; GtkWidget *separator; GtkWidget *label; GtkWidget *quitbox; int which; /* Our init, don't forget this! :) */ gtk_init (&argc, &argv); if (argc != 2) { fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n"); /* This just does cleanup in GTK and exits with an exit status of 1. */ exit (1); } which = atoi (argv[1]); /* Create our window */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* You should always remember to connect the delete_event signal * to the main window. This is very important for proper intuitive * behavior */ g_signal_connect (window, "delete-event", G_CALLBACK (delete_event), NULL); gtk_container_set_border_width (GTK_CONTAINER (window), 10); /* We create a vertical box (vbox) to pack the horizontal boxes into. * This allows us to stack the horizontal boxes filled with buttons one * on top of the other in this vbox. */ box1 = gtk_vbox_new (FALSE, 0); /* which example to show. These correspond to the pictures above. */ switch (which) { case 1: /* create a new label. */ label = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); /* Align the label to the left side. We'll discuss this function and * others in the section on Widget Attributes. */ gtk_misc_set_alignment (GTK_MISC (label), 0, 0); /* Pack the label into the vertical box (vbox box1). Remember that * widgets added to a vbox will be packed one on top of the other in * order. */ gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); /* Show the label */ gtk_widget_show (label); /* Call our make box function - homogeneous = FALSE, spacing = 0, * expand = FALSE, fill = FALSE, padding = 0 */ box2 = make_box (FALSE, 0, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Call our make box function - homogeneous = FALSE, spacing = 0, * expand = TRUE, fill = FALSE, padding = 0 */ box2 = make_box (FALSE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Creates a separator, we'll learn more about these later, * but they are quite simple. */ separator = gtk_hseparator_new (); /* Pack the separator into the vbox. Remember each of these * widgets is being packed into a vbox, so they'll be stacked * vertically. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); /* Create another new label, and show it. */ label = gtk_label_new ("gtk_hbox_new (TRUE, 0);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (TRUE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (TRUE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Another new separator. */ separator = gtk_hseparator_new (); /* The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 2: /* Create a new label, remember box1 is a vbox as created * near the beginning of main() */ label = gtk_label_new ("gtk_hbox_new (FALSE, 10);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 10, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 10, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); separator = gtk_hseparator_new (); /* The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); label = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, FALSE, 10); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); separator = gtk_hseparator_new (); /* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 3: /* This demonstrates the ability to use gtk_box_pack_end() to * right justify widgets. First, we create a new box as before. */ box2 = make_box (FALSE, 0, FALSE, FALSE, 0); /* Create the label that will be put at the end. */ label = gtk_label_new ("end"); /* Pack it using gtk_box_pack_end(), so it is put on the right * side of the hbox created in the make_box() call. */ gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0); /* Show the label. */ gtk_widget_show (label); /* Pack box2 into box1 (the vbox remember ? :) */ gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* A separator for the bottom. */ separator = gtk_hseparator_new (); /* This explicitly sets the separator to 400 pixels wide by 5 pixels * high. This is so the hbox we created will also be 400 pixels wide, * and the "end" label will be separated from the other labels in the * hbox. Otherwise, all the widgets in the hbox would be packed as * close together as possible. */ gtk_widget_set_size_request (separator, 400, 5); /* pack the separator into the vbox (box1) created near the start * of main() */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); } /* Create another new hbox.. remember we can use as many as we need! */ quitbox = gtk_hbox_new (FALSE, 0); /* Our quit button. */ button = gtk_button_new_with_label ("Quit"); /* Setup the signal to terminate the program when the button is clicked */ g_signal_connect_swapped (button, "clicked", G_CALLBACK (gtk_main_quit), window); /* Pack the button into the quitbox. * The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0); /* pack the quitbox into the vbox (box1) */ gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0); /* Pack the vbox (box1) which now contains all our widgets, into the * main window. */ gtk_container_add (GTK_CONTAINER (window), box1); /* And show everything left */ gtk_widget_show (button); gtk_widget_show (quitbox); gtk_widget_show (box1); /* Showing the window last so everything pops up at once. */ gtk_widget_show (window); /* And of course, our main function. */ gtk_main (); /* Control returns here when gtk_main_quit() is called, but not when * exit() is used. */ return 0; }
int main (int argc, char *argv[]) { GtkWidget *ventana; GtkWidget *boton; GtkWidget *caja1; GtkWidget *caja2; GtkWidget *separator; GtkWidget *etiqueta; GtkWidget *quitbox; int which; /* ¡No olvidar la siguiente llamada! */ gtk_init (&argc, &argv); if (argc != 2) { fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n"); /* hacemos limpieza en GTK y devolvemos el valor de 1 */ gtk_exit (1); } which = atoi (argv[1]); /* Creamos la ventana */ ventana = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* Siempre hay que conectar la señal de destrucción con la * ventana principal. Esto es muy importante para que el * comportamiento de la ventana sea intuitivo. */ gtk_signal_connect (GTK_OBJECT (ventana), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); gtk_container_border_width (GTK_CONTAINER (ventana), 10); /* Creamos una caja vertical donde empaquetaremos las cajas * horizontales. Así podemos apilar las cajas horizontales * llenas con botones una encima de las otras. */ caja1 = gtk_vbox_new (FALSE, 0); /* Aclaramos cúal es el ejemplo a mostrar. Se corresponde con * las imágenes anteriores. */ switch (which) { case 1: /* creamos una nueva etiqueta. */ etiqueta = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); /* Alineamos la etiqueta a la izquierda. Está función * será discutida en detalle en la sección de los * atributos de los widgets. */ gtk_misc_set_alignment (GTK_MISC (etiqueta), 0, 0); /* Empaquetamos la etiqueta en la caja vertical (vbox * caja1). Siempre hay que recordar que los widgets añadidos a * una vbox serán empaquetados uno encimo de otro. */ gtk_box_pack_start (GTK_BOX (caja1), etiqueta, FALSE, FALSE, 0); /* mostramos la etiqueta. */ gtk_widget_show (etiqueta); /* llamada a la función que hace las cajas. Los argumentos * son homogenous = FALSE, expand = FALSE, fill = FALSE, * padding = 0 */ caja2 = make_box (FALSE, 0, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* Llamad a la función para hacer cajas - * homogeneous = FALSE, spacing = 0, expand = FALSE, * fill = FALSE, padding = 0 */ caja2 = make_box (FALSE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (FALSE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* creamos un separador. Más tarde aprenderemos más cosas * sobre ellos, pero son bastante sencillos. */ separator = gtk_hseparator_new (); /* empaquetamos el separador el la vbox. Los widgets serán * apilados verticalmente. */ gtk_box_pack_start (GTK_BOX (caja1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); /* creamos una nueva etiqueta y la mostramos */ etiqueta = gtk_label_new ("gtk_hbox_new (TRUE, 0);"); gtk_misc_set_alignment (GTK_MISC (etiqueta), 0, 0); gtk_box_pack_start (GTK_BOX (caja1), etiqueta, FALSE, FALSE, 0); gtk_widget_show (etiqueta); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (TRUE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (TRUE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* un nuevo separador */ separator = gtk_hseparator_new (); /* Los tres últimos argumentos son: expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (caja1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 2: /* Nueva etiqueta */ etiqueta = gtk_label_new ("gtk_hbox_new (FALSE, 10);"); gtk_misc_set_alignment (GTK_MISC (etiqueta), 0, 0); gtk_box_pack_start (GTK_BOX (caja1), etiqueta, FALSE, FALSE, 0); gtk_widget_show (etiqueta); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (FALSE, 10, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (FALSE, 10, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); separator = gtk_hseparator_new (); /* Los argumentos son: expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (caja1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); etiqueta = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); gtk_misc_set_alignment (GTK_MISC (etiqueta), 0, 0); gtk_box_pack_start (GTK_BOX (caja1), etiqueta, FALSE, FALSE, 0); gtk_widget_show (etiqueta); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (FALSE, 0, TRUE, FALSE, 10); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* Los argumentos son: homogeneous, spacing, expand, fill, * padding */ caja2 = make_box (FALSE, 0, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); separator = gtk_hseparator_new (); /* Los argumentos son: expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (caja1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 3: /* Con esto demostramos como hay que usar gtk_box_pack_end () * para conseguir que los widgets esten alineados a la izquierda. */ caja2 = make_box (FALSE, 0, FALSE, FALSE, 0); /* la última etiqueta*/ etiqueta = gtk_label_new ("end"); /* la empaquetamos usando gtk_box_pack_end(), por lo que se * sitúa en el lado derecho de la hbox.*/ gtk_box_pack_end (GTK_BOX (caja2), etiqueta, FALSE, FALSE, 0); /* mostrar la etiqueta */ gtk_widget_show (etiqueta); /* empaquetamos caja2 en caja1 */ gtk_box_pack_start (GTK_BOX (caja1), caja2, FALSE, FALSE, 0); gtk_widget_show (caja2); /* el separador para la parte de abajo. */ separator = gtk_hseparator_new (); /* Así se determina el tamaño del separador a 400 pixels * de largo por 5 de alto. La hbox también tendrá 400 * pixels de largo y la etiqueta "end" estará separada de * las demás etiquetas en la hbox. Si no establecemos estos * parámetros todos los widgets en la hbox serán * empaquetados tan juntos como se pueda.*/ gtk_widget_set_usize (separator, 400, 5); /* Empaquetamos el separador creado al principio de main() en * la vbox (caja1). */ gtk_box_pack_start (GTK_BOX (caja1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); } /* Creamos otra hbox... recordar que podemos crear tantas como * queramos. */ quitbox = gtk_hbox_new (FALSE, 0); /* El botón de salida. */ boton = gtk_button_new_with_label ("Quit"); /* Establecemos la señal de destrucción de la ventana. * Recuerde que emitirá la señal de "destroy" que a su vez * será procesada por el controlador de señales, tal y como * ya hemos visto. */ gtk_signal_connect_object (GTK_OBJECT (boton), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), GTK_OBJECT (ventana)); /* Empaquetamos el botón en la caja de salida (quitbox). * los tres últimos argumentos de gtk_box_pack_start * son:expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (caja1), quitbox, FALSE, FALSE, 0); /* empaquetamos la vbox (caja1) que ya contiene todos los widgets * en la ventana principal. */ gtk_container_add (GTK_CONTAINER (ventana), caja1); /* mostramos todo aquello que faltaba por mostrar */ gtk_widget_show (boton); gtk_widget_show (quitbox); gtk_widget_show (caja1); /* Si mostramos la ventana lo último todo aparece de golpe. */ gtk_widget_show (ventana); /* por supuesto tenemos una función main. */ gtk_main (); /* El programa llega aquí cuando se llama a gtk_main_quit(), * pero no cuando se llama a gtk_exit(). */ return 0; }
/*! Create the vertex buffer object for this element */ void GLPlane3D::initVBO(void) { _vertex_points.clear(); _normal_vectors.clear(); //--------------------------------------------------------- // This creates the box geometry make_box(_center_x, _center_y, _center_z, _width, _height, _rows, _cols, _vertex_points, _normal_vectors); _num_vertices = _vertex_points.size(); // create memory for the vertices, etc. float* vertices = new float[_num_vertices * 5]; float* normals = new float[_num_vertices * 3]; // copy the data to the vectors for(int i=0; i<_vertex_points.size() ; i++) { Vertex v = _vertex_points[i]; vertices[(i*5)] = v.x(); vertices[(i*5)+1] = v.y(); vertices[(i*5)+2] = v.z(); vertices[(i*5)+3] = v.u(); vertices[(i*5)+4] = v.v(); Vertex n = _normal_vectors[i]; normals[(i*3)] = n.x(); normals[(i*3)+1] = n.y(); normals[(i*3)+2] = n.z(); } glUseProgram(_program); glGenVertexArrays(1, _vaoID); // Create our Vertex Array Object glBindVertexArray(_vaoID[0]); // Bind our Vertex Array Object so we can use it glGenBuffers(3, _vboID); // Generate our Vertex Buffer Object //////////////////////////////////////////////////////////////////////////////////////////////////////////// // vertices glBindBuffer(GL_ARRAY_BUFFER, _vboID[0]); // Bind our Vertex Buffer Object glBufferData(GL_ARRAY_BUFFER, _num_vertices * 5 * sizeof(GLfloat), vertices, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW int locPos = glGetAttribLocation(_program, "in_Position"); glVertexAttribPointer((GLuint)locPos, 3, GL_FLOAT, GL_FALSE, 5*sizeof(GLfloat), 0); // Set up our vertex attributes pointer glEnableVertexAttribArray(locPos); // int tex_idx = glGetAttribLocation(_program, "in_TexCoord"); glVertexAttribPointer((GLuint)tex_idx, 2, GL_FLOAT, GL_TRUE, 5*sizeof(GLfloat), (const GLvoid*)(3 * sizeof(GLfloat))); glEnableVertexAttribArray(tex_idx); //////////////////////////////////////////////////////////////////////////////////////////////////////////// //Normals glBindBuffer(GL_ARRAY_BUFFER, _vboID[1]); // Bind our second Vertex Buffer Object glBufferData(GL_ARRAY_BUFFER, _num_vertices * 3 * sizeof(GLfloat), normals, GL_STATIC_DRAW); // Set the size and data of our VBO and set it to STATIC_DRAW int locNorm = glGetAttribLocation(_program, "in_Normal"); glVertexAttribPointer((GLuint)locNorm, 3, GL_FLOAT, GL_FALSE, 0, 0); // Set up our vertex attributes pointer glEnableVertexAttribArray(locNorm); // glBindVertexArray(0); // Disable our Vertex Buffer Object // delete the memory delete vertices; delete normals; }
void init_qc(void) { integer p[3],q[3],hv,i,j; real tau[3],period[3],tautl; integer np,no,na,nb,nc,nt; if (size_per_cpu) { box_param.x *= cpu_dim.x; box_param.y *= cpu_dim.y; box_param.z *= cpu_dim.z; } if ((box_param.x==0) || (box_param.y==0) || (box_param.z==0)) error("box_param not set!"); appr[0] = box_param.x; appr[1] = box_param.y; appr[2] = box_param.z; /* defining constants */ tautl = (sqrt(5.0)+1.0)*0.5; if (0==myid) printf("Approximant %d %d %d\n\n",appr[0],appr[1],appr[2]); /* generate fibonacci numbers */ for (j=0;j<3;j++) { p[j] =1;q[j]=0;hv=0; for (i=0;i<appr[j];i++) { hv=q[j]; q[j]=p[j]; p[j]=p[j]+hv; } tau[j]=((real) p[j])/((real) q[j]); period[j]=4*(tautl*p[j]+q[j])/sqrt(tautl+2.0); if (0==myid) { printf("p(%1d)= %3d,q(%1d)= %3d,tau(%1d)= %3f\n", j,p[j],j,q[j],j,tau[j]); printf("period in atomic units %10.5f\n",period[j]); } } /* analytical computation of size */ no=4*(p[0]*p[1]*p[2]+p[2]*q[0]*q[1]+p[1]*q[0]*q[2]+ p[0]*q[1]*q[2]-q[0]*q[1]*q[2]); np=4*(p[0]*p[1]*p[2]+p[1]*p[2]*q[0]+p[0]*p[2]*q[1]+ p[0]*p[1]*q[2]+q[0]*q[1]*q[2]); na=np+no;nb=3*na;nc=2*np;nt=na+nb+nc; if (0==myid) { printf("\nnumber of prolate rhombohedra (p) %d\n",np); printf("number of oblate rhombohedra (o) %d\n",no); printf("number of vertex atoms (a) %d\n",na); printf("number of edge atoms (b) %d\n",nb); printf("number of large atoms (c) %d\n",nc); printf("total number %d\n\n ",nt); } box_x.x=period[0]; box_y.y=period[1]; box_z.z=period[2]; box_x.y=0; box_x.z=0; box_y.x=0; box_y.z=0; box_z.x=0; box_z.y=0; make_box(); }
int main (int argc, char *argv[]) { GtkWidget *window; GtkWidget *button; GtkWidget *box1; GtkWidget *box2; GtkWidget *separator; GtkWidget *label; GtkWidget *quitbox; int which; /* 初期化する、これを忘れるな! :) */ gtk_init (&argc, &argv); if (argc != 2) { fprintf (stderr, "usage: packbox num, where num is 1, 2, or 3.\n"); /* ただ GTK をクリーンアップし、exit ステータス 1 で終了 */ gtk_exit (1); } which = atoi (argv[1]); /* window を作成 */ window = gtk_window_new (GTK_WINDOW_TOPLEVEL); /* 常に main window へ destroy シグナルを接続するのを覚えているべ * きだ。これは適切な直感的振舞いのために非常に重要である */ gtk_signal_connect (GTK_OBJECT (window), "delete_event", GTK_SIGNAL_FUNC (delete_event), NULL); gtk_container_border_width (GTK_CONTAINER (window), 10); /* 水平ボックスをその中にパックするために垂直ボックス(vbox)を作成 * する。これは、この vbox に、ボタンで満たされた水平ボックスを他 * の上部に積むことを許すものだ。*/ box1 = gtk_vbox_new (FALSE, 0); /* 表示する例。これは上の図に対応する。*/ switch (which) { case 1: /* 新しいラベルを作成する。*/ label = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); /* ラベルを左サイドに並べる。この節ではこの関数および他のウィ * ジェット属性について議論する。*/ gtk_misc_set_alignment (GTK_MISC (label), 0, 0); /* 垂直ボックス (vbox box1) にラベルをパックする。vbox に加え * られたウィジェットは他のもののトップから順にパックされること * を覚えておこう。*/ gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); /* ラベルを表示 */ gtk_widget_show (label); /* ボックス作成関数を呼ぶ - homogeneous = FALSE, spacing = 0, * expand = FALSE, fill = FALSE, padding = 0 */ box2 = make_box (FALSE, 0, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* ボックス作成関数を呼ぶ - homogeneous = FALSE, spacing = 0, * expand = FALSE, fill = FALSE, padding = 0 */ box2 = make_box (FALSE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* セパレータを作成、これらについては後ほど詳しく学ぶが、 * 全く簡単だ。*/ separator = gtk_hseparator_new (); /* vbox にセパレータをパックする。これらのウィジェットは vbox * にパックされているので、これらは垂直に積まれる。*/ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); /* もう一つの新しいラベルを作成し、これを表示する。*/ label = gtk_label_new ("gtk_hbox_new (TRUE, 0);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (TRUE, 0, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (TRUE, 0, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* もう一つの新しいセパレータ。*/ separator = gtk_hseparator_new (); /* この gtk_box_pack_start への最後の 3 引数は次の通り: expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 2: /* 新しいラベルを作成、box1 は main() の始め近くで作成された * vbox である。*/ label = gtk_label_new ("gtk_hbox_new (FALSE, 10);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 10, TRUE, FALSE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 10, TRUE, TRUE, 0); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); separator = gtk_hseparator_new (); /* この gtk_box_pack_start への最後の 3 引数は次の通り: * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); label = gtk_label_new ("gtk_hbox_new (FALSE, 0);"); gtk_misc_set_alignment (GTK_MISC (label), 0, 0); gtk_box_pack_start (GTK_BOX (box1), label, FALSE, FALSE, 0); gtk_widget_show (label); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, FALSE, 10); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* 引数は次の通り: homogeneous, spacing, expand, fill, padding */ box2 = make_box (FALSE, 0, TRUE, TRUE, 10); gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); separator = gtk_hseparator_new (); /* この gtk_box_pack_start への最後の 3 引数は次の通り: * expand, fill, padding. */ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); break; case 3: /* これは gtk_box_pack_end() のウィジェットの右揃えの能力を説明す * るものである。第1に、先に新しいボックスを作成する。*/ box2 = make_box (FALSE, 0, FALSE, FALSE, 0); /* 最後に配置されるラベルを作成する。*/ label = gtk_label_new ("end"); /* gtk_box_pack_end() を使ってこれをパックするため、make_box() * 呼び出しで作成された hbox の右端に配置される。*/ gtk_box_pack_end (GTK_BOX (box2), label, FALSE, FALSE, 0); /* ラベルを表示する。*/ gtk_widget_show (label); /* box2 を box1 にパックする(この vbox を覚えているかい? :) */ gtk_box_pack_start (GTK_BOX (box1), box2, FALSE, FALSE, 0); gtk_widget_show (box2); /* 下端のセパレータ */ separator = gtk_hseparator_new (); /* これは明示的にセパレータを 400 ピクセル幅で 5 ピクセル高さ * に設定する。それゆえこの作成した hbox も 400 ピクセル幅にな * り、"end" ラベルはこの hbox 中の他のラベルと分離される。 * 一方で、この hbox の全てのウィジェットは可能ならお互いに閉 * じたものとしてパックされる。*/ gtk_widget_set_usize (separator, 400, 5); /* この main() の最初付近で作成された vbox (box1) の中にセパレー * タをパックする。*/ gtk_box_pack_start (GTK_BOX (box1), separator, FALSE, TRUE, 5); gtk_widget_show (separator); } /* もう一つの新しい hbox を作成する..。必要なだけたくさんを使える ことを覚えておこう! */ quitbox = gtk_hbox_new (FALSE, 0); /* quit ボタン。*/ button = gtk_button_new_with_label ("Quit"); /* この window を破壊するシグナルを設定する。これは "destroy" シグ * ナルをこの window に送る。これは前で定義された我々のシグナルハ * ンドラによって引き起こされることを覚えておこう。*/ gtk_signal_connect_object (GTK_OBJECT (button), "clicked", GTK_SIGNAL_FUNC (gtk_main_quit), GTK_OBJECT (window)); /* quitbox 中にこの button をパックする。gtk_box_pack_start への最 * 後の 3 引数は expand, fill, padding だ。 */ gtk_box_pack_start (GTK_BOX (quitbox), button, TRUE, FALSE, 0); /* quitbox を vbox (box1) の中にパックする。*/ gtk_box_pack_start (GTK_BOX (box1), quitbox, FALSE, FALSE, 0); /* 今全ての我々のウィジェットを含んだ vbox (box1) を、メインの * window の中にパックする。*/ gtk_container_add (GTK_CONTAINER (window), box1); /* そして全てを表示する。*/ gtk_widget_show (button); gtk_widget_show (quitbox); gtk_widget_show (box1); /* 全てを一度にポップアップするために最後にこの window を表示。*/ gtk_widget_show (window); /* そして勿論、メインの関数。 */ gtk_main (); /* gtk_main_quit() が呼ばれた時に制御が帰るが、gtk_exit が使われた * 場合はそうではない。*/ return 0; }
int main(int argc, char const *argv[]) { GtkWidget *window; GtkWidget *button; GtkWidget *box1; // for vbox GtkWidget *box2; // for hboxes GtkWidget *separator; GtkWidget *label; GtkWidget *quitbox; int which; gtk_init(&argc, &argv); if(argc != 2) { // 2nd parameter fprintf(stderr, "usage: packbox num, where num is 1, 2, or 3.\n"); exit(1); } which = atoi(argv[1]); window = gtk_window_new(GTK_WINDOW_TOPLEVEL); g_signal_connect(window, "delete-event", G_CALLBACK(delete_event), NULL); gtk_container_set_border_width(GTK_CONTAINER(window), 10); // Use a vbox to pack other hboxes box1 = gtk_vbox_new(FALSE, 0); g_print("box1 = gtk_vbox_new(FALSE, 0);"); // switch between examples switch(which) { case 1: createLabelAndPack("gtk_hbox_new (gboolean homogeneous, \ gint spacing) -> gtk_hbox_new(FALSE, 0);", box1, FALSE, FALSE, 0); /* Make three hbox and pack them into one vbox */ // homogeneous = FALSE, spacing = 0, expand = FALSE, fill = FALSE, padding = 0 box2 = make_box(FALSE, 0, FALSE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); // homogeneous = FALSE, spacing = 0, expand = TRUE, fill = FALSE, padding = 0 */ box2 = make_box(FALSE, 0, TRUE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); // Args are: homogeneous, spacing, expand, fill, padding box2 = make_box(FALSE, 0, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); /* Put a seperator */ separator = gtk_hseparator_new(); // pack the separator into vbox gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, TRUE, 5); gtk_widget_show(separator); // Create another new label, and show it. createLabelAndPack("gtk_hbox_new (gboolean homogeneous, \ gint spacing) -> gtk_hbox_new(TRUE, 0);", box1, FALSE, FALSE, 0); /* Make two hbox and pack them into one vbox */ box2 = make_box(TRUE, 0, TRUE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); box2 = make_box(TRUE, 0, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); /* Another new separator. */ separator = gtk_hseparator_new(); /* The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, TRUE, 5); gtk_widget_show(separator); break; case 2: createLabelAndPack("gtk_hbox_new (gboolean homogeneous, \ gint spacing) -> gtk_hbox_new(FALSE, 10)", box1, FALSE, FALSE, 0); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box(FALSE, 10, TRUE, FALSE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box(FALSE, 10, TRUE, TRUE, 0); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); separator = gtk_hseparator_new(); /* The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, TRUE, 5); gtk_widget_show(separator); createLabelAndPack("gtk_hbox_new (gboolean homogeneous, \ gint spacing) -> gtk_hbox_new(FALSE, 0);", box1, FALSE, FALSE, 0); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box(FALSE, 0, TRUE, FALSE, 10); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); /* Args are: homogeneous, spacing, expand, fill, padding */ box2 = make_box(FALSE, 0, TRUE, TRUE, 10); gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); separator = gtk_hseparator_new(); /* The last 3 arguments to gtk_box_pack_start are: expand, fill, padding. */ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, TRUE, 5); gtk_widget_show(separator); break; case 3: /* This demonstrates the ability to use gtk_box_pack_end() to * right justify widgets. First, we create a new box as before. */ box2 = make_box(FALSE, 0, FALSE, FALSE, 0); /* Create the label that will be put at the end. */ label = gtk_label_new("end"); /* Pack it using gtk_box_pack_end(), so it is put on the right * side of the hbox created in the make_box() call. */ gtk_box_pack_end(GTK_BOX(box2), label, FALSE, FALSE, 0); /* Show the label. */ gtk_widget_show(label); /* Pack box2 into box1(the vbox remember ? :) */ gtk_box_pack_start(GTK_BOX(box1), box2, FALSE, FALSE, 0); gtk_widget_show(box2); /* A separator for the bottom. */ separator = gtk_hseparator_new(); /* This explicitly sets the separator to 400 pixels wide by 5 pixels * high. This is so the hbox we created will also be 400 pixels wide, * and the "end" label will be separated from the other labels in the * hbox. Otherwise, all the widgets in the hbox would be packed as * close together as possible. */ gtk_widget_set_size_request(separator, 400, 5); /* pack the separator into the vbox(box1) created near the start * of main() */ gtk_box_pack_start(GTK_BOX(box1), separator, FALSE, TRUE, 5); gtk_widget_show(separator); } /* Create another new hbox.. remember we can use as many as we need! */ quitbox = gtk_hbox_new(FALSE, 0); /* Our quit button. */ button = gtk_button_new_with_label("Quit"); /* Setup the signal to terminate the program when the button is clicked */ g_signal_connect_swapped(button, "clicked", G_CALLBACK(gtk_main_quit), window); /* Pack the button into the quitbox. * The last 3 arguments to gtk_box_pack_start are: * expand, fill, padding. */ gtk_box_pack_start(GTK_BOX(quitbox), button, TRUE, FALSE, 0); /* pack the quitbox into the vbox(box1) */ gtk_box_pack_start(GTK_BOX(box1), quitbox, FALSE, FALSE, 0); /* Pack the vbox(box1) which now contains all our widgets, into the * main window. */ gtk_container_add(GTK_CONTAINER(window), box1); /* And show everything left */ gtk_widget_show(button); gtk_widget_show(quitbox); gtk_widget_show(box1); /* Showing the window last so everything pops up at once. */ gtk_widget_show(window); /* And of course, our main function. */ gtk_main(); /* Control returns here when gtk_main_quit() is called, but not when * exit() is used. */ return 0; }