//------------------------------------------------------------------------- void COption::ChooseFont(ObjType t, CDC &PrinterDC, HWND Window) { CHOOSEFONT cf; LOGFONT aLogFont = *(GetFont(GetCurrentFont(t))); cf.lStructSize = sizeof(CHOOSEFONT); cf.hwndOwner = Window; cf.hDC = PrinterDC.m_hDC; cf.lpLogFont = &aLogFont; cf.iPointSize = 10; cf.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_BOTH; cf.rgbColors = cBLACK; cf.lCustData = 0; cf.lpfnHook = NULL; cf.lpTemplateName = NULL; cf.hInstance = NULL; cf.lpszStyle = NULL; cf.nFontType = SCREEN_FONTTYPE; cf.nSizeMin = 5; cf.nSizeMax = 128; if (::ChooseFont(&cf)) { CurrentFont[ t ] = AddFont(&aLogFont); } }
/** * @function GUI_W_RadioAdd * @brief add a radio * @param const rect_st *rec: object dimension * @param const void *str: text of the checkbox (will be copied into it) * @param const uint8_t *pCurrentId: pointer to current id of the selected radio * @param uint8_t id: id of the radio * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error. */ g_obj_st /*@null@*/ *GUI_W_RadioAdd(const rect_st *rec, const void /*@null@*/ *str, const uint8_t *pCurrentId, uint8_t id) { g_obj_st *g_obj = NULL, *res = NULL; radio_st *radio = NULL; /*check parameters*/ if(rec != NULL && pCurrentId != NULL) { /*allocate a generic object*/ g_obj = GUI_AddGenericObject(); if(g_obj != NULL) { /*allocate & init the radio*/ radio = salloc(sizeof(radio_st)); if(radio != NULL) { radio->colorText = GetColor(G_COL_TEXT); radio->font = GetCurrentFont(); radio->str = AllocateAndCopyStr(str); radio->pCurrentId = pCurrentId; radio->id = id; radio->state = *pCurrentId == id? 1: 0; /*linkage between generic obj & radio*/ g_obj->rec = *rec; g_obj->draw = RadioDraw; g_obj->task = RadioRefresh; g_obj->obj = radio; GUI_ObjSetFocusable(g_obj, true); /*radio is a focusable object*/ res = g_obj; } } } return res; }
/** * @function GUI_DBG_Task * @brief debug display task * @param none * @return none */ void GUI_DBG_Task(void) { gui_font_t font; #define DEBUG_STR 50 char str[DEBUG_STR]; if(bDispMem) { /*display every 1s*/ if(IsTimerElapsed(tmDisp)) { /*save current user font*/ font = GetCurrentFont(); /*configure P2D*/ P2D_SetDisplayMode(DISPLAY_SOLID); P2D_SetClip(NULL); SetFont(G_FONT_DEFAULT); P2D_SetColors(COLOR_BLACK, COLOR_LIGHT_GREY); snprintf(str, DEBUG_STR, "MEM:%06d/%06dB CY:%04d", sallocGetUsed(), sallocGetTotal(), cycleCnt); /*display info*/ P2D_PutText(0, LCD_GetHeight() - P2D_GetTextHeight(), str); /*restore current user font*/ SetFont(font); tmDisp = GetPeriodicTimeout(1000); cycleCnt = 0; } cycleCnt++; } }
wxCoord wxDC::GetCharHeight() const { wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int h = -1; GetCurrentFont()->GetHeight(&h); return YDEV2LOGREL(h); }
/** * @function GUI_W_RotaryValueAdd * @brief add a rotary value (use with rot button) * @param const rect_st *rec: object dimension * @param int32_t *pVar: pointer to the int32_t of the rot button * @param const int8_t *pStep: pointer to the counter step of the rot button * @param const void *strUnit: unit string; may be null * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error. */ g_obj_st /*@null@*/ *GUI_W_RotaryValueAdd(const rect_st *rec, int32_t *pVar, const int8_t *pStep, const void /*@null@*/ *strUnit, gui_img_t img) { g_obj_st *g_obj = NULL, *res = NULL; rot_val_st *rval = NULL; /*check parameters*/ if(rec != NULL && pVar != NULL && pStep != NULL) { /*allocate a generic object*/ g_obj = GUI_AddGenericObject(); if(g_obj != NULL) { /*allocate & init the rotary value box*/ rval = salloc(sizeof(rot_val_st)); if(rval != NULL) { /*allocate the string containing the unit*/ rval->strUnit = AllocateAndCopyStr(strUnit); if(strUnit == NULL || rval->strUnit != NULL) { /*init rval*/ rval->pVar = pVar; rval->pStep = pStep; rval->min = INT32_MIN; rval->max = INT32_MAX; rval->oldVal = *pVar; rval->selectedDigit = 0; rval->posDot = 0; rval->lock = 0; rval->wCar = GetMaxCarWidth(); rval->spacing = P2D_GetGlyphWidth((uint8_t)'.'); rval->fsm = 0; /*str unit x position*/ rval->xUnit = rec->w - 8; //rec->x + rec->w - 5; rval->xUnit -= P2D_GetTextWidth(rval->strUnit); rval->img = img; /*context*/ rval->colorText = GetColor(G_COL_TEXT); rval->font = GetCurrentFont(); /*linkage between generic obj & rotary value box*/ g_obj->rec = *rec; g_obj->draw = RotValDraw; g_obj->task = RotValRefresh; g_obj->obj = rval; res = g_obj; } } } } return res; }
wxCoord wxDC::GetCharWidth() const { wxCHECK_MSG( Ok(), -1, wxT("invalid dc") ); wxCHECK_MSG( m_font.Ok(), -1, wxT("no font selected") ); int w = -1; GetCurrentFont()->GetStringWidth("H", 1, &w); // VS: YDEV is corrent, it should *not* be XDEV, because font's are only // scaled according to m_scaleY return YDEV2LOGREL(w); }
/** * @function GUI_W_TabAddToParent * @brief add a tab into a tab container * @param g_obj_st *obj: pointer to the tab container * @param const void *str: tab string * @param gui_img_t img: tab image * @param uint8_t selected * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error. */ g_obj_st /*@null@*/ *GUI_W_TabAddToParent(g_obj_st /*@null@*/ *obj, const void /*@null@*/ *str, gui_img_t img, uint8_t selected) { g_obj_st *res = NULL; parent_tab_st *parentTab = NULL; tab_st *tab = NULL; rect_st tabRec; if(obj == NULL) obj = GUI_GetLastAddedObject(); /*check parameters*/ if(obj != NULL && obj->obj != NULL && obj->draw == ParentTabDraw) { parentTab = (parent_tab_st *) obj->obj; /*compute the tab dimension*/ tabRec.x = parentTab->tabPosX; tabRec.y = obj->rec.y; tabRec.w = 6 + P2D_GetTextWidth(str) + SpriteGetWidth(img); /*+6: 2px for left, 2px between img & txt, 2px for right*/ tabRec.h = parentTab->tabHeight + 1; /*+1: allow to overlap the upper line of the parent tab*/ /*update the parent tabPosX, for a next tab creation*/ parentTab->tabPosX = tabRec.x + tabRec.w + 2; /*check if the tab fits (even partially) in its parent; if not, /ragequit*/ P2D_Clip(&tabRec, &obj->rec); if(P2D_GetPixelCnt(&tabRec) > 0) { /*something to display? allocate the tab*/ tab = salloc(sizeof(tab_st)); if(tab != NULL) { tab->str = AllocateAndCopyStr(str); tab->img = img; tab->selected = selected; tab->colorText = GetColor(G_COL_TEXT); tab->font = GetCurrentFont(); /*finally, allocate & link the generic object*/ res = GUI_AddGenericObject(); if(res != NULL) { res->rec = tabRec; res->draw = TabDraw; res->task = NULL; res->obj = tab; GUI_ObjSetFocusable(res, true); /*tab is a focusable object*/ } } } } return res; }
/** * @function GUI_W_UsrEntryAdd * @brief add user entry * @param const rect_st *rec: object dimension * @param const void *buffer: text of the user entry (may be modified) * @param uint16_t sizeMax: size (in bytes) of the buffer, including the \0 * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error. */ g_obj_st /*@null@*/ *GUI_W_UsrEntryAdd(const rect_st *rec, void *buffer, uint16_t sizeMax, bool bEditable) { g_obj_st *g_obj = NULL, *res = NULL; usr_entry_st *entry = NULL; /*check parameters*/ if(rec != NULL && buffer != NULL && sizeMax > 2) { /*allocate a generic object*/ g_obj = GUI_AddGenericObject(); if(g_obj != NULL) { /*allocate a entry*/ entry = salloc(sizeof(usr_entry_st)); if(entry != NULL) { /*entry settings*/ entry->buffer = (uint8_t *) buffer; entry->buffer[sizeMax - 1] = 0; /*ensure that the user string is \0 terminated*/ entry->sizeMax = sizeMax; entry->len = gstrlen(entry->buffer); entry->tBlink = 0; entry->tScroll = 0; entry->bBlink = false; entry->bPressed = false; entry->bEditable = bEditable; entry->colText = GetColor(G_COL_TEXT); entry->font = GetCurrentFont(); /*start displaying at the very begining of the string*/ entry->offsetDisplay = 0; /*start with the whole string selected*/ entry->cursStart = 0; entry->cursStop = gstrlen(entry->buffer); /*linkage between generic obj & usr entry*/ g_obj->rec = *rec; g_obj->draw = EntryDraw; g_obj->task = EntryTask; g_obj->obj = entry; res = g_obj; } } } return res; }
void wxDC::SetFont(const wxFont& font) { wxCHECK_RET( Ok(), wxT("invalid dc") ); wxFont f(font.Ok() ? font : DEFAULT_FONT); wxFont oldfont(m_font); m_font = f; if ( !m_surface->SetFont(GetCurrentFont()) ) { m_font = oldfont; return; } }
void wxDC::DoGetTextExtent(const wxString& string, wxCoord *x, wxCoord *y, wxCoord *descent, wxCoord *externalLeading, wxFont *theFont) const { wxCHECK_RET( Ok(), wxT("invalid dc") ); wxCHECK_RET( m_font.Ok(), wxT("no font selected") ); wxCHECK_RET( !theFont || theFont->Ok(), wxT("invalid font") ); wxFont oldFont; if ( theFont != NULL ) { oldFont = m_font; wxConstCast(this, wxDC)->SetFont(*theFont); } wxCoord xx = 0, yy = 0; DFBRectangle rect; wxIDirectFBFontPtr f = GetCurrentFont(); if ( f->GetStringExtents(wxSTR_TO_DFB(string), -1, &rect, NULL) ) { // VS: YDEV is corrent, it should *not* be XDEV, because font's are // only scaled according to m_scaleY xx = YDEV2LOGREL(rect.w); yy = YDEV2LOGREL(rect.h); if ( descent ) { int d; if ( f->GetDescender(&d) ) *descent = YDEV2LOGREL(-d); else *descent = 0; } } if ( x ) *x = xx; if ( y ) *y = yy; if ( externalLeading ) *externalLeading = 0; if ( theFont != NULL ) wxConstCast(this, wxDC)->SetFont(oldFont); }
void CCherryComboBox::OnPaint() { CRect clientRect; GetClientRect(clientRect); CPaintDC dc(this); // device context for painting CCherryMemDC memDC(&dc, clientRect); Graphics graphics(memDC.GetSafeHdc()); graphics.SetInterpolationMode(InterpolationModeDefault); graphics.SetPixelOffsetMode(PixelOffsetModeNone); if (m_pBackMemDC) m_pBackMemDC->Draw(&memDC); if (m_pCurrentImage) { if (m_pCurrentImage->GetBitmapLastStatus() == Ok) { if ((UINT)clientRect.Width() > m_pCurrentImage->GetWidth() && (UINT)clientRect.Height() > m_pCurrentImage->GetHeight()) // 원본 이미지 보다 큰 경우 3x3 확대하여 출력한다. m_pCurrentImage->Draw9PatchImage(&graphics, clientRect); else // Source 크기보다 Client가 작거나 같은 경우는 Client 크기로 출력한다. m_pCurrentImage->DrawImage(&graphics, clientRect); } } CString strText; GetWindowText(strText); if (!strText.IsEmpty()) { strText.Replace(_T("&"), _T("")); GetCurrentFont()->DrawText(&graphics, strText, m_textRect); } }
INT_PTR CALLBACK PhpOptionsGeneralDlgProc( _In_ HWND hwndDlg, _In_ UINT uMsg, _In_ WPARAM wParam, _In_ LPARAM lParam ) { switch (uMsg) { case WM_INITDIALOG: { HWND comboBoxHandle; ULONG i; LOGFONT font; PhpPageInit(hwndDlg); comboBoxHandle = GetDlgItem(hwndDlg, IDC_MAXSIZEUNIT); for (i = 0; i < sizeof(PhSizeUnitNames) / sizeof(PWSTR); i++) ComboBox_AddString(comboBoxHandle, PhSizeUnitNames[i]); SetDlgItemText(hwndDlg, IDC_SEARCHENGINE, PhaGetStringSetting(L"SearchEngine")->Buffer); SetDlgItemText(hwndDlg, IDC_PEVIEWER, PhaGetStringSetting(L"ProgramInspectExecutables")->Buffer); if (PhMaxSizeUnit != -1) ComboBox_SetCurSel(comboBoxHandle, PhMaxSizeUnit); else ComboBox_SetCurSel(comboBoxHandle, sizeof(PhSizeUnitNames) / sizeof(PWSTR) - 1); SetDlgItemInt(hwndDlg, IDC_ICONPROCESSES, PhGetIntegerSetting(L"IconProcesses"), FALSE); SetDlgItemCheckForSetting(hwndDlg, IDC_ALLOWONLYONEINSTANCE, L"AllowOnlyOneInstance"); SetDlgItemCheckForSetting(hwndDlg, IDC_HIDEONCLOSE, L"HideOnClose"); SetDlgItemCheckForSetting(hwndDlg, IDC_HIDEONMINIMIZE, L"HideOnMinimize"); SetDlgItemCheckForSetting(hwndDlg, IDC_COLLAPSESERVICES, L"CollapseServicesOnStart"); SetDlgItemCheckForSetting(hwndDlg, IDC_ICONSINGLECLICK, L"IconSingleClick"); SetDlgItemCheckForSetting(hwndDlg, IDC_ICONTOGGLESVISIBILITY, L"IconTogglesVisibility"); SetDlgItemCheckForSetting(hwndDlg, IDC_ENABLEPLUGINS, L"EnablePlugins"); ReadCurrentUserRun(); if (CurrentUserRunPresent) { Button_SetCheck(GetDlgItem(hwndDlg, IDC_STARTATLOGON), BST_CHECKED); if (CurrentUserRunStartHidden) Button_SetCheck(GetDlgItem(hwndDlg, IDC_STARTHIDDEN), BST_CHECKED); } else { EnableWindow(GetDlgItem(hwndDlg, IDC_STARTHIDDEN), FALSE); } // Set the font of the button for a nice preview. if (GetCurrentFont(&font)) { CurrentFontInstance = CreateFontIndirect(&font); if (CurrentFontInstance) SendMessage(GetDlgItem(hwndDlg, IDC_FONT), WM_SETFONT, (WPARAM)CurrentFontInstance, TRUE); } } break; case WM_DESTROY: { if (CurrentFontInstance) DeleteObject(CurrentFontInstance); PhClearReference(&NewFontSelection); } break; case WM_COMMAND: { switch (LOWORD(wParam)) { case IDC_STARTATLOGON: { EnableWindow(GetDlgItem(hwndDlg, IDC_STARTHIDDEN), Button_GetCheck(GetDlgItem(hwndDlg, IDC_STARTATLOGON)) == BST_CHECKED); } break; case IDC_FONT: { LOGFONT font; CHOOSEFONT chooseFont; if (!GetCurrentFont(&font)) { // Can't get LOGFONT from the existing setting, probably // because the user hasn't ever chosen a font before. // Set the font to something familiar. GetObject((HFONT)SendMessage(PhMainWndHandle, WM_PH_GET_FONT, 0, 0), sizeof(LOGFONT), &font); } memset(&chooseFont, 0, sizeof(CHOOSEFONT)); chooseFont.lStructSize = sizeof(CHOOSEFONT); chooseFont.hwndOwner = hwndDlg; chooseFont.lpLogFont = &font; chooseFont.Flags = CF_FORCEFONTEXIST | CF_INITTOLOGFONTSTRUCT | CF_SCREENFONTS; if (ChooseFont(&chooseFont)) { PhMoveReference(&NewFontSelection, PhBufferToHexString((PUCHAR)&font, sizeof(LOGFONT))); // Update the button's font. if (CurrentFontInstance) DeleteObject(CurrentFontInstance); CurrentFontInstance = CreateFontIndirect(&font); SendMessage(GetDlgItem(hwndDlg, IDC_FONT), WM_SETFONT, (WPARAM)CurrentFontInstance, TRUE); } } break; } } break; case WM_NOTIFY: { LPNMHDR header = (LPNMHDR)lParam; switch (header->code) { case PSN_APPLY: { BOOLEAN startAtLogon; BOOLEAN startHidden; PhSetStringSetting2(L"SearchEngine", &(PhaGetDlgItemText(hwndDlg, IDC_SEARCHENGINE)->sr)); PhSetStringSetting2(L"ProgramInspectExecutables", &(PhaGetDlgItemText(hwndDlg, IDC_PEVIEWER)->sr)); PhSetIntegerSetting(L"MaxSizeUnit", PhMaxSizeUnit = ComboBox_GetCurSel(GetDlgItem(hwndDlg, IDC_MAXSIZEUNIT))); PhSetIntegerSetting(L"IconProcesses", GetDlgItemInt(hwndDlg, IDC_ICONPROCESSES, NULL, FALSE)); SetSettingForDlgItemCheck(hwndDlg, IDC_ALLOWONLYONEINSTANCE, L"AllowOnlyOneInstance"); SetSettingForDlgItemCheck(hwndDlg, IDC_HIDEONCLOSE, L"HideOnClose"); SetSettingForDlgItemCheck(hwndDlg, IDC_HIDEONMINIMIZE, L"HideOnMinimize"); SetSettingForDlgItemCheck(hwndDlg, IDC_COLLAPSESERVICES, L"CollapseServicesOnStart"); SetSettingForDlgItemCheck(hwndDlg, IDC_ICONSINGLECLICK, L"IconSingleClick"); SetSettingForDlgItemCheck(hwndDlg, IDC_ICONTOGGLESVISIBILITY, L"IconTogglesVisibility"); SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLEPLUGINS, L"EnablePlugins"); startAtLogon = Button_GetCheck(GetDlgItem(hwndDlg, IDC_STARTATLOGON)) == BST_CHECKED; startHidden = Button_GetCheck(GetDlgItem(hwndDlg, IDC_STARTHIDDEN)) == BST_CHECKED; WriteCurrentUserRun(startAtLogon, startHidden); if (NewFontSelection) { PhSetStringSetting2(L"Font", &NewFontSelection->sr); PostMessage(PhMainWndHandle, WM_PH_UPDATE_FONT, 0, 0); } SetWindowLongPtr(hwndDlg, DWLP_MSGRESULT, PSNRET_NOERROR); } return TRUE; } } break; } return FALSE; }
/** * @function GUI_W_ListCreate * @brief add list container * @param const rect_st *rec: list dimension * @param bool bHeader: if true, categories will be displayed (*rec will be shared between list & its header) * @param scroll_param_st **pvScroll: if non null, will recieve the addr of the internal vertical scroll struct * @param scroll_param_st **phScroll: if non null, will recieve the addr of the internal horizontal scroll struct * @return g_obj_st *: pointer to the associated generic object if succedeed, NULL if error. */ g_obj_st /*@null@*/ *GUI_W_ListCreate(const rect_st *rec, bool bHeader, scroll_param_st /*@null@*/ **pvScroll, scroll_param_st /*@null@*/ **phScroll) { g_obj_st *g_obj = NULL, *g_obj_header = NULL, *res = NULL; list_st *list = NULL; list_header_st *header = NULL; length_t hItem = P2D_GetTextHeight(); rect_st lrec; /*create the generic object for the list's header; configure it later*/ if(bHeader) { g_obj_header = GUI_AddGenericObject(); if(g_obj_header != NULL) { header = (list_header_st *) salloc(sizeof(list_header_st)); } } /*check parameters*/ if(rec != NULL && rec->w >= LIST_W_MIN && hItem > 0 && rec->h >= hItem * LIST_H_MIN && (header != NULL || bHeader == false)) { /*allocate a generic object*/ g_obj = GUI_AddGenericObject(); if(g_obj != NULL) { /*allocate and init the list*/ list = (list_st *) salloc(sizeof(list_st)); if(list != NULL) { /* *rec may be shared between list & its header*/ lrec = *rec; if(bHeader) { lrec.y += hItem + 2; lrec.h -= hItem + 2; } /*ensures that all internal links are NULL & var = 0*/ gmemset( (void *) list, 0, sizeof(list_st)); /*init. the list*/ list->font = GetCurrentFont(); list->hItem = hItem; list->colBackOdd = GetColor(G_COL_E_BACKGROUND); list->colBackEven = P2D_Alpha_a_on_b(GetColor(G_COL_SPECIAL), list->colBackOdd, 32); list->vScroll.wndSize = lrec.h / hItem; list->hScroll.wndSize = lrec.w; list->g_obj_header = g_obj_header; /*return scroller addresses*/ if(pvScroll != NULL) *pvScroll = &(list->vScroll); if(phScroll != NULL) *phScroll = &(list->hScroll); /*linkage between generic obj & list*/ g_obj->rec = lrec; g_obj->draw = ListDraw; g_obj->task = ListRefresh; g_obj->obj = list; GUI_ObjSetStatic(g_obj, true); /*list_st handle refresh event itself*/ /*header linkage, if any*/ if(header != NULL) { lrec.y = rec->y; lrec.h = hItem + 2; header->xt = -1; header->g_obj_list = g_obj; g_obj_header->rec = lrec; g_obj_header->draw = HeaderDraw; g_obj_header->task = HeaderRefresh; g_obj_header->obj = header; GUI_ObjSetStatic(g_obj, true); /*header handles refresh event itself*/ } res = g_obj; } } } return res; }