int main(void) { // instantiate window GWindow window = newGWindow(320, 240); // instantiate slider addToRegion(window, newGLabel("0"), "SOUTH"); GSlider slider = newGSlider(0, 100, 50); setActionCommand(slider, "slide"); addToRegion(window, slider, "SOUTH"); addToRegion(window, newGLabel("100"), "SOUTH"); // listen for events while (true) { // wait for event GActionEvent event = waitForEvent(ACTION_EVENT); // if window was closed if (getEventType(event) == WINDOW_CLOSED) { break; } // if action command is "slide" if (strcmp(getActionCommand(event), "slide") == 0) { printf("slider was slid to %i\n", getValue(slider)); } } // that's all folks closeGWindow(window); return 0; }
o/** * slider.c * * David J. Malan * [email protected] * * Demonstrates a slider. */ // standard libraries #include <stdio.h> #include <string.h> // Stanford Portable Library #include <spl/gevents.h> #include <spl/ginteractors.h> #include <spl/gwindow.h> int main(void) { // instantiate window GWindow window = newGWindow(320, 240); // instantiate slider addToRegion(window, newGLabel("0"), "SOUTH"); GSlider slider = newGSlider(0, 100, 50); setActionCommand(slider, "slide"); addToRegion(window, slider, "SOUTH"); addToRegion(window, newGLabel("100"), "SOUTH"); // listen for events while (true) { // wait for event GActionEvent event = waitForEvent(ACTION_EVENT); // if window was closed if (getEventType(event) == WINDOW_CLOSED) { break; } // if action command is "slide" if (strcmp(getActionCommand(event), "slide") == 0) { printf("slider was slid to %i\n", getValue(slider)); } } // that's all folks closeGWindow(window); return 0; }
int main(void) { GWindow window = newGWindow(320, 240); GButton button = newGButton("button"); setActionCommand( button, "check" ); addToRegion(window, button, "SOUTH"); while( true ) { GActionEvent event = waitForEvent( ACTION_EVENT ); if( getEventType(event) == WINDOW_CLOSED ) { break; } else if( strcmp( getActionCommand(event) , "click") == 0 ) { printf("button was clicked\n"); } } closeGWindow(window); return 0; }
int main(void) { // instantiate window GWindow window = newGWindow(320, 240); // instantiate button GButton button = newGButton("Button"); setActionCommand(button, "click"); // add button to southern region of window addToRegion(window, button, "SOUTH"); // listen for events while (true) { // wait for event GActionEvent event = waitForEvent(ACTION_EVENT); // if window was closed if (getEventType(event) == WINDOW_CLOSED) { break; } // if action command is "click" if (strcmp(getActionCommand(event), "click") == 0) { printf("button was clicked\n"); } } // that's all folks closeGWindow(window); return 0; }
void writeCylinder ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; vect_t base, height; if (translate) { VADD2(base, form.data.pt[0], form.tr_vec); } else { VMOVE(base, form.data.pt[0]); } VSUB2(height, form.data.pt[1], form.data.pt[0]); VSCALE(base, base, IntavalUnitInMm); VSCALE(height, height, IntavalUnitInMm); fastf_t radius = form.radius1 * IntavalUnitInMm; sprintf(name, "s%lu.rcc", (long unsigned)++rcc_counter); mk_rcc(wdbp, name, base, height, radius); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
void writeRectangularBox ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; point_t min, max; if (translate) { VADD2(min, form.data.pt[0], form.tr_vec); VADD2(max, form.data.pt[1], form.tr_vec); } else { VMOVE(min, form.data.pt[0]); VMOVE(max, form.data.pt[1]); } VSCALE(min, min, IntavalUnitInMm); VSCALE(max, max, IntavalUnitInMm); sprintf(name, "s%lu.rpp", (long unsigned int)++rpp_counter); mk_rpp(wdbp, name, min, max); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
int main(void) { // instantiate window GWindow window = newGWindow(320, 240); GCheckBox checkBox = newGCheckBox("I agree"); setActionCommand(checkBox, "check"); addToRegion(window, checkBox, "SOUTH"); while (true) { GActionEvent event = waitForEvent(ACTION_EVENT); if (getEventType(event) == WINDOW_CLOSED) { break; } if (strcmp(getActionCommand(event), "check") == 0) { if (isSelected(checkBox)) { printf("Checkbox was checked\n"); } else { printf("Checkbox was unchecked\n"); } } } closeGWindow(window); return 0; }
/** * Instantiates paddle in bottom-middle of window. */ GRect initPaddle(GWindow window) { // creats a paddle GRect paddle = newGRect(0,0,80,10); setColor(paddle,"GREY"); setFilled(paddle, true); add(window, paddle); addToRegion(window, paddle, "SOUTH"); return paddle; }
void writePlateBot ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; fastf_t vertices[MAX_NPTS * 3]; if (translate) { for (size_t i = 0; i < form.data.bot.num_vertices; ++i) { vertices[i * 3] = (form.data.bot.vertices[i * 3] + form.tr_vec[0]) * IntavalUnitInMm; vertices[i * 3 + 1] = (form.data.bot.vertices[i * 3 + 1] + form.tr_vec[1]) * IntavalUnitInMm; vertices[i * 3 + 2] = (form.data.bot.vertices[i * 3 + 2] + form.tr_vec[2]) * IntavalUnitInMm; } } else { for (size_t i = 0; i<form.data.bot.num_vertices; ++i) { vertices[i * 3] = form.data.bot.vertices[i * 3] * IntavalUnitInMm; vertices[i * 3 + 1] = form.data.bot.vertices[i * 3 + 1] * IntavalUnitInMm; vertices[i * 3 + 2] = form.data.bot.vertices[i * 3 + 2] * IntavalUnitInMm; } } fastf_t thickness[MAX_TRIANGLES]; for (size_t i = 0; i < form.data.bot.num_faces; ++i) thickness[i] = form.thickness * IntavalUnitInMm; bu_bitv* faceMode = bu_bitv_new(form.data.bot.num_faces); sprintf(name, "s%lu.pbot", (long unsigned)++bot_counter); mk_bot(wdbp, name, RT_BOT_PLATE, RT_BOT_UNORIENTED, 0, form.data.bot.num_vertices, form.data.bot.num_faces, vertices, form.data.bot.faces, thickness, faceMode); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); bu_bitv_free(faceMode); }
void writeSolidBot ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; fastf_t vertices[MAX_NPTS * 3]; if (translate) { for (size_t i = 0; i < form.data.bot.num_vertices; ++i) { vertices[i * 3] = (form.data.bot.vertices[i * 3] + form.tr_vec[0]) * IntavalUnitInMm; vertices[i * 3 + 1] = (form.data.bot.vertices[i * 3 + 1] + form.tr_vec[1]) * IntavalUnitInMm; vertices[i * 3 + 2] = (form.data.bot.vertices[i * 3 + 2] + form.tr_vec[2]) * IntavalUnitInMm; } } else { for (size_t i = 0; i < form.data.bot.num_vertices; ++i) { vertices[i * 3] = form.data.bot.vertices[i * 3] * IntavalUnitInMm; vertices[i * 3 + 1] = form.data.bot.vertices[i * 3 + 1] * IntavalUnitInMm; vertices[i * 3 + 2] = form.data.bot.vertices[i * 3 + 2] * IntavalUnitInMm; } } sprintf(name, "s%lu.sbot", (long unsigned)++bot_counter); mk_bot(wdbp, name, RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, form.data.bot.num_vertices, form.data.bot.num_faces, vertices, form.data.bot.faces, 0, 0); smoothBot(wdbp, name); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
void writeArb8 ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; point_t shuffle[8]; if (translate) { VADD2(shuffle[0], form.data.pt[0], form.tr_vec); VADD2(shuffle[1], form.data.pt[7], form.tr_vec); VADD2(shuffle[2], form.data.pt[3], form.tr_vec); VADD2(shuffle[3], form.data.pt[1], form.tr_vec); VADD2(shuffle[4], form.data.pt[6], form.tr_vec); VADD2(shuffle[5], form.data.pt[5], form.tr_vec); VADD2(shuffle[6], form.data.pt[4], form.tr_vec); VADD2(shuffle[7], form.data.pt[2], form.tr_vec); } else { VMOVE(shuffle[0], form.data.pt[0]); VMOVE(shuffle[1], form.data.pt[7]); VMOVE(shuffle[2], form.data.pt[3]); VMOVE(shuffle[3], form.data.pt[1]); VMOVE(shuffle[4], form.data.pt[6]); VMOVE(shuffle[5], form.data.pt[5]); VMOVE(shuffle[6], form.data.pt[4]); VMOVE(shuffle[7], form.data.pt[2]); } for (size_t i = 0; i < 8; ++i) { VSCALE(shuffle[i], shuffle[i], IntavalUnitInMm); } sprintf(name, "s%lu.arb8", (long unsigned)++arb8_counter); mk_arb8(wdbp, name, reinterpret_cast<fastf_t*>(shuffle)); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); }
void writePipe ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; fastf_t radius = form.radius1 * IntavalUnitInMm; bu_list pipePointList; mk_pipe_init(&pipePointList); for (size_t i = 1; i < form.npts; ++i) { point_t pipePoint; if (translate) { VADD2(pipePoint, form.data.pt[i-1], form.tr_vec); } else { VMOVE(pipePoint, form.data.pt[i-1]); } VSCALE(pipePoint, pipePoint, IntavalUnitInMm); mk_add_pipe_pt(&pipePointList, pipePoint, radius, 2 * radius / 3., radius / 2.); } sprintf(name, "s%lu.pipe", (long unsigned int)++pipe_counter); if (mk_pipe(wdbp, name, &pipePointList) == 0) { addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); } mk_pipe_free(&pipePointList); }
void writeRingModeBox ( rt_wdb* wdbp, Form& form, bool translate ) { char name[NAMELEN + 1]; // get the transformed outer points vect_t outer[MAX_NPTS]; if (translate) { for (size_t i = 0; i < form.npts; ++i) VADD2(outer[i], form.data.pt[i], form.tr_vec); } else { for (size_t i = 0; i < form.npts; ++i) { VMOVE(outer[i], form.data.pt[i]); } } for (size_t i1 = 0; i1 < form.npts; ++i1) { VSCALE(outer[i1], outer[i1], IntavalUnitInMm); } // compute inner points vect_t inner[MAX_NPTS]; for (size_t i2 = 0; i2 < form.npts; ++i2) { vect_t a, b, c; VMOVE(a, outer[i2]); if (i2 == 0) { VMOVE(b, outer[i2 + 1]); VMOVE(c, outer[form.npts-1]); } else if (i2 == form.npts-1) { VMOVE(b, outer[0]); VMOVE(c, outer[i2 - 1]); } else { VMOVE(b, outer[i2 + 1]); VMOVE(c, outer[i2 - 1]); } vect_t b_v, c_v; VSUB2(b_v, b, a); VSUB2(c_v, c, a); vect_t n_v; VCROSS(n_v, b_v, c_v); // with on b_v vect_t width_b_v; VCROSS(width_b_v, b_v, n_v); if (VDOT(width_b_v, c_v) < 0) VREVERSE(width_b_v, width_b_v); VUNITIZE(width_b_v); VSCALE(width_b_v, width_b_v, form.width * IntavalUnitInMm); // with on c_v vect_t width_c_v; VCROSS(width_c_v, c_v, n_v); if (VDOT(width_c_v, b_v) < 0) VREVERSE(width_c_v, width_c_v); VUNITIZE(width_c_v); VSCALE(width_c_v, width_c_v, form.width * IntavalUnitInMm); // intersection VUNITIZE(b_v); VUNITIZE(c_v); vect_t cb_v; VSUB2(cb_v, b_v, c_v); fastf_t l_cb_v = MAGNITUDE(cb_v); if (!NEAR_ZERO(l_cb_v, VUNITIZE_TOL)) { vect_t width_cb_v; VSUB2(width_cb_v, width_b_v, width_c_v); vect_t s_b_v; VSCALE(s_b_v, b_v, MAGNITUDE(width_cb_v) / l_cb_v); vect_t res; VADD2(res, a, width_c_v); VADD2(res, res, s_b_v); VMOVE(inner[i2], res); } else { VMOVE(inner[i2], outer[i2]); } } // bot parameters // vertices size_t num_vertices = 0; size_t outer_i[MAX_NPTS]; size_t inner_i[MAX_NPTS]; fastf_t vertices[MAX_NPTS * 3]; for (size_t i3 = 0; i3 < form.npts; ++i3) { size_t i = 0; // outer // search for duplicate vertex for (; i < num_vertices; ++i) { if (NEAR_EQUAL(outer[i3][0], vertices[3 * i], VUNITIZE_TOL) && NEAR_EQUAL(outer[i3][1], vertices[3 * i + 1], VUNITIZE_TOL) && NEAR_EQUAL(outer[i3][2], vertices[3 * i + 2], VUNITIZE_TOL)) { outer_i[i3] = i; break; } } if (i == num_vertices) { // add a new vertex vertices[num_vertices * 3] = outer[i3][0]; vertices[num_vertices * 3 + 1] = outer[i3][1]; vertices[num_vertices * 3 + 2] = outer[i3][2]; outer_i[i3] = num_vertices; ++num_vertices; } // inner // search for duplicate vertex for (i = 0; i < num_vertices; ++i) { if (NEAR_EQUAL(inner[i3][0], vertices[3 * i], VUNITIZE_TOL) && NEAR_EQUAL(inner[i3][1], vertices[3 * i + 1], VUNITIZE_TOL) && NEAR_EQUAL(inner[i3][2], vertices[3 * i + 2], VUNITIZE_TOL)) { inner_i[i3] = i; break; } } if (i == num_vertices) { // add a new vertex vertices[num_vertices * 3] = inner[i3][0]; vertices[num_vertices * 3 + 1] = inner[i3][1]; vertices[num_vertices * 3 + 2] = inner[i3][2]; inner_i[i3] = num_vertices; ++num_vertices; } } // faces size_t num_faces = 0; int faces[MAX_TRIANGLES * 3]; for (size_t i4 = 0; i4 < form.npts; ++i4) { size_t nextIndex = (i4 + 1) % form.npts; addTriangle(faces, num_faces, outer_i[i4], outer_i[nextIndex], inner_i[i4]); addTriangle(faces, num_faces, inner_i[i4], outer_i[nextIndex], inner_i[nextIndex]); } fastf_t thickness[MAX_TRIANGLES]; for (size_t i5 = 0; i5 < num_faces; ++i5) thickness[i5] = form.thickness * IntavalUnitInMm; bu_bitv* faceMode = bu_bitv_new(num_faces); sprintf(name, "s%lu.pbot", (long unsigned)++bot_counter); mk_bot(wdbp, name, RT_BOT_PLATE, RT_BOT_UNORIENTED, 0, num_vertices, num_faces, vertices, faces, thickness, faceMode); addToRegion(form.compnr, name); if (form.s_compnr >= 1000) excludeFromRegion(form.s_compnr, name); bu_bitv_free(faceMode); }