Browse Source

Basic line drawing is back IN

ssao
A.Olokhtonov 5 months ago
parent
commit
8b4b4e09f7
  1. 3
      README.txt
  2. 2
      client/index.js
  3. 2
      client/tools.js
  4. 4
      client/webgl_geometry.js
  5. 25
      client/webgl_listeners.js

3
README.txt

@ -42,11 +42,14 @@ Release:
+ Dynamic svg cursor to represent the brush + Dynamic svg cursor to represent the brush
+ Eraser + Eraser
* Line drawing * Line drawing
- Live preview
- Alignment (horizontal, vertical, diagonal, etc)
+ Undo + Undo
- Undo for images (add, move, scale) - Undo for images (add, move, scale)
- Undo for eraser - Undo for eraser
- Redo - Redo
- Snapping to grid - Snapping to grid
- Snapping to other points?
* Polish * Polish
+ Use typedvector where appropriate + Use typedvector where appropriate
- Show what's happening while the desk is loading (downloading, processing, uploading to gpu) - Show what's happening while the desk is loading (downloading, processing, uploading to gpu)

2
client/index.js

@ -180,9 +180,11 @@ async function main() {
'zoomdown': false, 'zoomdown': false,
'imagemoving': false, 'imagemoving': false,
'imagescaling': false, 'imagescaling': false,
'linedrawing': false,
'active_image': null, 'active_image': null,
'scaling_corner': null, 'scaling_corner': null,
'ruler_origin': null,
'current_strokes': {}, 'current_strokes': {},

2
client/tools.js

@ -21,7 +21,7 @@ function switch_tool(state, item) {
document.querySelector('canvas').classList.add(new_class); document.querySelector('canvas').classList.add(new_class);
if (tool === 'pencil' || tool === 'eraser') { if (tool === 'pencil' || tool === 'eraser' || tool === 'ruler') {
update_cursor(state); update_cursor(state);
document.querySelector('.brush-dom').classList.remove('dhide'); document.querySelector('.brush-dom').classList.remove('dhide');
} else { } else {

4
client/webgl_geometry.js

@ -139,7 +139,7 @@ function recompute_dynamic_data(state, context) {
context.dynamic_stroke_count = total_strokes; context.dynamic_stroke_count = total_strokes;
} }
function geometry_add_point(state, context, player_id, point, is_pen) { function geometry_add_point(state, context, player_id, point, is_pen, raw = false) {
if (!state.online) return; if (!state.online) return;
const player = state.players[player_id]; const player = state.players[player_id];
@ -149,7 +149,7 @@ function geometry_add_point(state, context, player_id, point, is_pen) {
point.pressure = config.min_pressure; point.pressure = config.min_pressure;
} }
if (points.length > 0) { if (points.length > 0 && !raw) {
// pulled from "perfect-freehand" package. MIT // pulled from "perfect-freehand" package. MIT
// https://github.com/steveruizok/perfect-freehand/ // https://github.com/steveruizok/perfect-freehand/
const streamline = 0.5; const streamline = 0.5;

25
client/webgl_listeners.js

@ -213,7 +213,8 @@ function mousedown(e, state, context) {
schedule_draw(state, context); schedule_draw(state, context);
} else if (state.tools.active === 'ruler') { } else if (state.tools.active === 'ruler') {
state.linedrawing = true;
state.ruler_origin = canvasp;
} else if (state.tools.active === 'eraser') { } else if (state.tools.active === 'eraser') {
state.erasing = true; state.erasing = true;
} else if (state.tools.active === 'pointer') { } else if (state.tools.active === 'pointer') {
@ -412,6 +413,19 @@ function mousemove(e, state, context) {
} }
} }
if (state.linedrawing) {
// TODO: we should do something different when we allow multiple dynamic strokes per player
geometry_clear_player(state, context, state.me);
const p1 = {'x': state.ruler_origin.x, 'y': state.ruler_origin.y, 'pressure': 128};
const p2 = {'x': canvasp.x, 'y': canvasp.y, 'pressure': 128};
geometry_add_point(state, context, state.me, p1, false, true);
geometry_add_point(state, context, state.me, p2, false, true);
do_draw = true;
}
if (do_draw) { if (do_draw) {
schedule_draw(state, context); schedule_draw(state, context);
} }
@ -482,6 +496,13 @@ function mouseup(e, state, context) {
state.erasing = false; state.erasing = false;
return; return;
} }
if (state.linedrawing) {
state.linedrawing = false;
queue_event(state, stroke_event(state));
schedule_draw(state, context);
return;
}
} }
function mouseleave(e, state, context) { function mouseleave(e, state, context) {
@ -507,7 +528,7 @@ function update_cursor(state) {
let svg; let svg;
if (state.tools.active === 'pencil') { if (state.tools.active === 'pencil' || state.tools.active === 'ruler') {
const current_color = color_from_u32(me.color); const current_color = color_from_u32(me.color);
const stroke = (me.color === 0xFFFFFF ? 'black' : 'white'); const stroke = (me.color === 0xFFFFFF ? 'black' : 'white');

Loading…
Cancel
Save