void cGUIButton::OnDraw() { iRect rc = scrRect(); // background if( style & GUISTYLE_BACKGR ) GUIDrawBar(rc, color[0]); else if( style & GUISTYLE_GRADIENT ) GUIDrawGradient( rc, color[0], color[1] ); // image int img = (style & GUISTYLE_PRESSED) ? img1 : img0; GUIDrawImg( rc, img, imgColor, imgAlign); // text GUIDrawText( rc, txt, txtColor, txtAlign, txtOffset); // border if( style & GUISTYLE_BORDER ) GUIDrawRect(rc, color[2]); else if( style & GUISTYLE_BORDER3D ) GUIDrawRect3D(rc, color[2], style & GUISTYLE_PRESSED ); }
static void WndDrawCursor( a_window *wnd, wnd_line_piece *line, wnd_row row, int piece ) { const char *p; if( _Is( wnd, WSW_NOT_TO_SCREEN ) ) return; if( _Isnt( wnd, WSW_CHAR_CURSOR ) ) return; if( !line->tabstop ) return; if( wnd->current.row != row ) return; if( wnd->current.piece != piece ) return; if( wnd->current.col < 0 ) return; if( line->length == 0 ) { GUIDrawText( wnd->gui, " ", 1, row, line->indent, WndCursorAttr ); } else if( wnd->current.col < line->length ) { line->indent += GUIGetExtentX( wnd->gui, line->text, wnd->current.col ); p = line->text + wnd->current.col; GUIDrawText( wnd->gui, p, GUICharLen( *p ), row, line->indent, WndCursorAttr ); } }
static void WndDrawSelect( a_window *wnd, wnd_line_piece *line, wnd_row row, int piece ) { int first; int len; gui_ord indent; if( _Is( wnd, WSW_NOT_TO_SCREEN ) ) return; if( WndSelected( wnd, line, row, piece, &first, &len ) ){ indent = line->indent; if( first != 0 ) { indent += GUIGetExtentX( wnd->gui, line->text, first ); } GUIDrawText( wnd->gui, line->text+first, len, row, indent, WndSelectedAttr ); } }
static void WndDrawTheLine( a_window *wnd, wnd_line_piece *line, wnd_row row ) { gui_ord extent; gui_point start,end; gui_ord max_y; gui_ord max_x; wnd_bar_info *bar_info; if( _Isnt( wnd, WSW_NOT_TO_SCREEN ) ) { if( line->underline ) { max_y = WndMaxCharY( wnd ); start.x = line->indent; start.y = row * max_y + max_y / 2; end.x = line->indent + line->extent; end.y = start.y; GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr ); return; } else if( line->vertical_line ) { max_y = WndMaxCharY( wnd ); max_x = WndAvgCharX( wnd ); start.x = line->indent + max_x / 2; end.x = start.x; start.y = row * max_y; end.y = start.y + max_y; GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr ); return; } else if( line->draw_hook | line->draw_line_hook ) { if( GUIIsGUI() ) { max_y = WndMaxCharY( wnd ); max_x = WndAvgCharX( wnd ); start.x = line->indent + max_x / 2; end.x = start.x + max_x; start.y = row * max_y + max_y / 2; end.y = start.y; GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr ); start.x = line->indent + max_x / 2; end.x = start.x; start.y = row * max_y; end.y = start.y; if( line->draw_hook ) { end.y += max_y / 2; } else { end.y += max_y; } GUIDrawLine( wnd->gui, &start, &end, GUI_PEN_SOLID, 0, line->attr ); } else { char ch[3]; if( line->draw_hook ) { ch[0] = GUIGetCharacter( GUI_INACT_FRAME_LL_CORNER ); } else { ch[0] = GUIGetCharacter( GUI_INACT_RIGHT_TITLE_MARK ); } ch[1] = GUIGetCharacter( GUI_INACT_FRAME_BOTTOM ); ch[2] = '\0'; GUIDrawText( wnd->gui, ch, 2, row, line->indent, line->attr ); } return; } else if( line->draw_bar ) { bar_info = (wnd_bar_info *)line->text; if( bar_info->bar_group ) { GUIDrawBarGroup( wnd->gui, row, line->indent, line->extent - bar_info->bar_size2, bar_info->bar_size2, bar_info->bar_style, bar_info->bar_colour, bar_info->bar_colour2, bar_info->bar_selected ); } else { GUIDrawBar( wnd->gui, row, line->indent, line->extent, bar_info->bar_style, bar_info->bar_colour, bar_info->bar_selected ); } return; } else if( line->bitmap ) { GUIDrawHotSpot( wnd->gui, line->text[0], row, line->indent, line->attr ); return; } else if( line->extent == WND_NO_EXTEND ) { GUIDrawText( wnd->gui, line->text, line->length, row, line->indent, line->attr ); } else { GUIDrawTextExtent( wnd->gui, line->text, line->length, row, line->indent, line->attr, line->extent ); } } extent = GUIGetExtentX( wnd->gui, line->text, line->length ); if( line->extent != WND_MAX_EXTEND ) { if( line->extent > extent ) { extent = line->extent; } } if( line->indent + extent > wnd->max_indent ) { wnd->max_indent = line->indent + extent; } }
static bool StatusEventProc( gui_window *gui, gui_event gui_ev, void *parm ) /**************************************************************************/ { static bool button_pressed = false; gui_ctl_id id; gui_key key; gui_keystate state; const char *msg; parm = parm; if( gui == NULL ) return( false ); switch( gui_ev ) { case GUI_INIT_WINDOW: return( true ); case GUI_PAINT: { if( StatusBarLen == 0 ) { break; } msg = GetVariableStrVal( Messages[MsgLine0] ); GUIDrawTextExtent( gui, msg, strlen( msg ), LINE0_ROW, LINE0_COL * CharSize.x, WND_STATUS_TEXT, GUI_NO_COLUMN ); GUIDrawTextExtent( gui, StatusLine1, strlen( StatusLine1 ), LINE1_ROW, LINE1_COL * CharSize.x, WND_STATUS_TEXT, GUI_NO_COLUMN ); #ifdef _UI { int len1, len2; char num[20]; memset( StatusBarBuf, ' ', StatusBarLen ); StatusBarBuf[StatusBarLen] = '\0'; itoa( Percent, num, 10 ); strcat( num, "%" ); memcpy( StatusBarBuf + StatusBarLen / 2 - 1, num, strlen( num ) ); // draw bar in two parts len1 = (StatusBarLen * (long)Percent) / 100; if( len1 < 0 ) { len1 = 0; } else if( len1 > StatusBarLen ) { len1 = StatusBarLen; } len2 = StatusBarLen - len1; if( len1 > 0 ) { GUIDrawText( gui, StatusBarBuf, len1, STATUS_ROW, StatusBarRect.x, WND_STATUS_BAR ); } if( len2 > 0 ) { GUIDrawText( gui, StatusBarBuf + len1, len2, STATUS_ROW, StatusBarRect.x + len1 * CharSize.x, WND_STATUS_TEXT ); } memset( StatusBarBuf, UiGChar[UI_SBOX_TOP_LINE], StatusBarLen ); GUIDrawText( gui, StatusBarBuf, StatusBarLen, STATUS_ROW - 1, StatusBarRect.x, WND_STATUS_TEXT ); GUIDrawText( gui, StatusBarBuf, StatusBarLen, STATUS_ROW + 1, StatusBarRect.x, WND_STATUS_TEXT ); } #else { gui_coord coord; int str_len, width, height; int bar_width, len1, len2, divider; gui_point start, end; gui_rect rStatusBar; // sprintf( StatusBarBuf, "%d%%", Percent ); // clear whole bar GUIFillRect( gui, &StatusBarRect, WND_STATUS_BAR ); // calculate where divider splits rectangle bar_width = StatusBarRect.width; divider = (bar_width * (long)Percent) / 100; if( divider < 0 ) { divider = 0; } else if( divider > bar_width ) { divider = bar_width; } rStatusBar = StatusBarRect; rStatusBar.width = divider; // calculate position for text (centre it) str_len = strlen( StatusBarBuf ); width = GUIGetExtentX( gui, StatusBarBuf, str_len ); height = GUIGetExtentY( gui, StatusBarBuf ); coord.y = StatusBarRect.y + (StatusBarRect.height - height) / 2; coord.x = StatusBarRect.x + (StatusBarRect.width - width) / 2; divider += StatusBarRect.x; if( coord.x > divider ) { // text is completely to right of divider GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT ); GUIDrawTextPos( gui, StatusBarBuf, str_len, &coord, WND_STATUS_TEXT ); } else if( coord.x + width < divider ) { // text is completely to left of divider GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT ); GUIDrawTextPos( gui, StatusBarBuf, str_len, &coord, WND_STATUS_BAR ); } else { // need to split text len1 = ((long)(divider - coord.x) * str_len) / width; if( len1 < 0 ) { len1 = 0; } else if( len1 > str_len ) { len1 = str_len; } len2 = str_len - len1; // recalc divider, so it falls on a character boundary divider = coord.x + GUIGetExtentX( gui, StatusBarBuf, len1 ); rStatusBar.width = divider - StatusBarRect.x; GUIFillRect( gui, &rStatusBar, WND_STATUS_TEXT ); if( len1 > 0 ) { GUIDrawTextPos( gui, StatusBarBuf, len1, &coord, WND_STATUS_BAR ); } if( len2 > 0 ) { coord.x = divider; GUIDrawTextPos( gui, StatusBarBuf + len1, len2, &coord, WND_STATUS_TEXT ); } } // draw frame start.x = StatusBarRect.x; start.y = StatusBarRect.y; end.x = StatusBarRect.width + StatusBarRect.x; end.y = start.y; // top line GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME ); start.y = StatusBarRect.y + StatusBarRect.height; // bottom line end.y = start.y; GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME ); end.y = StatusBarRect.y; start.x = StatusBarRect.x; end.x = start.x; // left side GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME ); start.x = StatusBarRect.x + StatusBarRect.width; end.x = start.x; // right side GUIDrawLine( gui, &start, &end, GUI_PEN_SOLID, 1, WND_STATUS_FRAME ); } #endif return( false ); } case GUI_DESTROY: StatusWnd = NULL; return( false ); case GUI_CONTROL_CLICKED: GUIGetFocus( gui, &id ); GUI_GETID( parm, id ); switch( id ) { case CTL_CANCEL: if( !button_pressed ) { button_pressed = true; if( MsgBox( gui, "IDS_QUERYABORT", GUI_YES_NO ) == GUI_RET_YES ) { CancelSetup = true; } button_pressed = false; break; } case CTL_DONE: if( !button_pressed ) { CancelSetup = true; break; } } return( true ); case GUI_KEYDOWN: GUI_GET_KEY_STATE( parm, key, state ); state = state; switch( key ) { case GUI_KEY_ESCAPE: if( !button_pressed ) { button_pressed = true; if( MsgBox( gui, "IDS_QUERYABORT", GUI_YES_NO ) == GUI_RET_YES ) { CancelSetup = true; } button_pressed = false; break; } default: break; } return( true ); default: break; } return( false ); }
void cGUIEdit::OnDraw() { iRect rc = scrRect(); dword col = color[0]; if(m_edit) col = GUIColorShift(col,GUICOLORSHIFT/2); int width = rect.Width(); int height = rect.Height(); int cursorx = Chr2Pos(m_sel2); int deltax = 0; if(cursorx>width-height/2) deltax = -(cursorx-(width-height/2)); // background if( style & GUISTYLE_BACKGR ) GUIDrawBar(rc, col ); else if( style & GUISTYLE_GRADIENT ) GUIDrawGradient( rc, color[0], color[1]); // image GUIDrawImg( rc, img0, imgColor, imgAlign); // clip content fRect oldclip = R9_GetClipping(); fRect newclip = fRect(rc); R9_AddClipping(newclip); if( R9_IsClipping() ) { // selection fRect rc1; if(m_sel1!=m_sel2) { rc1 = rc; rc1.p2.x = rc1.p1.x; rc1.p1.x += Chr2Pos(m_sel1) + deltax; rc1.p2.x += Chr2Pos(m_sel2) + deltax; R9_ClipBar(rc1); GUIDrawBar( rc1, color[3]); } // text iRect rr = rc; rr.Offset(iV2(deltax, 0)); GUIDrawText( rr, txt, txtColor, GUIALIGN_LEFT|GUIALIGN_CENTERY, txtOffset); // cursor if(m_edit) { static dword s_time = 0; s_time += Editor::app->DeltaTime(); if(s_time<=400) { rc1.p1.x = (float)rc.p1.x + Chr2Pos(m_sel2) + deltax; rc1.p1.y = (float)rc.p1.y+2; rc1.p2.x = rc1.p1.x+1; rc1.p2.y = (float)rc.p2.y-2; R9_ClipBar(rc1); GUIDrawBar( rc1, txtColor); } if(s_time>700) s_time = 0; } } R9_SetClipping(oldclip); // border if( style & GUISTYLE_BORDER ) GUIDrawRect(rc, color[2]); else if( style & GUISTYLE_BORDER3D ) GUIDrawRect3D(rc, color[2], style & GUISTYLE_PRESSED ); }