/*#####################################################*/ bool board_init() { core_init(); timer_init(); RtcInit(); /*-----------------------------------------------------*/ /* Set up the Uart 0 like debug interface with RxBuff = 256, TxBuff = 256, 115200b/s*/ Uart[0] = new_(new_uart); Uart[0]->TxPin = Uart0_Tx_PinMux_E16; Uart[0]->RxPin = Uart0_Rx_PinMux_E15; Uart[0]->BaudRate = 115200; Uart[0]->RxBuffSize = 256; Uart[0]->TxBuffSize = 256; Uart[0]->rxFifoTrigLevel = 1; Uart[0]->txFifoTrigLevel = 1; Uart[0]->UartNr = 0; uart_open(Uart[0]); DebugCom = Uart[0]; /*-----------------------------------------------------*/ LED[0] = gpio_assign(1, 21, GPIO_DIR_OUTPUT, false); LED[1] = gpio_assign(1, 22, GPIO_DIR_OUTPUT, false); LED[2] = gpio_assign(1, 23, GPIO_DIR_OUTPUT, false); LED[3] = gpio_assign(1, 24, GPIO_DIR_OUTPUT, false); /*-----------------------------------------------------*/ /* Display board message*/ #if defined(BOARD_MESSAGE) UARTprintf(DebugCom, "Use %s Board.\n\r", BOARD_MESSAGE); #endif /*-----------------------------------------------------*/ /* Set up the Twi 0 to communicate with PMIC and the Onboard serial EEprom memory */ UARTPuts(DebugCom, "Setup TWI 0 with RxBuff = 258, TxBuff = 258....." , -1); TWI[0] = new_(new_twi); TWI[0]->SdaPin = Twi0_Sda_PinMux_C17; TWI[0]->SclPin = Twi0_Scl_PinMux_C16; TWI[0]->BaudRate = 100000; TWI[0]->TwiNr = 0; TWI[0]->Priority = 0; TWI[0]->UseInterrupt = TRUE; TWI[0]->RxBuffSize = 258; TWI[0]->TxBuffSize = 258; twi_open(TWI[0]); UARTPuts(DebugCom, "OK.\n\r" , -1); /*-----------------------------------------------------*/ if(!is_beaglebone()) return false; /*-----------------------------------------------------*/ /* Set up the Twi 1 to communicate with PMIC and the Onboard serial EEprom memory */ UARTPuts(DebugCom, "Setup TWI 1 with RxBuff = 258, TxBuff = 258....." , -1); TWI[1] = new_(new_twi); TWI[1]->SdaPin = Twi1_Sda_PinMux_B16; TWI[1]->SclPin = Twi1_Scl_PinMux_A16; TWI[1]->BaudRate = 100000; TWI[1]->TwiNr = 1; TWI[1]->Priority = 0; TWI[1]->UseInterrupt = TRUE; TWI[1]->RxBuffSize = 258; TWI[1]->TxBuffSize = 258; twi_open(TWI[1]); UARTPuts(DebugCom, "OK.\n\r" , -1); /*-----------------------------------------------------*/ /* Set up the Twi 2 to communicate with PMIC and the Onboard serial EEprom memory */ UARTPuts(DebugCom, "Setup TWI 2 with RxBuff = 258, TxBuff = 258....." , -1); TWI[2] = new_(new_twi); TWI[2]->SdaPin = Twi2_Sda_PinMux_D18; TWI[2]->SclPin = Twi2_Scl_PinMux_D17; TWI[2]->BaudRate = 100000; TWI[2]->TwiNr = 2; TWI[2]->Priority = 0; TWI[2]->UseInterrupt = TRUE; TWI[2]->RxBuffSize = 258; TWI[2]->TxBuffSize = 258; twi_open(TWI[2]); UARTPuts(DebugCom, "OK.\n\r" , -1); /*-----------------------------------------------------*/ beaglebone_detect_extension_boards(); /*-----------------------------------------------------*/ #if USE_ADXL345 ADXL345_1 = new_(new_adxl345); ADXL345_1->MasterSlaveAddr = ADXL345_SLAVE_ADDR_ALT_0; ADXL345_1->TwiStruct = TWI[2]; ADXL345_1->Calibration_X = -14; ADXL345_1->Calibration_Y = 11; ADXL345_1->Calibration_Z = 24; ADXL345_1->FilterBuffSize = 4; if(adxl345_init(ADXL345_1)) { UARTPuts(DebugCom, "ADXL345 detected on TWI2.\n\r" , -1); } else { if(ADXL345_1) free(ADXL345_1); UARTPuts(DebugCom, "ADXL345 not detected.\n\r" , -1); } #endif /*-----------------------------------------------------*/ UARTPuts(DebugCom, "Init MMCSD0 .......", -1); sdCtrl[0].SdNr = 0; mmcsd_init(&sdCtrl[0], 0, 6, LED[0]); UARTPuts(DebugCom, "OK.\n\r", -1); mmcsd_idle(&sdCtrl[0]); /*-----------------------------------------------------*/ eMMC_Res = gpio_assign(1, 20, GPIO_DIR_OUTPUT, false); gpio_out(eMMC_Res, 0); Sysdelay(10); gpio_out(eMMC_Res, 1); UARTPuts(DebugCom, "Init MMCSD1 .......", -1); sdCtrl[1].SdNr = 1; mmcsd_init(&sdCtrl[1], -1, -1, LED[0]); UARTPuts(DebugCom, "OK.\n\r", -1); mmcsd_idle(&sdCtrl[1]); /*-----------------------------------------------------*/ #ifdef usb_1_msc UARTPuts(DebugCom, "Init USBMSC1 Host.......", -1); usb_msc_host_init(1, LED[2]); UARTPuts(DebugCom, "OK.\n\r", -1); usb_msc_host_idle(1); #elif defined( usb_1_mouse ) && !defined( touch ) /*-----------------------------------------------------*/ UARTPuts(DebugCom, "Init USBMOUSE1 Host.......", -1); usb_mouse_host_init(1); UARTPuts(DebugCom, "OK.\n\r", -1); #endif /*-----------------------------------------------------*/ #if defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToMmcSd0) UARTPuts(DebugCom, "Bridge USBMSC0 Dev for MMCSD0 Interface.......", -1); drv_rw_func.DriveStruct = &sdCtrl[0]; drv_rw_func.drv_ioctl_func = mmcsd_ioctl; drv_rw_func.drv_r_func = mmcsd_read; drv_rw_func.drv_w_func = mmcsd_write; usb_msc_dev_init(0); UARTPuts(DebugCom, "OK.\n\r", -1); /*-----------------------------------------------------*/ #elif defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToMmcSd1) UARTPuts(DebugCom, "Bridge USBMSC0 Dev for MMCSD1 Interface.......", -1); drv_rw_func.DriveStruct = &sdCtrl[1]; drv_rw_func.drv_ioctl_func = mmcsd_ioctl; drv_rw_func.drv_r_func = mmcsd_read; drv_rw_func.drv_w_func = mmcsd_write; usb_msc_dev_init(0); UARTPuts(DebugCom, "OK.\n\r", -1); /*-----------------------------------------------------*/ #elif defined( usb_0_dev_msc ) && defined ( BridgeUsbDev0ToUsbHost1) && defined(usb_1_msc) && !defined(usb_1_mouse) extern unsigned int g_ulMSCInstance0Usb1;//UsbMsc driver UARTPuts(DebugCom, "Bridge USBMSC0 Dev for USBMSC1Host Interface.......", -1); drv_rw_func.DriveStruct = (void *)g_ulMSCInstance0Usb1; drv_rw_func.drv_ioctl_func = usb_msc_host_ioctl; drv_rw_func.drv_r_func = usb_msc_host_read; drv_rw_func.drv_w_func = usb_msc_host_write; usb_msc_dev_init(0); UARTPuts(DebugCom, "OK.\n\r", -1); #endif /*-----------------------------------------------------*/ #ifdef lcd TouchScreen = new_(new_touchscreen); TouchScreen->TwiStruct = TWI[1]; #endif bool LCD3_Cape_Detected = false; if(Board1ConfigData) if(!memcmp(Board1ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true; if(Board2ConfigData) if(!memcmp(Board2ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true; if(Board3ConfigData) if(!memcmp(Board3ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true; if(Board4ConfigData) if(!memcmp(Board4ConfigData + 4, "A0BeagleBone LCD3 CAPE", 22)) LCD3_Cape_Detected = true; if(LCD3_Cape_Detected) { /*-----------------------------------------------------*/ HARDBTN[0] = gpio_assign(1, 16, GPIO_DIR_INPUT, false); HARDBTN[1] = gpio_assign(1, 17, GPIO_DIR_INPUT, false); HARDBTN[2] = gpio_assign(3, 19, GPIO_DIR_INPUT, false); HARDBTN[3] = gpio_assign(1, 28, GPIO_DIR_INPUT, false); HARDBTN[4] = gpio_assign(0, 7, GPIO_DIR_INPUT, false); /*-----------------------------------------------------*/ LED[4] = gpio_assign(1, 28, GPIO_DIR_OUTPUT, false); LED[5] = gpio_assign(1, 18, GPIO_DIR_OUTPUT, false); /*-----------------------------------------------------*/ #ifdef lcd ScreenBuff = new_(new_screen); ScreenBuff->raster_timings = &lcd_S035Q01_beaglebone_exp; ScreenBuff->BackLightLevel = 60; ScreenBuff->PmicTwiModuleStruct = TWI[0]; screen_init(ScreenBuff); UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size); TouchScreen->screen_max_x = (double)ScreenBuff->raster_timings->X; TouchScreen->screen_max_y = (double)ScreenBuff->raster_timings->Y; TouchScreen->pDisplay = ScreenBuff; InitTouchScreen(TouchScreen); UARTPuts(DebugCom, "Init calibration of LCD resistive touch screen....." , -1); TouchCalibrate(TouchScreen, ScreenBuff); UARTPuts(DebugCom, "OK.\n\r" , -1); put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren); box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y); #endif } else { #ifdef lcd if(ft5x06_init(TouchScreen, 0, 30)) { UARTPuts(DebugCom, "Capacitive touch screen detected and set up successful.\n\r" , -1); #endif UARTPuts(DebugCom, "I suppose that is BeagleBone Multimedia cape from Chipsee.\n\r" , -1); /*-----------------------------------------------------*/ HARDBTN[0] = gpio_assign(1, 19, GPIO_DIR_INPUT, false); HARDBTN[1] = gpio_assign(1, 16, GPIO_DIR_INPUT, false); HARDBTN[2] = gpio_assign(1, 17, GPIO_DIR_INPUT, false); HARDBTN[3] = gpio_assign(0, 7, GPIO_DIR_INPUT, false); //HARDBTN[4] = gpio_assign(1, 3, GPIO_DIR_INPUT, false); If you use BBB this pin is used by the DAT3 of eMMC onboard memory(if you want to use this pin you will use the eMMC in 1 bit data bus mode). /*-----------------------------------------------------*/ #ifdef lcd ScreenBuff = new_(new_screen); ScreenBuff->raster_timings = &lcd_AT070TN92_beaglebone_exp; ScreenBuff->BackLightPort = 1; ScreenBuff->BackLightPin = 18; screen_init(ScreenBuff); TouchScreen->screen_max_x = ScreenBuff->raster_timings->X; TouchScreen->screen_max_y = ScreenBuff->raster_timings->Y; TouchScreen->pDisplay = ScreenBuff; UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size); put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren); box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y); backlight_on(ScreenBuff); } else { //UARTPuts(DebugCom, "No display detected.\n\r" , -1); //free_touchscreen(TouchScreen); UARTPuts(DebugCom, "I suppose that is BeagleBone Multimedia cape from Chipsee.\n\r" , -1); /*-----------------------------------------------------*/ HARDBTN[0] = gpio_assign(1, 19, GPIO_DIR_INPUT, false); HARDBTN[1] = gpio_assign(1, 16, GPIO_DIR_INPUT, false); HARDBTN[2] = gpio_assign(1, 17, GPIO_DIR_INPUT, false); HARDBTN[3] = gpio_assign(0, 7, GPIO_DIR_INPUT, false); //HARDBTN[4] = gpio_assign(1, 3, GPIO_DIR_INPUT, false); /*-----------------------------------------------------*/ ScreenBuff = new_(new_screen); ScreenBuff->raster_timings = &HDMI_DISPLAY_MODE_STRUCT; ScreenBuff->BackLightPort = 1; ScreenBuff->BackLightPin = 18; screen_init(ScreenBuff); #ifdef touch TouchScreen->screen_max_x = ScreenBuff->raster_timings->X; TouchScreen->screen_max_y = ScreenBuff->raster_timings->Y; TouchScreen->pDisplay = ScreenBuff; InitTouchScreen(TouchScreen); UARTPuts(DebugCom, "Init calibration of LCD resistive touch screen....." , -1); TouchCalibrate(TouchScreen, ScreenBuff); UARTPuts(DebugCom, "OK.\n\r" , -1); #endif UARTprintf(DebugCom, "LCD display initialize successful for %dx%d resolution, %d Bit bus.\n\r" , ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, ScreenBuff->raster_timings->bus_size); put_rectangle(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y, true, controls_color.Scren); box_cache_clean(ScreenBuff, 0, 0, ScreenBuff->raster_timings->X, ScreenBuff->raster_timings->Y); backlight_on(ScreenBuff); } #endif } return true; }
void TouchCalibrate(LcdTouch_t* structure, tDisplay *pDisplay) { timer_interval(&TimerTouchCalibrate, 25); put_rectangle(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y, true, ClrBlack); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); double TouchX = 0, TouchY = 0; double screen_max_x = structure->screen_max_x; double screen_max_y = structure->screen_max_y; structure->screen_max_x = 4095; structure->screen_max_y = 4095; structure->LcdTouch_L_Calibration_Value = 0; structure->LcdTouch_R_Calibration_Value = 4095; structure->LcdTouch_U_Calibration_Value = 0; structure->LcdTouch_D_Calibration_Value = 4095; double LcdTouch_L_Calibration_Value; double LcdTouch_R_Calibration_Value; double LcdTouch_U_Calibration_Value; double LcdTouch_D_Calibration_Value; TouchPaintPoint(pDisplay, (((double)pDisplay->raster_timings->X * (double)12.5) / (double)100), (((double)pDisplay->raster_timings->Y * (double)12.5) / (double)100), ClrRed); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); double Xbuffer[FilterTouchCalibrateSize]; double Ybuffer[FilterTouchCalibrateSize]; unsigned int Cnt = 0; unsigned int Cnt1 = 0; while(1) { if(timer_tick(&TimerTouchCalibrate)) { TouchIdle(structure); if(Cnt < FilterTouchCalibrateSize && structure->TouchResponse.touch_event1 == Cursor_Move) { Xbuffer[Cnt] = structure->TouchResponse.x1; Ybuffer[Cnt] = structure->TouchResponse.y1; Cnt++; } else if(structure->TouchResponse.touch_event1 == Cursor_Up) { for(Cnt1 = 1; Cnt1 < Cnt; Cnt1++) { Xbuffer[0] += Xbuffer[Cnt1]; Ybuffer[0] += Ybuffer[Cnt1]; } Xbuffer[0] /= Cnt; Ybuffer[0] /= Cnt; TouchX = Xbuffer[0]; TouchY = Ybuffer[0]; break; } } } //TouchX = structure->TouchResponse.x1; //TouchY = structure->TouchResponse.y1; LcdTouch_L_Calibration_Value = (double)TouchX; LcdTouch_U_Calibration_Value = (double)TouchY; put_rectangle(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y, true, ClrBlack); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); //delay(500); TouchPaintPoint(pDisplay, (double)pDisplay->raster_timings->X - (((double)pDisplay->raster_timings->X * (double)12.5) / (double)100), (((double)pDisplay->raster_timings->Y * (double)12.5) / (double)100), ClrRed); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); Cnt = 0; Cnt1 = 0; while(1) { if(timer_tick(&TimerTouchCalibrate)) { TouchIdle(structure); if(Cnt < FilterTouchCalibrateSize && structure->TouchResponse.touch_event1 == Cursor_Move) { Xbuffer[Cnt] = structure->TouchResponse.x1; Ybuffer[Cnt] = structure->TouchResponse.y1; Cnt++; } else if(structure->TouchResponse.touch_event1 == Cursor_Up) { for(Cnt1 = 1; Cnt1 < Cnt; Cnt1++) { Xbuffer[0] += Xbuffer[Cnt1]; Ybuffer[0] += Ybuffer[Cnt1]; } Xbuffer[0] /= Cnt; Ybuffer[0] /= Cnt; TouchX = Xbuffer[0]; TouchY = Ybuffer[0]; break; } } } //TouchX = structure->TouchResponse.x1; //TouchY = structure->TouchResponse.y1; LcdTouch_R_Calibration_Value = (double)TouchX; LcdTouch_U_Calibration_Value += (double)TouchY; put_rectangle(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y, true, ClrBlack); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); //delay(500); TouchPaintPoint(pDisplay, (double)pDisplay->raster_timings->X - (((double)pDisplay->raster_timings->X * (double)12.5) / (double)100), (double)pDisplay->raster_timings->Y - (((double)pDisplay->raster_timings->Y * (double)12.5) / (double)100), ClrRed); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); Cnt = 0; Cnt1 = 0; while(1) { if(timer_tick(&TimerTouchCalibrate)) { TouchIdle(structure); if(Cnt < FilterTouchCalibrateSize && structure->TouchResponse.touch_event1 == Cursor_Move) { Xbuffer[Cnt] = structure->TouchResponse.x1; Ybuffer[Cnt] = structure->TouchResponse.y1; Cnt++; } else if(structure->TouchResponse.touch_event1 == Cursor_Up) { for(Cnt1 = 1; Cnt1 < Cnt; Cnt1++) { Xbuffer[0] += Xbuffer[Cnt1]; Ybuffer[0] += Ybuffer[Cnt1]; } Xbuffer[0] /= Cnt; Ybuffer[0] /= Cnt; TouchX = Xbuffer[0]; TouchY = Ybuffer[0]; break; } } } //TouchX = structure->TouchResponse.x1; //TouchY = structure->TouchResponse.y1; LcdTouch_R_Calibration_Value += (double)TouchX; LcdTouch_D_Calibration_Value = (double)TouchY; put_rectangle(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y, true, ClrBlack); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); //delay(500); TouchPaintPoint(pDisplay, (((double)pDisplay->raster_timings->X * (double)12.5) / (double)100), (double)pDisplay->raster_timings->Y - (((double)pDisplay->raster_timings->Y * (double)12.5) / (double)100), ClrRed); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); Cnt = 0; Cnt1 = 0; while(1) { if(timer_tick(&TimerTouchCalibrate)) { TouchIdle(structure); if(Cnt < FilterTouchCalibrateSize && structure->TouchResponse.touch_event1 == Cursor_Move) { Xbuffer[Cnt] = structure->TouchResponse.x1; Ybuffer[Cnt] = structure->TouchResponse.y1; Cnt++; } else if(structure->TouchResponse.touch_event1 == Cursor_Up) { for(Cnt1 = 1; Cnt1 < Cnt; Cnt1++) { Xbuffer[0] += Xbuffer[Cnt1]; Ybuffer[0] += Ybuffer[Cnt1]; } Xbuffer[0] /= Cnt; Ybuffer[0] /= Cnt; TouchX = Xbuffer[0]; TouchY = Ybuffer[0]; break; } } } //TouchX = structure->TouchResponse.x1; //TouchY = structure->TouchResponse.y1; LcdTouch_L_Calibration_Value += (double)TouchX; LcdTouch_D_Calibration_Value += (double)TouchY; put_rectangle(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y, true, ClrBlack); box_cache_clean(pDisplay, 0, 0, pDisplay->raster_timings->X, pDisplay->raster_timings->Y); //CacheDataCleanBuff((unsigned int)&pDisplay->DisplayData + 32, pDisplay->Width * pDisplay->Height * 4); LcdTouch_L_Calibration_Value /= 2; LcdTouch_R_Calibration_Value /= 2; LcdTouch_U_Calibration_Value /= 2; LcdTouch_D_Calibration_Value /= 2; double X_middle = LcdTouch_L_Calibration_Value + ((LcdTouch_R_Calibration_Value - LcdTouch_L_Calibration_Value) / 2); LcdTouch_L_Calibration_Value = X_middle - ((X_middle - LcdTouch_L_Calibration_Value) * 1.33); LcdTouch_R_Calibration_Value = X_middle + ((LcdTouch_R_Calibration_Value - X_middle) * 1.33); double Y_middle = LcdTouch_U_Calibration_Value + ((LcdTouch_D_Calibration_Value - LcdTouch_U_Calibration_Value) / 2); LcdTouch_U_Calibration_Value = Y_middle - ((Y_middle - LcdTouch_U_Calibration_Value) * 1.33); LcdTouch_D_Calibration_Value = Y_middle + ((LcdTouch_D_Calibration_Value - Y_middle) * 1.33); structure->screen_max_x = screen_max_x; structure->screen_max_y = screen_max_y; structure->LcdTouch_L_Calibration_Value = LcdTouch_L_Calibration_Value; structure->LcdTouch_R_Calibration_Value = LcdTouch_R_Calibration_Value; structure->LcdTouch_U_Calibration_Value = LcdTouch_U_Calibration_Value; structure->LcdTouch_D_Calibration_Value = LcdTouch_D_Calibration_Value; }
//####################################################################################### void scrollbar(tScrollBar *settings, tControlCommandData* control_comand) { if(settings == NULL) return; if(control_comand->Comand != Control_Nop) { /* Parse commands */ #ifdef NO_ENUM_ON_SWITCH switch((unsigned char)control_comand->Comand) #else switch((int)control_comand->Comand) #endif { case Control_Entire_Repaint: settings->Internals.NeedEntireRepaint = true; return; case Control_Entire_Refresh: settings->Internals.NeedEntireRefresh = true; return; case Control_Refresh: settings->Internals.NeedEntireRefresh = true; break; case Control_Set_Position_X: settings->Position.X = (signed int)control_comand->Data; return; case Control_Set_Position_Y: settings->Position.Y = (signed int)control_comand->Data; return; case Control_Set_Size_X: settings->Size.X = (signed int)control_comand->Data; return; case Control_Set_Size_Y: settings->Size.X = (signed int)control_comand->Data; return; case Control_Set_Enabled: settings->Enabled = (bool)control_comand->Data; return; case Control_Set_Visible: settings->Visible = (bool)control_comand->Data; return; } } tWindow *ParentWindow = (tWindow*)settings->Internals.ParentWindow; if(settings->Internals.Control.Initiated == false) { if(ParentWindow) { settings->Internals.Position.X = settings->Position.X + ParentWindow->Internals.Position.X + settings->Internals.PositionOffset.X; settings->Internals.Position.Y = settings->Position.Y + ParentWindow->Internals.Position.Y + settings->Internals.PositionOffset.Y; } else { settings->Internals.Position.X = settings->Position.X; settings->Internals.Position.Y = settings->Position.Y; } settings->Internals.Size.X = settings->Size.X; settings->Internals.Size.Y = settings->Size.Y; settings->Internals.OldMinimum = settings->Minimum; settings->Internals.OldMaximum = settings->Maximum; settings->Internals.OldValue = settings->Value; settings->Internals.BtnSettings = new_button(settings->Internals.ParentWindow); tButton* ButtonSettings = settings->Internals.BtnSettings; ButtonSettings->Internals.NoPaintBackGround = false; ButtonSettings->Internals.ContinuouslyPushTimerDisabled = true; ButtonSettings->Enabled = settings->Enabled; ButtonSettings->Color.Scren = settings->Color.Scren; settings->Internals.BtnUpSettings = new_button(settings->Internals.ParentWindow); tButton* BtnUpSettings = settings->Internals.BtnUpSettings; BtnUpSettings->Internals.NoPaintBackGround = true; BtnUpSettings->Enabled = settings->Enabled; BtnUpSettings->Color.Scren = settings->Color.Scren; settings->Internals.BtnDnSettings = new_button(settings->Internals.ParentWindow); tButton* BtnDnSettings = settings->Internals.BtnDnSettings; BtnDnSettings->Internals.NoPaintBackGround = true; BtnDnSettings->Enabled = settings->Enabled; BtnDnSettings->Color.Scren = settings->Color.Scren; if(settings->Size.X < settings->Size.Y) { settings->Internals.BtnSettings->Position.X = 2; settings->Internals.BtnSettings->Position.Y = settings->Size.X; settings->Internals.BtnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y - ParentWindow->Internals.Position.Y; settings->Internals.BtnSettings->Internals.PositionOffset.X = settings->Internals.Position.X - ParentWindow->Internals.Position.X; BtnUpSettings->Position.X = 2; BtnUpSettings->Position.Y = 2; BtnUpSettings->Internals.PositionOffset.X = settings->Internals.Position.X; BtnUpSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y; BtnUpSettings->Size.X = settings->Internals.Size.X - 4; BtnUpSettings->Size.Y = settings->Internals.Size.X - 4; BtnDnSettings->Position.X = 2; BtnDnSettings->Position.Y = settings->Internals.Size.Y - (settings->Internals.Size.X - 2); BtnDnSettings->Internals.PositionOffset.X = settings->Internals.Position.X; BtnDnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y; BtnDnSettings->Size.X = settings->Internals.Size.X - 4; BtnDnSettings->Size.Y = settings->Internals.Size.X - 4; } else { settings->Internals.BtnSettings->Position.X = settings->Size.Y; settings->Internals.BtnSettings->Position.Y = 2; settings->Internals.BtnSettings->Internals.PositionOffset.X = settings->Internals.Position.X - ParentWindow->Internals.Position.X; settings->Internals.BtnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y - ParentWindow->Internals.Position.Y; /* Left */ BtnUpSettings->Position.X = 2; BtnUpSettings->Position.Y = 2; BtnUpSettings->Internals.PositionOffset.X = settings->Internals.Position.X; BtnUpSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y; BtnUpSettings->Size.X = settings->Internals.Size.Y - 4; BtnUpSettings->Size.Y = settings->Internals.Size.Y - 4; /* Right */ BtnDnSettings->Position.X = settings->Internals.Size.X - (settings->Internals.Size.Y - 2); BtnDnSettings->Position.Y = 2; BtnDnSettings->Internals.PositionOffset.X = settings->Internals.Position.X; BtnDnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y; BtnDnSettings->Size.X = settings->Internals.Size.Y - 4; BtnDnSettings->Size.Y = settings->Internals.Size.Y - 4; } //settings->Internals.BtnSettings->Color.Scren = settings->Color.Enabled.Buton.Pull; } if(settings->Value > settings->Maximum) settings->Value = settings->Maximum; if(settings->Value < settings->Minimum) settings->Value = settings->Minimum; /* Verify if position on size has been modified */ if(ParentWindow) { if(((settings->Position.X + ParentWindow->Internals.Position.X + settings->Internals.PositionOffset.X) != settings->Internals.Position.X || (settings->Position.Y + ParentWindow->Internals.Position.Y + settings->Internals.PositionOffset.Y) != settings->Internals.Position.Y || settings->Size.X != settings->Internals.Size.X || settings->Size.Y != settings->Internals.Size.Y || settings->Size.MinBtnSize != settings->Internals.Size.MinBtnSize || settings->Minimum != settings->Internals.OldMinimum|| settings->Maximum != settings->Internals.OldMaximum || settings->Value != settings->Internals.OldValue || settings->Internals.OldStateEnabled != settings->Enabled || ParentWindow->Internals.OldStateEnabled != settings->Internals.ParentWindowStateEnabled) && settings->Visible == true) settings->Internals.NeedEntireRefresh = true; } else { if((settings->Position.X != settings->Internals.Position.X || settings->Position.Y != settings->Internals.Position.Y || settings->Size.X != settings->Internals.Size.X || settings->Size.Y != settings->Internals.Size.Y || settings->Size.MinBtnSize != settings->Internals.Size.MinBtnSize || settings->Minimum != settings->Internals.OldMinimum|| settings->Maximum != settings->Internals.OldMaximum || settings->Internals.OldStateEnabled != settings->Enabled || settings->Value != settings->Internals.OldValue) && settings->Visible == true) settings->Internals.NeedEntireRefresh = true; } signed int X_StartBox = settings->Internals.Position.X; signed int Y_StartBox = settings->Internals.Position.Y; signed int X_LenBox = settings->Internals.Size.X; signed int Y_LenBox = settings->Internals.Size.Y; tDisplay *pDisplay = settings->Internals.pDisplay; /*Clear background of box with actual painted dimensions and positions if they been changed*/ if(settings->Internals.NeedEntireRefresh == true || settings->Internals.OldStateVisible != settings->Visible) { if(!settings->Internals.NoPaintBackGround || !settings->Visible) { settings->Internals.OldStateVisible = settings->Visible; tRectangle back_up_clip = pDisplay->sClipRegion; pDisplay->sClipRegion.sXMin = X_StartBox; pDisplay->sClipRegion.sYMin = Y_StartBox; pDisplay->sClipRegion.sXMax = X_StartBox + X_LenBox; pDisplay->sClipRegion.sYMax = Y_StartBox + Y_LenBox; clip_limit(&pDisplay->sClipRegion, &back_up_clip); put_rectangle(pDisplay, X_StartBox, Y_StartBox, X_LenBox, Y_LenBox, true, settings->Color.Scren); box_cache_clean(pDisplay, X_StartBox, Y_StartBox, X_LenBox, Y_LenBox); pDisplay->sClipRegion = back_up_clip; if(!settings->Visible) return; } settings->Internals.NeedEntireRefresh = true; } /* Verify if is Entire refresh, entire repaint, or state changed */ if((settings->Internals.NeedEntireRefresh == true || settings->Internals.NeedEntireRepaint == true || settings->Internals.Control.Initiated == false) && settings->Visible == true) { /* Copy new locations and dimensions to actual locations and dimensions */ if(ParentWindow) { settings->Internals.Position.X = settings->Position.X + ParentWindow->Internals.Position.X + settings->Internals.PositionOffset.X; settings->Internals.Position.Y = settings->Position.Y + ParentWindow->Internals.Position.Y + settings->Internals.PositionOffset.Y; } else { settings->Internals.Position.X = settings->Position.X; settings->Internals.Position.Y = settings->Position.Y; } settings->Internals.Size.X = settings->Size.X; settings->Internals.Size.Y = settings->Size.Y; settings->Internals.Size.MinBtnSize = settings->Size.MinBtnSize; settings->Internals.OldMinimum = settings->Minimum; settings->Internals.OldMaximum = settings->Maximum; if((settings->Size.X == 0 || settings->Size.Y == 0) && settings->Internals.Control.Initiated == true ) return; if(settings->Value > settings->Maximum) settings->Value = settings->Internals.OldMaximum; if(settings->Value < settings->Minimum) settings->Value = settings->Internals.OldMinimum; X_StartBox = settings->Internals.Position.X; Y_StartBox = settings->Internals.Position.Y; X_LenBox = settings->Internals.Size.X; Y_LenBox = settings->Internals.Size.Y; //CursorState _cursor = control_comand->Cursor; //control_comand->Cursor = Cursor_Up; tRectangle back_up_clip = pDisplay->sClipRegion; pDisplay->sClipRegion.sXMin = X_StartBox; pDisplay->sClipRegion.sYMin = Y_StartBox; pDisplay->sClipRegion.sXMax = X_StartBox + X_LenBox; pDisplay->sClipRegion.sYMax = Y_StartBox + Y_LenBox; clip_limit(&pDisplay->sClipRegion, &back_up_clip); if(settings->Size.X < settings->Size.Y) { settings->Internals.BtnSettings->Position.X = 2; settings->Internals.BtnSettings->Position.Y = settings->Size.X; settings->Internals.BtnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y - ParentWindow->Internals.Position.Y; settings->Internals.BtnSettings->Internals.PositionOffset.X = settings->Internals.Position.X - ParentWindow->Internals.Position.X; } else { settings->Internals.BtnSettings->Position.X = settings->Size.Y; settings->Internals.BtnSettings->Position.Y = 2; settings->Internals.BtnSettings->Internals.PositionOffset.X = settings->Internals.Position.X - ParentWindow->Internals.Position.X; settings->Internals.BtnSettings->Internals.PositionOffset.Y = settings->Internals.Position.Y - ParentWindow->Internals.Position.Y; } paint_scrollbar(settings, pDisplay, X_StartBox, Y_StartBox, X_LenBox, Y_LenBox, control_comand); pDisplay->sClipRegion = back_up_clip; //control_comand->Cursor = _cursor; settings->Internals.ParentWindowStateEnabled = ParentWindow->Internals.OldStateEnabled; settings->Internals.OldStateVisible = settings->Visible; settings->Internals.OldStateEnabled = settings->Enabled; settings->Internals.Control.Initiated = true; settings->Internals.NeedEntireRefresh = false; settings->Internals.NeedEntireRepaint = false; control_comand->WindowRefresh |= true; } if(settings->Internals.OldStateCursor != control_comand->Cursor && settings->Enabled == true && settings->Visible == true) { settings->Internals.OldStateCursor = control_comand->Cursor; } tRectangle back_up_clip = pDisplay->sClipRegion; pDisplay->sClipRegion.sXMin = X_StartBox; pDisplay->sClipRegion.sYMin = Y_StartBox; pDisplay->sClipRegion.sXMax = X_StartBox + X_LenBox; pDisplay->sClipRegion.sYMax = Y_StartBox + Y_LenBox; clip_limit(&pDisplay->sClipRegion, &back_up_clip); if(control_comand->Cursor)paint_scrollbar(settings, pDisplay, X_StartBox, Y_StartBox, X_LenBox, Y_LenBox, control_comand); pDisplay->sClipRegion = back_up_clip; bool inside_window = check_if_inside_box(X_StartBox, Y_StartBox, X_LenBox, Y_LenBox, control_comand->X, control_comand->Y); bool _inside_window = check_if_inside_box(pDisplay->sClipRegion.sXMin, pDisplay->sClipRegion.sYMin, pDisplay->sClipRegion.sXMax - pDisplay->sClipRegion.sXMin, pDisplay->sClipRegion.sYMax - pDisplay->sClipRegion.sYMin, control_comand->X, control_comand->Y); if(!_inside_window) inside_window = false; if(inside_window == true && control_comand->Cursor == Cursor_Down) settings->Internals.CursorDownInsideBox = true; if(settings->Internals.CursorDownInsideBox == true && (control_comand->Cursor == Cursor_Up || control_comand->Cursor == Cursor_NoAction)) settings->Internals.CursorDownInsideBox = false; //control_comand->WindowRefresh |= true; //control_comand->CursorCoordonateUsed |= settings->Internals.CursorDownInsideBox; }
/*#####################################################*/ int main(void) { board_init(); /*******************************************************/ timer_interval(&TimerScanTouch, 10); /*******************************************************/ #ifdef lcd #ifdef USE_BACK_SCREEN BackScreen = new_(new_screen); memcpy((void *)BackScreen, (void *)ScreenBuff, sizeof(new_screen)); #ifdef gcc BackScreen->DisplayData = malloc((BackScreen->raster_timings->X * BackScreen->raster_timings->Y * sizeof(BackScreen->DisplayData[0])) + (BackScreen->raster_timings->palete_len * sizeof(BackScreen->DisplayData[0]))); #else BackScreen->DisplayData = memalign(sizeof(BackScreen->DisplayData[0]) << 3, (BackScreen->raster_timings->X * BackScreen->raster_timings->Y * sizeof(BackScreen->DisplayData[0])) + (BackScreen->raster_timings->palete_len * sizeof(BackScreen->DisplayData[0]))); #endif MainWindow = new_window(NULL, BackScreen); #else MainWindow = new_window(NULL, ScreenBuff); #endif window_new_button(MainWindow, Btn1); window_new_checkbox(MainWindow, CB1); window_new_listbox(MainWindow, ListBox1); window_new_progressbar(MainWindow, PBar1); window_new_scrollbar(MainWindow, ScrollBar1); window_new_textbox(MainWindow, TextBox1); window_new_picturebox(MainWindow, PictureBox1); window_new_window(MainWindow, Window1); MainWindow->WindowMoveLimits.sXMin = 0; MainWindow->WindowMoveLimits.sXMax = ScreenBuff->raster_timings->X; MainWindow->WindowMoveLimits.sYMin = 20; MainWindow->WindowMoveLimits.sYMax = ScreenBuff->raster_timings->Y - 100; #ifdef USE_BACK_SCREEN KbdWindow = new_window(NULL, BackScreen); window_new_keyboard(KbdWindow, Kbd); HeaderWindow = new_window(NULL, BackScreen); #else KbdWindow = new_window(NULL, ScreenBuff); window_new_keyboard(KbdWindow, Kbd); HeaderWindow = new_window(NULL, ScreenBuff); #endif HeaderWindow->WindowMoveLimits.sXMin = 0; HeaderWindow->WindowMoveLimits.sXMax = ScreenBuff->raster_timings->X; HeaderWindow->WindowMoveLimits.sYMin = 0; HeaderWindow->WindowMoveLimits.sYMax = 20; HeaderWindow->HideHeader = true; HeaderWindow->HideHScroll = true; HeaderWindow->HideVScroll = true; KbdWindow->WindowMoveLimits.sXMin = 0; KbdWindow->WindowMoveLimits.sXMax = ScreenBuff->raster_timings->X; KbdWindow->WindowMoveLimits.sYMin = ScreenBuff->raster_timings->Y - 100; KbdWindow->WindowMoveLimits.sYMax = ScreenBuff->raster_timings->Y; KbdWindow->HideHeader = true; KbdWindow->HideHScroll = true; KbdWindow->HideVScroll = true; KbdWindow->Caption.Font = (tFont *)&g_sFontCmss18b; /* Set location and size of virtual keyboard */ Kbd->Position.X = 0; Kbd->Position.Y = 0; Kbd->Size.X = ScreenBuff->raster_timings->X - 6; Kbd->Size.Y = 98; Window1->Internals.FullScreen = false; Window1->Position.X = 400; Window1->Position.Y = 400; Window1->Size.X = 400; Window1->Size.Y = 300; window_new_button(Window1, Btn2); window_new_window(Window1, Window2); Window2->Internals.FullScreen = false; Window2->Position.X = 10; Window2->Position.Y = 50; Window2->Size.X = 300; Window2->Size.Y = 200; window_new_button(Window2, Btn3); window_new_tab_group(Window2, TabGroup1); //TabGroup1->Internals.FullScreen = false; TabGroup1->Position.X = 10; TabGroup1->Position.Y = 50; TabGroup1->Size.X = 200; TabGroup1->Size.Y = 100; tab_group_new_tab(TabGroup1, "Tab1"); tab_group_new_tab(TabGroup1, "Tab2"); tab_group_new_tab(TabGroup1, "Tab3"); tab_group_new_tab(TabGroup1, "Tab4"); tab_group_new_tab(TabGroup1, "Tab5"); tab_group_new_tab(TabGroup1, "Tab6"); tab_group_new_tab(TabGroup1, "Tab7"); tab_group_new_tab(TabGroup1, "Tab8"); tab_group_new_button(TabGroup1, Btn4, 0); tab_group_new_button(TabGroup1, Btn5, 1); tab_group_new_button(TabGroup1, Btn6, 2); tab_group_new_button(TabGroup1, Btn7, 3); tab_group_new_button(TabGroup1, Btn8, 4); tab_group_new_button(TabGroup1, Btn9, 5); tab_group_new_button(TabGroup1, Btn10, 6); tab_group_new_button(TabGroup1, Btn11, 7); Btn5->Position.X = 30; /* Enable clear background on refresh */ PictureBox1->PaintBackground = true; /* Set callback's for picture box*/ PictureBox1->Events.OnMove.CallBack = picture_box_callback; PictureBox1->Events.OnDown.CallBack = picture_box_callback_on_down; /* Refresh is used to refresh the picture box when the window or picture box position , size is modified */ PictureBox1->Events.Refresh.CallBack = picture_box_refresh_callback; /* Set callback's for Btn1*/ Btn1->Events.OnUp.CallbackData = PictureBox1; Btn1->Events.OnUp.CallBack = picture_box_clear_callback; /* Clear the picture box */ picture_box_clear_callback(PictureBox1); char TmpStr[30]; unsigned int CntItems = 0; for(CntItems = 0; CntItems < 100; CntItems++) { sprintf(TmpStr, "%d", CntItems); listbox_item_add(ListBox1, TmpStr); } listbox_item_insert(ListBox1, "Inserted Item", 1); listbox_item_remove(ListBox1, 3); string(TextBoxString, "Multiplatform SDK to create standalone applications\n\r1\n\r2\n\r3\n\r4\n\r5\n\r6\n\r7\n\r8\n\r9\n\r10\n\r11\n\r12\n\r13\n\r14\n\r15\n\r16\n\r17\n\r18"); TextBox1->text(TextBox1, TextBoxString); TextBox1->text(TextBox1, TextBox1->to_uper(TextBox1)); tControlCommandData control_comand; control_comand.Comand = Control_Nop; control_comand.CursorCoordonateUsed = true; #endif /*******************************************************/ /*arg's for console*/ char *argv[2]; argv[0] = NULL; /*******************************************************/ bool old_connected = false; #ifdef BridgeUsbDev0ToMmcSd0 if(sdCtrl[0].connected == false) usb_msc_dev_media_change_state(0, false); #elif defined(BridgeUsbDev0ToMmcSd1) if(sdCtrl[1].connected == false) usb_msc_dev_media_change_state(0, false); #endif /*******************************************************/ unsigned int PwrLoadCount = 0; /*******************************************************/ while(1) { if(timer_tick(&TimerScanTouch)) { if(PwrLoadCount) PwrLoadCount--; //UARTprintf(DebugCom, "X= %d, Y= %d, But= %d, Whel= %d.\n\r" , MouseXPosition, MouseYPosition, g_ulButtons, MouseWheel); #ifdef lcd #ifdef USE_BACK_SCREEN if(BackScreen) #else if(ScreenBuff) #endif { memset(&control_comand, 0, sizeof(tControlCommandData)); #ifdef touch if(TouchScreen->TouchScreen_Type == TouchScreen_Type_Int) TouchIdle(TouchScreen); else if(TouchScreen->TouchScreen_Type == TouchScreen_Type_FT5x06) ft5x06_TouchIdle(TouchScreen); control_comand.X = TouchScreen->TouchResponse.x1; control_comand.Y = TouchScreen->TouchResponse.y1; control_comand.Cursor = (CursorState)TouchScreen->TouchResponse.touch_event1; #endif #ifdef usb_1_mouse usb_mouse_host_idle(1, &control_comand); #elif defined(usb_1_msc) usb_msc_host_idle(1); #endif HeaderWindow->idle(HeaderWindow, &control_comand); MainWindow->idle(MainWindow, &control_comand); KbdWindow->idle(KbdWindow, &control_comand); #ifdef USE_BACK_SCREEN if(control_comand.WindowRefresh) ScreenReRefreshCnt = 2; if(ScreenReRefreshCnt) { ScreenReRefreshCnt--; screen_copy(ScreenBuff, BackScreen, true, control_comand.X, control_comand.Y, 0x00000000); //put_rectangle(ScreenBuff, control_comand.X, control_comand.Y, 2, 2, true, 0x00000000); //box_cache_clean(ScreenBuff, control_comand.X, control_comand.Y, 2, 2); } #else put_rectangle(ScreenBuff, control_comand.X, control_comand.Y, 2, 2, true, 0x00000000); box_cache_clean(ScreenBuff, control_comand.X, control_comand.Y, 2, 2); #endif } else PwrLoadCount++; #endif #ifdef BridgeUsbDev0ToMmcSd0 mmcsd_idle(&sdCtrl[0]); if(old_connected == false && sdCtrl[0].connected == true) { old_connected = true; usb_msc_dev_media_change_state(0, true); } else if(old_connected == true && sdCtrl[0].connected == false) { old_connected = false; usb_msc_dev_media_change_state(0, false); } #elif defined(BridgeUsbDev0ToMmcSd1) mmcsd_idle(&sdCtrl[1]); if(old_connected == false && sdCtrl[1].connected == true) { old_connected = true; usb_msc_dev_media_change_state(1, true); } else if(old_connected == true && sdCtrl[1].connected == false) { old_connected = false; usb_msc_dev_media_change_state(1, false); } #endif } signed int R_Chr = UARTGetcNoBlocking(DebugCom); argv[1] = (char *)R_Chr; console(2, argv); } }
//####################################################################################### static void paint_scrollbar(tScrollBar* settings, tDisplay *pDisplay, signed int x_start, signed int y_start, signed int x_len, signed int y_len, tControlCommandData* control_comand) { unsigned int color = 0; tWindow *ParentWindow = (tWindow*)settings->Internals.ParentWindow; tRectangle back_up_clip = pDisplay->sClipRegion; pDisplay->sClipRegion.sXMin = x_start; pDisplay->sClipRegion.sYMin = y_start; pDisplay->sClipRegion.sXMax = x_start + x_len; pDisplay->sClipRegion.sYMax = y_start + y_len; clip_limit(&pDisplay->sClipRegion, &back_up_clip); if(settings->Internals.NeedEntireRefresh == true || settings->Internals.NeedEntireRepaint == true || settings->Internals.Control.Initiated == false) { if(settings->Enabled) color = controls_color.Control_Color_Enabled_Border_Push; else color = settings->Color.Disabled.Border; put_rectangle(pDisplay, x_start, y_start, x_len, y_len, false, controlls_change_color(color, -2)); put_rectangle(pDisplay, x_start + 1, y_start + 1, x_len - 2, y_len - 2, true, color); control_comand->WindowRefresh |= true; } signed int ValueBetweenMinAndMax = (settings->Internals.OldMaximum - settings->Internals.OldMinimum); tButton* ButtonSettings = settings->Internals.BtnSettings; tButton* BtnUpSettings = settings->Internals.BtnUpSettings; tButton* BtnDnSettings = settings->Internals.BtnDnSettings; if(settings->Size.X < settings->Size.Y) { BtnUpSettings->Position.X = 2; BtnUpSettings->Position.Y = 2; BtnUpSettings->Internals.PositionOffset.X = x_start - ParentWindow->Internals.Position.X; BtnUpSettings->Internals.PositionOffset.Y = y_start - ParentWindow->Internals.Position.Y; BtnUpSettings->Size.X = settings->Internals.Size.X - 4; BtnUpSettings->Size.Y = settings->Internals.Size.X - 4; BtnDnSettings->Position.X = 2; BtnDnSettings->Position.Y = settings->Internals.Size.Y - (settings->Internals.Size.X - 2); BtnDnSettings->Internals.PositionOffset.X = x_start - ParentWindow->Internals.Position.X; BtnDnSettings->Internals.PositionOffset.Y = y_start - ParentWindow->Internals.Position.Y; BtnDnSettings->Size.X = settings->Internals.Size.X - 4; BtnDnSettings->Size.Y = settings->Internals.Size.X - 4; } else { /* Left */ BtnUpSettings->Position.X = 2; BtnUpSettings->Position.Y = 2; BtnUpSettings->Internals.PositionOffset.X = x_start - ParentWindow->Internals.Position.X; BtnUpSettings->Internals.PositionOffset.Y = y_start - ParentWindow->Internals.Position.Y; BtnUpSettings->Size.X = settings->Internals.Size.Y - 4; BtnUpSettings->Size.Y = settings->Internals.Size.Y - 4; /* Right */ BtnDnSettings->Position.X = settings->Internals.Size.X - (settings->Internals.Size.Y - 2); BtnDnSettings->Position.Y = 2; BtnDnSettings->Internals.PositionOffset.X = x_start - ParentWindow->Internals.Position.X; BtnDnSettings->Internals.PositionOffset.Y = y_start - ParentWindow->Internals.Position.Y; BtnDnSettings->Size.X = settings->Internals.Size.Y - 4; BtnDnSettings->Size.Y = settings->Internals.Size.Y - 4; } if(control_comand->Cursor != Cursor_NoAction || settings->Internals.NeedEntireRefresh == true || settings->Internals.NeedEntireRepaint == true) { BtnUpSettings->Internals.NeedEntireRefresh = settings->Internals.NeedEntireRefresh; BtnUpSettings->Enabled = settings->Enabled; CursorState back = control_comand->Cursor; if(BtnUpSettings->Internals.NeedEntireRefresh) control_comand->Cursor = Cursor_Up; button((void*)BtnUpSettings, control_comand); //control_comand->Cursor = back; BtnDnSettings->Internals.NeedEntireRefresh = settings->Internals.NeedEntireRefresh; BtnDnSettings->Enabled = settings->Enabled; //CursorState back = control_comand->Cursor; //if(BtnDnSettings->Internals.NeedEntireRefresh) control_comand->Cursor = Cursor_Up; button((void*)BtnDnSettings, control_comand); control_comand->Cursor = back; } signed int BtnSize = 0; if(settings->Size.X < settings->Size.Y) BtnSize = settings->Size.Y - ((settings->Size.X - 2)<<1) - 4 - ValueBetweenMinAndMax; else BtnSize = settings->Size.X - ((settings->Size.Y - 2)<<1) - 4 - ValueBetweenMinAndMax; if(BtnSize < settings->Size.MinBtnSize) BtnSize = settings->Size.MinBtnSize; bool scroll_internal_modified = false; if(BtnUpSettings->Events.CursorDown || BtnUpSettings->Events.CursorMove || settings->Internals.OldValue != settings->Value) { BtnUpSettings->Events.CursorDown = false; BtnUpSettings->Events.CursorMove = false; if(settings->Value > settings->Minimum) { if(settings->Internals.OldValue == settings->Value) { settings->Value--; scroll_internal_modified = true; //control_comand->WindowRefresh |= true; //settings->Internals.NeedEntireRefresh = true; } else { settings->Internals.NeedEntireRefresh = false; //control_comand->CursorCoordonateUsed = true; //control_comand->WindowRefresh |= true; } } } if(BtnDnSettings->Events.CursorDown || BtnDnSettings->Events.CursorMove || settings->Internals.OldValue != settings->Value) { BtnDnSettings->Events.CursorDown = false; BtnDnSettings->Events.CursorMove = false; if(settings->Value < settings->Maximum) { if(settings->Internals.OldValue == settings->Value) { settings->Value++; scroll_internal_modified = true; //control_comand->WindowRefresh |= true; //settings->Internals.NeedEntireRefresh = true; } else { settings->Internals.NeedEntireRefresh = false; //control_comand->CursorCoordonateUsed = true; //control_comand->WindowRefresh |= true; } } } bool CursorBtnSelfModified = false; if(ValueBetweenMinAndMax < 1) { ValueBetweenMinAndMax = 1; if(settings->Size.X < settings->Size.Y) { ButtonSettings->Position.X = 2; ButtonSettings->Position.Y = settings->Size.X; //ButtonSettings->Position.X = settings->Position.X + 2; //ButtonSettings->Position.Y = settings->Position.Y + 2 + (settings->Size.X - 2); ButtonSettings->Size.X = settings->Size.X - 4; ButtonSettings->Size.Y = settings->Size.Y - 4 - ((settings->Size.X - 2)<<1); } else { ButtonSettings->Position.X = settings->Size.Y; ButtonSettings->Position.Y = 2; //ButtonSettings->Position.X = settings->Position.X + 2 + (settings->Size.Y - 2); //ButtonSettings->Position.Y = settings->Position.Y + 2; ButtonSettings->Size.X = settings->Size.X - 4 - ((settings->Size.Y - 2)<<1); ButtonSettings->Size.Y = settings->Size.Y - 4; } } else { if(control_comand->CursorCoordonateUsed == false&& settings->Enabled == true && settings->Visible == true) { if(settings->Size.X < settings->Size.Y) { ButtonSettings->Size.Y = BtnSize; ////signed int Steps = settings->Size.Y - 4 - BtnSize; //ButtonSettings->Position.X = settings->Position.X + 2; ////ButtonSettings->Position.Y = settings->Position.Y + 2; ButtonSettings->Size.X = settings->Size.X - 4; //ButtonSettings->Size.Y = settings->Size.Y - 4; if(ButtonSettings->Events.CursorDown == true) { settings->Internals.CoordonateOfTouchDown = control_comand->Y; settings->Internals.CoordonateOfButtonDown = ButtonSettings->Internals.Position.Y - settings->Internals.PositionOffset.Y; ButtonSettings->Events.CursorDown = false; } else if(control_comand->Cursor == Cursor_Move && settings->Internals.CursorDownInsideBox == true && ButtonSettings->Internals.CursorDownInsideBox == true) { ButtonSettings->Position.Y = settings->Internals.CoordonateOfButtonDown + ((control_comand->Y - (ParentWindow->Internals.Position.Y)) - settings->Internals.CoordonateOfTouchDown); if(ButtonSettings->Position.Y < settings->Position.Y + (settings->Size.X - 2) + 2) ButtonSettings->Position.Y = settings->Position.Y + 2 + (settings->Size.X - 2); else if((ButtonSettings->Position.Y + ButtonSettings->Size.Y) > (settings->Position.Y + settings->Size.Y) - 2 - (settings->Size.X - 2)) ButtonSettings->Position.Y = ((settings->Position.Y + settings->Size.Y) - 2) - ButtonSettings->Size.Y - (settings->Size.X - 2); settings->Value = percentage_to(settings->Minimum, settings->Maximum, settings->Size.Y - 4 - BtnSize - ((settings->Size.X - 2)<<1), (ButtonSettings->Position.Y - (settings->Position.Y + 2) - (settings->Size.X - 2))); CursorBtnSelfModified = true; } } else { ButtonSettings->Size.X = BtnSize; ////signed int Steps = settings->Size.X - 4 - BtnSize; //ButtonSettings->Position.Y = settings->Position.Y + 2; ////ButtonSettings->Position.X = settings->Position.X + 2; ButtonSettings->Size.Y = settings->Size.Y - 4; //ButtonSettings->Size.X = settings->Size.X - 4; if(ButtonSettings->Events.CursorDown == true) { settings->Internals.CoordonateOfTouchDown = control_comand->X; settings->Internals.CoordonateOfButtonDown = ButtonSettings->Internals.Position.X; ButtonSettings->Events.CursorDown = false; } else if(control_comand->Cursor == Cursor_Move && settings->Internals.CursorDownInsideBox == true && ButtonSettings->Internals.CursorDownInsideBox == true) { ButtonSettings->Position.X = settings->Internals.CoordonateOfButtonDown + ((control_comand->X - (ParentWindow->Internals.Position.X)) - settings->Internals.CoordonateOfTouchDown); if(ButtonSettings->Position.X < settings->Position.X + (settings->Size.Y - 2) + 2) ButtonSettings->Position.X = settings->Position.X + 2 + (settings->Size.Y - 2); else if((ButtonSettings->Position.X + ButtonSettings->Size.X) > (settings->Position.X + settings->Size.X) - 2 - (settings->Size.Y - 2)) ButtonSettings->Position.X = ((settings->Position.X + settings->Size.X) - 2) - ButtonSettings->Size.X - (settings->Size.Y - 2); settings->Value = percentage_to(settings->Minimum, settings->Maximum, settings->Size.X - 4 - BtnSize - ((settings->Size.Y - 2)<<1), (ButtonSettings->Position.X - (settings->Position.X + 2) - (settings->Size.Y - 2))); CursorBtnSelfModified = true; } } } } bool ValueIsChangedExternaly = false; if(settings->Internals.OldValue != settings->Value) { settings->Internals.OldValue = settings->Value; //settings->Events.ValueChanged = true; ValueIsChangedExternaly = true; settings->Events.ValueChanged = true; if(settings->Events.OnValueChanged.CallBack) { settings->Events.OnValueChanged.CallbackReturnData = settings->Events.OnValueChanged.CallBack(settings->Events.OnValueChanged.CallbackData); } } if(settings->Enabled) ButtonSettings->Color.Scren = settings->Color.Enabled.Buton.Pull; else ButtonSettings->Color.Scren = settings->Color.Disabled.Buton; if(BtnSize > settings->Size.MinBtnSize) { if(settings->Size.X < settings->Size.Y) ButtonSettings->Position.Y = (settings->Value + 2 + (settings->Size.X - 2)) - settings->Minimum; else ButtonSettings->Position.X = (settings->Value + 2 + (settings->Size.Y - 2)) - settings->Minimum; } else { if(settings->Size.X < settings->Size.Y) ButtonSettings->Position.Y = 2 + (settings->Size.X - 2) + to_percentage(settings->Minimum, settings->Maximum, settings->Size.Y - ((settings->Size.X - 2)<<1) - 4 - settings->Size.MinBtnSize, settings->Value); else ButtonSettings->Position.X = 2 + (settings->Size.Y - 2) + to_percentage(settings->Minimum, settings->Maximum, settings->Size.X - ((settings->Size.Y - 2)<<1) - 4 - settings->Size.MinBtnSize, settings->Value); } if(settings->Internals.NeedEntireRefresh == true || settings->Internals.NeedEntireRepaint == true) { ButtonSettings->Internals.NoPaintBackGround = true; ButtonSettings->Internals.NeedEntireRefresh = true; ButtonSettings->Enabled = settings->Enabled; CursorState back = control_comand->Cursor; control_comand->Cursor = Cursor_Up; button((void*)ButtonSettings, control_comand); control_comand->Cursor = back; ButtonSettings->Internals.NoPaintBackGround = false; } else if(ButtonSettings->Position.X + ParentWindow->Internals.Position.X + ButtonSettings->Internals.PositionOffset.X != ButtonSettings->Internals.Position.X || ButtonSettings->Position.Y + ParentWindow->Internals.Position.Y + ButtonSettings->Internals.PositionOffset.Y != ButtonSettings->Internals.Position.Y) { ButtonSettings->Internals.NeedEntireRefresh = true; CursorState back = control_comand->Cursor; if(scroll_internal_modified) control_comand->Cursor = Cursor_Up; button((void*)ButtonSettings, control_comand); control_comand->Cursor = back; ButtonSettings->Internals.NoPaintBackGround = false; } else { CursorState back = control_comand->Cursor; if(CursorBtnSelfModified) control_comand->Cursor = Cursor_Down; if(ValueIsChangedExternaly) { ButtonSettings->Internals.NeedEntireRefresh = true; control_comand->Cursor = Cursor_Up; } button((void*)ButtonSettings, control_comand); control_comand->Cursor = back; } pDisplay->sClipRegion.sXMin = x_start; pDisplay->sClipRegion.sYMin = y_start; pDisplay->sClipRegion.sXMax = x_start + x_len; pDisplay->sClipRegion.sYMax = y_start + y_len; clip_limit(&pDisplay->sClipRegion, &back_up_clip); box_cache_clean(pDisplay, x_start, y_start, x_len, y_len); pDisplay->sClipRegion = back_up_clip; settings->Internals.NeedEntireRefresh = false; }