46 cout<<
"Displaying border at "<<x<<
","<<y<<
"\n";
47 cout<<
"with the dimensions of "<<wid<<
","<<y<<
"\n";
48 cout<<
"Scrollbar: "<<scrollbar<<endl;
49 cout<<
"------------\n";
76 button_ratio[0] = 0.91096;
77 button_ratio[1] = 0.0345;
78 button_ratio[2] = 0.0585;
80 scrollbar_ratio[0] = 0.91096;
81 scrollbar_ratio[1] = 0.1;
82 scrollbar_ratio[2] = 0.0585;
84 scrollbar_ratio[3] = 0.73;
89 horizontal_per_level = 0.05;
90 horizontal_spacer = 0.01;
91 vertical_left_of_text = 0.02;
92 text_spacing = (font_size_float/100)+(horizontal_spacer*2);
96 if (wid < 0 || hei < 0) {
97 printf(
"Cannot draw border with negative height or width\n" );
100 if (x+wid > 1) wid = 1-
x;
101 if (y-hei < -1) hei = -1+
y;
111 xcoord[5] = x+(wid*ratio[0])+(wid*vertical_left_of_text);
112 ycoord[5] = y-(wid*ratio[0])-(wid*horizontal_spacer);
113 width[5] = ( wid*(1-ratio[0]-ratio[1]) )-(wid*vertical_left_of_text*2);
114 height[5] = ( hei*(1-ratio[0]) )-(wid*horizontal_spacer*2);
117 xcoord[1] = x+(wid*button_ratio[0]);
118 ycoord[1] = y-(wid*button_ratio[1]);
119 width[1] = wid*button_ratio[2];
120 height[1] = width[1];
123 xcoord[2] = xcoord[1];
124 ycoord[2] = y-hei+( wid*(button_ratio[2]+button_ratio[1]) );
128 height[2] = width[1];
131 xcoord[3] = x+(wid*scrollbar_ratio[0]);
132 ycoord[3] = y-(wid*scrollbar_ratio[1]);
133 width[3] = wid*scrollbar_ratio[2];
135 height[3] = hei-(height[1]+height[2])-( (height[2]*scrollbar_ratio[3])*2 );
138 xcoord[4] = xcoord[3];
141 max_lines = (height[5]/text_spacing)-1;
148 float x = xcoord[0],
y = ycoord[0], wid = width[0], hei = height[0];
207 if (has_scrollbar != 0) DisplayScrollbar();
210 if (cur_highlighted > 0) HighlightCount( cur_highlighted, 1 );
211 if (cur_selected > 0) HighlightCount( cur_selected, 2 );
233 if (item_count == 0)
return;
236 RenderTextItem( ItemList, 0 );
240 static int count = 0;
241 float new_y = 0, new_x = 0;
244 if (current == 0)
return;
245 if (level == 0) count = 0;
246 if ( (count-top_item_number) >= max_lines )
return;
248 if (count < top_item_number) {count++; }
else {
249 new_y = ycoord[5]-( text_spacing*(count+1-top_item_number) )+horizontal_spacer;
250 new_x = xcoord[5]+( horizontal_per_level*(level-1) );
257 if (max <= 0)
return;
258 for (cur = 0; cur <
max; cur++)
259 RenderTextItem( current->
child[cur], level+1 );
264 master = ItemList->
FindChild( parent_name );
266 if (master == NULL) ItemList->
AddChild( name, description, col );
268 else master->
AddChild( name, description, col );
275 if (search == 0)
return;
284 if (search == 0)
return;
291 if (ItemList != NULL)
delete ItemList;
303 ChompIntoItems( text, NULL );
318 search = ItemList->
FindCount( cur_selected, 0 );
319 if (search == 0)
return '\0';
320 if (type == 1)
return search->
name;
339 if (Inside( x, y, 0 ) == 0)
return 0;
342 if ( x > xcoord[1] && x < (xcoord[1]+width[1]) ) {
344 if ( y < ycoord[1] && y > (ycoord[1]-height[1]) ) {
353 if (top_item_number < 0) top_item_number = 0;
354 if (cur_selected < 0) cur_selected = 0;
357 if ( y < ycoord[2] && y > (ycoord[2]-height[2]) ) {
366 if ( top_item_number >= (item_count-max_lines) ) {
369 float tmp = item_count-max_lines;
371 sprintf( LINE,
"%.0f", tmp );
372 top_item_number = atoi( LINE );
374 top_item_number = item_count-max_lines;
380 if (Inside( x, y, 5 ) != 0 && do_highlight > 0)
381 cur_selected = LocateCount( y );
382 if (Inside( x, y, 3 ) != 0 && Inside( x, y, 4 ) == 0) {
386 top_item_number -= page_size;
387 if (top_item_number < 0) top_item_number = 0;
390 top_item_number += page_size;
391 if ( top_item_number >= (item_count-max_lines) ) {
393 float tmp = item_count-max_lines;
395 sprintf( LINE,
"%.0f", tmp );
396 top_item_number = atoi( LINE );
398 top_item_number = item_count-max_lines;
403 if ( Inside( x, y, 4 ) )
409 if (do_highlight == 0)
return 0;
410 if (Inside( x, y, 5 ) == 0)
return 0;
411 cur_highlighted = LocateCount( y );
416 if (scroll_start == 0 && Inside( x, y, 4 ) == 0)
return 0;
417 if (scroll_start == 0) scroll_start =
y;
424 if (type == 1)
return MouseClick( button, state, x, y );
430 int TextArea::Inside(
float x,
float y,
int group )
432 if (x < xcoord[group] || y > ycoord[group])
return 0;
433 if ( x > (xcoord[group]+width[group]) )
return 0;
434 if ( y < (ycoord[group]-height[group]) )
return 0;
438 void TextArea::LoadTextures(
void )
462 int TextArea::LocateCount(
float y )
464 float base = ycoord[5]-y-horizontal_spacer;
465 if (base < 0)
return 0;
466 base /= text_spacing;
470 sprintf( LINE,
"%.0f", base );
478 void TextArea::HighlightCount(
int count,
int type )
481 if (count <= 0 || count > max_lines+1)
return;
482 y = ycoord[5]-( text_spacing*(count-1) )-horizontal_spacer+( ( text_spacing-(font_size_float/100) )/2 );
485 if (type == 1)
ShowColor( x, y, width[5], text_spacing, 1, 1, 1, 0.25 );
486 if (type == 2)
ShowColor( x, y, width[5], text_spacing, 0.2, 0.2, 0.4, 0.5 );
490 void TextArea::DisplayScrollbar(
void )
492 float new_y = 0, new_height = 0, item_perc = 0, page_perc = 0, y_dist = 0;
493 ShowColor( xcoord[3], ycoord[3], width[3], height[3], 0.51, 0.47, 0.79, 1 );
494 if (item_count <= max_lines) {
495 ShowColor( xcoord[3], ycoord[3], width[3], height[3], 0.66, 0.6, 1, 1 );
496 ShowColor( xcoord[3], ycoord[3], width[3], height[3], 0, 1, 1, 0.05 );
500 item_perc = item_count;
501 item_perc = 1/item_perc;
504 page_perc = max_lines;
505 page_perc /= item_count;
507 if (scroll_cur != 0) {
508 float move = ( (scroll_cur-scroll_start)/height[3] )/item_perc;
512 sprintf( LINE,
"%.0f", move );
513 change = atoi( LINE );
519 top_item_number += change;
520 if ( top_item_number >= (item_count-max_lines) ) {
522 sprintf( LINE,
"%.0f", item_count-max_lines );
523 top_item_number = atoi( LINE );
525 top_item_number = item_count-max_lines;
529 top_item_number -= change;
530 if (top_item_number < 0) top_item_number = 0;
532 if (change != 0) scroll_start = scroll_cur;
535 y_dist = item_perc*top_item_number;
537 new_y = ycoord[3]-(y_dist*height[3]);
538 new_height = page_perc*height[3];
541 height[4] = new_height;
543 ShowColor( xcoord[3], new_y, width[3], new_height, 0.66, 0.6, 1, 1 );
544 if (scroll_start == 0)
545 ShowColor( xcoord[3], new_y, width[3], new_height, 0, 1, 1, 0.05 );
547 ShowColor( xcoord[3], new_y, width[3], new_height, 1, 0, 0, 0.05 );
550 void TextArea::ChompIntoItems(
const char *text,
const char *parent )
552 char *temp = strdup( text );
553 char *cur = temp, chr =
'\0';
554 int i = 0, max = strlen( temp );
555 float cur_width = 0, wid = 0, end = glutStrokeWidth( GLUT_STROKE_ROMAN,
'A' );
558 for (i = 0; i <=
max; i++) {
559 if (temp[i] ==
'\r')
continue;
561 if (wid+cur_width > width[5] || temp[i] ==
'\n') {
567 if (cur[0] ==
'\n') cur++;
569 }
else {wid += cur_width; }}
570 if (temp[i] !=
'\0')
AddTextItem(
"content", cur, parent );
583 if (new_name != 0)
name = strdup( new_name );
611 if (search_name == NULL)
return this;
612 if (strcmp(
name, search_name ) == 0)
return this;
615 if (match != NULL)
return match;
626 for (cur2 = 0; cur2 < child_count-1; cur2++)
630 child[cur2+1] = temp;
637 static int current = 0;
638 if (cur == 0) current = 0;
640 if (count == current)
return this;
644 if (match != NULL)
return match;
661 newlist[cur] =
child[cur];