Exemplo n.º 1
0
END_TEST

START_TEST (test_win_handler_move_cursor)
{
  Win *w;
  int ret;
  int i;
  win_properties props = { 0, 0 };

  /* Test non cursor window. */
  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);
  ret = win_move_cursor (w, -1);
  fail_unless (ret < 0);
  win_free (w);

  /* Test cursor window */
  props.properties = WIN_PROP_CURSOR;
  w = win_create (0, 0, 20, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);
  ret = win_go_to_line (w, 60);
  fail_unless (ret == 0);
  ret = win_move_cursor (w, 1);
  fail_unless (ret == 0);
  ret = win_move_cursor (w, -1);
  fail_unless (ret == 0);
  ret = win_move_cursor (w, 25);
  fail_unless (ret == 0);
  ret = win_move_cursor (w, -25);
  fail_unless (ret == 0);


  for (i = 0; i < 125; i++)
    {
      ret = win_move_cursor (w, 1);
      fail_unless (ret == 0);
    }
  for (i = 0; i < 125; i++)
    {
      ret = win_move_cursor (w, -1);
      fail_unless (ret == 0);
    }
  win_free (w);
}
Exemplo n.º 2
0
END_TEST

START_TEST (test_win_handler_get_line)
{
  Win *w;
  int ret;
  int i;
  char buf[64];
  const char *line;

  win_properties props = { 0, WIN_PROP_CURSOR, NULL, 0, NULL };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);

  for (i = 0; i < 150; i++)
    {
      sprintf (buf, "Line %d", i);
      ret = win_add_line (w, buf, 0, i);
      fail_unless (ret == 0);
    }

  for (i = 0; i < 150; i++)
    {
      sprintf (buf, "Line %d", i);
      line = win_get_line (w, i);
      fail_unless (strcmp (line, buf) == 0);
    }
  line = win_get_line (w, -1);
  fail_unless (line == NULL);
  line = win_get_line (w, 200);
  fail_unless (line == NULL);

  win_free (w);
}
Exemplo n.º 3
0
ProfWin *
cons_create(void)
{
    int cols = getmaxx(stdscr);
    console = win_create(CONS_WIN_TITLE, cols, WIN_CONSOLE);
    return console;
}
Exemplo n.º 4
0
/*-----------------------------------------------------------------------------*/
void
plot_win (int ti, YT_PLOT *plot, int iw, int ih, int ih_one)
{
  int  wi;
  int  yi = 1;

  // создаем экранную форму и рисуем главную рамочку
  YT_WIN  *win = win_create (iw, ih);
  win_rect (win, '=', '|', 0, 0, iw, ih);

  // здесь надо идти не по списку функций, а по фреймам!
  for (wi=0; plot->fr[wi][0] != -1; wi++) {

    plot_win_main (plot, win,  /* fi */wi, ti,  1, yi, iw-2, ih_one);

    yi += ih_one;
    win_horz (win, '=', yi, 2, iw-3);
    yi++;
  }

  // выводим экранную форму
  win_draw (win, 0, 0);

  return;
}
Exemplo n.º 5
0
END_TEST

START_TEST (test_win_handler_tag)
{
  Win *w;
  int ret;
  int i;
  char buf[64];

  win_properties props = { 0, WIN_PROP_CURSOR };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);

  for (i = 0; i < 150; i++)
    {
      sprintf (buf, "Line nr %d", i);
      ret = win_add_line (w, buf, 0, i);
      fail_unless (ret == 0);
    }
  for (i = 0; i < 150; i++)
    {
      ret = win_go_to_line (w, i);
      fail_unless (ret == 0);
      ret = win_get_tag (w);
      fail_unless (ret == i, "tag = %d != %d", ret, i);
    }
  win_free (w);
}
Exemplo n.º 6
0
END_TEST

START_TEST (test_win_handler_syntax)
{
  Win *w;
  int ret;
  int i;
  char buf[64];
  const char *line;
  win_attribute attr[] = { {1, 0x01}, {2, 0x02}, {3, 0x03} };
  char *scan =
    strdup
    ("{id='1',type='1',match='int'},{id='2',match='Line'},{id='1',match='[[:digit:]]*'}");

  win_properties props =
    { 0, WIN_PROP_CURSOR | WIN_PROP_SYNTAX, attr, 3, scan };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);

  for (i = 0; i < 45; i++)
    {
      sprintf (buf, "Line int %d", i);
      ret = win_add_line (w, buf, 1, i);
      fail_unless (ret == 0);
    }
  win_go_to_line (w, 5);
  free (scan);

  win_free (w);
}
Exemplo n.º 7
0
/**
 * This function creates a new icon button widget. It allocates required memory
 * and initializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the icon button's child reference, given by
 * wtk_icon_button_as_child(), like this:
 * "win_destroy(wtk_icon_button_as_child(myButtonPtr));".
 * Usually it will be destroyed automatically when it's parent is destroyed.
 *
 * \param parent Parent window, possibly wtk_frame_as_parent(myFramePtr).
 * \param area Area of the internal contents.
 * \param icon Bitmap to draw as the icon.
 * \param selected Initial state of icon button, true if checked/selected.
 * \param group Icon button group to be a member of.
 * \param command Command to send to parent window. Must be non-zero to be
 *                enabled.
 *
 * \return Pointer to icon button, or NULL if failed.
 */
struct wtk_icon_button *wtk_icon_button_create(struct win_window *parent,
		struct win_area const *area, struct gfx_bitmap *icon,
		bool selected, struct wtk_icon_group *group, win_command_t command)
{
	struct wtk_icon_button *icon_button;
	struct win_attributes attr;

	Assert(group);
	Assert(area);
	Assert(icon);
	Assert(parent);

	/* Allocate memory for check box control data. */
	icon_button = membag_alloc(sizeof(struct wtk_icon_button));
	if (!icon_button) {
		goto outofmem_icon_button;
	}

	icon_button->state = WTK_ICONBUTTON_NORMAL;
	icon_button->group = group;
	icon_button->command = command;

	/* Handling information. */
	attr.event_handler = wtk_icon_button_handler;
	attr.custom = icon_button;

	/* Prepare container frame. */
	attr.area = *area;
	attr.background = icon;
	attr.behavior = 0;

	icon_button->container = win_create(parent, &attr);
	if (!icon_button->container) {
		goto outofmem_container;
	}

	/* Select the icon button in the group if either no icon button is
	 * currently selected (empty group), or the user has requested it takes
	 * over the selection */
	if (selected || (group->selected == NULL)) {
		/* Add ourselves to the icon group, take over selection if required. */
		wtk_icon_button_select(icon_button);
	}

	/* Make sure we haven't filled up the group reference count, and
	 * increment. */
	Assert(group->num_references < (wtk_icon_group_size_t)-1L);
	++(group->num_references);

	return icon_button;

outofmem_container:
	membag_free(icon_button);

outofmem_icon_button:
	return NULL;
}
Exemplo n.º 8
0
/**
 * This function creates a new check box widget. It allocates required memory
 * and intializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 *
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the check box' child reference, given by
 * wtk_check_box_as_child(), like this:
 * "win_destroy(wtk_check_box_as_child(my_check_box_ptr));".
 * Usually it will be destroyed automatically when it's parent is destroyed.
 *
 * \param parent Parent window, possibly wtk_frame_as_parent(my_frame_ptr).
 * \param area Area of the internal contents.
 * \param caption Pointer to caption string. Will be copied into widget.
 * \param selected Initial state of check box, true if checked/selected.
 * \param command Command to send to parent window. Must be non-zero to be
 *                enabled.
 *
 * \return Pointer to check box, or NULL if failed.
 */
struct wtk_check_box *wtk_check_box_create(struct win_window *parent,
		struct win_area const *area,
		char const *caption, bool selected, win_command_t command)
{
	struct win_attributes attr;
	struct wtk_check_box *check_box;

	Assert(area);
	Assert(caption);
	Assert(parent);

	/* Allocate memory for check box control data. */
	check_box = membag_alloc(sizeof(struct wtk_check_box));
	if (!check_box) {
		goto outofmem_check_box;
	}

	check_box->state = WTK_CHECKBOX_NORMAL;
	check_box->selected = selected;
	check_box->command = command;

	/* Allocate memory for caption string, and copy text. */
	check_box->caption = membag_alloc((strlen(caption) + 1) * sizeof(char));
	if (!check_box->caption) {
		goto outofmem_caption;
	}

	wtk_copy_string(check_box->caption, caption);

	/* Handling information. */
	attr.event_handler = wtk_check_box_handler;
	attr.custom = check_box;

	/* Prepare container frame. */
	attr.area = *area;
	attr.background = NULL;
	attr.behavior = WIN_BEHAVIOR_REDRAW_PARENT;

	check_box->container = win_create(parent, &attr);
	if (!check_box->container) {
		goto outofmem_container;
	}

	return check_box;

outofmem_container:
	membag_free(check_box->caption);

outofmem_caption:
	membag_free(check_box);

outofmem_check_box:
	return NULL;
}
Exemplo n.º 9
0
END_TEST

START_TEST (test_win_handler_mark)
{
  Win *w;
  int ret;
  win_properties props = { 0, 0 };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);

  ret = win_set_mark (w, 15, 1, '?');
  fail_unless (ret < 0);
  win_free (w);

  props.indent = 100;
  props.properties = WIN_PROP_MARKS | WIN_PROP_CURSOR;
  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);
  ret = win_set_mark (w, 1115, 1, '?');
  fail_unless (ret < 0);
  ret = win_set_mark (w, -1, 1, '?');
  fail_unless (ret == 0);	/* Last line */
  ret = win_set_mark (w, 15, 100, '?');
  fail_unless (ret < 0);
  ret = win_set_mark (w, 15, 9, '?');
  fail_unless (ret < 0);
  ret = win_set_mark (w, 15, -1, '?');
  fail_unless (ret < 0);
  ret = win_set_mark (w, 15, 2, '\001');
  fail_unless (ret < 0);

  ret = win_set_mark (w, 2, 2, '?');
  fail_unless (ret == 0);
  win_free (w);

}
Exemplo n.º 10
0
/**
 * This function creates a new button widget. It allocates required memory and
 * intializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 *
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the button's child reference, given by
 * wtk_button_as_child(), like this:
 *   "win_destroy(wtk_button_as_child(myButtonPtr));".
 * Usually it will be destroyed automatically when it's parent is destroyed.
 *
 * \param parent Parent window, possibly wtk_frame_as_parent(myFramePtr).
 * \param area Area of the internal contents.
 * \param caption Pointer to caption string. Will be copied into widget.
 * \param command_data Custom data to put into a command event when "clicked".
 *
 * \return Pointer to button, or NULL if failed.
 */
struct wtk_button *wtk_button_create(struct win_window *parent,
		struct win_area const *area,
		char const *caption, win_command_t command_data)
{
	struct win_attributes attr;
	struct wtk_button *button;

	Assert(area);
	Assert(caption);
	Assert(parent);

	/* Allocate memory for button control data. */
	button = membag_alloc(sizeof(struct wtk_button));
	if (!button) {
		goto outofmem_button;
	}

	button->state = WTK_BUTTON_NORMAL;
	button->command = command_data;

	/* Allocate memory for caption string, and copy text. */
	button->caption = membag_alloc((strlen(caption) + 1) * sizeof(char));
	if (!button->caption) {
		goto outofmem_caption;
	}

	wtk_copy_string(button->caption, caption);

	/* Handling information. */
	attr.event_handler = wtk_button_handler;
	attr.custom = button;

	/* Prepare container frame. */
	attr.area = *area;
	attr.background = NULL;
	attr.behavior = 0x00;

	button->container = win_create(parent, &attr);
	if (!button->container) {
		goto outofmem_container;
	}

	return button;

outofmem_container:
	membag_free(button->caption);

outofmem_caption:
	membag_free(button);

outofmem_button:
	return NULL;
}
Exemplo n.º 11
0
int main(int argc, char **argv) {
  const char *appdir = fs_appdir();

  if (!fs_mkdir(appdir)) {
    LOG_FATAL("Failed to create app directory %s", appdir);
  }

  // load base options from config
  char config[PATH_MAX] = {0};
  snprintf(config, sizeof(config), "%s" PATH_SEPARATOR "config", appdir);
  options_read(config);

  // override options from the command line
  options_parse(&argc, &argv);

  if (OPTION_help) {
    options_print_help();
    return EXIT_SUCCESS;
  }

  if (!exception_handler_install()) {
    LOG_WARNING("Failed to initialize exception handler");
    return EXIT_FAILURE;
  }

  struct window *window = win_create();
  if (!window) {
    LOG_WARNING("Failed to initialize window");
    return EXIT_FAILURE;
  }

  const char *load = argc > 1 ? argv[1] : NULL;
  if (load && strstr(load, ".trace")) {
    struct tracer *tracer = tracer_create(window);
    tracer_run(tracer, load);
    tracer_destroy(tracer);
  } else {
    struct emu *emu = emu_create(window);
    emu_run(emu, load);
    emu_destroy(emu);
  }

  win_destroy(window);

  exception_handler_uninstall();

  // persist options for next run
  options_write(config);

  return EXIT_SUCCESS;
}
Exemplo n.º 12
0
/*-----------------------------------------------------------------------------*/
void
win_test1 ()
{
  int iw=60,  ih=30;
  YT_WIN  *win;

  // создаем экранную форму и рисуем главную рамочку
  win = win_create (iw, ih);  
  win_rect (win, '=', '=', 0, 0, 60, 30);

  win_line (win, '*', 2, 2,  15, 15);
  win_line (win, '*', 2, 2,  15, 5);
  win_ellipse  (win, '@',  15,15, 25,25);             
  win_triangle (win, '$',  40, 5,   35, 20,  50, 15);
  
  win_draw (win, 0, 0); // выводим экранную форму
  return;
}
Exemplo n.º 13
0
END_TEST

START_TEST (test_win_handler_text)
{
  int ret;
  Win *w;
  win_properties props = { 0, 0 };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);

  win_set_status (w, "test");
  win_set_status (w, "");
  win_set_status (w, "test test\ntest");

  ret = win_add_line (w, "line 1", 0, 1);
  fail_unless (ret == 0);

  ret = win_add_line (w, "line 1", 1, 1);
  fail_unless (ret == 0);

  ret = win_add_line (w, "line 1", 0, 1);
  fail_unless (ret == 0);
  ret = win_add_line (w, "line 1", 1, 1);
  fail_unless (ret == 0);
  ret = win_add_line (w, "line 1", 1, 1);
  fail_unless (ret == 0);
  ret = win_add_line (w, "line\001 1", 1, 1);
  fail_unless (ret < 0);

  ret = win_load_file (w, CONFDIR "text_test_bad.txt");
  fail_unless (ret < 0);

  ret = win_load_file (w, CONFDIR "text_test_short_file.txt");
  fail_unless (ret == 0);

  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);

  ret = win_load_file (w, CONFDIR "text_test_long.txt");
  fail_unless (ret == 0);

  win_free (w);
}
Exemplo n.º 14
0
END_TEST

START_TEST (test_win_handler_get_curpos)
{
  Win *w;
  int ret;
  int i;
  char buf[64];
  const char *name;
  int line;

  win_properties props = { 0, WIN_PROP_CURSOR };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);

  /* No name */
  name = win_get_filename (w);
  fail_unless (name == NULL);

  /* With name. */
  ret = win_load_file (w, CONFDIR "text_test.txt");
  fail_unless (ret == 0);
  name = win_get_filename (w);
  fail_unless (name != NULL);

  for (i = 0; i < 10; i++)
    {
      ret = win_go_to_line (w, i);
      fail_unless (ret == 0);
      line = win_get_cursor (w);
      fail_unless (line == i);
    }

  win_free (w);
}
Exemplo n.º 15
0
/**
 * This function creates a new radio button widget. It allocates required memory
 * and intializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the radio button's child reference, given by
 * wtk_radio_button_as_child(), like this:
 * "win_destroy(wtk_radio_button_as_child(myButtonPtr));".
 * Usually it will be destroyed automatically when it's parent is destroyed.
 *
 * \param parent Parent window, possibly wtk_frame_as_parent(myFramePtr).
 * \param area Area of the internal contents.
 * \param caption Pointer to caption string. Will be copied into widget.
 * \param selected Initial state of radio button, true if checked/selected.
 * \param group Radio button group to be a member of.
 * \param command Command to send to parent window. Must be non-zero to be
 *                enabled.
 *
 * \return Pointer to radio button, or NULL if failed.
 */
struct wtk_radio_button *wtk_radio_button_create(struct win_window *parent,
		struct win_area const *area,
		char const *caption,
		bool selected,
		struct wtk_radio_group *group, win_command_t command)
{
	struct wtk_radio_button *radio_button;
	struct win_attributes attr;

	Assert(group);
	Assert(area);
	Assert(caption);
	Assert(parent);

	/* Allocate memory for check box control data. */
	radio_button = membag_alloc(sizeof(struct wtk_radio_button));
	if (!radio_button) {
		goto outofmem_radio_button;
	}

	radio_button->state = WTK_RADIOBUTTON_NORMAL;
	radio_button->group = group;
	radio_button->command = command;

	/* Allocate memory for caption string, and copy text. */
	radio_button->caption = membag_alloc(
			(strlen(caption) + 1) * sizeof(char));
	if (!radio_button->caption) {
		goto outofmem_caption;
	}

	wtk_copy_string(radio_button->caption, caption);

	/* Handling information. */
	attr.event_handler = wtk_radio_button_handler;
	attr.custom = radio_button;

	/* Prepare container frame. */
	attr.area = *area;
	attr.background = NULL;
	attr.behavior = WIN_BEHAVIOR_REDRAW_PARENT;

	radio_button->container = win_create(parent, &attr);
	if (!radio_button->container) {
		goto outofmem_container;
	}

	/* Select the radio button in the group if either no radio button is
	 * currently selected (empty group), or the user has requested it takes
	 * over the selection */
	if (selected || (group->selected == NULL)) {
		wtk_radio_button_select(radio_button);
	}

	/* Make sure we haven't filled up the group reference count, and
	 * increment. */
	Assert(group->num_references < (wtk_radio_group_size_t)-1L);
	++(group->num_references);

	return radio_button;

outofmem_container:
	membag_free(radio_button->caption);

outofmem_caption:
	membag_free(radio_button);

outofmem_radio_button:
	return NULL;
}
Exemplo n.º 16
0
/**
 * \brief Create a new plot widget.
 *
 * Allocates the necessary memory and intializes the window and data for
 * plot widgets. If there is not enough memory, the function returns
 * NULL.\n To destroy a plot widget and all its contents, and free its
 * memory, call \ref win_destroy() on the plot's child reference, given
 * by \ref wtk_plot_as_child(), similar to:
 * \code
	win_destroy(wtk_plot_as_child(my_plot_ptr));
\endcode
 *
 * The plotted graph will shift from right to left as new data values are added.
 * Data values will be overwritten in the ring buffer as they shift out of
 * the plot window.
 * The maximum parameter scales the input value to fit the plot dimensions.
 *
 * The num_datapoints parameter must not exceed the maximum membag size,
 * and never over 255.
 *
 *
 * Refer to <gfx/wtk.h> for available configuration options.
 *
 * \param parent Pointer to parent win_window struct.
 * \param area Pointer to win_area struct with position and size of the
 *        plot. Minimum size in both x and y direction is 4 pixels.
 * \param maximum Maximum value of the plot.
 * \param num_datapoints Number of datapoints of the plot.
 * \param draw_color Plot drawing color.
 * \param background Pointer to background bitmap for frame. NULL for
 *        transparent background. When background is transparent
 *        the parent window will automatically be redrawn
 *        when the basic frame is drawn.
 * \param option Configuration options for plot.
 *
 * \return Pointer to new plot, if memory allocation was successful.
 */
struct wtk_plot *wtk_plot_create(struct win_window *parent,
		struct win_area const *area, uint8_t maximum,
		uint8_t num_datapoints, gfx_color_t draw_color,
		struct gfx_bitmap *background, uint8_t option)
{
	uint16_t length;

	/* Do sanity check on parameters. */
	Assert(maximum > 0);
	Assert(area);
	Assert(parent);
	Assert(num_datapoints > 1);

	/* Attributes scratchpad. */
	struct win_attributes attr;

	/* Allocate memory for the control data. */
	struct wtk_plot *plot = membag_alloc(sizeof(struct wtk_plot));
	if (!plot) {
		goto outofmem_plot;
	}

	/* Allocate memory for the control data. */
	plot->plot_buffer = membag_alloc(num_datapoints);
	if (!plot->plot_buffer) {
		goto outofmem_plot_buffer;
	}

	/* Initialize the plot data. */
	plot->maximum = maximum;
	plot->num_datapoints = num_datapoints;
	plot->buffer_start = 0;
	plot->option = option;
	plot->draw_color = draw_color;
	plot->background = background;

	plot->axis_option = 0;
	plot->axis_spacing_x = 0;
	plot->axis_offset_x = 0;
	plot->axis_spacing_y = 0;
	plot->axis_offset_y = 0;
	plot->axis_color = 0;
	plot->axis_zero_color = 0;

	/* Do sanity check of specified window area parameters
	 * according to the orientation of the plot.
	 */
	attr.area = *area;
	Assert(attr.area.size.x > 3);
	Assert(attr.area.size.y > 3);

	/* Makes the plot fit inside the window border. */
	length = attr.area.size.x;
	length -= 2;

	/* Calculate the spacing between datapoints. */
	plot->spacing = length / (num_datapoints - 1);

	/* Calculate the fixed-point remainder of the above operation. */
	plot->spacing_error = (uint8_t)(
		(((uint16_t)(length - plot->spacing * (num_datapoints - 1)))
		* WTK_PLOT_SCALE_FACTOR) / ((uint16_t)(num_datapoints - 1)));

	/* Set up handling information. */
	attr.event_handler = wtk_plot_handler;
	attr.custom = plot;

	/* Set background for window */
	if (background) {
		attr.background = background;
		attr.behavior = 0;
	} else {
		attr.background = NULL;
		if (option & WTK_PLOT_DONT_REDRAW_PARENT) {
			attr.behavior = 0;
		} else {
			attr.behavior = WIN_BEHAVIOR_REDRAW_PARENT;
		}
	}

	/* Create a new window for the plot. */
	plot->container = win_create(parent, &attr);
	if (!plot->container) {
		goto outofmem_container;
	}

	return plot;

outofmem_container:
	membag_free(plot->plot_buffer);

outofmem_plot_buffer:
	membag_free(plot);

outofmem_plot:
	return NULL;
}
Exemplo n.º 17
0
void welcome(void)
{

char name[6][35]={
			" _  __         _   _      _ ",
			"| |/ /        | \\ | |    | |",
			"| ' / ___ _ __|  \\| | ___| |",
			"|  < / _ \\ '__| . ` |/ _ \\ |",
			"| . \\  __/ |  | |\\  |  __/ |____ ",
			"|_|\\_\\___|_|  |_| \\_|\\___|______|"		
		};

char msg1[]="version 0.1";
char msg2[]="(c) copyright '6 bytes more',2010";
char msg3[]="witten by nitheeh k l";
char warning[7][38]={"Warning: this is the first release",
		"of the kenel and is under testing.",
		"nothing found here has necessarily",
		"been reviewed by professionals with ",
		"the expertise requierd to provide",
		"you with complete, accurate or",
		"reliable information."
		};

u16int screenattr	= blightgray|fred;
u16int name_attr	= screenattr;
u16int msg_attr		= blightgray|fdarkgray;
u16int warning_attr	= blightgray|fwhite;

	clearscreen();
	set_screenbackground(screenattr);
	
	u8int row,col;
	u8int i;	
	row=2;col=25;

	for(i=0;i<6;i++,row++)
	{
		writestring(row,col,name[i],name_attr);
	}
	
	h_doubleline(row,24,59,warning_attr);

	writestring(11,2,msg1,msg_attr);
	writestring(12,2,msg2,msg_attr);
	writestring(13,2,msg3,msg_attr);
	
	row=16;
	for(i=0;i<7;i++,row++)
		writestring(row,2,warning[i],warning_attr);

	u8int row1,col1,row2,col2;

	row1=11;col1=40;
	row2=23;col2=78;

//	window win_boot;
	char win_boot_title[16]="booting....";
	u16int win_boot_wattr=bblack|fwhite;
	u16int win_boot_battr=bblack|flightgray;
	
	win_init(&win_boot,row1,col1,row2,col2,win_boot_title,win_boot_wattr,win_boot_battr);
	win_create(&win_boot);

}	
Exemplo n.º 18
0
/**
 * This function creates a new label widget. It allocates required memory
 * and intializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 *
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the label's child reference, given by
 * wtk_label_as_child(),
 * like this: "win_destroy(wtk_label_as_child(myStaticTextPtr));".
 * Usually it will be destroyed automatically when it's parent is destroyed.
 *
 * \param parent Parent window, possibly wtk_frame_as_parent(myFramePtr).
 * \param area Area of the internal contents.
 * \param caption Pointer to caption string. Will be copied into widget.
 * \param text_color Foreground color of the text when drawn.
 * \param background Background of the label.
 * \param align_right True if caption is to be aligned to the right,
 *                    false otherwise.
 * \return Pointer to label, or NULL if failed.
 */
struct wtk_label *wtk_label_create(struct win_window *parent,
		struct win_area const *area, char const *caption,
		gfx_color_t text_color, struct gfx_bitmap *background,
		bool align_right)
{
	struct win_attributes attr;
	struct wtk_label *label;

	Assert(area);
	Assert(caption);
	Assert(parent);

	/* Allocate memory for label control data. */
	label = membag_alloc(sizeof(struct wtk_label));
	if (!label) {
		goto outofmem_label;
	}

	label->text_color = text_color;
	label->align_right = align_right;

	/* Allocate memory for caption string, and copy text. */
	label->caption = membag_alloc((strlen(caption) + 1) * sizeof(char));
	if (!label->caption) {
		goto outofmem_caption;
	}

	wtk_copy_string(label->caption, caption);
	
	/* Handling information. */
	attr.event_handler = wtk_label_handler;
	attr.custom = label;

	/* Prepare container frame. */
	attr.area = *area;
	
	/* Set background for label. */
	if (background) {
		attr.background = background;
		attr.behavior = 0;
	} else {
		attr.background = NULL;
		attr.behavior = WIN_BEHAVIOR_REDRAW_PARENT;
	}
	
	label->container = win_create(parent, &attr);
	if (!label->container) {
		goto outofmem_container;
	}

	return label;

outofmem_container:
	membag_free(label->caption);

outofmem_caption:
	membag_free(label);

outofmem_label:
	return NULL;
}
Exemplo n.º 19
0
/**
 * \brief Create a new slider widget.
 *
 * Allocates the necessary memory and intializes the window and data for slider
 * widgets. If there is not enough memory, the function returns NULL.\n
 * To destroy a slider widget and all its contents, and free its memory, call
 * \ref win_destroy() on the slider's child reference, given by
 * \ref wtk_slider_as_child(), like this:
 * "win_destroy(wtk_slider_as_child(my_slider_ptr));".\par
 *
 * Slider widgets fill the specified area and perform a mapping of the slider
 * knob's position to a value between 0 and maximum. The length of the slider
 * cannot exceed 255 pixels.\par
 *
 * By default, the value 0 corresponds to the top-most position for a vertical
 * slider, and the left-most position for a horizontal one. The slider's
 * orientation and inversion of the value can be configured.\par
 *
 * A slider can be configured to issue command events whenever its value is
 * changed by a pointer and/or when a pointer releases it.\par
 *
 * Refer to <gfx/wtk.h> for available configuration options.
 *
 * \todo Revisit, support larger sliders and values given a config symbol.
 *
 * \param parent Pointer to parent win_window struct.
 * \param area Pointer to win_area struct with position and size of the slider.
 * \param maximum Maximum value of the slider.
 * \param value Initial value of the slider.
 * \param option Configuration options for slider.
 *               See \ref gfx_wtk_slider_options
 * \param command Command to send to parent window. Must be non-zero if used.
 *
 * \return Pointer to new slider, if memory allocation was successful.
 */
struct wtk_slider *wtk_slider_create(struct win_window *parent,
		struct win_area const *area, uint8_t maximum, uint8_t value,
		uint8_t option, win_command_t command)
{
	struct win_attributes   attr;
	struct wtk_slider       *slider;
	uint8_t                 length;

	// Do sanity check on parameters.
	assert(maximum > 0);
	assert(area);
	assert(parent);

	// Allocate memory for the control data.
	slider = membag_alloc(sizeof(struct wtk_slider));
	if (!slider) {
		goto outofmem_slider;
	}

	// Initialize the slider data.
	slider->state = WTK_SLIDER_NORMAL;
	slider->maximum = maximum;
	slider->value = value;
	slider->option = option;

	// Invert the initial value if slider is inverted.
	if (option & WTK_SLIDER_INVERT) {
		value = maximum - value;
	}

	slider->value = value;

	// Enforce a non-zero command value, if these are enabled.
	if (option & (WTK_SLIDER_CMD_MOVE | WTK_SLIDER_CMD_RELEASE)) {
		assert(command > 0);
		slider->command = command;
	}

	// Set up event handling for the widget window.
	attr.event_handler = wtk_slider_handler;
	attr.custom = slider;

	// Do a sanity check of the specified window area parameters.
	attr.area = *area;
	assert(attr.area.size.x > 0);
	assert(attr.area.size.y > 0);

	if (option & WTK_SLIDER_VERTICAL) {
		assert(attr.area.size.x > 3);
		assert(attr.area.size.x <= (uint8_t) ~ 0);
		assert(attr.area.size.y > WTK_SLIDER_KNOB_WIDTH);
		length = attr.area.size.y;
	} else {
		assert(attr.area.size.x > WTK_SLIDER_KNOB_WIDTH);
		assert(attr.area.size.y <= (uint8_t) ~ 0);
		assert(attr.area.size.y > 3);
		length = attr.area.size.x;
	}

	// Set slider knob position according to initial value.
	length -= WTK_SLIDER_KNOB_WIDTH;
	slider->position = wtk_rescale_value(value, maximum, length);

	/* All drawing is done in wtk_slider_handler() to reduce overhead.
	 * Slider has no transparent areas, so parent does not need redrawing.
	 */
	attr.background = NULL;
	attr.behavior = 0;

	// Create the widget window.
	slider->container = win_create(parent, &attr);
	if (!slider->container) {
		goto outofmem_container;
	}

	// Store absolute position
	win_translate_win_to_root(slider->container, &slider->root_pos);
	return slider;

outofmem_container:
	membag_free(slider);

outofmem_slider:
	return NULL;
}
Exemplo n.º 20
0
/**
 * This function creates a new frame widget. It allocates required memory and
 * intializes necessary windows to create the widget. If there is not enough
 * memory, the function returns NULL.
 *
 * To destroy the widget and all its contents, and free its memory, call
 * win_destroy() on the frame's child reference, given by wtk_frame_as_child(),
 * like this: "win_destroy(wtk_frame_as_child(my_frame_ptr));".
 * The frame's internal area will equal the area parameter, but the total
 * extents will be slightly larger, to accommodate for titlebar, borders etc.
 *
 * \param parent Parent window.
 * \param area Area of the internal contents.
 * \param caption Pointer to caption string. Will be copied into widget.
 * \param allow_resize True if resize handle should be included on the frame.
 * \param frame_handler Optional command event handler, for applications.
 * \param custom_data Optional custom data link, for applications.
 *
 * \return Pointer to frame, or NULL if failed.
 */
struct wtk_frame *wtk_frame_create(struct win_window *parent,
		struct win_area const *area,
		char const *caption,
		bool allow_resize,
		wtk_frame_handler_t frame_handler, void *custom_data)
{
	struct win_attributes attr;
	struct wtk_frame *frame;

	Assert(area);
	Assert(caption);
	Assert(parent);

	/* Allocate memory for frame control data. */
	frame = membag_alloc(sizeof(struct wtk_frame));
	if (!frame) {
		goto outofmem_frame;
	}

	frame->state = WTK_FRAME_NORMAL;
	frame->frame_handler = frame_handler;
	frame->custom_data = custom_data;

	/* Allocate memory for caption string, and copy text. */
	frame->caption = membag_alloc((strlen(caption) + 1) * sizeof(char));
	if (!frame->caption) {
		goto outofmem_caption;
	}

	wtk_copy_string(frame->caption, caption);

	/* Start with valid area info, but only contents frame will keep the
	 * original area. The other frames will be resized properly at the end.
	 * All windows have the same event handler, and the same link back to
	 * the widget object.
	 */
	attr.area = *area;
	attr.event_handler = wtk_frame_handler;
	attr.custom = frame;

	/* Prepare container frame, which will contain title bar, border, size,
	 * handle etc.
	 */
	attr.background = NULL;
	attr.behavior = WIN_BEHAVIOR_RAISE_ON_PRESS;

	/* Create the container window, the proper size will be set later. */
	frame->container = win_create(parent, &attr);
	if (!frame->container) {
		goto outofmem_container;
	}

	/* Prepare the contents frame, which will contain whatever controls
	 * owned by the frame. Size will be equal to the given area parameter.
	 */
	attr.area.pos.x = WTK_FRAME_LEFTBORDER;
	attr.area.pos.y = WTK_FRAME_TOPBORDER + WTK_FRAME_TITLEBAR_HEIGHT;
	attr.background = &wtk_frame_background;
	attr.behavior = 0;

	frame->contents = win_create(frame->container, &attr);
	if (!frame->contents) {
		goto outofmem_contents;
	}

	/* Only create resize handle window if resize is allowed. */
	if (allow_resize) {
		/* Prepare resize handle. Proper position will be set later.
		 * Size is set here, though.
		 */
		attr.area.size.x = WTK_FRAME_RESIZE_WIDTH;
		attr.area.size.y = WTK_FRAME_RESIZE_HEIGHT;
		attr.background = NULL;
		attr.behavior = 0;

		frame->resize = win_create(frame->container, &attr);
		if (!frame->resize) {
			goto outofmem_resize;
		}

		win_show(frame->resize);
	} else {
		frame->resize = NULL;
	}

	/* Now, resize and rearrange according to size of contents frame, which
	 * is equal to the given area parameter.
	 */
	wtk_resize_frame(frame, area);

	/* Make sure internals are visible when frame is mapped. */
	win_show(frame->contents);

	return frame;

outofmem_resize:
	win_destroy(frame->contents);

outofmem_contents:
	win_destroy(frame->container);

outofmem_container:
	membag_free(frame->caption);

outofmem_caption:
	membag_free(frame);

outofmem_frame:
	return NULL;
}
Exemplo n.º 21
0
/**
 * \brief Create a new progress bar widget.
 *
 * Allocates the necessary memory and intializes the window and data for
 * progress bar widgets. If there is not enough memory, the function returns
 * NULL.\n To destroy a progress bar widget and all its contents, and free its
 * memory, call \ref win_destroy() on the progress bar's child reference, given
 * by \ref wtk_progress_bar_as_child(), like this:
 * "win_destroy(wtk_progress_bar_as_child(my_progress_bar_ptr));".\par
 *
 * Progress bar widgets divide their window area in two non-overlapping
 * rectangles: one with a fill color, and one with a background color.
 * The ratio between the two rectangles' sizes is given by the progress bar's
 * value relative to its maximum: a higher value gives a larger fill.\par
 *
 * By default, a vertically oriented progress bar fills from the top, while a
 * horizontal one fills from the left. The progress bar's orientation and fill
 * direction can both be configured at the time of creation. The fill and
 * background colors can be changed at runtime.\par
 *
 * Refer to <gfx/wtk.h> for available configuration options.
 *
 * \param parent Pointer to parent win_window struct.
 * \param area Pointer to win_area struct with position and size of the
 *             progress bar. Minimum size in both x and y direction is 3 pixels.
 * \param maximum Maximum value of the progress bar.
 * \param value Initial value of the progress bar.
 * \param fill_color Color for filled area.
 * \param background_color Color for background area.
 * \param option Configuration options for progress bar.
 *
 * \return Pointer to new progress bar, if memory allocation was successful.
 */
struct wtk_progress_bar *wtk_progress_bar_create(struct win_window *parent,
		struct win_area const *area, uint8_t maximum, uint8_t value,
		gfx_color_t fill_color, gfx_color_t background_color,
		uint8_t option)
{
	uint8_t length;

	/* Do sanity check on parameters. */
	Assert(maximum > 0);
	Assert(value <= maximum);
	Assert(area);
	Assert(parent);

	/* Attributes scratchpad. */
	struct win_attributes attr;

	/* Allocate memory for the control data. */
	struct wtk_progress_bar *bar
		= membag_alloc(sizeof(struct wtk_progress_bar));
	if (!bar) {
		goto outofmem_bar;
	}

	/* Initialize the progress bar data. */
	bar->maximum = maximum;
	bar->value = value;
	bar->option = option;

	/* Set the progress bar's colors and prepare the value for computation
	 * of the bar's end position according to the invert option.
	 */
	if (option & WTK_PROGRESS_BAR_INVERT) {
		bar->fill_color = background_color;
		bar->background_color = fill_color;
		value = maximum - value;
	} else {
		bar->fill_color = fill_color;
		bar->background_color = background_color;
	}

	/* Set up handling information. */
	attr.event_handler = wtk_progress_bar_handler;
	attr.custom = bar;

	/* Do sanity check of specified window area parameters
	 * according to the orientation of the progress bar.
	 */
	attr.area = *area;
	Assert(attr.area.size.x > 3);
	Assert(attr.area.size.y > 3);

	if (option & WTK_PROGRESS_BAR_VERTICAL) {
		Assert(attr.area.size.y < (uint8_t) ~0);
		length = attr.area.size.y;
	} else {
		Assert(attr.area.size.x < (uint8_t) ~0);
		length = attr.area.size.x;
	}

	length -= 2;

	/* Set the progress bar's end position. */
	bar->position = wtk_rescale_value(value, maximum, length);

	/* All drawing is done in wtk_progress_bar_handler() so no background is
	 * needed.
	 */
	attr.background = NULL;

	/* Since the widget has no transparent areas, the parent does not need
	 * to be redrawn.
	 */
	attr.behavior = 0;

	/* Create a new window for the progress bar. */
	bar->container = win_create(parent, &attr);
	if (!bar->container) {
		goto outofmem_container;
	}

	return bar;

outofmem_container:
	membag_free(bar);

outofmem_bar:
	return NULL;
}
Exemplo n.º 22
0
END_TEST

START_TEST (test_win_handler_scroll)
{
  int ret;
  Win *w;
  win_properties props = { 0, 0 };

  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test_long.txt");

  fail_unless (ret == 0);
  ret = win_scroll (w, -1);
  fail_unless (ret < 0);	/* at the first line already. */

  ret = win_scroll (w, 130);
  fail_unless (ret < 0);	/* scroll to far down. */

  ret = win_scroll (w, -15);
  fail_unless (ret == 0);

  ret = win_scroll (w, -1);
  fail_unless (ret == 0);

  ret = win_scroll (w, 5);
  fail_unless (ret == 0);

  ret = win_scroll (w, 1);
  fail_unless (ret == 0);

  win_to_top (w);

  ret = win_go_to_line (w, -2);
  fail_unless (ret < 0);
  ret = win_go_to_line (w, 180);
  fail_unless (ret < 0);

  ret = win_go_to_line (w, 15);
  fail_unless (ret == 0);

  ret = win_move (w, -1);
  fail_unless (ret == 0);
  ret = win_move (w, -4);
  fail_unless (ret == 0);
  ret = win_move (w, 1);
  fail_unless (ret == 0);
  ret = win_move (w, 4);
  fail_unless (ret == 0);

  win_clear (w);

  win_free (w);

  props.properties = WIN_PROP_CURSOR;
  w = win_create (0, 0, 40, 80, &props);
  fail_unless (w != NULL);
  ret = win_load_file (w, CONFDIR "text_test_long.txt");
  ret = win_go_to_line (w, 15);
  fail_unless (ret == 0);
  ret = win_move (w, -1);
  fail_unless (ret == 0);
  ret = win_move (w, -4);
  fail_unless (ret == 0);
  ret = win_move (w, 1);
  fail_unless (ret == 0);
  ret = win_move (w, 4);
  fail_unless (ret == 0);

  win_clear (w);

  win_free (w);
}
Exemplo n.º 23
0
static void terminal_init(void)
{
	win_init(&win_terminal,row1,col1,row2,col2,win_terminal_title,win_terminal_wattr,win_terminal_battr);
	win_create(&win_terminal);
	return;
}