void Control::mouseEvent(KeyState state, Keys key, int x, int y) { if(_keys[key] == state) return; setMouseX(x, key); setMouseY(y, key); _keys[key] = state; state = state == STATE_NO_PRESSED ? STATE_UP : STATE_DOWN; if(key >= MOUSE_LEFT && key <= MOUSE_BUTTON_5) { switch(state) { case STATE_UP: for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++) reinterpret_cast<Hud*>(*it)->end(key); break; case STATE_DOWN: for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++) reinterpret_cast<Hud*>(*it)->start(getMouseX(key), getMouseY(key), key); break; default: break; } } for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) { Event e = *it; if(e.key == key && (state == e.state || e.state == STATE_ANY)) callCallBack(e.instance, e.callback, state, key, getMouseX(e.key), getMouseY(e.key)); } }
void end_lesson(int min,int sec,int eff,int err, int speed) { int change=0,y,x; show_summary(min, sec, eff, err, speed); draw_3dbox(260,220,320,240,15); settextstyle(0,0,1); color_text(280,227,"Ok",3); showMouse(); while(1) { while(1) { x=getMouseX(); /* get the mouse position*/ y=getMouseY(); if(x>=260&&x<=320&&y>=220&&y<=240 && !change) { change = 1; settextstyle(0,0,1); hideMouse(); draw_3dbox(260,220,320,240,6); /* change the color of the box*/ /* change the text color*/ color_text(280,227,"Ok",15); /*cursor on yes*/ showMouse(); } if((x<=260||x>=320||y<=220||y>=240)&& change) { change = 0; hideMouse(); draw_3dbox(260,220,320,240,15); /* when mouse moves away change the color to normal one*/ color_text(280,227,"Ok",3); showMouse(); /*cursor on yes/no*/ } if(mouseClicked()) { x=getMouseX(); /*get the position where mouse is clicked*/ y=getMouseY(); while(1) if(mouseReleased()) /* get the position*/ break; /* where mouse is clicked*/ break; /* and released */ } }/*end of while 2 which changes color of button*/ /*check the position of mouse clicked*/ if(x>=260&&x<=320&&y>=220&&y<=240) // back { hideMouse(); up_down_button(260,220,320,240,280,227,19,15,15,6); break; } }/*end of while 1*/ }
void draw(void *userData) { DemoData *d = (DemoData *) userData; char buf[256]; int x, y; /* Exit on key press */ if (getKey()) exitPolo(); /* Clear screen with right mouse button */ if (isMouseButtonPressed(1)) clearScreen(); /* Paint with left mouse button */ if (isMouseButtonPressed(0)) { if ((getMouseX() < 128) && (getMouseY() < 128)) setDrawTint(getColorFromHSVA(getMouseX() / 128, getMouseY() / 128, 1, BRUSH_ALPHA)); else drawImage(getMouseX() - getImageWidth(d->brush) / 2, getMouseY() - getImageHeight(d->brush) / 2, d->brush); } /* Draw left bar */ setPenColor(POLO_STEEL); setFillGradient(POLO_SILVER, POLO_TUNGSTEN); drawRect(-1, -1, TOOLBAR_WIDTH, getScreenHeight() + 2); /* Draw frames per second and time display */ setPenColor(POLO_BLACK); sprintf(buf, "FPS: %.3f", d->frame / (getTime() + 0.001)); drawText((TOOLBAR_WIDTH - getTextDrawWidth(buf)) / 2, getScreenHeight() - getTextDrawHeight(buf) - 10, buf); /* Increment frame number */ d->frame++; /* Paint color palette */ for (x = 0; x < 128; x++) for (y = 0; y < 128; y++) { setPenColor(getColorFromHSV(x / 128.0, y / 128.0, 1.0)); drawPoint(x, y); } }
// *************************************************************** void CToolSelectRotate::beginAction(CInstance &instance) { //H_AUTO(R2_CToolSelectRotate_beginAction) _MouseStartX = getMouseX(); _StartAngle = (float) instance.getObjectTable()->toNumber("Angle"); setRotateInProgress(true, instance); }
void OBEngine::onTick() { if ( m_uiMode == UI_PLAYBACK ) { // do playback and nothing else if ( m_playbackTimer.isOver() ) { m_playbackStepIdx+=2; int stopIdx = m_ship.getStopPoint(); if ( m_playbackStepIdx > stopIdx ) { m_playbackStepIdx = stopIdx; } m_playbackTimer.start(PLAYBACK_STEP_TIME); } } int mx = getMouseX(); int my = getMouseY(); if ( m_uiMode == UI_ADJUSTINGPOINT ) { if ( m_hoverAccelPoint == NULL ) return; m_ship.adjustAccelerationPoint(m_hoverAccelPoint, mx, my, m_hoverAccelPoint->m_mag); m_ship.calcPoints(); } else if ( m_uiMode == UI_ADJUSTINGMARS) { // place mars's startling position. // First get the angle from the center FGDoubleVector mouse; mouse.setXY(mx-m_screenW/2, my-m_screenH/2); double angle = mouse.getAngle(); // note mars's position and velocity at that angle FGDoubleVector newPos; FGDoubleVector newVel; m_mars.m_orbit.getPos(angle, newPos); m_mars.m_orbit.getVel(angle, newVel); // set it m_marsPath.m_startPos.set(newPos); m_marsPath.m_startVel.set(newVel); // recalc m_marsPath.calcPoints(); } else { if ( m_uiMode == UI_ADDINGPOINT ) { m_hoverPathPointIdx = m_ship.getNearestPointIdx(mx, my); } else { m_hoverAccelPoint = m_ship.getNearestAccelPoint(mx, my); } } }
bool Widget::isWithin(void) const { float x = getMouseX(); float y = getMouseY(); return(x > 0 && x < getWidth()) && (y > 0 && y < getHeight()); }
// *************************************************************** void CToolSelectRotate::updateAction(CInstance &instance) { //H_AUTO(R2_CToolSelectRotate_updateAction) CEntityCL *entity = instance.getEntity(); if (entity) { setMouseCursor("r2ed_tool_rotating.tga"); setEntityAngle(*entity, instance, (float) ((getMouseX() - _MouseStartX) * NLMISC::Pi / 180) + _StartAngle); } }
void Control::keyboardEvent(KeyState state, Keys key) { if(_keys[key] == state) return; _keys[key] = state; state = state == STATE_NO_PRESSED ? STATE_UP : STATE_DOWN; for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) { Event e = *it; if(e.key == key && (state == e.state || e.state == STATE_ANY)) callCallBack(e.instance, e.callback, state, key, getMouseX(e.key), getMouseY(e.key)); } }
void Control::idle() { if(getCurrentTime() < _lastIdleTime + 50) return; _lastIdleTime = getCurrentTime(); for(std::vector<Event>::const_iterator it = _events.begin(); it != _events.end(); it++) { Event e = *it; if(e.key == NO_KEY) continue; if(((_keys[e.key] == STATE_NO_PRESSED || _keys[e.key] == STATE_PRESSED) && e.state == _keys[e.key]) || e.state == STATE_ANY) callCallBack(e.instance, e.callback, _keys[e.key], e.key, getMouseX(e.key), getMouseY(e.key)); } }
void ofxSimpleGuiSliderBase<Type>::updateSlider() { if(!enabled) return; if(pct > width) { pct = width; } else { pct = getMouseX() - x; float temp = ofMap(pct, 0.0, width, min, max, true); targetValue = (Type)temp; oldValue = *value; // save oldValue (so the draw doesn't update target but uses it) } }
void ofxSimpleGuiColorPicker::updateSlider() { if(!enabled) return; int i= (getMouseY() - y) / config->sliderTextHeight; if(i<0 || i>=4) return; if(pct[i] > width) { pct[i] = width; } else { pct[i] = getMouseX() - x; setValue(ofMap(pct[i], 0.0, (float)width, 0, max), i); } }
void Control::mouseMoveEvent(int x, int y, int pointer) { if(!_multiPointer) pointer = MOUSE_LEFT; setMouseX(x, pointer); setMouseY(y, pointer); if(isKeyPressed(static_cast<Control::Keys>(pointer))) { for(std::vector<Hud*>::const_iterator it = _huds.begin(); it != _huds.end(); it++) reinterpret_cast<Hud*>(*it)->update(getMouseX(pointer), getMouseY(pointer), pointer); } for(std::vector<Event>::iterator it = _events.begin(); it != _events.end(); it++) { Event e = *it; if(e.state == STATE_MOUSE_MOVE && isKeyPressed(e.key)) callCallBack(e.instance, e.callback, STATE_MOUSE_MOVE, e.key, x, y); } }
static void processDrawCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) { tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); s32 mx = getMouseX() - x; s32 my = getMouseY() - y; s32 brushSize = sprite->brushSize*Size; s32 offset = (brushSize - Size) / 2; mx -= offset; my -= offset; mx -= mx % Size; my -= my % Size; if(mx < 0) mx = 0; if(my < 0) my = 0; if(mx+brushSize >= CANVAS_SIZE) mx = CANVAS_SIZE - brushSize; if(my+brushSize >= CANVAS_SIZE) my = CANVAS_SIZE - brushSize; drawCursorBorder(sprite, x + mx, y + my, brushSize, brushSize); bool left = checkMouseDown(&rect, tic_mouse_left); bool right = checkMouseDown(&rect, tic_mouse_right); if(left || right) { sx += mx / Size; sy += my / Size; u8 color = left ? sprite->color : sprite->color2; s32 pixels = sprite->brushSize; for(s32 j = 0; j < pixels; j++) for(s32 i = 0; i < pixels; i++) setSheetPixel(sprite, sx+i, sy+j, color); history_add(sprite->history); } } }
void Viewport::mouseMoved(gcn::MouseEvent &event) { // Check if we are on the map if (!mMap || !player_node) return; const int x = (event.getX() + (int) mPixelViewX); const int y = (event.getY() + (int) mPixelViewY); mHoverBeing = actorSpriteManager->findBeingByPixel(x, y); mBeingPopup->show(getMouseX(), getMouseY(), mHoverBeing); mHoverItem = actorSpriteManager->findItem(x / mMap->getTileWidth(), y / mMap->getTileHeight()); updateCursorType(); }
static void processSelectCanvasMouse(Sprite* sprite, s32 x, s32 y) { tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx -= mx % Size; my -= my % Size; drawCursorBorder(sprite, x + mx, y + my, Size, Size); if(checkMouseDown(&rect, tic_mouse_left)) { if(sprite->select.drag) { s32 x = mx / Size; s32 y = my / Size; s32 rl = MIN(x, sprite->select.start.x); s32 rt = MIN(y, sprite->select.start.y); s32 rr = MAX(x, sprite->select.start.x); s32 rb = MAX(y, sprite->select.start.y); sprite->select.rect = (tic_rect){rl, rt, rr - rl + 1, rb - rt + 1}; } else { sprite->select.drag = true; sprite->select.start = (tic_point){mx / Size, my / Size}; sprite->select.rect = (tic_rect){sprite->select.start.x, sprite->select.start.y, 1, 1}; } } else if(sprite->select.drag) { copySelection(sprite); sprite->select.drag = false; } } }
void moveSelectedUnits() { float coords[2] = { getMouseX(), getMouseY() }; for (int a = 0; a < unitSpawnIndex; a++) { if (u_Current.getSelected() && u_Current.getTarget() == NOTHING) { PosDim unit = u_Current.getPosDim(); if (coords[0] > xSpace(100) - (unit.w / 2)) { coords[0] = xSpace(100) - (unit.h / 2); } else if (coords[0] < xSpace(0) + (unit.w / 2)) { coords[0] = xSpace(0) + (unit.w / 2); } if (coords[1] > ySpace(100) - (unit.h / 2)) { coords[1] = ySpace(100) - (unit.h / 2); } else if (coords[1] < ySpace(20) + (unit.h / 2)) { coords[1] = ySpace(20) + (unit.h / 2); } u_Current.setTargetCoords(coords[0], coords[1]); u_Current.setUnitCollision(false); } } }
static void drawSheet(Sprite* sprite, s32 x, s32 y) { tic_rect rect = {x, y, TIC_SPRITESHEET_SIZE, TIC_SPRITESHEET_SIZE}; sprite->tic->api.rect_border(sprite->tic, rect.x - 1, rect.y - 1, rect.w + 2, rect.h + 2, (tic_color_white)); sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, (tic_color_black)); if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) { s32 offset = (sprite->size - TIC_SPRITESIZE) / 2; selectSprite(sprite, getMouseX() - x - offset, getMouseY() - y - offset); } } }
int MouseCtrl::sendMouseInput(int CtrlFlag){ //CtrlFlag can be (MOUSEEVENTF_RIGHTUP)(MOUSEEVENTF_RIGHTDOWN)(MOUSEEVENTF_LEFTUP)(MOUSEEVENTF_LEFTDOWN) myMouseInputs[0].type = INPUT_MOUSE; myMouseInputs[0].mi = MOUSEINPUT(); myMouseInputs[0].mi.mouseData = NULL; myMouseInputs[0].mi.time = NULL; myMouseInputs[0].mi.dwExtraInfo = NULL; myMouseInputs[0].mi.dx = getMouseX(); myMouseInputs[0].mi.dy = getMouseY(); myMouseInputs[0].mi.dwFlags = CtrlFlag; if(SendInput(1, myMouseInputs, sizeof(INPUT))){ //printf("Click simulation is succeeded.\n"); return true; }else{ printf("Click simulation is failed.\n\n\n\n\n"); return false; } }
static void processFillCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 l, s32 t) { tic_mem* tic = sprite->tic; tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx -= mx % Size; my -= my % Size; drawCursorBorder(sprite, x + mx, y + my, Size, Size); bool left = checkMouseClick(&rect, tic_mouse_left); bool right = checkMouseClick(&rect, tic_mouse_right); if(left || right) { s32 sx = l + mx / Size; s32 sy = t + my / Size; u8 color = getSheetPixel(sprite, sx, sy); u8 fill = left ? sprite->color : sprite->color2; if(color != fill) { tic->api.key(tic, tic_key_ctrl) ? replaceColor(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill) : floodFill(sprite, l, t, l + sprite->size-1, t + sprite->size-1, sx, sy, color, fill); } history_add(sprite->history); } } }
void draw(){ // Something change?? if(*iHasChanged != -1) { onFileChange(); *iHasChanged = -1; } shader.use(); shader.setUniform("u_time", getTime()); shader.setUniform("u_mouse", getMouseX(), getMouseY()); shader.setUniform("u_resolution",getWindowWidth(), getWindowHeight()); glm::mat4 mvp = glm::mat4(1.); if (iGeom != -1) { shader.setUniform("u_eye", -cam.getPosition()); shader.setUniform("u_normalMatrix", cam.getNormalMatrix()); shader.setUniform("u_modelMatrix", model_matrix); shader.setUniform("u_viewMatrix", cam.getViewMatrix()); shader.setUniform("u_projectionMatrix", cam.getProjectionMatrix()); mvp = cam.getProjectionViewMatrix() * model_matrix; } shader.setUniform("u_modelViewProjectionMatrix", mvp); unsigned int index = 0; for (std::map<std::string,Texture*>::iterator it = textures.begin(); it!=textures.end(); ++it) { shader.setUniform(it->first,it->second,index); shader.setUniform(it->first+"Resolution",it->second->getWidth(),it->second->getHeight()); index++; } vbo->draw(&shader); if(bCursor){ cursor.draw(); } }
static void drawCanvasOvr(Sprite* sprite, s32 x, s32 y) { tic_rect rect = getSpriteRect(sprite); s32 r = rect.x + rect.w; s32 b = rect.y + rect.h; const s32 Size = CANVAS_SIZE / sprite->size; for(s32 sy = rect.y, j = y; sy < b; sy++, j += Size) for(s32 sx = rect.x, i = x; sx < r; sx++, i += Size) sprite->tic->api.rect(sprite->tic, i, j, Size, Size, getSheetPixel(sprite, sx, sy)); if(hasCanvasSelection(sprite)) drawSelection(sprite, x + sprite->select.rect.x * Size - 1, y + sprite->select.rect.y * Size - 1, sprite->select.rect.w * Size + 2, sprite->select.rect.h * Size + 2); if(!sprite->editPalette) { switch(sprite->mode) { case SPRITE_DRAW_MODE: processDrawCanvasMouse(sprite, x, y, rect.x, rect.y); break; case SPRITE_PICK_MODE: processPickerCanvasMouse(sprite, x, y, rect.x, rect.y); break; case SPRITE_SELECT_MODE: processSelectCanvasMouse(sprite, x, y); break; case SPRITE_FILL_MODE: processFillCanvasMouse(sprite, x, y, rect.x, rect.y); break; } } tic_rect canvasRect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; if(checkMouseDown(&canvasRect, tic_mouse_middle)) { s32 mx = getMouseX() - x; s32 my = getMouseY() - y; sprite->color = getSheetPixel(sprite, rect.x + mx / Size, rect.y + my / Size); } }
static void processPickerCanvasMouse(Sprite* sprite, s32 x, s32 y, s32 sx, s32 sy) { tic_rect rect = {x, y, CANVAS_SIZE, CANVAS_SIZE}; const s32 Size = CANVAS_SIZE / sprite->size; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx -= mx % Size; my -= my % Size; drawCursorBorder(sprite, x + mx, y + my, Size, Size); if(checkMouseDown(&rect, tic_mouse_left)) sprite->color = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); if(checkMouseDown(&rect, tic_mouse_right)) sprite->color2 = getSheetPixel(sprite, sx + mx / Size, sy + my / Size); } }
/** * \brief get Mouse Position * \return rect with x datafield as mouse X-value, y datafield as mouse Y-value, w as 1, h as 1, */ jlug::Rect jlug::Input::getMousePos(void) { jlug::Rect rect(getMouseX(), getMouseY(), 1, 1); return rect; }
// Get the mouse X-position and translate it into game coordinates. float getEditMouseX() { Client *cl = (Client*)currentNode; return (getMouseX() - cl->getViewport()->center_x)/zoom + cl->getCamera().getX(); }
int continue_close(int min, int sec, int eff, int err, int speed) { unsigned int sum; void* summary; int x,y,j=-2,pr=-1,i; // sum=imagesize(200,90,380,250); sum=imagesize(170,90,410,250); summary= malloc(sum); getimage(170,90,410,250,summary); show_summary(min,sec,eff,err,speed); draw_3dbox(210,220,280,240,15); draw_3dbox(305,220,370,240,15); settextstyle(0,0,1); color_text(214,227,"Continue",3); color_text(317,227,"Close",3); showMouse(); while(1) { while(1) { x=getMouseX(); /* get the mouse position*/ y=getMouseY(); for(i=0;i<2;i++) { if(x>=210+(i*95)&&x<=280+(i*90)&&y>=220&&y<=240 ) { j=i; /* check the position*/ break; } } settextstyle(0,0,1); if(j>=0&&j<2&& j!=pr) { hideMouse(); draw_3dbox(210+(j*95),220,280+(j*90),240,6); /* change the color of the box*/ /* change the text color*/ if(j) color_text(317,227,"Close",15); /*cursor on no*/ else if(!j) color_text(214,227,"Continue",15); /*cursor on yes*/ showMouse(); } if(j!=pr && pr>=0 && pr<2) { hideMouse(); draw_3dbox(210+(pr*95),220,280+(pr*90),240,15); /* when mouse moves away change the color to normal one*/ if(pr) color_text(317,227,"Close",3); else if(!pr) color_text(214,227,"Continue",3); showMouse(); /*cursor on yes/no*/ } pr = j; /* keeps the current postion to use next time as previous*/ j = -1; if(mouseClicked()) { x=getMouseX(); /*get the position where mouse is clicked*/ y=getMouseY(); break; } }/*end of while 2 which changes color of button*/ /*check the position of mouse clicked*/ if(x>=210&&x<=280&&y>=220&&y<=240) // continue { hideMouse(); up_down_button(210,220,280,240,214,227,18,15,15,6); putimage(170,90,summary,COPY_PUT); //showMouse(); /*if clicked on back return to previous stage*/ free(summary); return 0; } else if(x>=305&&x<=370&&y>=220&&y<=240) { hideMouse(); up_down_button(305,220,370,240,317,227,23,15,15,6); free(summary); //if clicked on close exit from the lesson time_interval=0, min=0, sec=0, minute=0,second=0,eff=0, err=0, speed=0; pressed=0, correct= 0, wrong= 0, cpm=0, correction=0; showMouse(); return 1; } }/*end of while 1*/ }
/** * Process mouse activity */ void MouseHandler::mouseHandler() { debugC(2, kDebugMouse, "mouseHandler"); Status &gameStatus = _vm->getGameStatus(); Istate inventState = _vm->_inventory->getInventoryState(); if ((gameStatus._viewState != kViewPlay) && (inventState != kInventoryActive)) return; int16 cx = getMouseX(); int16 cy = getMouseY(); // gameStatus._cx = cx; // Save cursor coords // gameStatus._cy = cy; // Don't process if outside client area if ((cx < 0) || (cx > kXPix) || (cy < kDibOffY) || (cy > kViewSizeY + kDibOffY)) return; int16 objId = -1; // Current source object // Process cursor over an object or icon if (inventState == kInventoryActive) { // Check inventory icon bar first objId = _vm->_inventory->processInventory(kInventoryActionGet, cx, cy); } else { if (cy < 5 && cy > 0) { _vm->_topMenu->runModal(); } } if (!gameStatus._gameOverFl) { if (objId == -1) // No match, check rest of view objId = _vm->_object->findObject(cx, cy); if (objId >= 0) { // Got a match // Display object name next to cursor (unless CURSOR_NOCHAR) // Note test for swapped hero name const char *name = _vm->_text->getNoun(_vm->_object->_objects[(objId == kHeroIndex) ? _vm->_heroImage : objId]._nounIndex, kCursorNameIndex); if (name[0] != kCursorNochar) cursorText(name, cx, cy, U_FONT8, _TBRIGHTWHITE); // Process right click over object in view or iconbar if (_rightButtonFl) processRightClick(objId, cx, cy); } // Process cursor over an exit hotspot if (objId == -1) { int i = findExit(cx, cy, *_vm->_screenPtr); if (i != -1 && _hotspots[i]._viewx >= 0) { objId = kExitHotspot; cursorText(_vm->_text->getTextMouse(kMsExit), cx, cy, U_FONT8, _TBRIGHTWHITE); } } } // Left click over icon, object or to move somewhere if (_leftButtonFl) processLeftClick(objId, cx, cy); // Clear mouse click states resetLeftButton(); resetRightButton(); }
static void drawPalette(Sprite* sprite, s32 x, s32 y) { tic_rect rect = {x, y, PALETTE_WIDTH-1, PALETTE_HEIGHT-1}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); bool left = checkMouseDown(&rect, tic_mouse_left); bool right = checkMouseDown(&rect, tic_mouse_right); if(left || right) { s32 mx = getMouseX() - x; s32 my = getMouseY() - y; mx /= PALETTE_CELL_SIZE; my /= PALETTE_CELL_SIZE; s32 index = mx + my * PALETTE_COLS; if(left) sprite->color = index; if(right) sprite->color2 = index; } } sprite->tic->api.rect(sprite->tic, rect.x-1, rect.y-1, rect.w+2, rect.h+2, (tic_color_white)); sprite->tic->api.rect(sprite->tic, rect.x-1, rect.y+rect.h+1, PALETTE_WIDTH+1, 1, (tic_color_black)); { s32 offsetX = x + (sprite->color % PALETTE_COLS) * PALETTE_CELL_SIZE; s32 offsetY = y + (sprite->color / PALETTE_COLS) * PALETTE_CELL_SIZE; if(offsetY > y) sprite->tic->api.rect(sprite->tic, offsetX - 2, rect.y + rect.h+2, PALETTE_CELL_SIZE+3, 1, (tic_color_black)); } { static const u8 Icon[] = { 0b01000000, 0b11111111, 0b00000000, 0b00000010, 0b11111111, 0b00000000, 0b00010000, 0b11111111, }; tic_rect rect = {x + PALETTE_WIDTH + 3, y + (PALETTE_HEIGHT-8)/2-1, 8, 8}; bool down = false; bool over = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); over = true; showTooltip("EDIT PALETTE"); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) sprite->editPalette = !sprite->editPalette; } if(sprite->editPalette || down) { drawBitIcon(rect.x, rect.y+1, Icon, (over ? tic_color_light_blue : tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (over ? tic_color_light_blue : tic_color_white)); } } }
static void drawRGBSlider(Sprite* sprite, s32 x, s32 y, u8* value) { enum {Size = CANVAS_SIZE, Max = 255}; { static const u8 Icon[] = { 0b11100000, 0b11100000, 0b11100000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x, y-2, Size, 5}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) { s32 mx = getMouseX() - x; *value = mx * Max / (Size-1); } } sprite->tic->api.rect(sprite->tic, x, y+1, Size, 1, (tic_color_black)); sprite->tic->api.rect(sprite->tic, x, y, Size, 1, (tic_color_white)); { s32 offset = x + *value * (Size-1) / Max - 1; drawBitIcon(offset, y, Icon, (tic_color_black)); drawBitIcon(offset, y-1, Icon, (tic_color_white)); } { char buf[] = "FF"; sprintf(buf, "%02X", *value); sprite->tic->api.text(sprite->tic, buf, x - 18, y - 2, (tic_color_dark_gray)); } } { static const u8 Icon[] = { 0b01000000, 0b11000000, 0b01000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x - 4, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) (*value)--; } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (tic_color_white)); } } { static const u8 Icon[] = { 0b10000000, 0b11000000, 0b10000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, }; tic_rect rect = {x + Size + 2, y - 1, 2, 3}; bool down = false; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); if(checkMouseDown(&rect, tic_mouse_left)) down = true; if(checkMouseClick(&rect, tic_mouse_left)) (*value)++; } if(down) { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_white)); } else { drawBitIcon(rect.x, rect.y+1, Icon, (tic_color_black)); drawBitIcon(rect.x, rect.y, Icon, (tic_color_white)); } } }
static void drawSpriteToolbar(Sprite* sprite) { tic_mem* tic = sprite->tic; sprite->tic->api.rect(sprite->tic, 0, 0, TIC80_WIDTH, TOOLBAR_SIZE, (tic_color_white)); // draw sprite size control { tic_rect rect = {TIC80_WIDTH - 58, 1, 23, 5}; if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("CANVAS ZOOM"); if(checkMouseDown(&rect, tic_mouse_left)) { s32 mx = getMouseX() - rect.x; mx /= 6; s32 size = 1; while(mx--) size <<= 1; updateSpriteSize(sprite, size * TIC_SPRITESIZE); } } for(s32 i = 0; i < 4; i++) sprite->tic->api.rect(sprite->tic, rect.x + i*6, 1, 5, 5, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x, 2, 23, 3, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x+1, 3, 21, 1, (tic_color_white)); s32 size = sprite->size / TIC_SPRITESIZE, val = 0; while(size >>= 1) val++; sprite->tic->api.rect(sprite->tic, rect.x + val*6, 1, 5, 5, (tic_color_black)); sprite->tic->api.rect(sprite->tic, rect.x+1 + val*6, 2, 3, 3, (tic_color_white)); } bool bg = sprite->index < TIC_BANK_SPRITES; { static const char Label[] = "BG"; tic_rect rect = {TIC80_WIDTH - 2 * tic->font.width - 2, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1}; sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_black) : (tic_color_gray)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("TILES [tab]"); if(!bg && checkMouseClick(&rect, tic_mouse_left)) { sprite->index -= TIC_BANK_SPRITES; clearCanvasSelection(sprite); } } } { static const char Label[] = "FG"; tic_rect rect = {TIC80_WIDTH - 4 * tic->font.width - 4, 0, 2 * tic->font.width + 1, TIC_SPRITESIZE-1}; sprite->tic->api.rect(sprite->tic, rect.x, rect.y, rect.w, rect.h, bg ? (tic_color_gray) : (tic_color_black)); sprite->tic->api.fixed_text(sprite->tic, Label, rect.x+1, rect.y+1, (tic_color_white)); if(checkMousePos(&rect)) { setCursor(tic_cursor_hand); showTooltip("SPRITES [tab]"); if(bg && checkMouseClick(&rect, tic_mouse_left)) { sprite->index += TIC_BANK_SPRITES; clearCanvasSelection(sprite); } } } }