ft2-clone

Fasttracker 2 clone
Log | Files | Refs | README | LICENSE

ft2_checkboxes.c (7153B)


      1 // for finding memory leaks in debug mode with Visual Studio
      2 #if defined _DEBUG && defined _MSC_VER
      3 #include <crtdbg.h>
      4 #endif
      5 
      6 #include "ft2_header.h"
      7 #include "ft2_gui.h"
      8 #include "ft2_config.h"
      9 #include "ft2_sample_ed.h"
     10 #include "ft2_nibbles.h"
     11 #include "ft2_inst_ed.h"
     12 #include "ft2_pattern_ed.h"
     13 #include "ft2_trim.h"
     14 #include "ft2_mouse.h"
     15 #include "ft2_edit.h"
     16 #include "ft2_bmp.h"
     17 #include "ft2_wav_renderer.h"
     18 #include "ft2_smpfx.h"
     19 #include "ft2_structs.h"
     20 
     21 checkBox_t checkBoxes[NUM_CHECKBOXES] =
     22 {
     23 	// ------ RESERVED CHECKBOX ------
     24 	{ 0 },
     25 
     26 	/*
     27 	** -- STRUCT INFO: --
     28 	**  x        = x position
     29 	**  y        = y position
     30 	**  w        = clickable width in pixels, relative to x
     31 	**  h        = clickable height in pixels, relative to y
     32 	**  funcOnUp = function to call when released
     33 	*/
     34 
     35 	// ------ NIBBLES CHECKBOXES ------
     36 	//x, y,   w,  h,  funcOnUp
     37 	{ 3, 133, 70, 12, nibblesToggleSurround },
     38 	{ 3, 146, 40, 12, nibblesToggleGrid },
     39 	{ 3, 159, 45, 12, nibblesToggleWrap },
     40 
     41 	// ------ ADVANCED EDIT CHECKBOXES ------
     42 	//x,   y,   w,   h,  funcOnUp
     43 	{ 113,  94, 105, 12, toggleCopyMaskEnable },
     44 	{ 237, 107,  13, 12, toggleCopyMask0 },
     45 	{ 237, 120,  13, 12, toggleCopyMask1 },
     46 	{ 237, 133,  13, 12, toggleCopyMask2 },
     47 	{ 237, 146,  13, 12, toggleCopyMask3 },
     48 	{ 237, 159,  13, 12, toggleCopyMask4 },
     49 	{ 256, 107,  13, 12, togglePasteMask0 },
     50 	{ 256, 120,  13, 12, togglePasteMask1 },
     51 	{ 256, 133,  13, 12, togglePasteMask2 },
     52 	{ 256, 146,  13, 12, togglePasteMask3 },
     53 	{ 256, 159,  13, 12, togglePasteMask4 },
     54 	{ 275, 107,  13, 12, toggleTranspMask0 },
     55 	{ 275, 120,  13, 12, toggleTranspMask1 },
     56 	{ 275, 133,  13, 12, toggleTranspMask2 },
     57 	{ 275, 146,  13, 12, toggleTranspMask3 },
     58 	{ 275, 159,  13, 12, toggleTranspMask4 },
     59 
     60 	// ------ INSTRUMENT EDITOR CHECKBOXES ------
     61 	//x,   y,   w,   h,  funcOnUp
     62 	{   3, 175, 118, 12, cbVEnv },
     63 	{ 341, 192,  64, 12, cbVEnvSus },
     64 	{ 341, 217,  70, 12, cbVEnvLoop },
     65 	{   3, 262, 123, 12, cbPEnv },
     66 	{ 341, 279,  64, 12, cbPEnvSus },
     67 	{ 341, 304,  70, 12, cbPEnvLoop },
     68 
     69 	// ------ INSTRUMENT EDITOR EXTENSION CHECKBOXES ------
     70 	//x,   y,   w,   h,  funcOnUp
     71 	{   3, 112, 148, 12, cbInstMidiEnable },
     72 	{ 172, 112, 103, 12, cbInstMuteComputer },
     73 
     74 	// ------ SAMPLE EDITOR EFFECTS CHECKBOXES ------
     75 	//x,   y,   w,   h,  funcOnUp
     76 	{ 119, 384,  95, 12, cbSfxNormalization },
     77 
     78 	// ------ TRIM SCREEN CHECKBOXES ------
     79 	//x,   y,   w,   h,  funcOnUp
     80 	{   3, 107, 113, 12, cbTrimUnusedPatt },
     81 	{   3, 120, 132, 12, cbTrimUnusedInst },
     82 	{   3, 133, 110, 12, cbTrimUnusedSamp },
     83 	{   3, 146, 115, 12, cbTrimUnusedChans },
     84 	{   3, 159, 130, 12, cbTrimUnusedSmpData },
     85 	{ 139,  94, 149, 12, cbTrimSmpsTo8Bit },
     86 
     87 	// ------ CONFIG CHECKBOXES ------
     88 	//x,   y,   w,   h,  funcOnUp
     89 	{   3,  91,  77, 12, cbToggleAutoSaveConfig },
     90 	{ 512, 158, 107, 12, cbConfigVolRamp },
     91 	{ 113,  14, 108, 12, cbConfigPattStretch },
     92 	{ 113,  27, 117, 12, cbConfigHexCount },
     93 	{ 113,  40,  81, 12, cbConfigAccidential },
     94 	{ 113,  53,  92, 12, cbConfigShowZeroes },
     95 	{ 113,  66,  81, 12, cbConfigFramework },
     96 	{ 113,  79, 128, 12, cbConfigLineColors },
     97 	{ 113,  92, 126, 12, cbConfigChanNums },
     98 	{ 255,  14, 136, 12, cbConfigShowVolCol },
     99 	{ 237, 108,  13, 12, cbEnableCustomPointer },
    100 	{ 255, 158, 111, 12, cbSoftwareMouse },
    101 	// ---------------------------------
    102 	{ 212,   2, 150, 12, cbSampCutToBuff },
    103 	{ 212,  15, 153, 12, cbPattCutToBuff },
    104 	{ 212,  28, 159, 12, cbKillNotesAtStop },
    105 	{ 212,  41, 149, 12, cbFileOverwriteWarn },
    106 	{ 212,  68, 130, 12, cbMultiChanRec },
    107 	{ 212,  81, 157, 12, cbMultiChanKeyJazz },
    108 	{ 212,  94, 114, 12, cbMultiChanEdit },
    109 	{ 212, 107, 143, 12, cbRecKeyOff },
    110 	{ 212, 120,  89, 12, cbQuantization },
    111 	{ 212, 133, 180, 24, cbChangePattLenInsDel },
    112 	{ 212, 159, 169, 12, cbUseOldAboutScreen },
    113 	{ 411,  93,  83, 12, cbMIDIEnable },
    114 	{ 530, 106,  29, 12, cbMIDIRecAllChn },
    115 	{ 411, 119, 121, 12, cbMIDIRecTransp },
    116 	{ 411, 132, 109, 12, cbMIDIRecVelocity },
    117 	{ 411, 145, 124, 12, cbMIDIRecAftert },
    118 	{ 113, 115,  75, 12, cbVsyncOff },
    119 	{ 113, 128,  78, 12, cbFullScreen },
    120 	{ 113, 141,  75, 12, cbStretchImage },
    121 	{ 113, 154,  78, 12, cbPixelFilter },
    122 
    123 	// WAV RENDERER BPM MODE
    124 	//x,   y,   w,   h,  funcOnUp
    125 	{   3, 112,  71, 24, cbToggleWavRenderBPMMode }
    126 };
    127 
    128 void drawCheckBox(uint16_t checkBoxID)
    129 {
    130 	const uint8_t *gfxPtr;
    131 
    132 	assert(checkBoxID < NUM_CHECKBOXES);
    133 	checkBox_t *checkBox = &checkBoxes[checkBoxID];
    134 	if (!checkBox->visible)
    135 		return;
    136 
    137 	if (checkBoxID == CB_CONF_ACCIDENTAL)
    138 		gfxPtr = &bmp.checkboxGfx[4*(CHECKBOX_W*CHECKBOX_H)]; // for the special "Accidental" check button in Config Layout
    139 	else
    140 		gfxPtr = &bmp.checkboxGfx[0*(CHECKBOX_W*CHECKBOX_H)];
    141 
    142 	if (checkBox->checked)
    143 		gfxPtr += 2*(CHECKBOX_W*CHECKBOX_H);
    144 
    145 	if (checkBox->state == CHECKBOX_PRESSED)
    146 		gfxPtr += 1*(CHECKBOX_W*CHECKBOX_H);
    147 
    148 	blitFast(checkBox->x, checkBox->y, gfxPtr, CHECKBOX_W, CHECKBOX_H);
    149 }
    150 
    151 void showCheckBox(uint16_t checkBoxID)
    152 {
    153 	assert(checkBoxID < NUM_CHECKBOXES);
    154 	checkBoxes[checkBoxID].visible = true;
    155 	drawCheckBox(checkBoxID);
    156 }
    157 
    158 void hideCheckBox(uint16_t checkBoxID)
    159 {
    160 	assert(checkBoxID < NUM_CHECKBOXES);
    161 	checkBoxes[checkBoxID].state = 0;
    162 	checkBoxes[checkBoxID].visible = false;
    163 }
    164 
    165 void handleCheckBoxesWhileMouseDown(void)
    166 {
    167 	assert(mouse.lastUsedObjectID >= 0 && mouse.lastUsedObjectID < NUM_CHECKBOXES);
    168 	checkBox_t *checkBox = &checkBoxes[mouse.lastUsedObjectID];
    169 	if (!checkBox->visible)
    170 		return;
    171 
    172 	checkBox->state = CHECKBOX_UNPRESSED;
    173 	if (mouse.x >= checkBox->x && mouse.x < checkBox->x+checkBox->clickAreaWidth &&
    174 	    mouse.y >= checkBox->y && mouse.y < checkBox->y+checkBox->clickAreaHeight)
    175 	{
    176 		checkBox->state = CHECKBOX_PRESSED;
    177 	}
    178 
    179 	if (mouse.lastX != mouse.x || mouse.lastY != mouse.y)
    180 	{
    181 		mouse.lastX = mouse.x;
    182 		mouse.lastY = mouse.y;
    183 
    184 		drawCheckBox(mouse.lastUsedObjectID);
    185 	}
    186 }
    187 
    188 bool testCheckBoxMouseDown(void)
    189 {
    190 	uint16_t start, end;
    191 
    192 	if (ui.sysReqShown)
    193 	{
    194 		// if a system request is open, only test the first checkbox (reserved)
    195 		start = 0;
    196 		end = 1;
    197 	}
    198 	else
    199 	{
    200 		start = 1;
    201 		end = NUM_CHECKBOXES;
    202 	}
    203 
    204 	checkBox_t *checkBox = &checkBoxes[start];
    205 	for (uint16_t i = start; i < end; i++, checkBox++)
    206 	{
    207 		if (!checkBox->visible)
    208 			continue;
    209 
    210 		if (mouse.x >= checkBox->x && mouse.x < checkBox->x+checkBox->clickAreaWidth &&
    211 		    mouse.y >= checkBox->y && mouse.y < checkBox->y+checkBox->clickAreaHeight)
    212 		{
    213 			mouse.lastUsedObjectID = i;
    214 			mouse.lastUsedObjectType = OBJECT_CHECKBOX;
    215 			checkBox->state = CHECKBOX_PRESSED;
    216 			drawCheckBox(mouse.lastUsedObjectID);
    217 			return true;
    218 		}
    219 	}
    220 
    221 	return false;
    222 }
    223 
    224 void testCheckBoxMouseRelease(void)
    225 {
    226 	if (mouse.lastUsedObjectType != OBJECT_CHECKBOX || mouse.lastUsedObjectID == OBJECT_ID_NONE)
    227 		return;
    228 
    229 	assert(mouse.lastUsedObjectID < NUM_CHECKBOXES);
    230 	checkBox_t *checkBox = &checkBoxes[mouse.lastUsedObjectID];
    231 	if (!checkBox->visible)
    232 		return;
    233 
    234 	if (mouse.x >= checkBox->x && mouse.x < checkBox->x+checkBox->clickAreaWidth &&
    235 	    mouse.y >= checkBox->y && mouse.y < checkBox->y+checkBox->clickAreaHeight)
    236 	{
    237 		checkBox->checked ^= 1;
    238 
    239 		checkBox->state = CHECKBOX_UNPRESSED;
    240 		drawCheckBox(mouse.lastUsedObjectID);
    241 
    242 		if (checkBox->callbackFunc != NULL)
    243 			checkBox->callbackFunc();
    244 	}
    245 }