/** * Copyright (c) 2005, Ian Paul Larsen * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. **/ #include /** Callback Function. * We can attach this function to a widget * so that something happens after an event. */ void finished(struct ntw_event_data *evdata, ntwWidget *userdata){ printf("Window closed\n"); ntw_main_quit(); } /** Main. */ int main (int argc, char **argv){ /** Defining the widgets. * We'll use a window, button, and label to start off. */ ntwWidget *window; ntwWidget *button; ntwWidget *label; /** ntw_init must be called before we actually * do anything. This sets up the ntw server to listen on * our port. It also does some widget preparation. */ ntw_init(argc, argv); /** Now we'll create a window. * The first two arguments are the size of the window in pixels, * and the last is the height. */ window = ntw_window_new(150, 50, "Hello World"); /** Creating the button. * Like the window, the button is a container that * can hold one other widget. */ button = ntw_button_new(); /** Now that we have a button, we can put it * inside the window. */ ntw_container_add(window, button); /** Creating the label. * We don't just want a blank button. * The label widget is a string of text that we * can put in the button. */ label = ntw_label_new("Click to Quit"); /** Now that we have a label, we can put it * inside the button, the same way that we * put the button in the window. */ ntw_container_add(button, label); /** Now let's handle some events by attaching callback functions to widgets. * This first will call finished when the button is clicked. */ ntw_add_callback(button, BUTTON_CLICKED, (func_ptr) &finished, NULL, ASYNC); /** And these will call finished if the window if the user closes the window. */ ntw_add_callback(window, DESTROY_EVENT, (func_ptr) &finished, NULL, ASYNC); ntw_add_callback(window, DELETE_EVENT, (func_ptr) &finished, NULL, ASYNC); /** By default, top level windows are not visible. * This is so that we don't see the widgets appear * one by one as they're added to the window. * Now that everything's ready, we can make the window * visible. */ ntw_widget_show(window); /** ntw_main -- the main event loop * This is what handles events, and we have to call it after * everything else is prepared. */ ntw_main(); return 0; }