static int run_demo(struct demo *gui) { int ret = 1; static int init = 0; static struct node_editor nodedit; struct zr_context *ctx = &gui->ctx; if (!init) { memset(&nodedit, 0, sizeof(nodedit)); node_editor_init(&nodedit); init = 1; } /* windows */ simple_window(ctx); demo_window(ctx); node_editor_demo(ctx, &nodedit); #ifndef DEMO_DO_NOT_DRAW_IMAGES grid_demo(ctx); button_demo(ctx, &gui->icons); basic_demo(ctx, &gui->icons); #endif ret = control_window(ctx, gui); zr_buffer_info(&gui->status, &gui->ctx.memory); return ret; }
// The start of the Application int App::start(const std::vector<CL_String> &args) { // Setup the window CL_DisplayWindowDescription win_desc; win_desc.set_allow_resize(true); win_desc.set_title("3D GUI Example"); win_desc.set_size(CL_Size( 700, 700 ), false); window = CL_DisplayWindow(win_desc); // Connect the slots that we require CL_Slot slot_quit = window.sig_window_close().connect(this, &App::on_window_close); CL_Slot slot_input_down = (window.get_ic().get_keyboard()).sig_key_down().connect(this, &App::on_input_down); CL_GraphicContext gc = window.get_gc(); CL_Font font = CL_Font(gc, "tahoma", 16); // Initialise the GUI system GUI gui(this); // NOTE: The GUI component positions are still in 2D world, therefore // be careful not to overlap windows, else unpredicted results may occur! window1 = new Window1(gui, CL_Rect(0,0, CL_Size(256, 256))); slider_1_xrotation = new Slider(gui, CL_Rect(0, 512, CL_Size(200, 17))); slider_1_xrotation->object_matrix.translate_self(0.0f, 0.8f, 3.0f); slider_1_xrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_yrotation = new Slider(gui, CL_Rect(256*1, 512, CL_Size(200, 17))); slider_1_yrotation->object_matrix.translate_self(0.0f, 0.7f, 3.0f); slider_1_yrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_zrotation = new Slider(gui, CL_Rect(256*2, 512, CL_Size(200, 17))); slider_1_zrotation->object_matrix.translate_self(0.0f, 0.6f, 3.0f); slider_1_zrotation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_xtranslation = new Slider(gui, CL_Rect(256*3, 512, CL_Size(200, 17))); slider_1_xtranslation->object_matrix.translate_self(0.0f, 0.5f, 3.0f); slider_1_xtranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_xtranslation->component->set_position(500); slider_1_ytranslation = new Slider(gui, CL_Rect(256*4, 512, CL_Size(200, 17))); slider_1_ytranslation->object_matrix.translate_self(0.0f, 0.4f, 3.0f); slider_1_ytranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_ytranslation->component->set_position(500); slider_1_ztranslation = new Slider(gui, CL_Rect(256*5, 512, CL_Size(200, 17))); slider_1_ztranslation->object_matrix.translate_self(0.0f, 0.3f, 3.0f); slider_1_ztranslation->object_matrix.multiply(CL_Mat4f::rotate(CL_Angle(10, cl_degrees), 0.0f, 0.0f, 1.0f)); slider_1_ztranslation->component->set_position(500); while(!quit) { calculate_matrix(); gc.set_modelview(CL_Mat4f::identity()); gc.set_map_mode(CL_MapMode(cl_map_2d_upper_left)); // Draw the gradient CL_Draw::gradient_fill(gc, CL_Rect(0, 0, gc.get_width(), gc.get_height()/2), CL_Gradient(CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f), CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f))); CL_Draw::gradient_fill(gc, CL_Rect(0, gc.get_height()/2, gc.get_width(), gc.get_height()), CL_Gradient(CL_Colorf(0.0f, 0.0f, 0.2f, 1.0f), CL_Colorf(0.2f, 0.2f, 0.8f, 1.0f))); font.draw_text(gc, 8, 20, "GUI3D"); int xoffset = 160; int yoffset = 70; const int ygap = 35; font.draw_text(gc, xoffset, yoffset, "X Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Y Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Z Rotation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "X Translation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Y Translation"); yoffset += ygap; font.draw_text(gc, xoffset, yoffset, "Z Translation"); yoffset += ygap; if (!gui.run()) break; gc.set_map_mode(cl_user_projection); gc.set_projection(projection_matrix); gc.set_modelview(modelview_matrix); control_window(); gui.draw(); window.flip(1); CL_KeepAlive::process(); } return 0; }