Created
January 16, 2016 01:54
-
-
Save jerstlouis/beb4abc6d0814bd09a28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "buttons.h" | |
| #include "cursor.h" | |
| #include "cdaudio.h" | |
| #include "input.h" | |
| #include "pcx.h" | |
| #include "scrolbar.h" | |
| #include "video.h" | |
| #define NUMBUTTONS 38 | |
| #define NUMFONTS 5 | |
| #define EJECT 0x01 | |
| #define CLOSE 0x02 | |
| #define PLAY 0x03 | |
| #define STOP 0x04 | |
| #define PAUSE 0x05 | |
| #define TRACK 0x06 | |
| CD_Disk cd; | |
| button_t *pressed=NULL; | |
| button_t CDButtons[NUMBUTTONS]; | |
| font_t CDFonts [NUMFONTS ]; | |
| cursor_t cursor; | |
| scrollbar_t volumebar, positionbar; | |
| WORD volume=0, position=0; | |
| void CDPLAY_Command(button_t *button); | |
| /* | |
| ================= | |
| IN_RightButtonUp | |
| ================= | |
| */ | |
| void IN_RightButtonUp() | |
| { | |
| } | |
| /* | |
| ================= | |
| IN_RightButtonDown | |
| ================= | |
| */ | |
| void IN_RightButtonDown() | |
| { | |
| } | |
| /* | |
| ================= | |
| IN_LeftButtonUp | |
| ================= | |
| */ | |
| void IN_LeftButtonUp() | |
| { | |
| WORD b; | |
| for(b=0; b<NUMBUTTONS; b++) | |
| if(BTN_Up(&CDButtons[b],MOUSE_POS,&pressed)) | |
| CDPLAY_Command(&CDButtons[b]); | |
| pressed=NULL; | |
| positionbar.active=FALSE; | |
| if(volume!=volumebar.position) | |
| { | |
| volume=volumebar.position; | |
| //In case some weird cdroms need to have their volume set to 0 before... | |
| CD_SetVolume(0); | |
| CD_SetVolume(255-volume); | |
| } | |
| if(position!=positionbar.position) | |
| if(cd.Playing) | |
| { | |
| position=positionbar.position; | |
| CD_Move(position); | |
| } | |
| } | |
| /* | |
| ================= | |
| IN_LeftButtonDown | |
| ================= | |
| */ | |
| void IN_LeftButtonDown() | |
| { | |
| WORD b; | |
| for(b=0; b<NUMBUTTONS; b++) | |
| BTN_Down(&CDButtons[b],MOUSE_POS,&pressed); | |
| } | |
| BOOL ECERE_Init(int argc, char *argv[]) | |
| { | |
| WORD b; | |
| char temp[80]; | |
| BYTE palette[768]; | |
| BYTE Filters[64]= | |
| { | |
| 79,246,246,104,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201, | |
| 79,200,199,197,192,239,102,201 | |
| }; | |
| if(argc>1) | |
| CD_Init(atoi(argv[1])); | |
| else | |
| CD_Init(0); | |
| VID_Init(VGA320x200x256,1,0); | |
| MOUSE_Init(); | |
| //Set Palette | |
| PCX_LoadPAL(palette, "2.rgb"); | |
| VID_SetPalette(palette); | |
| //Load fonts | |
| FNT_Load(&CDFonts[0], "279.fnt", Filters); | |
| FNT_Load(&CDFonts[1], "280.fnt", Filters); | |
| FNT_Load(&CDFonts[2], "281.fnt", Filters); | |
| FNT_Load(&CDFonts[3], "282.fnt", Filters); | |
| FNT_Load(&CDFonts[4], "283.fnt", Filters); | |
| //Load buttons sprites | |
| SPR_Load(&BTNGFX[1], "0.pcx", "0.siz"); | |
| //Create tracks buttons | |
| for(b=0; b<25; b++) | |
| { | |
| itoa(b+1,temp,10); | |
| BTN_Create(&CDButtons[b],1,1,TRUE,(b%5)*17+235,(b/5)*17,temp,5,6,&CDFonts[4]); | |
| SET(CDButtons[b],23,TRACK); | |
| CDButtons[b].Extra=b+1; | |
| } | |
| //Create action buttons | |
| BTN_Create(&CDButtons[25],1,1,TRUE,60,30, "Eject",26,6,&CDFonts[2]); | |
| BTN_Create(&CDButtons[26],1,1,TRUE,60,30, "Close",26,6,&CDFonts[2]); | |
| BTN_Create(&CDButtons[27],1,1,TRUE,60,60, "Stop", 30,6,&CDFonts[2]); | |
| BTN_Create(&CDButtons[28],1,1,TRUE,60,90, "Play", 30,6,&CDFonts[2]); | |
| BTN_Create(&CDButtons[29],1,1,TRUE,60,120,"Pause",26,6,&CDFonts[2]); | |
| SET(CDButtons[27],9,STOP); | |
| SET(CDButtons[28],9,PLAY); | |
| SET(CDButtons[29],9,PAUSE); | |
| //Position bar | |
| SB_Create(&positionbar, SB_HORZ,1,1, 19,164, 0,5, TRUE, | |
| &CDButtons[30],44, &CDButtons[31],40, | |
| &CDButtons[32],34, &CDButtons[33],37); | |
| //Volume bar | |
| SB_Create(&volumebar, SB_VERT,1,1, 0,0, 256,5, TRUE, | |
| &CDButtons[34],42, &CDButtons[35],40, | |
| &CDButtons[36],28, &CDButtons[37],31); | |
| volumebar.position=volume=255-CD_GetVolume(); | |
| SB_PlaceThumb(&volumebar); | |
| //Create Cursors | |
| PCX_LoadBMP(&cursor.bitmap, "314.pcx"); | |
| cursor.hotspot=P2D(0,0); | |
| return TRUE; | |
| } | |
| BOOL ECERE_Main() | |
| { | |
| WORD b,t; | |
| char ch; | |
| //Update the CD player | |
| CD_Update(&cd); | |
| //Change buttons | |
| for(b=0; b<25; b++) | |
| REM(CDButtons[b]); | |
| REM(CDButtons[25]); | |
| REM(CDButtons[26]); | |
| DIS(CDButtons[27]); | |
| DIS(CDButtons[28]); | |
| DIS(CDButtons[29]); | |
| positionbar.range=0; | |
| if(cd.Valid) | |
| { | |
| for(t=cd.FirstTrack; t<=cd.LastTrack; t++) | |
| if(!cd.Tracks[t].Data && (t<=25)) | |
| PUT(CDButtons[t-1]); | |
| if(cd.Playing||cd.WasPlaying) | |
| { | |
| if(cd.Playing) | |
| { | |
| position=cd.Position.Min*60+cd.Position.Sec; | |
| if(positionbar.active) | |
| { | |
| cd.Position.Min=positionbar.position/60; | |
| cd.Position.Sec=positionbar.position%60; | |
| } | |
| else | |
| positionbar.position=position; | |
| } | |
| else | |
| { | |
| cd.Position.Min=position/60; | |
| cd.Position.Sec=position%60; | |
| positionbar.position=position; | |
| } | |
| positionbar.range=CD_HSG2Seconds(cd.Tracks[cd.Track].Length); | |
| } | |
| if(cd.Playing||cd.WasPlaying) | |
| { | |
| ENBL(CDButtons[27]); | |
| ENBL(CDButtons[29]); | |
| } | |
| if(!cd.Playing) | |
| ENBL(CDButtons[28]); | |
| } | |
| SB_PlaceThumb(&positionbar); | |
| if(cd.Opened) | |
| SET(CDButtons[26],9,CLOSE) | |
| else | |
| SET(CDButtons[25],9,EJECT) | |
| //Keyboard Input | |
| if(kbhit()) | |
| { | |
| ch=getch(); | |
| if(ch==27)return FALSE; | |
| } | |
| //Mouse input | |
| IN_Process(); | |
| for(b=0; b<NUMBUTTONS; b++) | |
| if(BTN_Update(&CDButtons[b],MOUSE_POS,&pressed)) | |
| CDPLAY_Command(&CDButtons[b]); | |
| //Display | |
| VID_ClearScreen(); | |
| for(b=0; b<NUMBUTTONS; b++) | |
| BTN_Draw(&CDButtons[b]); | |
| if(cd.Playing||cd.WasPlaying) | |
| { | |
| FNT_TextOut(&CDFonts[2],&SCREEN,P2D(270,185),"%2ld:%02d",cd.Position.Min,cd.Position.Sec); | |
| FNT_TextOut(&CDFonts[2],&SCREEN,P2D(0, 185),"Track %d",cd.Track); | |
| } | |
| FNT_TextOut(&CDFonts[2],&SCREEN,P2D(30,0),"ECERE CD Player",cd.Track); | |
| CSR_Display(&cursor, MOUSE_POS); | |
| VID_Display(); | |
| return TRUE; | |
| } | |
| void ECERE_Terminate() | |
| { | |
| WORD b,f; | |
| //Deinit everything | |
| for(f=0; f<NUMFONTS; f++) | |
| FNT_Free(&CDFonts[f]); | |
| for(b=0; b<NUMBUTTONS; b++) | |
| BTN_Free(&CDButtons[b]); | |
| SPR_Free(&BTNGFX[1]); | |
| BMP_Free(&cursor.bitmap); | |
| VID_Terminate(1); | |
| CD_Deinit(); | |
| } | |
| /* | |
| ================= | |
| CDPLAY_Command | |
| ================= | |
| */ | |
| void CDPLAY_Command(button_t *button) | |
| { | |
| if(SB_Command(&volumebar,button,MOUSE_POS)) | |
| { | |
| CD_SetVolume(255-volumebar.position); | |
| return; | |
| } | |
| if(SB_Command(&positionbar,button,MOUSE_POS)) | |
| return; | |
| switch(button->command) | |
| { | |
| case EJECT: | |
| CD_Eject(); | |
| break; | |
| case CLOSE: | |
| CD_CloseTray(); | |
| break; | |
| case STOP: | |
| CD_Stop(); | |
| break; | |
| case PLAY: | |
| if(!cd.Playing && cd.WasPlaying) | |
| CD_Resume(); | |
| else | |
| CD_PlayTrack(cd.Track); | |
| break; | |
| case PAUSE: | |
| if(!cd.Playing) | |
| CD_Resume(); | |
| else | |
| CD_Pause(); | |
| break; | |
| case TRACK: | |
| CD_PlayTrack(button->Extra); | |
| break; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment