Cov txheej txheem:

Embedded Window Manager: 10 Kauj Ruam
Embedded Window Manager: 10 Kauj Ruam

Video: Embedded Window Manager: 10 Kauj Ruam

Video: Embedded Window Manager: 10 Kauj Ruam
Video: Musicians talk about Buckethead 2024, Kaum ib hlis
Anonim
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager
Embedded Window Manager

Txoj haujlwm no qhia pom yuav ua li cas thiaj li ua tau tus thawj tswj qhov rai nrog txav tau lub qhov rais sib tshooj ntawm lub tshuab micro-controller nrog lub vaj huam sib luag LCD thiab kov lub vijtsam. Muaj cov lag luam muaj cov software pob los ua qhov no tab sis lawv tau them nyiaj thiab raug kaw. Qhov no, hu ua MiniWin, yog pub dawb thiab qhib-qhov chaw. Nws tau sau ua tiav raws C99 thiab tuaj yeem siv hauv C lossis C ++ daim ntawv thov. Lub hom phiaj ntawm MiniWin yog kom siv tau yooj yim, hloov pauv tau yooj yim, nthuav dav, nqa tau mus rau ntau yam khoom siv kho vajtse, thiab tsis muaj peev txheej tshaib plab heev.

Ib yam li muab cov cai los tswj koj lub qhov rais MiniWin muaj kev sib sau ntawm cov neeg siv kev tswj hwm - cov nyees khawm, cov swb, cov nyom, cov ntoo thiab lwm yam. Windows tuaj yeem txav mus los, hloov pauv, ua kom loj tshaj, txo qis, kaw - txhua yam uas koj ib txwm ua nrog lub qhov rais hauv cov thawj tswj qhov rai loj dua. TrueType fonts nrog kerning thiab tiv thaiv aliasing (ua cov ntawv zoo li smooooooth) kuj tseem txhawb rau cov ntawv zoo nkauj ua.

Hauv txhua lub qhov rais koj muaj cov neeg siv khoom (koj qhov chaw sab hauv ntawm tus ciam teb thiab hauv qab kab saum toj kawg nkaus). Ntawm qhov no koj tuaj yeem ntxiv kev tswj hwm los ua kev sib tham lossis koj tuaj yeem siv lub tsev qiv ntawv duab tsim los kos txhua yam koj xav tau. Txhua lub tsev qiv ntawv duab ua haujlwm yog lub qhov rais paub. Koj tsis tas yuav txhawj xeeb txog qhov koj lub qhov rai nyob qhov twg, nws sib tshooj li cas lossis yog tias nws tau txo qis.

Ntxiv rau ua koj tus kheej lub qhov rais kuj tseem muaj qee qhov kev sib tham nrog uas yooj yim heev rau tam sim ntawd - piv txwv li kev pom zoo cov lus sib tham (tsuas yog OK lossis Yog/Tsis yog nyees khawm), sijhawm/hnub teeb tsa, xaiv cov ntawv, xaiv xim thiab lwm yam.

MiniWin siv tus txheej txheem windows tus thawj tswj tsim kab lus kab ke. Windows tuaj yeem sib cuam tshuam nrog ib leeg thiab tus tswj xyuas qhov rai ntawm cov lus. Koj tsis hu lub luag haujlwm los ua tej yam ncaj qha, koj ntxiv cov lus rau kab thiab tus tswj xyuas qhov rai yuav tshaj tawm rau koj.

MiniWin tau raug xa mus rau cov phiaj xwm kev txhim kho nrog kov lub vijtsam qhia los ntawm cov tswj kev lag luam micro ST, NXP thiab Renesas. Muaj cov tsav tsheb kho vajtse thiab piv txwv cov phiaj xwm rau txhua yam khoom siv no. Ntxiv rau MiniWin tuaj yeem tsim rau Windows lossis Linux yog li koj tuaj yeem simulate koj li kev siv tus lej siv ua ntej koj tau txais koj cov cuab yeej kos.

MiniWin muaj tus lej tsim hluav taws xob. Koj tuaj yeem hais qhia koj lub qhov rais thiab tswj hwm hauv qhov yooj yim los tsim tib neeg nyeem tau JSON cov ntaub ntawv thiab tus lej tsim hluav taws xob cais cov ntaub ntawv thiab tsim cov cai rau koj (muaj ntau qhov piv txwv ua raws). Nws tsim Windows lossis Linux ua tiav daim ntawv thov kev sim uas tsuas tuaj yeem tsim tau thiab muaj koj cov duab LCD simulated nrog koj lub Windows MiniWin ua haujlwm. Koj tuaj yeem coj raws nraim tib txoj cai tsim tawm thiab tso nws mus rau hauv qhov project kos thiab muaj tib txoj cai qhia tib lub qhov rais thiab tswj lub sijhawm tom qab ntawm koj cov cuab yeej kos.

MiniWin yuav tsum tsis muaj kev txhawb nqa kev ua haujlwm ntawm lub cuab yeej kos. Nws tag nrho sau nyob rau hauv ib txoj xov. MiniWin tuaj yeem koom ua ke nrog RTOS khiav ntawm tus txheej txheem kos thiab muaj cov piv txwv ua ke MiniWin nrog FreeRTOS.

Cov lus qhia no qhia yuav ua li cas kom MiniWin nce thiab khiav ntawm STM32 M4 tus txheej txheem siv pheej yig STM32F429 Discovery board uas los nrog QVGA kov lub vijtsam zaub uas twb tau txuas lawm. Cov no tau yooj yim los ntawm koj cov khoom siv hluav taws xob.

MiniWin khiav ntawm ib nrab-ntau micro-controllers thiab saum toj no.

Khoom siv

STM32F429I-DISC1 pawg thawj coj loj thiab lub micro USB cable

STM32CubeIDE rub tawm uas yog pub dawb.

Kauj ruam 1: Tau txais Txoj Cai

Tau Txais Txoj Cai
Tau Txais Txoj Cai

Ua ntej tshaj plaws koj xav tau STM32CubeIDE teeb tsa. Koj tau txais qhov ntawd los ntawm ST lub vev xaib. Koj yuav tsum sau npe thiab nws yuav siv sijhawm me ntsis los rub tawm thiab teeb tsa nws. Nws yog dawb xwb.

Thaum qhov ntawd txhim kho rub tawm MiniWin qhov chaw thiab unzip nws. Nws loj, tab sis koj tsuas yog siv qee qhov me me ntawm nws. Nyem rau ntsuab 'Clone lossis rub tawm' khawm ntawm no …

github.com/miniwinwm/miniwinwm

ces xaiv Download Zip. Unzip cov ntsiab lus.

Kauj Ruam 2: Tsim Ib Qhov Piv Txwv

Tsim Ib Qhov Piv Txwv
Tsim Ib Qhov Piv Txwv
Tsim Ib Qhov Piv Txwv
Tsim Ib Qhov Piv Txwv

Ua ntej cia tsim ib qho ntawm cov haujlwm piv txwv. Qhov zoo yog hu ua MiniWinSimple. Pib STM32CubeIDE ces ua li no:

  1. Xaiv Cov Ntaub Ntawv | Ntshuam…
  2. Qhib General thiab xaiv Txoj Haujlwm Tseem Ceeb rau hauv Chaw Ua Haujlwm. Tom ntej no
  3. Nyem Xauj thiab mus rau qhov chaw uas koj unzipped MiniWin. Tom qab ntawd mus rau STM32CubeIDE / MiniWinSimple / STM32F429 nplaub tshev. Nyem Xaiv Folder.
  4. Hauv Project: zuam MiniWinSimple_STM32F429 ces nyem Ua Ntej.
  5. MiniWinSimple_STM32F429 qhov haujlwm yuav tshwm hauv koj li Project Explorer. Xaiv nws ces tsim nws nrog Project | Tsim Project.
  6. Tam sim no ntsaws koj lub USB cable rau lub rooj tsavxwm thiab koj lub khoos phis tawj thiab khiav nws siv Run | Debug thiab thaum nws rub tawm xaiv Run | Resume. Koj yuav tau txais lub vijtsam ntsuas ntsuas pom thawj zaug yog li kov qhov nruab nrab ntawm 3 tus ntoo khaub lig ntawm LCD zaub. Tam sim no koj tuaj yeem cuam tshuam nrog lub qhov rais ntawm cov zaub.

Txhawm rau txav lub qhov rais rub nws los ntawm nws lub npe kab ntawv. Txhawm rau hloov lub qhov rai siv daim duab peb sab dawb ntawm sab laug ntawm lub npe kab. MiniWin qhov rais tsis tuaj yeem hloov kho los ntawm kev rub cov ciam teb raws li cov lus qhia MiniWin tau siv rau me me heev. Txhawm rau txo qis, ua kom siab lossis kaw lub qhov rai siv cov cim ntawm sab xis ntawm qhov kawg ntawm kab ntawv (kaw yuav xiam oob qhab). Thaum lub qhov rais raug txo qis koj tsis tuaj yeem txav cov cim tsawg ib ncig. Lawv tsim los ntawm hauv qab sab laug mus rau sab xis.

Kauj ruam 3: Khiav Code Generator

Khiav lub Code Generator
Khiav lub Code Generator

Tam sim no peb yuav hloov qhov piv txwv txoj haujlwm los ntawm kev tsim qee lub qhov rais ntawm peb tus kheej thiab tso tus lej tshiab rau hauv. Ua qhov no peb yuav ua tus lej tsim hluav taws xob.

  1. Qhib cov lus txib kom sai thiab mus rau daim nplaub tshev uas koj unzipped MiniWin thiab tom qab ntawd mus rau Tools / CodeGen nplaub tshev.
  2. Qhov ua tiav rau Windows CodeGen.exe twb muaj lawm. Rau Linux koj yuav tsum tsim nws los ntawm kev ntaus ua. (Koj kuj tseem tuaj yeem tsim nws los ntawm qhov chaw rau Windows yog tias koj txhawj xeeb khiav lub rub tawm ua haujlwm tab sis koj xav tau lub khoos phis tawj thiab txhim kho ib puag ncig teeb tsa. Saib MiniWin cov ntaub ntawv hauv cov ntawv docs kom paub meej).
  3. Hauv phau ntawv no yog qee qhov piv txwv JSON cov ntaub ntawv. Peb yuav siv example_empty.json. Koj yuav tsum tau kho nws ua ntej txhawm rau teeb tsa nws rau Windows lossis Linux. Qhib nws hauv tus editor thiab nyob rau sab saum toj uas koj yuav pom "TargetType" hloov pauv "Linux" lossis "Windows" tus nqi rau qhov koj tab tom siv lub tshuab tsim hluav taws xob rau.
  4. Tam sim no ntaus codegen example_empty.json hauv qhov hais kom ua.
  5. Mus rau koj txoj haujlwm hauv STM32CubeIDE thiab qhib daim nplaub tshev MiniWinSimple_Common. Rho tawm tag nrho cov ntaub ntawv nyob rau ntawd.
  6. Peb tawm ntawm "TargetName" hauv JSON cov ntaub ntawv raws li lub hauv paus ntawm "MiniWinGen" yog li ntawd yog lub npe ntawm peb daim nplaub tshev tsim cov cai. Mus rau daim nplaub tshev uas koj unzipped MiniWin thiab tom qab ntawv MiniWinGen_Common. Tam sim no xaiv tag nrho cov ntaub ntawv no thiab rub thiab tso tom qab ntawd rau hauv STM32CubeIDE hauv koj txoj haujlwm MiniWinSimple_Common nplaub tshev.
  7. Tam sim no rov tsim dua thiab rov ua txoj haujlwm hauv STM32CubeIDE thiab koj lub qhov rai tsim tshiab yuav tshwm. Lub pob nyob rau hauv lub qhov rais tau ploj mus vim tias example_empty.json tsis txhais ib qho.

Kauj Ruam 4: Ntxiv Qhov rai

Ntxiv Qhov rai
Ntxiv Qhov rai

Tam sim no peb yuav ntxiv lub qhov rai thib ob rau JSON cov ntawv teeb tsa thiab rov tsim dua cov cai.

1. Qhib example_empty.json hauv kab ntawv sau.

2. Hauv qab ntu "Windows" muaj cov kab lus ntawm lub qhov rai txhais uas tam sim no tsuas muaj ib lub qhov rai xwb. Luam tag nrho cov no…

{

"Name": "W1", "Title": "Window 1", "X": 10, "Y": 15, "Width": 200, "Height": 180, "Border": tseeb, "TitleBar": tseeb, "Pom": tseeb, "Tsawg": tsis tseeb}

thiab muab nws rov qab dua nrog tus lej cais qhov 2 lub ntsiab lus.

3. Hloov "W1" rau "W2" thiab "Window 1" mus rau "Window 2". Hloov "X", "Y", "Dav" thiab "Qhov siab" rau qee qhov sib txawv qhov tseem ceeb kom nco ntsoov lub vijtsam daws teeb meem yog 240 dav los ntawm 320 siab.

4. Txuag cov ntaub ntawv thiab khiav lub tshuab hluav taws xob dua.

5. Luam cov ntaub ntawv raws li hauv cov kauj ruam dhau los, rov tsim dua thiab rov ua dua. Tam sim no koj yuav muaj 2 lub qhov rais ntawm koj cov zaub.

Kauj Ruam 5: Ntxiv Kev Tswj

Ntxiv Kev Tswj
Ntxiv Kev Tswj

Tam sim no peb yuav ntxiv qee qhov kev tswj hwm rau koj lub qhov rais tshiab. Kho cov ntaub ntawv tib yam li hauv cov kauj ruam dhau los.

1. Hauv qhov tshwj xeeb rau lub qhov rais W1 ntxiv tus lej tom qab teeb tsa kawg ("Tsawg": tsis tseeb) tom qab ntawv ntxiv cov ntawv no

"MenuBar": muaj tseeb, "MenuBarEnabled": muaj tseeb, "MenuItems": ["Fred", "Bert", "Pete", "Alf", "Ian"], "Nyees khawm": [{"Npe": "B1", "Label": "Button1", "X": 10, "Y": 10, "Enabled": tseeb, "Pom": tseeb}]

Seem no ntxiv cov ntawv qhia zaub mov nrog 5 yam khoom thiab ua rau nws (cov ntawv qhia zaub mov tuaj yeem ua neeg thoob ntiaj teb tsis taus, sim nws). Nws kuj tseem ntxiv lub pob uas tau qhib thiab pom (lawv tuaj yeem tsim qhov tsis pom thiab tom qab ntawd pom pom hauv cov cai tom qab).

2. Rov tsim dua cov cai, theej nws hla, rov tsim dua, rov ua dua txhua yam zoo li ua ntej.

Kauj Ruam 6: Ua Tus Tswj Kev Ua Ib Yam

Ua Tus Tswj Xyuas Ua Ib Yam
Ua Tus Tswj Xyuas Ua Ib Yam

Tam sim no peb muaj cov neeg siv yooj yim interface peb xav tau kom nws ua qee yam. Txog qhov piv txwv no peb yuav nthuav tawm cov lus xaiv xim thaum lub pob hauv Qhov rai 1 raug nias.

Mus rau koj txoj haujlwm hauv STM32CubeIDE thiab qhib MiniWinSimple_Common nplaub tshev thiab tom qab ntawd qhib cov ntaub ntawv W1.c (lub npe ntawm cov ntawv no sib raug rau lub qhov rai "Npe" teb hauv JSON cov ntawv thaum tsim cov cai).

Hauv cov ntawv no koj yuav pom muaj nuj nqi window_W1_message_function (). Nws zoo li no:

void window_W1_message_function (const mw_message_t *message) {MW_ASSERT (message! = (void *) 0, "Null pointer parameter"); / * Cov kab tom ntej nres cov lus ceeb toom ntawm tus neeg sib tw raws li qhov sib txawv tam sim no tsis siv */ (tsis muaj dab tsi) window_W1_data; hloov (message-> message_id) {case MW_WINDOW_CREATED_MESSAGE: / * Ntxiv ib lub qhov rai pib qhov chaws ntawm no * / so; rooj plaub MW_MENU_BAR_ITEM_PRESSED_MESSAGE: / * Ntxiv qhov rai zaub mov tuav cov cai ntawm no * / so; rooj MW_BUTTON_PRESSED_MESSAGE: yog (message-> sender_handle == button_B1_handle) { / * Ntxiv koj tus lej lis dej num rau qhov kev tswj ntawm no * /} tawg; default: / * Khaws MISRA zoo siab * / so; }}

Qhov no tau hu los ntawm tus tswj xyuas qhov rai rau lub qhov rai no thaum twg tus thawj tswj qhov rai xav tau qhia rau lub qhov rais paub tias muaj qee yam tshwm sim. Hauv qhov no peb xav paub tias lub qhov rais tsuas yog khawm tau raug nias. Hauv qhov hloov pauv nqe lus rau hom lus koj yuav pom rooj plaub rau MW_BUTTON_PRESSED_MESSAGE. Txoj cai no sau thaum lub pob tau raug nias. Tsuas muaj ib lub pob nyob rau ntawm lub qhov rais no, tab sis tuaj yeem muaj ntau dua, yog li kev txheeb xyuas tau ua ntawm lub pob twg nws yog. Hauv qhov no nws tsuas yog khawm B1 (lub npe sib xws rau lub npe rau khawm hauv JSON cov ntaub ntawv dua).

Yog li tom qab qhov xwm txheej daim ntawv lo ntxiv cov cai kom pom cov lus sib tham xaiv xim, uas yog qhov no:

mw_create_window_dialog_colour_chooser (10, 10, "Xim", MW_HAL_LCD_RED, cuav, lus-> tus neeg tau txais kev pabcuam);

Qhov tsis yog raws li hauv qab no:

  • 10, 10 yog qhov chaw nyob ntawm qhov screen ntawm kev sib tham
  • "Xim" yog lub npe sib tham
  • MW_HAL_LCD_RED yog lub xim pib lub dialog yuav pib nrog
  • cuav txhais tau tias tsis qhia qhov loj me (sim teeb nws kom raug thiab pom qhov sib txawv)
  • message-> tus tau txais kev tuav yog leej twg yog tus tswv ntawm qhov kev sib tham, hauv qhov no nws yog lub qhov rai no. Lub qhov rais tuav yog nyob rau hauv txoj haujlwm cov lus ntsuas. Nov yog lub qhov rai qhov kev sib tham yuav raug xa mus rau.

Txhawm rau kom paub tus nqi ntawm cov xim uas tus neeg siv xaiv tus thawj tswj qhov rai yuav xa peb cov lus nrog cov xim uas tau xaiv thaum tus neeg siv nias lub pob OK hauv kev sib tham. Yog li peb yuav tsum cuam tshuam cov lus no ib yam nrog lwm qhov xwm txheej hauv kab lus hloov pauv uas zoo li qhov no:

rooj plaub MW_DIALOG_COLOUR_CHOOSER_OK_MESSAGE:

{mw_hal_lcd_colour_t xaiv_colour = message-> message_data; (tsis muaj dab tsi) xaiv_ xim; } tawg;

Peb tsis tau ua dab tsi nrog cov xim xaiv tseem yog li ntawd tsuas yog pov nws kom tsis muaj dab tsi los tiv thaiv kev ceeb toom cov neeg sau. Txoj cai kawg ntawm txoj haujlwm no tam sim no zoo li qhov no:

void window_W1_message_function (const mw_message_t *lus)

{MW_ASSERT (message! = (Void*) 0, "Null pointer parameter"); / * Cov kab tom ntej nres cov lus ceeb toom ntawm tus neeg sib tw raws li qhov sib txawv tam sim no tsis siv */ (tsis muaj dab tsi) window_W1_data; hloov (message-> message_id) {case MW_WINDOW_CREATED_MESSAGE: / * Ntxiv ib lub qhov rai pib qhov chaws ntawm no * / so; rooj plaub MW_MENU_BAR_ITEM_PRESSED_MESSAGE: / * Ntxiv qhov rai zaub mov tuav cov cai ntawm no * / so; case MW_BUTTON_PRESSED_MESSAGE: yog (message-> sender_handle == button_B1_handle) { / * Ntxiv koj tus lis haujlwm lis dej num rau kev tswj hwm ntawm no * / mw_create_window_dialog_colour_chooser (10, 10, "Xim", MW_HAL_LCD_RED, cuav, lus,) } tawg; rooj plaub MW_DIALOG_COLOUR_CHOOSER_OK_MESSAGE: {mw_hal_lcd_colour_t xaiv_colour = message-> message_data; (tsis muaj dab tsi) xaiv_ xim; } tawg; default: / * Khaws MISRA zoo siab * / so; }}

Khiav cov cai yog pom hauv daim duab saum toj no. Koj yuav pom tias thaum kev sib tham tau qhia koj yuav tsum tau teb rau nws thiab tso nws ua ntej koj ua lwm yam. Qhov no hu ua kev coj tus cwj pwm. Kev sib tham hauv MiniWin thiab txhua qhov ib txwm ua qauv thoob ntiaj teb thiab koj tsuas tuaj yeem muaj ib qho uas qhia ib zaug. Muaj lus piav qhia ntxiv ntawm no …

en.wikipedia.org/wiki/Modal_window

Kauj Ruam 7: Teeb duab hauv Qhov rai

Teeb duab hauv lub qhov rais
Teeb duab hauv lub qhov rais

Txog tam sim no peb tsuas yog siv kev tswj hwm, thiab lawv kos lawv tus kheej. Nws yog lub sijhawm los ua qee qhov kev kos duab ntawm peb lub qhov rais. Ib feem koj tuaj yeem kos rau yog sab hauv cov ciam teb (yog tias lawv muaj, lawv xaiv tau), sab hauv cov kab ntawv rub tawm (yog tias tau hais tseg, kuj xaiv tau) thiab hauv qab kab ntawv npe (yog tias muaj ib qho, uas yog xaiv ib yam nkaus). Nws tau hu ua thaj chaw cov neeg siv khoom hauv cov lus siv qhov rai.

Muaj lub tsev qiv ntawv ntawm cov duab qhia hauv MiniWin uas koj tuaj yeem siv tau. Lawv txhua tus paub qhov rai. Qhov ntawd txhais tau tias koj tsis tas yuav txhawj xeeb yog tias lub qhov rais pom tau, ib nrab tsis pom los ntawm lwm lub qhov rais, ntawm, ib nrab tawm lossis tag nrho ntawm lub vijtsam, lossis yog tias kev sib koom tes ntawm qhov chaw koj tab tom kos duab nyob ntawm cov neeg siv khoom lossis dhau nws. Nws yog txhua yam tau saib xyuas rau koj. Koj tsis tuaj yeem kos sab nraum koj thaj chaw thov.

Kev kos duab ntawm cov neeg siv khoom hauv cov lus siv lub qhov rais yog hu ua pleev xim thiab txhua lub qhov rais muaj xim ua haujlwm qhov twg koj ua koj daim duab. Koj tsis hu koj cov xim ua haujlwm, tus tswj qhov rai ua rau koj thaum xav tau. Nws xav tau thaum lub qhov rais txav los lossis lwm lub qhov rais nyob saum nws muaj txoj haujlwm lossis pom kev hloov. Yog tias koj xav tau koj lub qhov rais rov ua dua vim tias qee cov ntaub ntawv uas lub qhov rai cov ntsiab lus nyob ntawm qhov tau hloov pauv (piv txwv li koj paub tias yuav tsum tau pleev xim dua es tsis yog tus thawj tswj qhov rai paub), tom qab ntawd koj qhia tus thawj tswj qhov rai tias xav tau pleev xim thiab nws hu koj cov xim muaj nuj nqi. Koj tsis hu nws tus kheej. (Qhov no yog txhua yam tau qhia hauv ntu tom ntej).

Ua ntej tshaj, koj yuav tsum nrhiav koj cov xim ua haujlwm. Tus lej tsim hluav taws xob tsim nws rau koj thiab nws tsuas yog nyob saum cov lus tswj hwm kev ua haujlwm hloov kho hauv ntu dhau los. Mus rau koj qhov haujlwm thiab qhib cov ntawv W1.c dua.

Hauv cov ntawv no koj yuav pom muaj nuj nqi window_W1_paint_function (). Nws zoo li no:

void window_W1_paint_function (mw_handle_t window_handle, const mw_gl_draw_info_t *kos_info)

{MW_ASSERT (kos_info! = (Tsis muaj dab tsi*) 0, "Null pointer parameter"); / * Sau lub qhov rai cov neeg siv khoom nrog dawb */ mw_gl_set_fill (MW_GL_FILL); mw_gl_set_solid_fill_colour (MW_HAL_LCD_WHITE); mw_gl_set_border (MW_GL_BORDER_OFF); mw_gl_clear_pattern (); mw_gl_rectangle (kos_info, 0, 0, mw_get_window_client_rect (window_handle).width, mw_get_window_client_rect (window_handle).height); / * Ntxiv koj lub qhov rai pleev xim chaws ntawm no */}

Qhov no yog qhov liab qab raws li tsim cov cai thiab txhua yam nws ua yog sau cov neeg siv khoom nrog cov khoom dawb. Cia kos lub voj voog puv daj rau ntawm cov neeg siv khoom. Ua ntej peb yuav tsum nkag siab lub tswvyim ntawm cov ntsiab lus duab (lwm qhov windows). Peb teeb tsa cov duab tsis hauv cov ntsiab lus duab thiab tom qab ntawd hu rau lub voj voog dav dav ua ntu zus. Yam peb yuav tsum tau teeb tsa hauv qhov piv txwv no yog seb lub voj voog puas muaj ciam teb, kab ciam txheej, xim ciam teb, txawm tias lub voj voos puv lawm, sau xim thiab sau qauv. Koj tuaj yeem pom cov cai saum toj no uas ua qee yam zoo sib xws rau kev sau cov neeg siv khoom nrog cov ciam teb tsis khov puv cov duab plaub dawb. Cov txiaj ntsig hauv cov ntsiab lus duab tsis nco qab ntawm txhua qhov kev hu ntawm cov xim muaj xim yog li koj yuav tsum teeb tsa qhov txiaj ntsig txhua lub sijhawm (lawv tau nco qab nrog cov xim ua haujlwm txawm hais tias).

Hauv cov cai saum toj no koj tuaj yeem pom tias sau tau qhib thiab sau cov qauv tawm, yog li peb tsis tas yuav teeb cov ntawd dua. Peb yuav tsum teeb tsa ciam teb rau ntawm, kab ciam txheej kom ruaj khov, ciam txheej xim rau xim dub thiab sau xim kom daj zoo li no:

mw_gl_set_fg_colour (MW_HAL_LCD_BLACK);

mw_gl_set_solid_fill_colour (MW_HAL_LCD_YELLOW); mw_gl_set_line (MW_GL_SOLID_LINE); mw_gl_set_border (MW_GL_BORDER_ON); mw_gl_circle (kos_info, window_simple_data.circle_x, window_simple_data.circle_y, 25);

Ntxiv cov cai no ntawm cov lus pom hauv txoj haujlwm no uas nws hais kom ntxiv koj cov cai. Tom ntej no peb yuav tsum kos lub voj voog uas ua tiav zoo li no:

mw_gl_circle (kos_info, 30, 30, 15);

Qhov no kos lub voj voos ntawm kev tswj hwm 30, 30 nrog lub vojvoog 15. Rov tsim dua cov cai thiab rov ua nws thiab koj yuav pom lub voj voog nyob hauv lub qhov rais raws li qhia saum toj no. Koj yuav pom tias lub voj voog thiab khawm sib tshooj tab sis khawm nyob saum. Qhov no yog tsim. Kev tswj hwm ib txwm nyob rau sab saum toj ntawm txhua yam koj kos rau ntawm cov neeg siv khoom.

Kauj Ruam 8: Cov Ntaub Ntawv Qhov Rai

Cov Ntaub Ntawv Qhov Rai
Cov Ntaub Ntawv Qhov Rai

Txog tam sim no peb tau siv peb tus kheej cov cai hauv Qhov rai 1 cov lus ua haujlwm (los lis cov lus xa tuaj) thiab nws cov xim muaj xim (kos rau ntawm lub qhov rais cov neeg siv khoom). Tam sim no nws yog lub sijhawm los txuas ob. Cia sau lub voj voos kos rau hauv cov xim ua haujlwm nrog cov xim uas tus neeg siv xaiv los ntawm cov xim xaiv thaum lub khawm raug nias. Nco ntsoov tias peb tsis hu xov tooj rau xim, tus tswj lub qhov rais ua nws, yog li peb cov lus muaj nuj nqi (uas paub cov xim xaiv) tsis tuaj yeem hu ua xim xim ncaj qha rau nws tus kheej. Hloov chaw peb yuav tsum khaws cov ntaub ntawv thiab qhia rau tus saib xyuas qhov rai paub tias yuav tsum tau pleev xim dua. Tus thawj tswj qhov rai yuav hu xov tooj rau xim uas tuaj yeem siv cov ntaub ntawv cached.

Nyob rau sab saum toj ntawm W1.c koj yuav pom cov ntaub ntawv khoob thiab cov khoom ntawm hom no tshaj tawm los ntawm lub tshuab hluav taws xob zoo li no:

typedef qauv

{ / * Ntxiv koj cov tswv cuab cov ntaub ntawv ntawm no * / char dummy; /* Qee tus neeg sau ntawv yws yws txog cov qauv uas tsis muaj; tshem qhov no thaum koj ntxiv koj cov tswv cuab */} window_W1_data_t; zoo li qub window_W1_data_t window_W1_data;

Nov yog qhov uas peb khaws peb cov ntaub ntawv yog li nws tau khaws cia thoob plaws kev hu thiab raug hu ua cov ntaub ntawv qhov rai. Peb tsuas yog xav khaws cov xim xaiv hauv no, zoo li no:

typedef qauv

{ / * Ntxiv koj cov tswv cuab cov ntaub ntawv ntawm no * / mw_hal_lcd_colour_t xaiv_colour; } window_W1_data_t; zoo li qub window_W1_data_t window_W1_data = {MW_HAL_LCD_YELLOW};

Peb mam muab nws pib xim daj. Tam sim no hauv kab lus peb yuav hloov txoj cai me ntsis kom txuag xim xaiv ntawm no zoo li no:

rooj plaub MW_DIALOG_COLOUR_CHOOSER_OK_MESSAGE:

{window_W1_data.chosen_colour = message-> message_data; } tawg;

Tom qab ntawd peb yuav hloov xim xim kom siv tus nqi no thaum nws kos lub voj voog zoo li no:

mw_gl_set_solid_fill_colour (window_W1_data.chosen_colour);

Tam sim no peb tau hloov cov ntaub ntawv uas cov ntsiab lus ntawm lub qhov rais nyob ntawm, yog li peb yuav tsum qhia rau tus thawj tswj qhov rai paub tias lub qhov rai xav tau kev rov ua dua. Peb ua nws hauv cov lus muaj nuj nqi thaum kev sib tham OK tau txais, zoo li no:

mw_paint_window_client (message-> tus tau txais_handle);

Qhov no tsis ua rau lub qhov rais pleev xim ncaj qha. Nws yog lub luag haujlwm muaj txiaj ntsig uas xa xov mus rau tus thawj tswj qhov rai uas lub qhov rai xav tau los pleev xim (yog tias koj nqis mus rau hauv nws koj tuaj yeem pom qhov no tshwm sim li cas). Lub qhov rai uas yuav tsum tau pleev xim rau hauv qhov no yog nws tus kheej, thiab tus tes tuav rau lub qhov rais yog nyob rau hauv cov lus ntsuas mus rau cov lus tuav haujlwm.

Tag nrho cov ntaub ntawv tam sim no zoo li qhov no yog tias koj tsis paub tseeb tias qee qhov ntawm cov cai snippets saum toj no mus:

#suav nrog

#include "miniwin.h" #include "miniwin_user.h" #include "W1.h" typedef struct { / * Ntxiv koj cov tswv cuab cov ntaub ntawv ntawm no * / mw_hal_lcd_colour_t xaiv_colour; } window_W1_data_t; zoo li qub window_W1_data_t window_W1_data = {MW_HAL_LCD_YELLOW}; void window_W1_paint_function (mw_handle_t window_handle, const mw_gl_draw_info_t *draw_info) {MW_ASSERT (kos_info! = (void *) 0, "Null pointer parameter"); / * Sau lub qhov rai cov neeg siv khoom nrog dawb */ mw_gl_set_fill (MW_GL_FILL); mw_gl_set_solid_fill_colour (MW_HAL_LCD_WHITE); mw_gl_set_border (MW_GL_BORDER_OFF); mw_gl_clear_pattern (); mw_gl_rectangle (kos_info, 0, 0, mw_get_window_client_rect (window_handle).width, mw_get_window_client_rect (window_handle).height); / * Ntxiv koj lub qhov rai pleev xim chaws ntawm no */ mw_gl_set_fg_colour (MW_HAL_LCD_BLACK); mw_gl_set_solid_fill_colour (window_W1_data.chosen_colour); mw_gl_set_line (MW_GL_SOLID_LINE); mw_gl_set_border (MW_GL_BORDER_ON); mw_gl_circle (kos_info, 30, 30, 15); } void window_W1_message_function (const mw_message_t *message) {MW_ASSERT (message! = (void *) 0, "Null pointer parameter"); / * Cov kab tom ntej nres cov lus ceeb toom ntawm tus neeg sib tw raws li qhov sib txawv tam sim no tsis siv */ (tsis muaj dab tsi) window_W1_data; hloov (message-> message_id) {case MW_WINDOW_CREATED_MESSAGE: / * Ntxiv ib lub qhov rai pib qhov chaws ntawm no * / so; rooj plaub MW_MENU_BAR_ITEM_PRESSED_MESSAGE: / * Ntxiv qhov rai zaub mov tuav cov cai ntawm no * / so; case MW_BUTTON_PRESSED_MESSAGE: yog (message-> sender_handle == button_B1_handle) { / * Ntxiv koj tus lis haujlwm lis dej num rau kev tswj hwm ntawm no * / mw_create_window_dialog_colour_chooser (10, 10, "Xim", MW_HAL_LCD_RED, cuav, lus,) } tawg; rooj plaub MW_DIALOG_COLOUR_CHOOSER_OK_MESSAGE: {window_W1_data.chosen_colour = message-> message_data; mw_paint_window_client (message-> tus tau txais_handle); } tawg; default: / * Khaws MISRA zoo siab * / so; }}

Tsim thiab khiav dua thiab koj yuav tsum muaj peev xwm teeb cov xim ntawm lub voj voog.

Qhov piv txwv ntawm cov ntaub ntawv qhov rai siv cov ntaub ntawv uas tau khaws cia hauv cov ntaub ntawv zoo li qub nyob rau sab saud cov ntaub ntawv. Qhov no zoo yog tias koj tsuas muaj ib qho piv txwv ntawm lub qhov rais, zoo li peb ua hauv qhov piv txwv no, tab sis yog tias koj muaj ntau dua ib qho piv txwv ces lawv txhua tus yuav faib cov ntaub ntawv tib yam. Nws muaj peev xwm muaj cov ntaub ntawv ib qho piv txwv yog li ntau zaus ntawm tib lub qhov rai hom muaj lawv tus kheej cov ntaub ntawv. Qhov no tau piav qhia hauv MiniWin cov ntaub ntawv pom hauv cov ntawv teev npe. Cov ntaub ntawv piv txwv siv nws los qhia ntau yam duab hauv tib lub qhov rai (raws li pom hauv daim duab tseem ceeb nyob rau sab saum toj ntawm cov lus qhia no).

Kauj Ruam 9: Qee qhov Font Fun kawg

Qee qhov Font Fun kawg
Qee qhov Font Fun kawg

MiniWin txhawb nqa TrueType font rendering. Yog tias muaj ib yam uas ua rau koj tus neeg siv interface zoo, nws yog fonts txaus nyiam. Cov kauj ruam kawg no qhia pom yuav ua li cas thiaj ua tau TrueType font hauv MiniWin qhov rai.

Muaj ob txoj hauv kev los ua kom muaj TrueType fonts. Ib qho yog kos lawv ncaj qha rau ntawm koj cov neeg siv khoom zoo li tau ua tiav rau lub voj voos ua ntej, lwm qhov yog ntxiv cov ntawv tswj lub thawv rau hauv koj lub qhov rais. Peb tab tom ua qhov kawg vim nws yooj yim dua.

Tam sim no peb yuav ntxiv cov ntawv tswj lub thawv rau hauv peb JSON cov ntaub ntawv teeb tsa. Ntxiv nws mus rau Qhov rai 2 lub ntsiab lus kom nws zoo li qhov no:

zoo li no:

{

"Npe": "W2", "Title": "Window 2", "X": 50, "Y": 65, "Width": 100, "Height": 80, "Border": tseeb, "TitleBar": tseeb, "Pom": tseeb, "Tsawg": tsis tseeb, "TextBoxes": [{"Lub Npe": "TB1", "X": 0, "Y": 0, "Dav": 115, "Qhov siab": 50, "Kev Ncaj Ncees": "Center", "BackgroundColour": "MW_HAL_LCD_YELLOW", "ForegroundColour": "MW_HAL_LCD_BLACK", "Font": "mf_rlefont_BLKCHCRY16", "Enabled": true, "Visible": true}]}

Lo lus nrawm txog TrueType fonts hauv MiniWin. Fonts tuaj hauv.ttf cov ntaub ntawv. Hauv cov thawj tswj qhov rai ntawm cov khoos phis tawj loj dua cov no tau muab tso rau hauv koj cov zaub thaum lawv xav tau. Qhov no siv ntau lub zog ua haujlwm thiab nco thiab tsis haum rau cov khoom siv me me. Hauv MiniWin lawv tau npaj ua ntej rau hauv bitmaps thiab txuas ntawm lub sijhawm suav sau ntawm qhov loj me font thiab style (bold, italics thiab lwm yam) piv txwv li koj yuav tsum txiav txim siab hom ntawv dab tsi ntawm qhov loj thiab style koj yuav siv thaum suav sijhawm. Qhov no tau ua tiav rau koj rau ob qho piv txwv fonts hauv MiniWin zip cov ntaub ntawv koj rub tawm. Yog tias koj xav siv lwm tus fonts ntawm lwm qhov ntau thiab tsawg thiab pom cov MiniWin cov ntaub ntawv hauv cov ntawv docs. Muaj cov cuab yeej hauv MiniWin rau Windows thiab Linux rau kev ua ua ntej.ttf cov ntaub ntawv rau hauv cov ntaub ntawv qhov chaws koj tuaj yeem tso rau hauv koj qhov project.

Thiab lo lus nrawm thib ob - feem ntau cov ntawv yog cai, suav nrog cov uas koj yuav pom hauv Microsoft Windows. Siv lawv ntawm qhov yuav siv rau tus kheej, tab sis txhua yam koj tshaj tawm koj yuav tsum xyuas kom daim ntawv tso cai fonts raug luam tawm nrog tso cai rau nws, ib yam li 2 fonts suav nrog hauv MiniWin, tab sis tsis yog Microsoft lub fonts!

Rov qab mus rau txoj cai! Tsim, tso cov ntaub ntawv, tsim thiab rov ua dua raws li ua ntej thiab koj yuav pom Qhov rai 2 tam sim no muaj qee cov ntawv sau tsis raug ntawm keeb kwm daj hauv cov ntawv tsis txaus ntseeg. Cia hloov cov ntawv los ntawm kho qhov rai 2 lub hauv paus ntaub ntawv W2.c.

Peb yuav tsum sib txuas lus nrog lub thawv ntawv peb nyuam qhuav tsim thiab txoj hauv kev koj ua li ntawd zoo li kev sib txuas lus hauv MiniWin yog xa nws cov lus. Peb xav teeb tsa cov ntawv hauv kev tswj hwm thaum lub qhov rais raug tsim tab sis ua ntej nws tau tshwm sim, yog li peb ntxiv cov cai hauv tus xa xov hauv MW_WINDOW_CREATED_MESSAGE rooj plaub. Qhov no tau txais los ntawm lub qhov rai chaws ua ntej lub qhov rai tshwm thiab yog npaj rau kev pib ua haujlwm zoo li no. Lub tshuab hluav taws xob tsim tsim ib qho chaw tuav uas zoo li qhov no hauv cov lus tuav haujlwm:

rooj MW_WINDOW_CREATED_MESSAGE:

/ * Ntxiv ib lub qhov rai pib qhov chaws ntawm no */ so;

Ntawm no peb yuav tshaj tawm cov lus rau lub thawv ntawv tswj qhia nws cov ntawv peb xav kom nws qhia los ntawm kev siv mw_post_message muaj nuj nqi zoo li no:

rooj MW_WINDOW_CREATED_MESSAGE:

/ * Ntxiv rau txhua qhov chaws pib qhov chaws ntawm no */ mw_post_message (MW_TEXT_BOX_SET_TEXT_MESSAGE, lus-> tus tau txais_handle, text_box_TB1_handle, 0UL, "Twas tsaus ntuj thiab cua daj cua dub …", MW_CONTROL_MESSAGE); tawg;

Cov no yog cov tsis:

  • MW_TEXT_BOX_SET_TEXT_MESSAGE - Nov yog hom lus peb xa mus rau kev tswj hwm. Lawv tau teev nyob rau hauv miniwin.h thiab sau tseg hauv cov ntaub ntawv.
  • message-> tus tau txais_handle - Qhov no yog leej twg cov lus los ntawm - lub qhov rai no - tus tuav uas yog hauv cov lus ntsuas tau dhau mus rau cov haujlwm ua haujlwm xov.
  • text_box_TB1_handle - Leej twg peb tab tom xa xov mus rau - tus tuav ntawm lub thawv ntawv tswj. Cov no tau teev nyob hauv cov ntaub ntawv tsim tawm miniwin_user.h.
  • 0UL - Cov ntaub ntawv tus nqi, tsis muaj dab tsi hauv qhov no.
  • "Twas tsaus ntuj thiab cua daj cua dub …" - Tus nqi taw qhia - cov ntawv tshiab.
  • MW_CONTROL_MESSAGE - Hom neeg tau txais uas yog kev tswj hwm.

Qhov ntawd yog nws. Rov tsim dua thiab rov ua dua raws li ib txwm muaj thiab koj yuav tau txais lub thawv ntawv qhia zoo li hauv daim duab saum toj no.

Kev tshaj tawm xov xwm yog qhov tseem ceeb rau MiniWin (zoo li nws yog rau txhua tus tswj qhov rai). Rau ntau qhov piv txwv saib ntawm cov piv txwv cov haujlwm hauv zip file thiab rau kev piav qhia ntxaws nyeem ntu ntawm MiniWin cov lus hauv cov ntaub ntawv.

Kauj ruam 10: Mus Ntxiv

Image
Image

Nov yog nws rau qhov kev qhia yooj yim rau MiniWin. MiniWin tuaj yeem ua ntau yam ntau dua li tau qhia ntawm no. Piv txwv li, lub vijtsam ntawm lub rooj tsavxwm uas siv hauv phau ntawv qhia no yog me me thiab cov kev tswjfwm me thiab yuav tsum tau siv nrog dibber. Txawm li cas los xij, lwm qhov piv txwv thiab kho vajtse siv kev tswj hwm loj dua (muaj 2 qhov loj me) ntawm cov lus loj dua thiab cov no tuaj yeem ua haujlwm ntiv tes.

Muaj ntau ntau hom kev tswj hwm dua li cov uas tau qhia ntawm no. Txog kev tswj hwm ntxiv saib ntawm ntau yam piv txwv JSON cov ntaub ntawv hauv cov cim tsim hluav taws xob. Txhua hom kev tswj hwm tau hais hauv cov piv txwv no.

Windows muaj ntau txoj kev xaiv. Ciam teb, kab npe thiab cov cim yog txhua yam teeb tsa tau. Koj tuaj yeem muaj cov kab tuav thiab cov qhov rai qhov rai cov neeg siv khoom, ntau qhov xwm txheej ntawm tib lub qhov rai thiab lub qhov rais tuaj yeem liab qab (tsuas yog thaj chaw cov neeg siv khoom, tsis muaj ciam teb lossis kab ntawv npe) uas txhais tau tias lawv tau tsau ntawm lub sijhawm suav nrog hauv qhov chaw (pom cov duab hauv ntu no nrog cov cim loj loj - cov no yog 6 lub qhov muag liab qab).

MiniWin siv tsis muaj lub cim xeeb hloov pauv. Qhov no ua rau nws haum rau cov cuab yeej txwv me me thiab yog qhov yuav tsum tau ua rau qee cov phiaj xwm kos. MiniWin thiab cov cai nws tsim tawm kuj tseem ua tiav MISRA 2012 ua tau raws qib 'xav tau'.

Yog xav paub ntxiv saib hauv daim ntawv docs rau cov ntaub ntawv thiab tseem muaj lwm yam piv txwv thov hauv zip file. Muaj cov piv txwv ntawm no qhia yuav siv tag nrho cov yam ntxwv ntawm MiniWin thiab yuav ua li cas sib xyaw MiniWin nrog FatFS thiab FreeRTOS.

Pom zoo: